@ledgerhq/coin-tron
Version:
Ledger Tron Coin integration
24 lines • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const account_1 = require("@ledgerhq/coin-framework/account");
const createTransaction_1 = __importDefault(require("./createTransaction"));
const getEstimateFees_1 = __importDefault(require("./getEstimateFees"));
const estimateMaxSpendable = async ({ account, parentAccount, transaction }) => {
const mainAccount = (0, account_1.getMainAccount)(account, parentAccount);
const fees = await (0, getEstimateFees_1.default)(mainAccount, {
...(0, createTransaction_1.default)(),
subAccountId: account.type === "Account" ? null : account.id,
...transaction,
recipient: transaction?.recipient || "0x0000000000000000000000000000000000000000",
amount: new bignumber_js_1.default(0),
}, account.type === "TokenAccount" ? account : undefined);
return account.type === "Account"
? bignumber_js_1.default.max(0, account.spendableBalance.minus(fees))
: account.balance;
};
exports.default = estimateMaxSpendable;
//# sourceMappingURL=estimateMaxSpendable.js.map