UNPKG

@ledgerhq/coin-algorand

Version:
31 lines 1.2 kB
import isEqual from "lodash/isEqual"; import { BigNumber } from "bignumber.js"; import { estimateMaxSpendable } from "./estimateMaxSpendable"; import { getEstimatedFees } from "./getFeesForTransaction"; /** * Calculate fees for the current transaction * @param {AlgorandAccount} account * @param {Transaction} transaction */ export const prepareTransaction = async (account, transaction) => { let recipient; let amount; if (transaction.mode === "send") { recipient = transaction.recipient; amount = transaction.useAllAmount ? await estimateMaxSpendable({ account, transaction }) : transaction.amount; } else if (transaction.mode === "optIn" || transaction.mode === "claimReward") { recipient = account.freshAddress; amount = new BigNumber(0); } else { throw new Error(`Unsupported transaction mode '${transaction.mode}'`); } const fees = await getEstimatedFees(account, transaction); const newTx = { ...transaction, fees, amount, recipient }; return isEqual(transaction, newTx) ? transaction : newTx; }; export default prepareTransaction; //# sourceMappingURL=prepareTransaction.js.map