UNPKG

@ledgerhq/coin-hedera

Version:
32 lines 1.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.estimateMaxSpendable = void 0; const helpers_1 = require("@ledgerhq/ledger-wallet-framework/account/helpers"); const index_1 = require("@ledgerhq/ledger-wallet-framework/account/index"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const constants_1 = require("../constants"); const estimateFees_1 = require("../logic/estimateFees"); const estimateMaxSpendable = async ({ account, parentAccount, }) => { const mainAccount = (0, index_1.getMainAccount)(account, parentAccount); const isTokenTransaction = (0, helpers_1.isTokenAccount)(account); const balance = account.balance; if (isTokenTransaction) { return Promise.resolve(balance); } const estimatedFees = await (0, estimateFees_1.estimateFees)({ currency: mainAccount.currency, operationType: constants_1.HEDERA_OPERATION_TYPES.CryptoTransfer, }); let maxSpendable = balance.minus(estimatedFees.tinybars); // set max spendable to 0 if negative // for cases where the user's account balance is smaller than the estimated fee if (maxSpendable.isLessThan(0)) { maxSpendable = new bignumber_js_1.default(0); } return Promise.resolve(maxSpendable); }; exports.estimateMaxSpendable = estimateMaxSpendable; //# sourceMappingURL=estimateMaxSpendable.js.map