UNPKG

@ledgerhq/coin-hedera

Version:
41 lines 1.45 kB
import { AmountRequired, NotEnoughBalance, InvalidAddress, InvalidAddressBecauseDestinationIsAlsoSource, RecipientRequired, } from "@ledgerhq/errors"; import { AccountId } from "@hashgraph/sdk"; import { calculateAmount, getEstimatedFees } from "./utils"; export const getTransactionStatus = async (account, transaction) => { const errors = {}; if (!transaction.recipient || transaction.recipient.length === 0) { errors.recipient = new RecipientRequired(""); } else { if (account.freshAddress === transaction.recipient) { errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource(""); } try { AccountId.fromString(transaction.recipient); } catch (err) { errors.recipient = new InvalidAddress("", { currencyName: account.currency.name, }); } } const { amount, totalSpent } = await calculateAmount({ transaction, account, }); if (transaction.amount.eq(0) && !transaction.useAllAmount) { errors.amount = new AmountRequired(); } else if (account.balance.isLessThan(totalSpent)) { errors.amount = new NotEnoughBalance(""); } const estimatedFees = await getEstimatedFees(account); return { amount, errors, estimatedFees, totalSpent, warnings: {}, }; }; //# sourceMappingURL=getTransactionStatus.js.map