From 3df413fa849c283b2c01d1b1d63d406675c3510e Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Sun, 2 Nov 2025 09:38:05 -0800 Subject: [PATCH] breakout modals into separate files --- src/components/wallet/CashuWallet.tsx | 119 +++- src/components/wallet/ConsolidationModal.tsx | 92 +++ src/components/wallet/ProofBreakdownModal.tsx | 83 +++ src/components/wallet/QRScannerModal.tsx | 63 ++ src/components/wallet/RemoveMintModal.tsx | 86 +++ src/components/wallet/SeedPhraseModal.tsx | 136 +++++ src/components/wallet/WalletModals.tsx | 546 ------------------ 7 files changed, 552 insertions(+), 573 deletions(-) create mode 100644 src/components/wallet/ConsolidationModal.tsx create mode 100644 src/components/wallet/ProofBreakdownModal.tsx create mode 100644 src/components/wallet/QRScannerModal.tsx create mode 100644 src/components/wallet/RemoveMintModal.tsx create mode 100644 src/components/wallet/SeedPhraseModal.tsx delete mode 100644 src/components/wallet/WalletModals.tsx diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index 56602d6..fa008d9 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -17,7 +17,11 @@ import { nostrPubkeyToBitcoinAddress } from '@/lib/bitcoin'; import { QRModal } from '@/components/ui/qr-modal'; import { WalletHeader } from './WalletHeader'; import { TransactionCard } from './PaymentCard'; -import { WalletModals } from './WalletModals'; +import { ProofBreakdownModal } from './ProofBreakdownModal'; +import { RemoveMintModal } from './RemoveMintModal'; +import { ConsolidationModal } from './ConsolidationModal'; +import { QRScannerModal } from './QRScannerModal'; +import { SeedPhraseModal } from './SeedPhraseModal'; import { Drawer, DrawerContent, DrawerDescription, DrawerHeader, DrawerTitle } from '@/components/ui/drawer'; import * as VisuallyHidden from '@radix-ui/react-visually-hidden'; import { TransactionHistory } from './TransactionHistory'; @@ -593,41 +597,102 @@ export function CashuWallet() { {/* Modals */} <> - setShowProofBreakdown(false)} proofBreakdown={proofBreakdown} - showRemoveMintModal={showRemoveMintModal} - setShowRemoveMintModal={setShowRemoveMintModal} + /> + + {/* Remove Mint Modal */} + setShowRemoveMintModal(false)} mintToRemove={mintToRemove} - onConfirmRemoveMint={handleConfirmRemoveMint} + onConfirm={handleConfirmRemoveMint} isLoading={isLoading || isNpubCashLoading} - showConsolidationModal={showConsolidationModal} - setShowConsolidationModal={setShowConsolidationModal} + /> + + {/* Consolidation Modal */} + setShowConsolidationModal(false)} utxos={utxos} - onConfirmConsolidation={handleConsolidateUtxos} + onConfirm={handleConsolidateUtxos} isConsolidating={isConsolidating} - showLightningAddressQR={showLightningAddressQR} - setShowLightningAddressQR={setShowLightningAddressQR} - lightningAddressQRCode={lightningAddressQRCode} - userPubkey={user?.pubkey} - npubCashUserInfo={npubCashUserInfo} - currentInvoice={currentInvoice} - showInvoiceModal={showInvoiceModal} - setShowInvoiceModal={setShowInvoiceModal} - mintQuoteUnsubscribeRef={mintQuoteUnsubscribeRef} - sentToken={sentToken} - setSentToken={setSentToken} - sentTokenQRCode={sentTokenQRCode} - showSeedPhraseInfo={showSeedPhraseInfo} - setShowSeedPhraseInfo={setShowSeedPhraseInfo} + /> + + {/* QR Modals */} + setShowLightningAddressQR(false)} + title="Lightning Address" + description="Scan this QR code to send payments to your Lightning address" + qrCodeUrl={lightningAddressQRCode} + content={user?.pubkey ? (npubCashUserInfo?.name || nip19.npubEncode(user.pubkey)) + '@npubx.cash' : ''} + icon="zap" + /> + + {currentInvoice && ( + { + if (mintQuoteUnsubscribeRef.current) { + mintQuoteUnsubscribeRef.current(); + mintQuoteUnsubscribeRef.current = null; + } + setShowInvoiceModal(false); + }} + onExpiry={() => { + if (mintQuoteUnsubscribeRef.current) { + mintQuoteUnsubscribeRef.current(); + mintQuoteUnsubscribeRef.current = null; + } + toast({ + variant: "destructive", + title: "Invoice Expired", + description: "The Lightning invoice has expired. Please create a new one.", + }); + }} + title="Lightning Invoice" + description={`Pay this invoice to receive ${currentInvoice.amount} sats`} + qrCodeUrl={currentInvoice.qrCodeUrl} + content={currentInvoice.invoice} + icon="zap" + expiryTimestamp={currentInvoice.expiry} + /> + )} + + {/* Sent Token Modal */} + {sentToken && ( + setSentToken(null)} + title="Cashu Token" + description="Share this token with the recipient to send them your sats" + qrCodeUrl={sentTokenQRCode} + content={sentToken} + icon="qr" + /> + )} + + {/* Seed Phrase Restore Modal */} + setShowSeedPhraseInfo(false)} onRestoreFromSeedPhrase={handleRestoreFromSeedPhrase} isRestoring={isRestoring} mints={mints} activeMintUrl={activeMintUrl} - showQRScanner={showQRScanner} - setShowQRScanner={setShowQRScanner} - stopScanning={stopScanning} + /> + + {/* QR Scanner Modal */} + { + setShowQRScanner(false); + await stopScanning(); + }} qrError={qrError} onPasteQRCode={handlePasteQRCode} /> diff --git a/src/components/wallet/ConsolidationModal.tsx b/src/components/wallet/ConsolidationModal.tsx new file mode 100644 index 0000000..80f9b92 --- /dev/null +++ b/src/components/wallet/ConsolidationModal.tsx @@ -0,0 +1,92 @@ +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { X, ArrowRightLeft, RefreshCw } from 'lucide-react'; +import { UTXO } from '@/lib/bitcoin'; + +interface ConsolidationModalProps { + isOpen: boolean; + onClose: () => void; + utxos: UTXO[]; + onConfirm: () => void; + isConsolidating: boolean; +} + +export function ConsolidationModal({ + isOpen, + onClose, + utxos, + onConfirm, + isConsolidating, +}: ConsolidationModalProps) { + if (!isOpen) return null; + + return ( +
+ 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.
+
+ +
+ +
+
+
+
+ ); +} diff --git a/src/components/wallet/ProofBreakdownModal.tsx b/src/components/wallet/ProofBreakdownModal.tsx new file mode 100644 index 0000000..25d53e4 --- /dev/null +++ b/src/components/wallet/ProofBreakdownModal.tsx @@ -0,0 +1,83 @@ +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 } from 'lucide-react'; + +export interface ProofBreakdown { + mintUrl: string; + denominations: { [key: number]: number }; + totalBalance: number; +} + +interface ProofBreakdownModalProps { + isOpen: boolean; + onClose: () => void; + proofBreakdown: ProofBreakdown | null; +} + +export function ProofBreakdownModal({ + isOpen, + onClose, + proofBreakdown, +}: ProofBreakdownModalProps) { + if (!isOpen || !proofBreakdown) return null; + + return ( +
+ e.stopPropagation()} + > + + + + + Token Breakdown + + + {new URL(proofBreakdown.mintUrl).hostname} + + + +
+
+ {proofBreakdown.totalBalance.toLocaleString()} sats +
+
Total Balance
+
+ +
+
Denominations:
+ {Object.entries(proofBreakdown.denominations) + .sort(([a], [b]) => parseInt(a) - parseInt(b)) + .map(([amount, count]) => ( +
+
+ + {parseInt(amount).toLocaleString()} sats +
+ + × {count} + +
+ ))} +
+ +
+ 💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations. +
+
+
+
+ ); +} diff --git a/src/components/wallet/QRScannerModal.tsx b/src/components/wallet/QRScannerModal.tsx new file mode 100644 index 0000000..0a99d62 --- /dev/null +++ b/src/components/wallet/QRScannerModal.tsx @@ -0,0 +1,63 @@ +import { Button } from '@/components/ui/button'; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import * as VisuallyHidden from '@radix-ui/react-visually-hidden'; + +interface QRScannerModalProps { + isOpen: boolean; + onClose: () => Promise; + qrError: string | null; + onPasteQRCode?: () => Promise; +} + +export function QRScannerModal({ + isOpen, + onClose, + qrError, + onPasteQRCode, +}: QRScannerModalProps) { + return ( + { + if (!open) { + await onClose(); + } + }}> + + + Scan QR Code + + + Position the QR code within the camera view to scan + + + + +
+
+ + {qrError && ( +
+ {qrError} +
+ )} +
+ +
+ +
+ +
+ ); +} diff --git a/src/components/wallet/RemoveMintModal.tsx b/src/components/wallet/RemoveMintModal.tsx new file mode 100644 index 0000000..79c5ada --- /dev/null +++ b/src/components/wallet/RemoveMintModal.tsx @@ -0,0 +1,86 @@ +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { X, AlertTriangle, RefreshCw } from 'lucide-react'; + +export interface MintToRemove { + url: string; + name?: string; +} + +interface RemoveMintModalProps { + isOpen: boolean; + onClose: () => void; + mintToRemove: MintToRemove | null; + onConfirm: () => void; + isLoading: boolean; +} + +export function RemoveMintModal({ + isOpen, + onClose, + mintToRemove, + onConfirm, + isLoading, +}: RemoveMintModalProps) { + if (!isOpen || !mintToRemove) return null; + + return ( +
+ + + + + + Remove Mint + + + Are you sure you want to remove this mint from your wallet? + + + +
+
{mintToRemove.name || new URL(mintToRemove.url).hostname}
+
+ +
+
⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.
+
💡 You can always add this mint back later if needed.
+
+ +
+ + +
+
+
+
+ ); +} diff --git a/src/components/wallet/SeedPhraseModal.tsx b/src/components/wallet/SeedPhraseModal.tsx new file mode 100644 index 0000000..e3628ab --- /dev/null +++ b/src/components/wallet/SeedPhraseModal.tsx @@ -0,0 +1,136 @@ +import { useState } from 'react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { X, Key, Loader2 } from 'lucide-react'; +import { useToast } from '@/hooks/useToast'; + +interface SeedPhraseModalProps { + isOpen: boolean; + onClose: () => void; + onRestoreFromSeedPhrase: (seedPhrase: string, mintUrl: string) => Promise; + isRestoring: boolean; + mints: Array<{ url: string; name?: string }>; + activeMintUrl: string | null; +} + +export function SeedPhraseModal({ + isOpen, + onClose, + onRestoreFromSeedPhrase, + isRestoring, + mints, + activeMintUrl, +}: SeedPhraseModalProps) { + const { toast } = useToast(); + const [seedPhraseInput, setSeedPhraseInput] = useState(''); + + if (!isOpen) return null; + + const handleRestore = async () => { + if (!seedPhraseInput.trim()) { + toast({ + variant: "destructive", + title: "Missing Information", + description: "Please enter your seed phrase.", + }); + return; + } + + if (!activeMintUrl) { + toast({ + variant: "destructive", + title: "No Active Mint", + description: "Please select a mint first.", + }); + return; + } + + try { + await onRestoreFromSeedPhrase(seedPhraseInput.trim(), activeMintUrl); + setSeedPhraseInput(''); + onClose(); + } catch (error) { + toast({ + variant: "destructive", + title: "Restore Failed", + description: error instanceof Error ? error.message : "Failed to restore from seed phrase", + }); + } + }; + + return ( +
+
e.stopPropagation()} + > +
+ + +
+ +

