@ledgerhq/coin-tezos
Version:
30 lines • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.estimateMaxSpendable = void 0;
const index_1 = require("@ledgerhq/coin-framework/account/index");
const prepareTransaction_1 = require("./prepareTransaction");
const createTransaction_1 = require("./createTransaction");
const getFeesForTransaction_1 = __importDefault(require("./getFeesForTransaction"));
const TEZOS_BURN_ADDRESS = "tz1burnburnburnburnburnburnburjAYjjX";
const estimateMaxSpendable = async ({ account, parentAccount, transaction, }) => {
const mainAccount = (0, index_1.getMainAccount)(account, parentAccount);
const tx = await (0, prepareTransaction_1.prepareTransaction)(mainAccount, {
...(0, createTransaction_1.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 (0, getFeesForTransaction_1.default)({
account: mainAccount,
transaction: tx,
});
// As we use `useAllAmount`, we know we will receive an amount value.
return estimation.amount;
};
exports.estimateMaxSpendable = estimateMaxSpendable;
exports.default = exports.estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map