UTXO consolidator, removed UTXO selection, centralized bitcoin hooks

This commit is contained in:
lemonknowsall committed 2025-10-23 10:41:56 -07:00
1 parent fabbb0b50e
commit cfd1e7269f
5 files changed
+403 -233

No files matched your search

+85 -1
View File
@@ -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({
</div>
)}
{/* Consolidation Modal */}
{showConsolidationModal && (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-[100] p-4"
onClick={() => setShowConsolidationModal(false)}
>
<Card
className="w-full max-w-md border-0 shadow-lg bg-background"
onClick={(e) => e.stopPropagation()}
>
<CardHeader className="relative">
<Button
onClick={() => setShowConsolidationModal(false)}
className="absolute top-2 right-2"
size="sm"
variant="ghost"
>
<X className="h-4 w-4" />
</Button>
<CardTitle className="flex items-center pr-8">
<ArrowRightLeft className="h-5 w-5 mr-2 text-primary" />
Consolidate UTXOs
</CardTitle>
<CardDescription>
Combine multiple UTXOs into a single transaction
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="bg-muted p-4 rounded-lg border">
<div className="text-center">
<div className="text-2xl font-bold text-primary mb-2">
{utxos.length} UTXO{utxos.length !== 1 ? 's' : ''}
</div>
<div className="text-sm text-muted-foreground">
Total Value: {utxos.reduce((sum, utxo) => sum + utxo.value, 0).toLocaleString()} sats
</div>
</div>
</div>
<div className="text-sm text-muted-foreground bg-muted/30 p-3 rounded space-y-2">
<div>🔄 <strong>What this does:</strong> Combines all your UTXOs into a single transaction, sending the total amount (minus fees) back to your own address.</div>
<div>💰 <strong>Benefits:</strong> Reduces transaction fees for future payments and simplifies your UTXO management.</div>
<div>⚠️ <strong>Note:</strong> This will create a new transaction on the Bitcoin network and may take some time to confirm.</div>
</div>
<div className="flex justify-center">
<Button
onClick={() => {
onConfirmConsolidation();
setShowConsolidationModal(false);
}}
disabled={isConsolidating || utxos.length <= 1}
>
{isConsolidating ? (
<>
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
Consolidating...
</>
) : (
<>
<ArrowRightLeft className="h-4 w-4 mr-2" />
Consolidate UTXOs
</>
)}
</Button>
</div>
</CardContent>
</Card>
</div>
)}
{/* QR Modals */}
<QRModal
isOpen={showLightningAddressQR}