UNPKG

@ledgerhq/coin-icon

Version:
41 lines 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const bignumber_js_1 = require("bignumber.js"); const node_1 = require("./api/node"); const buildTransaction_1 = require("./buildTransaction"); const node_2 = require("./api/node"); const logic_1 = require("./logic"); const cryptoassets_1 = require("@ledgerhq/cryptoassets"); /** * Fetch the transaction fees for a transaction * * @param {IconAccount} account * @param {Transaction} transaction */ const getEstimatedFees = async ({ account, transaction, }) => { const tx = { ...transaction, recipient: (0, cryptoassets_1.getAbandonSeedAddress)(account.currency.id), // Always use a fake recipient to estimate fees amount: (0, logic_1.calculateAmount)({ account, transaction: { ...transaction, fees: new bignumber_js_1.BigNumber(0), }, }), // Remove fees if present since we are fetching fees }; try { const { unsigned } = await (0, buildTransaction_1.buildTransaction)(account, tx); const stepLimit = await (0, node_1.getFees)(unsigned, account); transaction.stepLimit = stepLimit; const stepPrice = await (0, node_2.getStepPrice)(account); return stepLimit.multipliedBy(stepPrice); } catch { // Fix ME, the API of Icon throws an error when getting the fee with maximum balance return logic_1.FEES_SAFETY_BUFFER; } }; exports.default = getEstimatedFees; //# sourceMappingURL=getFeesForTransaction.js.map