@ledgerhq/coin-hedera
Version:
Ledger Hedera Coin integration
23 lines • 1.11 kB
JavaScript
;
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 bignumber_js_1 = __importDefault(require("bignumber.js"));
const index_1 = require("@ledgerhq/coin-framework/account/index");
const utils_1 = require("./utils");
const estimateMaxSpendable = async ({ account, parentAccount, }) => {
const balance = account.balance;
const mainAccount = (0, index_1.getMainAccount)(account, parentAccount);
const estimatedFees = await (0, utils_1.getEstimatedFees)(mainAccount);
let maxSpendable = balance.minus(estimatedFees);
// 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