@ledgerhq/coin-tezos
Version:
23 lines • 1.11 kB
JavaScript
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
import { prepareTransaction } from "./prepareTransaction";
import { createTransaction } from "./createTransaction";
import getEstimatedFees from "./getFeesForTransaction";
const TEZOS_BURN_ADDRESS = "tz1burnburnburnburnburnburnburjAYjjX";
export const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
const mainAccount = getMainAccount(account, parentAccount);
const tx = await prepareTransaction(mainAccount, {
...createTransaction(account),
...transaction,
// estimate using a burn address that exists so we don't enter into NotEnoughBalanceBecauseDestinationNotCreated
recipient: transaction?.recipient || TEZOS_BURN_ADDRESS,
useAllAmount: true,
});
const estimation = await getEstimatedFees({
account: mainAccount,
transaction: tx,
});
// As we use `useAllAmount`, we know we will receive an amount value.
return estimation.amount;
};
export default estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map