Skip to content

Commit

Permalink
fix(LIVE-13072): use NotEnoughGas to suggest buying more currency (#7188
Browse files Browse the repository at this point in the history
)

* fix(LIVE-13072): use NotEnoughGas to suggest buying more currency

* fix(LIVE-13072): use NotEnoughGas to suggest buying more currency

* fix(LIVE-13072): update condition
  • Loading branch information
cng-ledger committed Jun 25, 2024
1 parent a8a88fe commit d13a5d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-moons-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/coin-tron": patch
---

fix(LIVE-13071): use not enough gas error for Tron
24 changes: 21 additions & 3 deletions libs/ledger-live-common/src/families/tron/getTransactionStatus.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { getAccountCurrency, getFeesUnit } from "@ledgerhq/coin-framework/account";
import {
AmountRequired,
InvalidAddress,
InvalidAddressBecauseDestinationIsAlsoSource,
NotEnoughBalance,
NotEnoughGas,
RecipientRequired,
} from "@ledgerhq/errors";
import get from "lodash/get";
import sumBy from "lodash/sumBy";
import BigNumber from "bignumber.js";
import { AccountBridge } from "@ledgerhq/types-live";
import { Transaction, TronAccount } from "./types";
import { findSubAccountById, getAccountCurrency } from "../../account";
import { findSubAccountById } from "../../account";
import {
TronInvalidFreezeAmount,
TronInvalidUnDelegateResourceAmount,
Expand Down Expand Up @@ -250,12 +252,28 @@ export const getTransactionStatus: AccountBridge<Transaction>["getTransactionSta
});
}

return {
//
// Not enough gas check (on currency account)
// PTX swap uses this to support deeplink to buy additional currency
//
if (balance.lt(estimatedFees) || balance.isZero()) {
const query = new URLSearchParams({
...(account?.id ? { account: account.id } : {}),
});
errors.gasPrice = new NotEnoughGas(undefined, {
fees: formatCurrencyUnit(getFeesUnit(account.currency), estimatedFees),
ticker: account.currency.ticker,
cryptoName: account.currency.name,
links: [`ledgerlive://buy?${query.toString()}`],
});
}

return Promise.resolve({
errors,
warnings,
amount: amountSpent,
estimatedFees,
totalSpent,
family,
};
});
};

0 comments on commit d13a5d7

Please sign in to comment.