Restore from Seed Phrase

+
+ +

+ Enter your seed phrase to restore tokens from the active mint. +

+ + {activeMintUrl && ( +
+

+ Active Mint: {mints.find(m => m.url === activeMintUrl)?.name || new URL(activeMintUrl).hostname} +

+
+ )} + +
+
+ + setSeedPhraseInput(e.target.value)} + className="mt-1" + /> +
+ +
+

+ Note: This will restore tokens from the provided seed phrase and add them to your current wallet balance. +

+
+
+ +
+ +
+
+
+
+ ); +} diff --git a/src/components/wallet/WalletModals.tsx b/src/components/wallet/WalletModals.tsx deleted file mode 100644 index cbb300d..0000000 --- a/src/components/wallet/WalletModals.tsx +++ /dev/null @@ -1,546 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { Badge } from '@/components/ui/badge'; -import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft, Loader2, Clipboard } from 'lucide-react'; -import { QRModal } from '@/components/ui/qr-modal'; -import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; -import * as VisuallyHidden from '@radix-ui/react-visually-hidden'; -import { nip19 } from 'nostr-tools'; -import { useToast } from '@/hooks/useToast'; -import { UTXO } from '@/lib/bitcoin'; -import { useState } from 'react'; - -// Helper function to prevent complex template literals -const getLightningAddress = (userPubkey?: string, npubCashUserInfo?: { name?: string } | null): string => { - if (!userPubkey) return ''; - const username = npubCashUserInfo?.name || nip19.npubEncode(userPubkey); - return `${username}@npubx.cash`; -}; - -interface ProofBreakdown { - mintUrl: string; - denominations: { [key: number]: number }; - totalBalance: number; -} - -interface MintToRemove { - url: string; - name?: string; -} - -interface WalletModalProps { - // Proof Breakdown Modal - showProofBreakdown: boolean; - setShowProofBreakdown: (show: boolean) => void; - proofBreakdown: ProofBreakdown | null; - - // Remove Mint Modal - showRemoveMintModal: boolean; - setShowRemoveMintModal: (show: boolean) => void; - mintToRemove: MintToRemove | null; - 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; - lightningAddressQRCode: string; - userPubkey?: string; - npubCashUserInfo?: { name?: string } | null; - - // Invoice Modal - currentInvoice?: { - amount: number; - qrCodeUrl: string; - invoice: string; - expiry: number; - } | null; - showInvoiceModal: boolean; - setShowInvoiceModal: (show: boolean) => void; - mintQuoteUnsubscribeRef: React.MutableRefObject<(() => void) | null>; - - // Sent Token Modal - sentToken: string | null; - setSentToken: (token: string | null) => void; - sentTokenQRCode: string; - - // Seed Phrase Info Modal - showSeedPhraseInfo: boolean; - setShowSeedPhraseInfo: (show: boolean) => void; - - // Restore functionality - onRestoreFromSeedPhrase: (seedPhrase: string, mintUrl: string) => Promise; - isRestoring: boolean; - mints: Array<{ url: string; name?: string }>; - activeMintUrl: string | null; - - // QR Scanner Modal - showQRScanner: boolean; - setShowQRScanner: (show: boolean) => void; - stopScanning: () => Promise; - qrError: string | null; - onPasteQRCode?: () => Promise; -} - -export function WalletModals({ - showProofBreakdown, - setShowProofBreakdown, - proofBreakdown, - showRemoveMintModal, - setShowRemoveMintModal, - mintToRemove, - onConfirmRemoveMint, - isLoading, - showConsolidationModal, - setShowConsolidationModal, - utxos, - onConfirmConsolidation, - isConsolidating, - showLightningAddressQR, - setShowLightningAddressQR, - lightningAddressQRCode, - userPubkey, - npubCashUserInfo, - currentInvoice, - showInvoiceModal, - setShowInvoiceModal, - mintQuoteUnsubscribeRef, - sentToken, - setSentToken, - sentTokenQRCode, - showSeedPhraseInfo, - setShowSeedPhraseInfo, - onRestoreFromSeedPhrase, - isRestoring, - mints, - activeMintUrl, - showQRScanner, - setShowQRScanner, - stopScanning, - qrError, - onPasteQRCode, -}: WalletModalProps) { - const { toast } = useToast(); - - // Restore state - const [seedPhraseInput, setSeedPhraseInput] = useState(''); - return ( - <> - {/* Proof Breakdown Modal */} - {showProofBreakdown && proofBreakdown && ( -
setShowProofBreakdown(false)} - > - e.stopPropagation()} - > - - - - - Token Breakdown - - - {new URL(proofBreakdown.mintUrl).hostname} - - - -
-
- {proofBreakdown.totalBalance.toLocaleString()} sats -
-
Total Balance
-
- -
-
Denominations:
- {Object.entries(proofBreakdown.denominations) - .sort(([a], [b]) => parseInt(a) - parseInt(b)) - .map(([amount, count]) => ( -
-
- - {parseInt(amount).toLocaleString()} sats -
- - × {count} - -
- ))} -
- -
- 💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations. -
-
-
-
- )} - - {/* Remove Mint Modal */} - {showRemoveMintModal && mintToRemove && ( -
- - - - - - Remove Mint - - - Are you sure you want to remove this mint from your wallet? - - - -
-
{mintToRemove.name || new URL(mintToRemove.url).hostname}
-
- -
-
⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.
-
💡 You can always add this mint back later if needed.
-
- -
- - -
-
-
-
- )} - - {/* 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 */} - setShowLightningAddressQR(false)} - title="Lightning Address" - description="Scan this QR code to send payments to your Lightning address" - qrCodeUrl={lightningAddressQRCode} - content={getLightningAddress(userPubkey, npubCashUserInfo)} - icon="zap" - /> - - {currentInvoice && ( - { - if (mintQuoteUnsubscribeRef.current) { - mintQuoteUnsubscribeRef.current(); - mintQuoteUnsubscribeRef.current = null; - } - setShowInvoiceModal(false); - }} - onExpiry={() => { - if (mintQuoteUnsubscribeRef.current) { - mintQuoteUnsubscribeRef.current(); - mintQuoteUnsubscribeRef.current = null; - } - toast({ - variant: "destructive", - title: "Invoice Expired", - description: "The Lightning invoice has expired. Please create a new one.", - }); - }} - title="Lightning Invoice" - description={`Pay this invoice to receive ${currentInvoice.amount} sats`} - qrCodeUrl={currentInvoice.qrCodeUrl} - content={currentInvoice.invoice} - icon="zap" - expiryTimestamp={currentInvoice.expiry} - /> - )} - - {/* Sent Token Modal */} - {sentToken && ( - setSentToken(null)} - title="Cashu Token" - description="Share this token with the recipient to send them your sats" - qrCodeUrl={sentTokenQRCode} - content={sentToken} - icon="qr" - /> - )} - - {/* Seed Phrase Restore Modal */} - {showSeedPhraseInfo && ( -
setShowSeedPhraseInfo(false)} - > -
e.stopPropagation()} - > -
- - -
- -

Restore from Seed Phrase

-
- -

- Enter your seed phrase to restore tokens from the active mint. -

- - {activeMintUrl && ( -
-

- Active Mint: {mints.find(m => m.url === activeMintUrl)?.name || new URL(activeMintUrl).hostname} -

-
- )} - -
-
- - setSeedPhraseInput(e.target.value)} - className="mt-1" - /> -
- -
-

- Note: This will restore tokens from the provided seed phrase and add them to your current wallet balance. -

-
-
- -
- -
-
-
-
- )} - - {/* QR Scanner Modal */} - { - if (!open) { - setShowQRScanner(false); - await stopScanning(); - } - }}> - - {/* Header */} - - Scan QR Code - - - Position the QR code within the camera view to scan - - - - - {/* Camera container with square aspect ratio */} -
-
- - {/* Scanning area overlay frame */} - {/*
-
-
*/} - - {/* Error message */} - {qrError && ( -
- {qrError} -
- )} -
- - {/* Paste Button */} -
- -
- -
- - ); -}