UNPKG

@ledgerhq/coin-canton

Version:
36 lines 1.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.prepareTransaction = void 0; const bignumber_js_1 = __importDefault(require("bignumber.js")); const common_logic_1 = require("../common-logic"); const config_1 = __importDefault(require("../config")); const gateway_1 = require("../network/gateway"); const updateTransaction_1 = require("./updateTransaction"); const prepareTransaction = async (account, transaction) => { const amount = transaction.amount || (0, bignumber_js_1.default)(0); const fee = (0, bignumber_js_1.default)((await (0, common_logic_1.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 (0, gateway_1.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 = config_1.default.getCoinConfig(account.currency.id).nativeInstrumentId; } return (0, updateTransaction_1.updateTransaction)(transaction, { fee, tokenId, ...(instrumentAdmin ? { instrumentAdmin } : {}), }); }; exports.prepareTransaction = prepareTransaction; //# sourceMappingURL=prepareTransaction.js.map