@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
21 lines • 1.16 kB
JavaScript
import { BigNumber } from "bignumber.js";
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
import { AptosAPI } from "../network";
import { getEstimatedGas } from "./getFeesForTransaction";
import { getMaxSendBalance } from "./logic";
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../constants";
const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
const mainAccount = getMainAccount(account, parentAccount);
const aptosClient = new AptosAPI(mainAccount.currency.id);
let maxGasAmount = new BigNumber(DEFAULT_GAS);
let gasUnitPrice = new BigNumber(DEFAULT_GAS_PRICE);
if (transaction) {
const amount = transaction.amount.isZero() ? account.spendableBalance : transaction.amount;
const { estimate } = await getEstimatedGas(mainAccount, { ...transaction, amount }, aptosClient);
maxGasAmount = BigNumber(estimate.maxGasAmount);
gasUnitPrice = BigNumber(estimate.gasUnitPrice);
}
return getMaxSendBalance(account, parentAccount, maxGasAmount, gasUnitPrice);
};
export default estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map