From d13a5d7f8f23624feb3a4a041cd7966d3b100dcf Mon Sep 17 00:00:00 2001 From: C Ng <138497251+cng-ledger@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:37:50 +0100 Subject: [PATCH] fix(LIVE-13072): use NotEnoughGas to suggest buying more currency (#7188) * 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 --- .changeset/tall-moons-flow.md | 5 ++++ .../src/families/tron/getTransactionStatus.ts | 24 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .changeset/tall-moons-flow.md diff --git a/.changeset/tall-moons-flow.md b/.changeset/tall-moons-flow.md new file mode 100644 index 00000000000..b8ec412946f --- /dev/null +++ b/.changeset/tall-moons-flow.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/coin-tron": patch +--- + +fix(LIVE-13071): use not enough gas error for Tron diff --git a/libs/ledger-live-common/src/families/tron/getTransactionStatus.ts b/libs/ledger-live-common/src/families/tron/getTransactionStatus.ts index c5c012017dc..27ae045b966 100644 --- a/libs/ledger-live-common/src/families/tron/getTransactionStatus.ts +++ b/libs/ledger-live-common/src/families/tron/getTransactionStatus.ts @@ -1,8 +1,10 @@ +import { getAccountCurrency, getFeesUnit } from "@ledgerhq/coin-framework/account"; import { AmountRequired, InvalidAddress, InvalidAddressBecauseDestinationIsAlsoSource, NotEnoughBalance, + NotEnoughGas, RecipientRequired, } from "@ledgerhq/errors"; import get from "lodash/get"; @@ -10,7 +12,7 @@ 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, @@ -250,12 +252,28 @@ export const getTransactionStatus: AccountBridge["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, - }; + }); };