diff --git a/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts b/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts index 342390eb336..cb5d8564920 100644 --- a/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts +++ b/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts @@ -1,6 +1,6 @@ import { validate } from 'bitcoin-address-validation'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { UtxoResponseItem } from '@app/query/bitcoin/bitcoin-client'; @@ -107,13 +107,13 @@ export function determineUtxosForSpend({ export interface DetermineUtxosForSpendArgsMultipleRecipients { amount: number; feeRate: number; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; utxos: UtxoResponseItem[]; } interface DetermineUtxosForSpendAllArgsMultipleRecipients { feeRate: number; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; utxos: UtxoResponseItem[]; } diff --git a/src/app/common/transactions/bitcoin/use-generate-bitcoin-tx.ts b/src/app/common/transactions/bitcoin/use-generate-bitcoin-tx.ts index 0b4a68eacc6..e6b703d4e9d 100644 --- a/src/app/common/transactions/bitcoin/use-generate-bitcoin-tx.ts +++ b/src/app/common/transactions/bitcoin/use-generate-bitcoin-tx.ts @@ -3,8 +3,8 @@ import { useCallback } from 'react'; import * as btc from '@scure/btc-signer'; import { logger } from '@shared/logger'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { Money } from '@shared/models/money.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { determineUtxosForSpend, @@ -97,7 +97,7 @@ export function useGenerateUnsignedNativeSegwitSingleRecipientTx() { interface GenerateNativeSegwitMultipleRecipientsTxValues { amount: Money; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; } export function useGenerateUnsignedNativeSegwitMultipleRecipientsTx() { diff --git a/src/app/common/transactions/bitcoin/utils.ts b/src/app/common/transactions/bitcoin/utils.ts index 4a2845ed9e7..fd5363e4ad3 100644 --- a/src/app/common/transactions/bitcoin/utils.ts +++ b/src/app/common/transactions/bitcoin/utils.ts @@ -7,11 +7,11 @@ import { } from 'bitcoin-address-validation'; import { BTC_P2WPKH_DUST_AMOUNT } from '@shared/constants'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { BitcoinTransactionVectorOutput, BitcoinTx, } from '@shared/models/transactions/bitcoin-transaction.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { sumNumbers } from '@app/common/math/helpers'; import { satToBtc } from '@app/common/money/unit-conversion'; @@ -159,7 +159,7 @@ function getSpendableAmountMultipleRecipients({ }: { utxos: UtxoResponseItem[]; feeRate: number; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; }) { const balance = utxos.map(utxo => utxo.value).reduce((prevVal, curVal) => prevVal + curVal, 0); @@ -182,7 +182,7 @@ export function filterUneconomicalUtxosMultipleRecipients({ }: { utxos: UtxoResponseItem[]; feeRate: number; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; }) { const { spendableAmount: fullSpendableAmount } = getSpendableAmountMultipleRecipients({ utxos, @@ -207,7 +207,7 @@ export function filterUneconomicalUtxosMultipleRecipients({ export function getSizeInfoMultipleRecipients(payload: { inputLength: number; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; isSendMax?: boolean; }) { const { inputLength, recipients, isSendMax } = payload; diff --git a/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee-input.tsx b/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee-input.tsx index d7cbe16cd16..b0c238f15c8 100644 --- a/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee-input.tsx +++ b/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee-input.tsx @@ -3,8 +3,8 @@ import { useState } from 'react'; import { useField } from 'formik'; import { Stack } from 'leather-styles/jsx'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { createMoney } from '@shared/models/money.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { useOnMount } from '@app/common/hooks/use-on-mount'; import { satToBtc } from '@app/common/money/unit-conversion'; @@ -13,29 +13,26 @@ import { Input } from '@app/ui/components/input/input'; import { ErrorLabel } from '../error-label'; import { BitcoinCustomFeeFiat } from './bitcoin-custom-fee-fiat'; -import { - useBitcoinCustomFee, - useBitcoinCustomFeeMultipleRecipients, -} from './hooks/use-bitcoin-custom-fee'; +import { useBitcoinCustomFee } from './hooks/use-bitcoin-custom-fee'; + +const feeInputLabel = 'sats/vB'; interface Props { onClick?(): void; amount: number; isSendingMax: boolean; - recipient: string; + recipients: BitcoinRecipient[]; hasInsufficientBalanceError: boolean; errorMessage?: string; setCustomFeeInitialValue?(value: string): void; customFeeInitialValue: string; } -const feeInputLabel = 'sats/vB'; - export function BitcoinCustomFeeInput({ onClick, amount, isSendingMax, - recipient, + recipients, hasInsufficientBalanceError, setCustomFeeInitialValue, customFeeInitialValue, @@ -48,99 +45,6 @@ export function BitcoinCustomFeeInput({ }>(null); const getCustomFeeValues = useBitcoinCustomFee({ - amount: createMoney(amount, 'BTC'), - isSendingMax, - recipient, - }); - const [unknownError, setUnknownError] = useState(false); - const [customInsufficientBalanceError, setCustomInsufficientBalanceError] = useState(false); - - const hasError = hasInsufficientBalanceError || unknownError || customInsufficientBalanceError; - const errorMessage = - hasInsufficientBalanceError || customInsufficientBalanceError - ? 'Insufficient funds' - : 'Unknown error'; - - function processFeeValue(feeRate: string) { - try { - const feeValues = getCustomFeeValues(Number(feeRate)); - setFeeValue(feeValues); - - setUnknownError(false); - setCustomInsufficientBalanceError(false); - } catch (err) { - if (err instanceof InsufficientFundsError) { - return setCustomInsufficientBalanceError(true); - } - - setUnknownError(true); - } - } - - function onChange(e: React.ChangeEvent) { - const value = e.target.value; - setCustomFeeInitialValue?.(e.target.value); - processFeeValue(value); - } - - useOnMount(() => { - processFeeValue(customFeeInitialValue); - }); - return ( - - - - {feeInputLabel} - { - field.onChange(e); - onChange?.(e); - }} - /> - - {hasError && {errorMessage}} - - - {!hasError && feeValue && ( - - )} - - ); -} - -interface PropsMultipleRecipients { - onClick?(): void; - amount: number; - isSendingMax: boolean; - recipients: RpcSendTransferRecipient[]; - hasInsufficientBalanceError: boolean; - errorMessage?: string; - setCustomFeeInitialValue?(value: string): void; - customFeeInitialValue: string; -} - -export function BitcoinCustomFeeInputMultipleRecipients({ - onClick, - amount, - isSendingMax, - recipients, - hasInsufficientBalanceError, - setCustomFeeInitialValue, - customFeeInitialValue, -}: PropsMultipleRecipients) { - const [field] = useField('feeRate'); - - const [feeValue, setFeeValue] = useState(null); - - const getCustomFeeValues = useBitcoinCustomFeeMultipleRecipients({ amount: createMoney(amount, 'BTC'), isSendingMax, recipients, diff --git a/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee.tsx b/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee.tsx index e8a699176c8..7201e2eb805 100644 --- a/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee.tsx +++ b/src/app/components/bitcoin-custom-fee/bitcoin-custom-fee.tsx @@ -6,22 +6,16 @@ import { Stack, styled } from 'leather-styles/jsx'; import * as yup from 'yup'; import { BtcFeeType } from '@shared/models/fees/bitcoin-fees.model'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { createMoney } from '@shared/models/money.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { openInNewTab } from '@app/common/utils/open-in-new-tab'; import { Button } from '@app/ui/components/button/button'; import { Link } from '@app/ui/components/link/link'; import { OnChooseFeeArgs } from '../bitcoin-fees-list/bitcoin-fees-list'; -import { - BitcoinCustomFeeInput, - BitcoinCustomFeeInputMultipleRecipients, -} from './bitcoin-custom-fee-input'; -import { - useBitcoinCustomFee, - useBitcoinCustomFeeMultipleRecipients, -} from './hooks/use-bitcoin-custom-fee'; +import { BitcoinCustomFeeInput } from './bitcoin-custom-fee-input'; +import { useBitcoinCustomFee } from './hooks/use-bitcoin-custom-fee'; interface BitcoinCustomFeeProps { amount: number; @@ -31,7 +25,7 @@ interface BitcoinCustomFeeProps { onChooseFee({ feeRate, feeValue, time, isCustomFee }: OnChooseFeeArgs): Promise; onSetSelectedFeeType(value: BtcFeeType | null): void; onValidateBitcoinSpend(value: number): boolean; - recipient: string; + recipients: BitcoinRecipient[]; setCustomFeeInitialValue: Dispatch>; maxCustomFeeRate: number; } @@ -44,118 +38,12 @@ export function BitcoinCustomFee({ onChooseFee, onSetSelectedFeeType, onValidateBitcoinSpend, - recipient, + recipients, setCustomFeeInitialValue, maxCustomFeeRate, }: BitcoinCustomFeeProps) { const feeInputRef = useRef(null); const getCustomFeeValues = useBitcoinCustomFee({ - amount: createMoney(amount, 'BTC'), - isSendingMax, - recipient, - }); - - const onChooseCustomBtcFee = useCallback( - async ({ feeRate }: { feeRate: string }) => { - onSetSelectedFeeType(null); - const { fee: feeValue } = getCustomFeeValues(Number(feeRate)); - const isValid = onValidateBitcoinSpend(feeValue); - if (!isValid) return; - await onChooseFee({ feeRate: Number(feeRate), feeValue, time: '', isCustomFee: true }); - }, - [onSetSelectedFeeType, getCustomFeeValues, onValidateBitcoinSpend, onChooseFee] - ); - - const validationSchema = yup.object({ - feeRate: yup - .number() - .required('Fee is required') - .integer('Fee must be a whole number') - .test({ - message: 'Fee is too high', - test: value => { - return value <= maxCustomFeeRate; - }, - }), - }); - - return ( - - {props => ( -
- - - - Higher fee rates typically lead to faster confirmation times. - openInNewTab('https://buybitcoinworldwide.com/fee-calculator/')} - textStyle="body.02" - > - View fee calculator - - - { - feeInputRef.current?.focus(); - await props.setValues({ ...props.values }); - }} - customFeeInitialValue={customFeeInitialValue} - setCustomFeeInitialValue={setCustomFeeInitialValue} - recipient={recipient} - hasInsufficientBalanceError={hasInsufficientBalanceError} - /> - - - -
- )} -
- ); -} - -interface BitcoinCustomFeeMultipleRecipientsProps { - amount: number; - customFeeInitialValue: string; - hasInsufficientBalanceError: boolean; - isSendingMax: boolean; - onChooseFee({ feeRate, feeValue, time, isCustomFee }: OnChooseFeeArgs): Promise; - onSetSelectedFeeType(value: BtcFeeType | null): void; - onValidateBitcoinSpend(value: number): boolean; - recipients: RpcSendTransferRecipient[]; - setCustomFeeInitialValue: Dispatch>; - maxCustomFeeRate: number; -} - -export function BitcoinCustomFeeMultipleRecipients({ - amount, - customFeeInitialValue, - hasInsufficientBalanceError, - isSendingMax, - onChooseFee, - onSetSelectedFeeType, - onValidateBitcoinSpend, - recipients, - setCustomFeeInitialValue, - maxCustomFeeRate, -}: BitcoinCustomFeeMultipleRecipientsProps) { - const feeInputRef = useRef(null); - const getCustomFeeValues = useBitcoinCustomFeeMultipleRecipients({ amount: createMoney(amount, 'BTC'), isSendingMax, recipients, @@ -208,7 +96,7 @@ export function BitcoinCustomFeeMultipleRecipients({ View fee calculator - { diff --git a/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx b/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx index 710f1e4feb3..5dd3c892961 100644 --- a/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx +++ b/src/app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee.tsx @@ -1,13 +1,11 @@ import { useCallback } from 'react'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { Money, createMoney } from '@shared/models/money.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; import { i18nFormatCurrency } from '@app/common/money/format-money'; import { - determineUtxosForSpend, - determineUtxosForSpendAll, determineUtxosForSpendAllMultipleRecipients, determineUtxosForSpendMultipleRecipients, } from '@app/common/transactions/bitcoin/coinselect/local-coin-selection'; @@ -20,51 +18,10 @@ export const MAX_FEE_RATE_MULTIPLIER = 50; interface UseBitcoinCustomFeeArgs { amount: Money; isSendingMax: boolean; - recipient: string; -} -export function useBitcoinCustomFee({ amount, isSendingMax, recipient }: UseBitcoinCustomFeeArgs) { - const { balance } = useCurrentNativeSegwitAddressBalance(); - const { data: utxos = [] } = useCurrentNativeSegwitUtxos(); - const btcMarketData = useCryptoCurrencyMarketDataMeanAverage('BTC'); - - return useCallback( - (feeRate: number) => { - if (!feeRate || !utxos.length) return { fee: 0, fiatFeeValue: '' }; - - const satAmount = isSendingMax ? balance.amount.toNumber() : amount.amount.toNumber(); - - const determineUtxosArgs = { - amount: satAmount, - recipient, - utxos, - feeRate, - }; - const { fee } = isSendingMax - ? determineUtxosForSpendAll(determineUtxosArgs) - : determineUtxosForSpend(determineUtxosArgs); - - return { - fee, - fiatFeeValue: `~ ${i18nFormatCurrency( - baseCurrencyAmountInQuote(createMoney(Math.ceil(fee), 'BTC'), btcMarketData) - )}`, - }; - }, - [utxos, isSendingMax, balance.amount, amount.amount, recipient, btcMarketData] - ); -} - -interface UseBitcoinCustomFeeArgsMultipleRecipients { - amount: Money; - isSendingMax: boolean; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; } -export function useBitcoinCustomFeeMultipleRecipients({ - amount, - isSendingMax, - recipients, -}: UseBitcoinCustomFeeArgsMultipleRecipients) { +export function useBitcoinCustomFee({ amount, isSendingMax, recipients }: UseBitcoinCustomFeeArgs) { const { balance } = useCurrentNativeSegwitAddressBalance(); const { data: utxos = [] } = useCurrentNativeSegwitUtxos(); const btcMarketData = useCryptoCurrencyMarketDataMeanAverage('BTC'); diff --git a/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts b/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts index 7532c67a224..875408bc2fe 100644 --- a/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts +++ b/src/app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients.ts @@ -1,8 +1,8 @@ import { useMemo } from 'react'; import { BtcFeeType, btcTxTimeMap } from '@shared/models/fees/bitcoin-fees.model'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { Money, createMoney } from '@shared/models/money.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money'; import { formatMoneyPadded, i18nFormatCurrency } from '@app/common/money/format-money'; @@ -33,7 +33,7 @@ function getFeeForList( interface UseBitcoinFeesListArgs { amount: Money; - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; utxos: UtxoResponseItem[]; } export function useBitcoinFeesListMultipleRecipients({ diff --git a/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx b/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx index ababb2b10e3..c224bef6d77 100644 --- a/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx +++ b/src/app/features/bitcoin-choose-fee/bitcoin-choose-fee.tsx @@ -3,14 +3,11 @@ import { useState } from 'react'; import { Box, FlexProps, Stack, styled } from 'leather-styles/jsx'; import { BtcFeeType } from '@shared/models/fees/bitcoin-fees.model'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { Money } from '@shared/models/money.model'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { formatMoney } from '@app/common/money/format-money'; -import { - BitcoinCustomFee, - BitcoinCustomFeeMultipleRecipients, -} from '@app/components/bitcoin-custom-fee/bitcoin-custom-fee'; +import { BitcoinCustomFee } from '@app/components/bitcoin-custom-fee/bitcoin-custom-fee'; import { MAX_FEE_RATE_MULTIPLIER } from '@app/components/bitcoin-custom-fee/hooks/use-bitcoin-custom-fee'; import { OnChooseFeeArgs } from '@app/components/bitcoin-fees-list/bitcoin-fees-list'; import { useNativeSegwitBalance } from '@app/query/bitcoin/balance/btc-native-segwit-balance.hooks'; @@ -31,7 +28,7 @@ interface BitcoinChooseFeeProps extends FlexProps { onChooseFee({ feeRate, feeValue, time }: OnChooseFeeArgs): Promise; onSetSelectedFeeType(value: BtcFeeType | null): void; onValidateBitcoinSpend(value: number): boolean; - recipient: string; + recipients: BitcoinRecipient[]; recommendedFeeRate: string; showError: boolean; maxRecommendedFeeRate?: number; @@ -45,7 +42,7 @@ export function BitcoinChooseFee({ onChooseFee, onSetSelectedFeeType, onValidateBitcoinSpend, - recipient, + recipients, recommendedFeeRate, showError, maxRecommendedFeeRate = 0, @@ -76,82 +73,6 @@ export function BitcoinChooseFee({ defaultToCustomFee={defaultToCustomFee} customFee={ - } - feesList={feesList} - /> - - - - - - ); -} - -interface BitcoinChooseFeeMultipleRecipientsProps extends FlexProps { - amount: Money; - defaultToCustomFee: boolean; - feesList: React.JSX.Element; - isLoading: boolean; - isSendingMax: boolean; - onChooseFee({ feeRate, feeValue, time }: OnChooseFeeArgs): Promise; - onSetSelectedFeeType(value: BtcFeeType | null): void; - onValidateBitcoinSpend(value: number): boolean; - recipients: RpcSendTransferRecipient[]; - recommendedFeeRate: string; - showError: boolean; - maxRecommendedFeeRate?: number; -} -export function BitcoinChooseFeeMultipleRecipients({ - amount, - defaultToCustomFee, - feesList, - isLoading, - isSendingMax, - onChooseFee, - onSetSelectedFeeType, - onValidateBitcoinSpend, - recipients, - recommendedFeeRate, - showError, - maxRecommendedFeeRate = 0, - ...rest -}: BitcoinChooseFeeMultipleRecipientsProps) { - const nativeSegwitSigner = useCurrentAccountNativeSegwitIndexZeroSigner(); - const { btcBalance } = useNativeSegwitBalance(nativeSegwitSigner.address); - const hasAmount = amount.amount.isGreaterThan(0); - const [customFeeInitialValue, setCustomFeeInitialValue] = useState(recommendedFeeRate); - - return ( - - - {hasAmount && ( - - {formatMoney(amount)} - - )} - {showError ? ( - - ) : ( - - )} - { navigate(RouteUrls.Home); }; @@ -90,7 +98,7 @@ export function IncreaseBtcFeeDialog() { btcToSat(getBitcoinTxValue(currentBitcoinAddress, btcTx)).toNumber() )} isSendingMax={false} - recipient={recipient} + recipients={recipients} hasInsufficientBalanceError={false} customFeeInitialValue={initialFeeRate} /> diff --git a/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx b/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx index 66532aa2043..a0b5bcebf1e 100644 --- a/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx +++ b/src/app/pages/rpc-send-transfer/components/send-transfer-details.tsx @@ -1,12 +1,12 @@ import { HStack, Stack, styled } from 'leather-styles/jsx'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import { formatMoney } from '@app/common/money/format-money'; import { truncateMiddle } from '@app/ui/utils/truncate-middle'; interface SendTransferDetailsProps { - recipients: RpcSendTransferRecipient[]; + recipients: BitcoinRecipient[]; currentAddress: string; } diff --git a/src/app/pages/rpc-send-transfer/rpc-send-transfer-choose-fee.tsx b/src/app/pages/rpc-send-transfer/rpc-send-transfer-choose-fee.tsx index 855422ca624..4868c71c940 100644 --- a/src/app/pages/rpc-send-transfer/rpc-send-transfer-choose-fee.tsx +++ b/src/app/pages/rpc-send-transfer/rpc-send-transfer-choose-fee.tsx @@ -2,9 +2,9 @@ import { Outlet, useNavigate } from 'react-router-dom'; import { logger } from '@shared/logger'; import { BtcFeeType } from '@shared/models/fees/bitcoin-fees.model'; +import type { BitcoinRecipient } from '@shared/models/form.model'; import type { Money } from '@shared/models/money.model'; import { RouteUrls } from '@shared/route-urls'; -import type { RpcSendTransferRecipient } from '@shared/rpc/methods/send-transfer'; import { useLocationStateWithCache } from '@app/common/hooks/use-location-state'; import { useGenerateUnsignedNativeSegwitMultipleRecipientsTx } from '@app/common/transactions/bitcoin/use-generate-bitcoin-tx'; @@ -13,7 +13,7 @@ import { OnChooseFeeArgs, } from '@app/components/bitcoin-fees-list/bitcoin-fees-list'; import { useBitcoinFeesListMultipleRecipients } from '@app/components/bitcoin-fees-list/use-bitcoin-fees-list-multiple-recipients'; -import { BitcoinChooseFeeMultipleRecipients } from '@app/features/bitcoin-choose-fee/bitcoin-choose-fee'; +import { BitcoinChooseFee } from '@app/features/bitcoin-choose-fee/bitcoin-choose-fee'; import { useValidateBitcoinSpend } from '@app/features/bitcoin-choose-fee/hooks/use-validate-bitcoin-spend'; import { UtxoResponseItem } from '@app/query/bitcoin/bitcoin-client'; import { useSignBitcoinTx } from '@app/store/accounts/blockchain/bitcoin/bitcoin.hooks'; @@ -23,7 +23,7 @@ import { useRpcSendTransferState } from './rpc-send-transfer-container'; function useRpcSendTransferFeeState() { const amountAsMoney = useLocationStateWithCache('amountAsMoney') as Money; - const recipients = useLocationStateWithCache('recipients') as RpcSendTransferRecipient[]; + const recipients = useLocationStateWithCache('recipients') as BitcoinRecipient[]; const utxos = useLocationStateWithCache('utxos') as UtxoResponseItem[]; return { amountAsMoney, utxos, recipients }; @@ -71,7 +71,7 @@ export function RpcSendTransferChooseFee() { return ( <> - - {recipients.map((recipient: RpcSendTransferRecipient, index: number) => ( + {recipients.map((recipient: BitcoinRecipient, index: number) => ( setSelectedFeeType(value)} onValidateBitcoinSpend={onValidateBitcoinFeeSpend} - recipient={recipient} + recipients={recipients} recommendedFeeRate={recommendedFeeRate} showError={showInsufficientBalanceError} maxRecommendedFeeRate={feesList[0]?.feeRate} diff --git a/src/app/pages/send/send-crypto-asset-form/form/brc-20/brc-20-choose-fee.tsx b/src/app/pages/send/send-crypto-asset-form/form/brc-20/brc-20-choose-fee.tsx index b1a70c81976..f497b7d6622 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/brc-20/brc-20-choose-fee.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/brc-20/brc-20-choose-fee.tsx @@ -51,6 +51,12 @@ export function BrcChooseFee() { recipient, utxos, }); + const recipients = [ + { + address: recipient, + amount: amountAsMoney, + }, + ]; const recommendedFeeRate = feesList[1]?.feeRate.toString() || ''; const { showInsufficientBalanceError, onValidateBitcoinFeeSpend } = @@ -143,7 +149,7 @@ export function BrcChooseFee() { onSetSelectedFeeType={(value: BtcFeeType | null) => setSelectedFeeType(value)} onValidateBitcoinSpend={onValidateBitcoinFeeSpend} recommendedFeeRate={recommendedFeeRate} - recipient={recipient} + recipients={recipients} showError={showInsufficientBalanceError} maxRecommendedFeeRate={feesList[0]?.feeRate} /> diff --git a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-choose-fee.tsx b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-choose-fee.tsx index 0104ce58810..a7e484de64b 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/btc/btc-choose-fee.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/btc/btc-choose-fee.tsx @@ -32,6 +32,14 @@ export function BtcChooseFee() { recipient: txValues.recipient, utxos, }); + + const recipients = [ + { + address: txValues.recipient, + amount: amountAsMoney, + }, + ]; + const recommendedFeeRate = feesList[1]?.feeRate.toString() || ''; const { showInsufficientBalanceError, onValidateBitcoinAmountSpend } = useValidateBitcoinSpend( @@ -59,7 +67,7 @@ export function BtcChooseFee() { onChooseFee={previewTransaction} onValidateBitcoinSpend={onValidateBitcoinAmountSpend} onSetSelectedFeeType={(value: BtcFeeType | null) => setSelectedFeeType(value)} - recipient={txValues.recipient} + recipients={recipients} recommendedFeeRate={recommendedFeeRate} showError={showInsufficientBalanceError} maxRecommendedFeeRate={feesList[0]?.feeRate} diff --git a/src/shared/models/form.model.ts b/src/shared/models/form.model.ts index 7a40b77ef2a..908c77c4409 100644 --- a/src/shared/models/form.model.ts +++ b/src/shared/models/form.model.ts @@ -1,4 +1,5 @@ import { SupportedInscription } from './inscription.model'; +import type { Money } from './money.model'; export interface BitcoinSendFormValues { amount: number | string; @@ -37,3 +38,8 @@ export interface StacksTransactionFormValues { feeType: string; nonce?: number | string; } + +export interface BitcoinRecipient { + address: string; + amount: Money; +} diff --git a/src/shared/rpc/methods/send-transfer.ts b/src/shared/rpc/methods/send-transfer.ts index d1c48419bc8..cecf3e34945 100644 --- a/src/shared/rpc/methods/send-transfer.ts +++ b/src/shared/rpc/methods/send-transfer.ts @@ -8,7 +8,6 @@ import { btcAddressNetworkValidator, btcAddressValidator, } from '@shared/forms/bitcoin-address-validators'; -import type { Money } from '@shared/models/money.model'; import { accountSchema, @@ -60,19 +59,14 @@ export interface RpcSendTransferParamsLegacy extends SendTransferRequestParams { network: string; } -export interface RpcSendTransferRecipient { - address: string; - amount: Money; -} - -interface RpcSendTransferRecipientParam { +interface BitcoinRecipientParam { address: string; amount: string; } export interface RpcSendTransferParams { account?: number; - recipients: RpcSendTransferRecipientParam[]; + recipients: BitcoinRecipientParam[]; network: string; } diff --git a/tests/specs/rpc-get-addresses/get-addresses.spec.ts b/tests/specs/rpc-get-addresses/get-addresses.spec.ts index 99da32356a8..48b13fc6b15 100644 --- a/tests/specs/rpc-get-addresses/get-addresses.spec.ts +++ b/tests/specs/rpc-get-addresses/get-addresses.spec.ts @@ -58,7 +58,7 @@ async function interceptRequestPopup(context: BrowserContext) { } async function initiateGetAddresses(page: Page) { - return page.evaluate(async () => window.LeatherProvider?.request('getAddresses')); + return page.evaluate(async () => (window as any).LeatherProvider?.request('getAddresses')); } async function clickConnectLeatherButton(popup: Page) {