diff --git a/libs/ledger-live-common/src/families/aptos/getFeesForTransaction.ts b/libs/ledger-live-common/src/families/aptos/getFeesForTransaction.ts index 9f686025cb6..dd2cfe33531 100644 --- a/libs/ledger-live-common/src/families/aptos/getFeesForTransaction.ts +++ b/libs/ledger-live-common/src/families/aptos/getFeesForTransaction.ts @@ -54,7 +54,12 @@ export const getFee = async ( const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx); const completedTx = simulation[0]; - if (!completedTx.success) { + const expectedGas = BigNumber(gasLimit * gasPrice); + const isUnderMaxSpendable = !transaction.amount + .plus(expectedGas) + .isGreaterThan(account.spendableBalance); + + if (isUnderMaxSpendable && !completedTx.success) { switch (true) { case completedTx.vm_status.includes("SEQUENCE_NUMBER"): { res.errors.sequenceNumber = completedTx.vm_status; @@ -97,14 +102,7 @@ export const getFee = async ( res.estimate.sequenceNumber = sequenceNumber.toString(); res.estimate.maxGasAmount = gasLimit.toString(); - if (transaction.firstEmulation) { - res.fees = res.fees.plus(BigNumber(gasPrice)).multipliedBy(BigNumber(gasLimit)); - } else { - res.fees = res.fees - .plus(transaction.options.gasUnitPrice) - .multipliedBy(BigNumber(transaction.options.maxGasAmount)); - } - + res.fees = res.fees.plus(BigNumber(gasPrice)).multipliedBy(BigNumber(gasLimit)); CACHE.delete(getCacheKey(transaction)); return res; }; diff --git a/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts b/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts index d32884f0a23..60fa92ff778 100644 --- a/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts +++ b/libs/ledger-live-common/src/families/aptos/prepareTransaction.ts @@ -36,9 +36,13 @@ const prepareTransaction = async ( : transaction.amount; transaction.amount = amount; - if (transaction.firstEmulation) { - transaction.options.maxGasAmount = estimate.maxGasAmount; - } + transaction.options = { + ...transaction.options, + maxGasAmount: estimate.maxGasAmount, + gasUnitPrice: estimate.gasUnitPrice, + sequenceNumber: estimate.sequenceNumber, + expirationTimestampSecs: estimate.expirationTimestampSecs, + }; transaction.fees = fees; transaction.estimate = estimate;