@ledgerhq/coin-mina
Version:
21 lines • 824 B
JavaScript
import { BigNumber } from "bignumber.js";
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
import { getMaxAmount } from "../common-logic";
import { createTransaction } from "./createTransaction";
import getEstimatedFees from "./getEstimatedFees";
const estimateMaxSpendable = async ({ account, parentAccount, transaction }) => {
const a = getMainAccount(account, parentAccount);
const t = {
...createTransaction(account),
...transaction,
amount: a.spendableBalance,
};
const { fee } = await getEstimatedFees(t, a.freshAddress);
const maxSpendable = getMaxAmount(a, t, fee);
if (maxSpendable.lt(0)) {
return new BigNumber(0);
}
return maxSpendable;
};
export default estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map