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 { QRModal } from '@/components/ui/qr-modal'; import { nip19 } from 'nostr-tools'; import { useToast } from '@/hooks/useToast'; // 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; // 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; } export function WalletModals({ showProofBreakdown, setShowProofBreakdown, proofBreakdown, showRemoveMintModal, setShowRemoveMintModal, mintToRemove, onConfirmRemoveMint, isLoading, showLightningAddressQR, setShowLightningAddressQR, lightningAddressQRCode, userPubkey, npubCashUserInfo, currentInvoice, showInvoiceModal, setShowInvoiceModal, mintQuoteUnsubscribeRef, sentToken, setSentToken, sentTokenQRCode, showSeedPhraseInfo, setShowSeedPhraseInfo, }: WalletModalProps) { const { toast } = useToast(); 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.
)} {/* 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 Info Modal */} {showSeedPhraseInfo && (
setShowSeedPhraseInfo(false)} >
e.stopPropagation()} >

What is a Seed Phrase?

Your seed phrase is a secure way to backup and restore your wallet

🔐 Recovery Key

Your seed phrase is a 12-word recovery key that allows you to restore your wallet on any device. It's generated using industry-standard BIP39 wordlists.

💾 Backup Important

Write down your seed phrase and store it securely offline. Anyone with access to your seed phrase can control your wallet and funds.

🛡️ Security Tips

  • • Never share your seed phrase with anyone
  • • Store it offline in a secure location
  • • Don't take screenshots or store it digitally
  • • Use it only to restore your wallet

Note: The seed phrase shown above is masked for privacy. Click the copy button to access the actual phrase for backup purposes.

)} ); }