UNPKG

@ledgerhq/coin-canton

Version:
29 lines 1.33 kB
import BigNumber from "bignumber.js"; import { estimateFees } from "../common-logic"; import coinConfig from "../config"; import { getCalTokensCached } from "../network/gateway"; import { updateTransaction } from "./updateTransaction"; export const prepareTransaction = async (account, transaction) => { const amount = transaction.amount || BigNumber(0); const fee = BigNumber((await estimateFees(account.currency, BigInt(amount.toFixed()))).toString()); let tokenId = transaction.tokenId; let instrumentAdmin; if (transaction.subAccountId && account.subAccounts) { const subAccount = account.subAccounts.find((sub) => sub.type === "TokenAccount" && sub.id === transaction.subAccountId); if (subAccount) { const calTokens = await getCalTokensCached(account.currency); tokenId = calTokens.get(subAccount.token.id) || subAccount.token.name; instrumentAdmin = subAccount.token.contractAddress; } } // Default to native instrument if no tokenId set if (!tokenId) { tokenId = coinConfig.getCoinConfig(account.currency.id).nativeInstrumentId; } return updateTransaction(transaction, { fee, tokenId, ...(instrumentAdmin ? { instrumentAdmin } : {}), }); }; //# sourceMappingURL=prepareTransaction.js.map