From cfd1e7269f9a849f6c6cf3df6d0cc0f092e5223d Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Thu, 23 Oct 2025 10:41:56 -0700 Subject: [PATCH] UTXO consolidator, removed UTXO selection, centralized bitcoin hooks --- src/components/wallet/CashuWallet.tsx | 187 ++++--------------- src/components/wallet/UTXOSelector.tsx | 107 ++++------- src/components/wallet/WalletHeader.tsx | 12 +- src/components/wallet/WalletModals.tsx | 86 ++++++++- src/hooks/useBitcoinBalance.ts | 244 ++++++++++++++++++++++++- 5 files changed, 403 insertions(+), 233 deletions(-) diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index ad1a31e..f007c1f 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -11,8 +11,8 @@ import { useMintManager } from '@/hooks/cashu/useMintManager'; import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions'; import { useHistoryManager } from '@/hooks/cashu/useHistoryManager'; import { useNsecAccess } from '@/hooks/useNsecAccess'; -import { useBitcoinBalance, useBitcoinTransactionHistory } from '@/hooks/useBitcoinBalance'; -import { nostrPubkeyToBitcoinAddress, npubToBitcoinAddress, fetchUTXOs, getFeeRates, createBitcoinTransaction, broadcastTransaction, calculateMaxSendAmount, UTXO } from '@/lib/bitcoin'; +import { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance'; +import { nostrPubkeyToBitcoinAddress, UTXO } from '@/lib/bitcoin'; import { QRModal } from '@/components/ui/qr-modal'; import { WalletHeader } from './WalletHeader'; import { TransactionCard } from './PaymentCard'; @@ -48,9 +48,22 @@ export function CashuWallet() { const { copy: copyToClipboard } = useCopyToClipboard(); // Bitcoin hooks - including balance and transaction history - const { hasNsecAccess, getPrivateKey } = useNsecAccess(); const bitcoinAddress = user?.pubkey ? nostrPubkeyToBitcoinAddress(user.pubkey) : null; - const { data: bitcoinBalanceData, isLoading: isBitcoinBalanceLoading, refetch: refetchBitcoinBalance } = useBitcoinBalance(bitcoinAddress); + const { data: bitcoinBalanceData, isLoading: isBitcoinBalanceLoading } = useBitcoinBalance(bitcoinAddress); + + // Bitcoin operations hook + const { + utxos, + isLoadingUtxos, + feeRate, + isConsolidating, + bitcoinMaxAmount, + fetchBitcoinUtxos, + handleSendMax, + handleBitcoinSend, + handleBitcoinReceive, + handleConsolidateUtxos, + } = useBitcoinOperations(bitcoinAddress); const { setMint: setNpubCashMint, @@ -177,23 +190,11 @@ export function CashuWallet() { const [showBitcoinAddressQR, setShowBitcoinAddressQR] = useState(false); const [bitcoinAddressQRCode, setBitcoinAddressQRCode] = useState(''); const [showSeedPhraseInfo, setShowSeedPhraseInfo] = useState(false); + const [showConsolidationModal, setShowConsolidationModal] = useState(false); // UTXO state - const [utxos, setUtxos] = useState([]); const [utxoDropdownOpen, setUtxoDropdownOpen] = useState(false); - const [selectedUtxo, setSelectedUtxo] = useState(null); - const [isLoadingUtxos, setIsLoadingUtxos] = useState(false); - const [feeRate, setFeeRate] = useState(1); - // Calculate max send amount - const bitcoinMaxAmount = utxos.length > 0 ? calculateMaxSendAmount(utxos, feeRate) : 0; - - // Handle Send Max - const handleSendMax = () => { - if (bitcoinMaxAmount > 0) { - setBitcoinAmount(bitcoinMaxAmount.toString()); - } - }; // Handle drawer close with state reset const handleSendDrawerClose = (open: boolean) => { @@ -226,129 +227,6 @@ export function CashuWallet() { // Ref to track if we've fetched npub.cash user info const hasCheckedNpubCashRef = useRef(false); - // ============================================================================ - // BITCOIN HANDLERS - // ============================================================================ - - const handleBitcoinSend = async () => { - if (!hasNsecAccess || !bitcoinAmount || !pendingBitcoinRecipient || !bitcoinAddress) { - toast({ - variant: "destructive", - title: "Bitcoin Send Error", - description: "Missing required information for Bitcoin transaction", - }); - return; - } - - try { - const privateKey = getPrivateKey(); - if (!privateKey) { - throw new Error('Unable to access private key'); - } - - const amountSats = parseInt(bitcoinAmount); - if (isNaN(amountSats) || amountSats <= 0) { - throw new Error('Invalid amount'); - } - - // Determine if the recipient is a Bitcoin address or npub - let recipientAddress: string; - if (pendingBitcoinRecipient.startsWith('bc1') || pendingBitcoinRecipient.startsWith('1') || pendingBitcoinRecipient.startsWith('3')) { - // It's already a Bitcoin address - recipientAddress = pendingBitcoinRecipient; - } else if (pendingBitcoinRecipient.startsWith('npub')) { - // It's an npub, convert to Bitcoin address - recipientAddress = npubToBitcoinAddress(pendingBitcoinRecipient); - } else { - // Assume it's a hex pubkey - recipientAddress = nostrPubkeyToBitcoinAddress(pendingBitcoinRecipient); - } - - // Fetch UTXOs and fee rates - const [utxos, feeRates] = await Promise.all([ - fetchUTXOs(bitcoinAddress), - getFeeRates() - ]); - - // Check if this is a Send Max transaction - const isSendMax = amountSats === bitcoinMaxAmount && bitcoinMaxAmount > 0; - - // Create and sign transaction - const { txHex, fee } = await createBitcoinTransaction( - privateKey, - recipientAddress, - amountSats, - utxos, - feeRates.fastestFee, - isSendMax - ); - - // Broadcast transaction - const txId = await broadcastTransaction(txHex); - - toast({ - title: "Bitcoin Sent!", - description: `Transaction ${txId.slice(0, 8)}... confirmed (Fee: ${fee} sats)`, - }); - - // Reset form and refresh balance - setBitcoinAmount(''); - setBitcoinRecipient(''); - setPendingBitcoinRecipient(null); - refetchBitcoinBalance(); - setShowSendModal(false); - - } catch (error) { - console.error('Bitcoin send error:', error); - toast({ - variant: "destructive", - title: "Bitcoin Send Failed", - description: error instanceof Error ? error.message : 'Unknown error occurred', - }); - } - }; - - const handleBitcoinReceive = async () => { - if (!bitcoinAddress) return; - - try { - const qr = await generateQRCode(bitcoinAddress); - setBitcoinAddressQRCode(qr); - setShowBitcoinAddressQR(true); - } catch (error) { - console.error('QR generation error:', error); - toast({ - variant: "destructive", - title: "QR Code Error", - description: "Failed to generate QR code", - }); - } - }; - - // Fetch UTXOs for Bitcoin mode - const fetchBitcoinUtxos = async () => { - if (!bitcoinAddress || mode !== 'bitcoin') return; - - setIsLoadingUtxos(true); - try { - const [fetchedUtxos, feeRates] = await Promise.all([ - fetchUTXOs(bitcoinAddress), - getFeeRates() - ]); - setUtxos(fetchedUtxos); - setFeeRate(feeRates.fastestFee); - } catch (error) { - console.error('Error fetching UTXOs:', error); - toast({ - variant: "destructive", - title: "UTXO Error", - description: "Failed to fetch Bitcoin UTXOs", - }); - } finally { - setIsLoadingUtxos(false); - } - }; - // ============================================================================ // COMPUTED VALUES // ============================================================================ @@ -449,11 +327,8 @@ export function CashuWallet() { useEffect(() => { if (mode === 'bitcoin' && bitcoinAddress) { fetchBitcoinUtxos(); - } else { - // Clear UTXOs when not in Bitcoin mode - setUtxos([]); } - }, [mode, bitcoinAddress]); + }, [mode, bitcoinAddress, fetchBitcoinUtxos]); // ============================================================================ // EFFECTS - Cleanup @@ -514,8 +389,8 @@ export function CashuWallet() { utxos={utxos} utxoDropdownOpen={utxoDropdownOpen} setUtxoDropdownOpen={setUtxoDropdownOpen} - selectedUtxo={selectedUtxo} - setSelectedUtxo={setSelectedUtxo} + onShowConsolidationModal={() => setShowConsolidationModal(true)} + isConsolidating={isConsolidating} /> @@ -567,6 +442,11 @@ export function CashuWallet() { mintToRemove={mintToRemove} onConfirmRemoveMint={handleConfirmRemoveMint} isLoading={isLoading || isNpubCashLoading} + showConsolidationModal={showConsolidationModal} + setShowConsolidationModal={setShowConsolidationModal} + utxos={utxos} + onConfirmConsolidation={handleConsolidateUtxos} + isConsolidating={isConsolidating} showLightningAddressQR={showLightningAddressQR} setShowLightningAddressQR={setShowLightningAddressQR} lightningAddressQRCode={lightningAddressQRCode} @@ -614,7 +494,14 @@ export function CashuWallet() { activeMintUrl={activeMintUrl} onSend={() => { if (mode === 'bitcoin') { - handleBitcoinSend(); + handleBitcoinSend( + bitcoinAmount, + pendingBitcoinRecipient, + setBitcoinAmount, + setBitcoinRecipient, + setPendingBitcoinRecipient, + setShowSendModal + ); } else { const wasPendingBefore = pendingLightningAddress !== null && pendingLightningAddress !== ''; handleSend(); @@ -638,9 +525,8 @@ export function CashuWallet() { setBitcoinRecipient={setBitcoinRecipient} pendingBitcoinRecipient={pendingBitcoinRecipient} setPendingBitcoinRecipient={setPendingBitcoinRecipient} - hasNsecAccess={hasNsecAccess} bitcoinMaxAmount={bitcoinMaxAmount} - onSendMax={handleSendMax} + onSendMax={() => handleSendMax(setBitcoinAmount)} /> @@ -677,7 +563,7 @@ export function CashuWallet() { onSend={() => {}} onReceive={() => { if (mode === 'bitcoin') { - handleBitcoinReceive(); + handleBitcoinReceive(setBitcoinAddressQRCode, setShowBitcoinAddressQR); setShowReceiveModal(false); } else { handleReceive(); @@ -694,7 +580,6 @@ export function CashuWallet() { setBitcoinRecipient={() => {}} pendingBitcoinRecipient={null} setPendingBitcoinRecipient={() => {}} - hasNsecAccess={hasNsecAccess} /> diff --git a/src/components/wallet/UTXOSelector.tsx b/src/components/wallet/UTXOSelector.tsx index fff70ae..19c4050 100644 --- a/src/components/wallet/UTXOSelector.tsx +++ b/src/components/wallet/UTXOSelector.tsx @@ -1,5 +1,5 @@ import { Button } from '@/components/ui/button'; -import { ChevronDown, Wallet, Check } from 'lucide-react'; +import { ChevronDown, ArrowRightLeft } from 'lucide-react'; import { useState, useEffect } from 'react'; import { exchangeRateService } from '@/lib/exchangeRateService'; import { @@ -16,8 +16,8 @@ interface UTXOSelectorProps { bitcoinAddress: string; dropdownOpen: boolean; setDropdownOpen: (open: boolean) => void; - selectedUtxo: UTXO | null; - setSelectedUtxo: (utxo: UTXO | null) => void; + onShowConsolidationModal?: () => void; + isConsolidating?: boolean; } export function UTXOSelector({ @@ -26,8 +26,8 @@ export function UTXOSelector({ bitcoinAddress, dropdownOpen, setDropdownOpen, - selectedUtxo, - setSelectedUtxo, + onShowConsolidationModal, + isConsolidating, }: UTXOSelectorProps) { const [btcUsdRate, setBtcUsdRate] = useState(null); @@ -37,28 +37,6 @@ export function UTXOSelector({ .catch(() => setBtcUsdRate(null)); }, []); - // Auto-select first UTXO when UTXOs are loaded and none is selected - // Also handle case where selected UTXO is no longer available - useEffect(() => { - if (utxos.length > 0) { - if (!selectedUtxo) { - // No UTXO selected, select the first one - setSelectedUtxo(utxos[0]); - } else { - // Check if currently selected UTXO still exists in the list - const stillExists = utxos.some(utxo => - utxo.txid === selectedUtxo.txid && utxo.vout === selectedUtxo.vout - ); - if (!stillExists) { - // Selected UTXO no longer exists, select the first available one - setSelectedUtxo(utxos[0]); - } - } - } else { - // No UTXOs available, clear selection - setSelectedUtxo(null); - } - }, [utxos, selectedUtxo, setSelectedUtxo]); const formatBalance = (sats: number): string => { if (showSats) { @@ -93,21 +71,12 @@ export function UTXOSelector({ >
- {selectedUtxo ? ( - <> - - - {formatUTXOBlock(selectedUtxo)} - - - ) : ( - - {utxos.length === 0 ? 'No UTXOs' : `${utxos.length} UTXO${utxos.length !== 1 ? 's' : ''}`} - - )} + + {utxos.length === 0 ? 'No UTXOs' : `${utxos.length} UTXO${utxos.length !== 1 ? 's' : ''}`} +
- {selectedUtxo ? formatBalance(selectedUtxo.value) : formatBalance(totalBalance)} + {formatBalance(totalBalance)}
@@ -120,50 +89,40 @@ export function UTXOSelector({ No UTXOs available ) : ( - utxos.map((utxo, index) => { - const isSelected = selectedUtxo && - selectedUtxo.txid === utxo.txid && - selectedUtxo.vout === utxo.vout; - - return ( - setSelectedUtxo(isSelected ? null : utxo)} - > -
- {isSelected && ( -
- -
- )} -
-
- {formatUTXOBlock(utxo)} -
+ utxos.map((utxo, index) => ( + +
+
+
+ {formatUTXOBlock(utxo)}
-
- - {formatBalance(utxo.value)} - -
- - ); - }) +
+
+ + {formatBalance(utxo.value)} + +
+
+ )) )}
-
+ {onShowConsolidationModal && ( -
+ )}
); } diff --git a/src/components/wallet/WalletHeader.tsx b/src/components/wallet/WalletHeader.tsx index 0e1bd3a..2f70397 100644 --- a/src/components/wallet/WalletHeader.tsx +++ b/src/components/wallet/WalletHeader.tsx @@ -44,8 +44,8 @@ interface WalletHeaderProps { utxos: UTXO[]; utxoDropdownOpen: boolean; setUtxoDropdownOpen: (open: boolean) => void; - selectedUtxo: UTXO | null; - setSelectedUtxo: (utxo: UTXO | null) => void; + onShowConsolidationModal?: () => void; + isConsolidating?: boolean; } // Helper functions to prevent syntax errors in complex expressions @@ -134,8 +134,8 @@ export function WalletHeader({ utxos, utxoDropdownOpen, setUtxoDropdownOpen, - selectedUtxo, - setSelectedUtxo, + onShowConsolidationModal, + isConsolidating, }: WalletHeaderProps) { const [lightningAddressCopied, setLightningAddressCopied] = useState(false); const [bitcoinAddressCopied, setBitcoinAddressCopied] = useState(false); @@ -342,8 +342,8 @@ export function WalletHeader({ bitcoinAddress={userPubkey ? nostrPubkeyToBitcoinAddress(userPubkey) : ''} dropdownOpen={utxoDropdownOpen} setDropdownOpen={setUtxoDropdownOpen} - selectedUtxo={selectedUtxo} - setSelectedUtxo={setSelectedUtxo} + onShowConsolidationModal={onShowConsolidationModal} + isConsolidating={isConsolidating} /> )} diff --git a/src/components/wallet/WalletModals.tsx b/src/components/wallet/WalletModals.tsx index dbdbbdb..ad5a1ac 100644 --- a/src/components/wallet/WalletModals.tsx +++ b/src/components/wallet/WalletModals.tsx @@ -1,10 +1,11 @@ import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; -import { X, Coins, AlertTriangle, RefreshCw, Key } from 'lucide-react'; +import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft } from 'lucide-react'; import { QRModal } from '@/components/ui/qr-modal'; import { nip19 } from 'nostr-tools'; import { useToast } from '@/hooks/useToast'; +import { UTXO } from '@/lib/bitcoin'; // Helper function to prevent complex template literals const getLightningAddress = (userPubkey?: string, npubCashUserInfo?: { name?: string } | null): string => { @@ -37,6 +38,13 @@ interface WalletModalProps { onConfirmRemoveMint: () => void; isLoading: boolean; + // Consolidation Modal + showConsolidationModal: boolean; + setShowConsolidationModal: (show: boolean) => void; + utxos: UTXO[]; + onConfirmConsolidation: () => void; + isConsolidating: boolean; + // QR Modals showLightningAddressQR: boolean; setShowLightningAddressQR: (show: boolean) => void; @@ -74,6 +82,11 @@ export function WalletModals({ mintToRemove, onConfirmRemoveMint, isLoading, + showConsolidationModal, + setShowConsolidationModal, + utxos, + onConfirmConsolidation, + isConsolidating, showLightningAddressQR, setShowLightningAddressQR, lightningAddressQRCode, @@ -213,6 +226,77 @@ export function WalletModals({ )} + {/* Consolidation Modal */} + {showConsolidationModal && ( +
setShowConsolidationModal(false)} + > + e.stopPropagation()} + > + + + + + Consolidate UTXOs + + + Combine multiple UTXOs into a single transaction + + + +
+
+
+ {utxos.length} UTXO{utxos.length !== 1 ? 's' : ''} +
+
+ Total Value: {utxos.reduce((sum, utxo) => sum + utxo.value, 0).toLocaleString()} sats +
+
+
+ +
+
🔄 What this does: Combines all your UTXOs into a single transaction, sending the total amount (minus fees) back to your own address.
+
💰 Benefits: Reduces transaction fees for future payments and simplifies your UTXO management.
+
⚠️ Note: This will create a new transaction on the Bitcoin network and may take some time to confirm.
+
+ +
+ +
+
+
+
+ )} + {/* QR Modals */} ([]); + const [isLoadingUtxos, setIsLoadingUtxos] = useState(false); + const [feeRate, setFeeRate] = useState(1); + const [isConsolidating, setIsConsolidating] = useState(false); + + // Calculate max send amount + const bitcoinMaxAmount = utxos.length > 0 ? calculateMaxSendAmount(utxos, feeRate) : 0; + + // Fetch UTXOs for Bitcoin mode + const fetchBitcoinUtxos = async () => { + if (!bitcoinAddress) return; + + setIsLoadingUtxos(true); + try { + const [fetchedUtxos, feeRates] = await Promise.all([ + fetchUTXOs(bitcoinAddress), + getFeeRates() + ]); + setUtxos(fetchedUtxos); + setFeeRate(feeRates.fastestFee); + } catch (error) { + console.error('Error fetching UTXOs:', error); + toast({ + variant: "destructive", + title: "UTXO Error", + description: "Failed to fetch Bitcoin UTXOs", + }); + } finally { + setIsLoadingUtxos(false); + } + }; + + // Handle Send Max + const handleSendMax = (setBitcoinAmount: (amount: string) => void) => { + if (bitcoinMaxAmount > 0) { + setBitcoinAmount(bitcoinMaxAmount.toString()); + } + }; + + // Handle Bitcoin Send + const handleBitcoinSend = async ( + bitcoinAmount: string, + pendingBitcoinRecipient: string | null, + setBitcoinAmount: (amount: string) => void, + setBitcoinRecipient: (recipient: string) => void, + setPendingBitcoinRecipient: (recipient: string | null) => void, + setShowSendModal: (show: boolean) => void + ) => { + if (!hasNsecAccess || !bitcoinAmount || !pendingBitcoinRecipient || !bitcoinAddress) { + toast({ + variant: "destructive", + title: "Bitcoin Send Error", + description: "Missing required information for Bitcoin transaction", + }); + return; + } + + try { + const privateKey = getPrivateKey(); + if (!privateKey) { + throw new Error('Unable to access private key'); + } + + const amountSats = parseInt(bitcoinAmount); + if (isNaN(amountSats) || amountSats <= 0) { + throw new Error('Invalid amount'); + } + + // Determine if the recipient is a Bitcoin address or npub + let recipientAddress: string; + if (pendingBitcoinRecipient.startsWith('bc1') || pendingBitcoinRecipient.startsWith('1') || pendingBitcoinRecipient.startsWith('3')) { + // It's already a Bitcoin address + recipientAddress = pendingBitcoinRecipient; + } else if (pendingBitcoinRecipient.startsWith('npub')) { + // It's an npub, convert to Bitcoin address + recipientAddress = npubToBitcoinAddress(pendingBitcoinRecipient); + } else { + // Assume it's a hex pubkey + recipientAddress = nostrPubkeyToBitcoinAddress(pendingBitcoinRecipient); + } + + // Fetch UTXOs and fee rates + const [utxos, feeRates] = await Promise.all([ + fetchUTXOs(bitcoinAddress), + getFeeRates() + ]); + + // Check if this is a Send Max transaction + const isSendMax = amountSats === bitcoinMaxAmount && bitcoinMaxAmount > 0; + + // Create and sign transaction + const { txHex, fee } = await createBitcoinTransaction( + privateKey, + recipientAddress, + amountSats, + utxos, + feeRates.fastestFee, + isSendMax + ); + + // Broadcast transaction + const txId = await broadcastTransaction(txHex); + + toast({ + title: "Bitcoin Sent!", + description: `Transaction ${txId.slice(0, 8)}... confirmed (Fee: ${fee} sats)`, + }); + + // Reset form and refresh balance + setBitcoinAmount(''); + setBitcoinRecipient(''); + setPendingBitcoinRecipient(null); + refetchBitcoinBalance(); + setShowSendModal(false); + + } catch (error) { + console.error('Bitcoin send error:', error); + toast({ + variant: "destructive", + title: "Bitcoin Send Failed", + description: error instanceof Error ? error.message : 'Unknown error occurred', + }); + } + }; + + // Handle Bitcoin Receive + const handleBitcoinReceive = async ( + setBitcoinAddressQRCode: (qr: string) => void, + setShowBitcoinAddressQR: (show: boolean) => void + ) => { + if (!bitcoinAddress) return; + + try { + const qr = await generateQRCode(bitcoinAddress); + setBitcoinAddressQRCode(qr); + setShowBitcoinAddressQR(true); + } catch (error) { + console.error('QR generation error:', error); + toast({ + variant: "destructive", + title: "QR Code Error", + description: "Failed to generate QR code", + }); + } + }; + + // Handle UTXO Consolidation + const handleConsolidateUtxos = async () => { + if (!hasNsecAccess || !bitcoinAddress || utxos.length <= 1) { + toast({ + variant: "destructive", + title: "Consolidation Error", + description: "Cannot consolidate UTXOs", + }); + return; + } + + setIsConsolidating(true); + try { + const privateKey = getPrivateKey(); + if (!privateKey) { + throw new Error('Unable to access private key'); + } + + // For consolidation, we send all UTXOs to our own address (self-send) + const consolidationAmount = calculateMaxSendAmount(utxos, feeRate); + + if (consolidationAmount <= 0) { + throw new Error('Insufficient funds for consolidation'); + } + + // Fetch current UTXOs and fee rates + const [fetchedUtxos, feeRates] = await Promise.all([ + fetchUTXOs(bitcoinAddress), + getFeeRates() + ]); + + // Create consolidation transaction (self-send with all UTXOs) + const { txHex, fee } = await createBitcoinTransaction( + privateKey, + bitcoinAddress, // Send to our own address + consolidationAmount, + fetchedUtxos, + feeRates.fastestFee, + true // sendMax = true + ); + + // Broadcast transaction + const txId = await broadcastTransaction(txHex); + + toast({ + title: "UTXOs Consolidated!", + description: `Transaction ${txId.slice(0, 8)}... confirmed (Fee: ${fee} sats)`, + }); + + // Refresh UTXOs and balance + refetchBitcoinBalance(); + fetchBitcoinUtxos(); + + } catch (error) { + console.error('UTXO consolidation error:', error); + toast({ + variant: "destructive", + title: "Consolidation Failed", + description: error instanceof Error ? error.message : 'Unknown error occurred', + }); + } finally { + setIsConsolidating(false); + } + }; + + return { + // State + utxos, + isLoadingUtxos, + feeRate, + isConsolidating, + bitcoinMaxAmount, + + // Functions + fetchBitcoinUtxos, + handleSendMax, + handleBitcoinSend, + handleBitcoinReceive, + handleConsolidateUtxos, + }; +}