UNPKG

@ledgerhq/coin-hedera

Version:
45 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTransactionStatus = void 0; const errors_1 = require("@ledgerhq/errors"); const sdk_1 = require("@hashgraph/sdk"); const utils_1 = require("./utils"); const getTransactionStatus = async (account, transaction) => { const errors = {}; if (!transaction.recipient || transaction.recipient.length === 0) { errors.recipient = new errors_1.RecipientRequired(""); } else { if (account.freshAddress === transaction.recipient) { errors.recipient = new errors_1.InvalidAddressBecauseDestinationIsAlsoSource(""); } try { sdk_1.AccountId.fromString(transaction.recipient); } catch (err) { errors.recipient = new errors_1.InvalidAddress("", { currencyName: account.currency.name, }); } } const { amount, totalSpent } = await (0, utils_1.calculateAmount)({ transaction, account, }); if (transaction.amount.eq(0) && !transaction.useAllAmount) { errors.amount = new errors_1.AmountRequired(); } else if (account.balance.isLessThan(totalSpent)) { errors.amount = new errors_1.NotEnoughBalance(""); } const estimatedFees = await (0, utils_1.getEstimatedFees)(account); return { amount, errors, estimatedFees, totalSpent, warnings: {}, }; }; exports.getTransactionStatus = getTransactionStatus; //# sourceMappingURL=getTransactionStatus.js.map