@ledgerhq/coin-mina
Version:
26 lines • 1.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = require("bignumber.js");
const index_1 = require("@ledgerhq/coin-framework/account/index");
const common_logic_1 = require("../common-logic");
const createTransaction_1 = require("./createTransaction");
const getEstimatedFees_1 = __importDefault(require("./getEstimatedFees"));
const estimateMaxSpendable = async ({ account, parentAccount, transaction }) => {
const a = (0, index_1.getMainAccount)(account, parentAccount);
const t = {
...(0, createTransaction_1.createTransaction)(account),
...transaction,
amount: a.spendableBalance,
};
const { fee } = await (0, getEstimatedFees_1.default)(t, a.freshAddress);
const maxSpendable = (0, common_logic_1.getMaxAmount)(a, t, fee);
if (maxSpendable.lt(0)) {
return new bignumber_js_1.BigNumber(0);
}
return maxSpendable;
};
exports.default = estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map