UNPKG

@ledgerhq/coin-ton

Version:
19 lines 979 B
import { updateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers"; import { fetchAccountInfo } from "./bridge/bridgeHelpers/api"; import { buildTonTransaction, findSubAccountById, getTonEstimatedFees } from "./utils"; const prepareTransaction = async (account, transaction) => { const accountInfo = await fetchAccountInfo(account.freshAddress); const subAccount = findSubAccountById(account, transaction.subAccountId ?? ""); const simpleTx = buildTonTransaction(transaction, accountInfo.seqno, account); const fees = await getTonEstimatedFees(account, accountInfo.status === "uninit", simpleTx); let amount; if (transaction.useAllAmount) { amount = subAccount ? subAccount.spendableBalance : account.spendableBalance.minus(fees); } else { amount = transaction.amount; } return updateTransaction(transaction, { fees, amount }); }; export default prepareTransaction; //# sourceMappingURL=prepareTransaction.js.map