UNPKG

@ledgerhq/live-common

Version:
88 lines 3.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useCoinControlScreenViewModelCore = useCoinControlScreenViewModelCore; const formatCurrencyUnit_1 = require("@ledgerhq/coin-framework/currencies/formatCurrencyUnit"); const react_1 = require("react"); const changeToReturn_1 = require("../utils/changeToReturn"); const react_2 = require("../../../../families/bitcoin/react"); const useSendFlowAmountReviewCore_1 = require("../../hooks/useSendFlowAmountReviewCore"); const useCoinControlAmountInput_1 = require("./useCoinControlAmountInput"); function useCoinControlScreenViewModelCore({ account, parentAccount, transaction, status, bridgePending, uiConfig: _uiConfig, transactionActions, locale, accountUnit, amountError, networkFees, labels, onLearnMoreClick, }) { const amountReviewCore = (0, useSendFlowAmountReviewCore_1.useSendFlowAmountReviewCore)({ account, parentAccount, transaction, status, bridgePending, transactionActions, labels: { getCtaLabel: labels.getCtaLabel, reviewCta: labels.reviewCta, }, }); const { updateTransactionWithPatch, amountComputationPending } = amountReviewCore; const amountInput = (0, useCoinControlAmountInput_1.useCoinControlAmountInput)({ transaction, status, onUpdateTransaction: updateTransactionWithPatch, locale, accountUnit, }); const utxoDisplayData = (0, react_2.useBitcoinUtxoDisplayData)({ account, transaction, status, locale, }); const changeToReturnFormatted = (0, react_1.useMemo)(() => { const hasAmountForChange = transaction.useAllAmount || transaction.amount?.gt(0); if (!hasAmountForChange) return ""; const changeAmount = (0, changeToReturn_1.getChangeToReturn)(status); return (0, formatCurrencyUnit_1.formatCurrencyUnit)(accountUnit, changeAmount, { showCode: true, disableRounding: true, locale, }); }, [accountUnit, locale, status, transaction.amount, transaction.useAllAmount]); const onSelectStrategy = (0, react_1.useCallback)((value) => { const strategy = Number.parseInt(value, 10); if (Number.isNaN(strategy)) return; if (!("utxoStrategy" in transaction) || transaction.utxoStrategy == null) return; updateTransactionWithPatch({ utxoStrategy: { ...transaction.utxoStrategy, strategy, excludeUTXOs: [] }, }); }, [transaction, updateTransactionWithPatch]); const strategyOptionsWithLabels = (0, react_1.useMemo)(() => { const options = utxoDisplayData?.pickingStrategyOptions ?? []; return options.map(opt => ({ value: opt.value, label: labels.getStrategyOptionLabel(opt.labelKey), })); }, [utxoDisplayData?.pickingStrategyOptions, labels]); return { amountValue: amountInput.amountValue, onAmountChange: amountInput.onAmountChange, amountError, utxoDisplayData, strategyOptionsWithLabels, changeToReturnFormatted, onSelectStrategy, reviewLabel: amountReviewCore.reviewLabel, reviewShowIcon: amountReviewCore.reviewShowIcon, reviewDisabled: amountReviewCore.reviewDisabled, reviewLoading: amountComputationPending, strategyLabel: labels.strategyLabel, onLearnMoreClick, learnMoreLabel: labels.learnMoreLabel, coinToSendLabel: labels.coinToSendLabel, changeToReturnLabel: labels.changeToReturnLabel, enterAmountPlaceholder: labels.enterAmountPlaceholder, amountToSendLabel: labels.amountToSendLabel, amountInputLabel: labels.amountInputLabel, networkFees, }; } //# sourceMappingURL=useCoinControlScreenViewModelCore.js.map