UNPKG

@ledgerhq/live-common

Version:
47 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSendFlowAmountReviewCore = useSendFlowAmountReviewCore; const react_1 = require("react"); const bignumber_js_1 = require("bignumber.js"); const helpers_1 = require("@ledgerhq/ledger-wallet-framework/account/helpers"); const impl_1 = require("../../../bridge/impl"); const amountReview_1 = require("../amount/utils/amountReview"); function useSendFlowAmountReviewCore({ account, parentAccount, transaction, status, bridgePending, transactionActions, labels, }) { const mainAccount = (0, react_1.useMemo)(() => (0, helpers_1.getMainAccount)(account, parentAccount ?? undefined), [account, parentAccount]); const accountCurrency = (0, react_1.useMemo)(() => (0, helpers_1.getAccountCurrency)(mainAccount), [mainAccount]); const updateTransactionWithPatch = (0, react_1.useCallback)((patch) => { transactionActions.updateTransaction(currentTx => { const bridge = (0, impl_1.getAccountBridge)(account, parentAccount ?? undefined); return bridge.updateTransaction(currentTx, patch); }); }, [account, parentAccount, transactionActions]); const rawTransactionAmount = transaction.amount ?? new bignumber_js_1.BigNumber(0); const hasRawAmount = transaction.useAllAmount || rawTransactionAmount.gt(0); const shouldPrepare = Boolean(transaction.recipient) && hasRawAmount; const amountComputationPending = bridgePending && shouldPrepare; const estimatedFees = status.estimatedFees ?? new bignumber_js_1.BigNumber(0); const maxAvailable = (0, react_1.useMemo)(() => (0, amountReview_1.getMaxAvailable)(account, estimatedFees), [account, estimatedFees]); const hasInsufficientFundsError = (0, react_1.useMemo)(() => (0, amountReview_1.isInsufficientFundsAmountError)(status), [status]); const hasErrors = Object.keys(status.errors ?? {}).length > 0; const hasAmount = hasRawAmount; const reviewDisabled = (hasErrors && !hasInsufficientFundsError) || !hasAmount || amountComputationPending; const reviewLabel = hasInsufficientFundsError ? labels.getCtaLabel(accountCurrency?.ticker ?? "CRYPTO") : labels.reviewCta; return { mainAccount, accountCurrency, updateTransactionWithPatch, hasRawAmount, shouldPrepare, amountComputationPending, maxAvailable, hasInsufficientFundsError, hasErrors, hasAmount, reviewLabel, reviewShowIcon: !hasInsufficientFundsError, reviewDisabled, }; } //# sourceMappingURL=useSendFlowAmountReviewCore.js.map