diff --git a/src/families/cosmos/js-prepareTransaction.ts b/src/families/cosmos/js-prepareTransaction.ts index 0bc88f1eb7..06e63cc840 100644 --- a/src/families/cosmos/js-prepareTransaction.ts +++ b/src/families/cosmos/js-prepareTransaction.ts @@ -24,13 +24,16 @@ const prepareTransaction = async ( account: Account, transaction: Transaction ): Promise => { - const patch: Partial = {}; + let memo = transaction.memo; + let fees = transaction.fees; + let gas = transaction.gas; + let amount = transaction.amount; let gasQty = new BigNumber(250000); const gasPrice = new BigNumber(getEnv("COSMOS_GAS_PRICE")); if (transaction.useAllAmount) { - patch.amount = getMaxEstimatedBalance( + amount = getMaxEstimatedBalance( account, account.balance .dividedBy(new BigNumber(getEnv("COSMOS_GAS_AMPLIFIER"))) @@ -39,12 +42,12 @@ const prepareTransaction = async ( } if (transaction.mode !== "send" && !transaction.memo) { - patch.memo = "Ledger Live"; + memo = "Ledger Live"; } const unsignedPayload = await buildTransaction(account, { ...transaction, - ...patch, + amount, }); // be sure payload is complete @@ -53,7 +56,7 @@ const prepareTransaction = async ( typeUrl: "/cosmos.tx.v1beta1.TxBody", value: { messages: unsignedPayload, - memo: transaction.memo || patch.memo || "", + memo: transaction.memo || memo || "", }, }; @@ -111,11 +114,19 @@ const prepareTransaction = async ( } } - patch.gas = gasQty; + gas = gasQty; - patch.fees = gasPrice.multipliedBy(gasQty).integerValue(); + fees = gasPrice.multipliedBy(gasQty).integerValue(); - return { ...transaction, ...patch }; + if ( + transaction.memo !== memo || + transaction.fees !== fees || + transaction.gas !== gas + ) { + return { ...transaction, memo, fees, gas }; + } + + return transaction; }; export default prepareTransaction; diff --git a/src/families/cosmos/js-signOperation.ts b/src/families/cosmos/js-signOperation.ts index df442f667b..cd19b1c01f 100644 --- a/src/families/cosmos/js-signOperation.ts +++ b/src/families/cosmos/js-signOperation.ts @@ -45,7 +45,7 @@ const signOperation = ({ let cancelled; async function main() { - const { accountNumber, sequence } = await getAccount( + const { accountNumber, sequence, spendableBalance } = await getAccount( account.freshAddress ); @@ -152,6 +152,8 @@ const signOperation = ({ const hash = ""; // resolved at broadcast time const accountId = account.id; + const fee = transaction.fees || new BigNumber(0); + const type: OperationType = transaction.mode === "undelegate" ? "UNDELEGATE" @@ -176,8 +178,10 @@ const signOperation = ({ id: encodeOperationId(accountId, hash, type), hash, type, - value: transaction.amount, - fee: transaction.fees || new BigNumber(0), + value: transaction.useAllAmount + ? spendableBalance + : transaction.amount.plus(fee), + fee, extra: {}, blockHash: null, blockHeight: null,