@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
23 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = require("bignumber.js");
const index_1 = require("@ledgerhq/coin-framework/account/index");
const network_1 = require("../network");
const getFeesForTransaction_1 = require("./getFeesForTransaction");
const logic_1 = require("./logic");
const constants_1 = require("../constants");
const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
const mainAccount = (0, index_1.getMainAccount)(account, parentAccount);
const aptosClient = new network_1.AptosAPI(mainAccount.currency.id);
let maxGasAmount = new bignumber_js_1.BigNumber(constants_1.DEFAULT_GAS);
let gasUnitPrice = new bignumber_js_1.BigNumber(constants_1.DEFAULT_GAS_PRICE);
if (transaction) {
const amount = transaction.amount.isZero() ? account.spendableBalance : transaction.amount;
const { estimate } = await (0, getFeesForTransaction_1.getEstimatedGas)(mainAccount, { ...transaction, amount }, aptosClient);
maxGasAmount = (0, bignumber_js_1.BigNumber)(estimate.maxGasAmount);
gasUnitPrice = (0, bignumber_js_1.BigNumber)(estimate.gasUnitPrice);
}
return (0, logic_1.getMaxSendBalance)(account, parentAccount, maxGasAmount, gasUnitPrice);
};
exports.default = estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map