@ledgerhq/coin-aptos
Version:
Ledger Aptos Coin integration
20 lines • 1.04 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 { estimate } = await getEstimatedGas(mainAccount, transaction, aptosClient);
maxGasAmount = BigNumber(estimate.maxGasAmount);
gasUnitPrice = BigNumber(estimate.gasUnitPrice);
}
return getMaxSendBalance(mainAccount, transaction, maxGasAmount, gasUnitPrice);
};
export default estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map