breakout modals into separate files

This commit is contained in:
lemonknowsall committed 2025-11-02 09:38:05 -08:00
1 parent 3fbdf1fc60
commit 3df413fa84
7 files changed
+552 -573

No files matched your search

+92 -27
View File
@@ -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 */}
<>
<WalletModals
showProofBreakdown={showProofBreakdown}
setShowProofBreakdown={setShowProofBreakdown}
{/* Proof Breakdown Modal */}
<ProofBreakdownModal
isOpen={showProofBreakdown}
onClose={() => setShowProofBreakdown(false)}
proofBreakdown={proofBreakdown}
showRemoveMintModal={showRemoveMintModal}
setShowRemoveMintModal={setShowRemoveMintModal}
/>
{/* Remove Mint Modal */}
<RemoveMintModal
isOpen={showRemoveMintModal}
onClose={() => setShowRemoveMintModal(false)}
mintToRemove={mintToRemove}
onConfirmRemoveMint={handleConfirmRemoveMint}
onConfirm={handleConfirmRemoveMint}
isLoading={isLoading || isNpubCashLoading}
showConsolidationModal={showConsolidationModal}
setShowConsolidationModal={setShowConsolidationModal}
/>
{/* Consolidation Modal */}
<ConsolidationModal
isOpen={showConsolidationModal}
onClose={() => 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 */}
<QRModal
isOpen={showLightningAddressQR}
onClose={() => 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 && (
<QRModal
isOpen={showInvoiceModal}
onClose={() => {
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 && (
<QRModal
isOpen={!!sentToken}
onClose={() => 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 */}
<SeedPhraseModal
isOpen={showSeedPhraseInfo}
onClose={() => setShowSeedPhraseInfo(false)}
onRestoreFromSeedPhrase={handleRestoreFromSeedPhrase}
isRestoring={isRestoring}
mints={mints}
activeMintUrl={activeMintUrl}
showQRScanner={showQRScanner}
setShowQRScanner={setShowQRScanner}
stopScanning={stopScanning}
/>
{/* QR Scanner Modal */}
<QRScannerModal
isOpen={showQRScanner}
onClose={async () => {
setShowQRScanner(false);
await stopScanning();
}}
qrError={qrError}
onPasteQRCode={handlePasteQRCode}
/>
@@ -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 (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-[100] p-4"
onClick={onClose}
>
<Card
className="w-full max-w-md border-0 shadow-lg bg-background"
onClick={(e) => e.stopPropagation()}
>
<CardHeader className="relative">
<Button
onClick={onClose}
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={() => {
onConfirm();
onClose();
}}
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>
);
}
@@ -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 (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
onClick={onClose}
>
<Card
className="w-full max-w-md border-0 shadow-lg bg-background"
onClick={(e) => e.stopPropagation()}
>
<CardHeader className="relative">
<Button
onClick={onClose}
className="absolute top-2 right-2"
size="sm"
variant="ghost"
>
<X className="h-4 w-4" />
</Button>
<CardTitle className="flex items-center pr-8">
<Coins className="h-5 w-5 mr-2" />
Token Breakdown
</CardTitle>
<CardDescription>
{new URL(proofBreakdown.mintUrl).hostname}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="text-center py-2">
<div className="text-2xl font-bold text-primary">
{proofBreakdown.totalBalance.toLocaleString()} sats
</div>
<div className="text-sm text-muted-foreground">Total Balance</div>
</div>
<div className="space-y-2">
<div className="text-sm font-medium text-muted-foreground">Denominations:</div>
{Object.entries(proofBreakdown.denominations)
.sort(([a], [b]) => parseInt(a) - parseInt(b))
.map(([amount, count]) => (
<div key={amount} className="flex items-center justify-between p-2 bg-muted/30 rounded">
<div className="flex items-center gap-2">
<Coins className="h-4 w-4 text-muted-foreground" />
<span className="font-medium">{parseInt(amount).toLocaleString()} sats</span>
</div>
<Badge variant="secondary" className="bg-primary/10 text-primary">
× {count}
</Badge>
</div>
))}
</div>
<div className="text-xs text-muted-foreground bg-muted/30 p-3 rounded">
💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations.
</div>
</CardContent>
</Card>
</div>
);
}
+63
View File
@@ -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<void>;
qrError: string | null;
onPasteQRCode?: () => Promise<void>;
}
export function QRScannerModal({
isOpen,
onClose,
qrError,
onPasteQRCode,
}: QRScannerModalProps) {
return (
<Dialog open={isOpen} onOpenChange={async (open) => {
if (!open) {
await onClose();
}
}}>
<DialogContent className="max-w-[min(90vw,500px)] w-full p-4 sm:p-6">
<DialogHeader>
<DialogTitle>Scan QR Code</DialogTitle>
<VisuallyHidden.Root asChild>
<DialogDescription>
Position the QR code within the camera view to scan
</DialogDescription>
</VisuallyHidden.Root>
</DialogHeader>
<div className="relative w-full" style={{ aspectRatio: '1 / 1' }}>
<div
id="qr-reader"
className="w-full h-full rounded-xl overflow-hidden bg-muted"
/>
{qrError && (
<div className="absolute inset-x-4 top-4 p-3 bg-destructive text-destructive-foreground rounded-lg text-center z-50 shadow-lg">
{qrError}
</div>
)}
</div>
<div className="mt-4 flex justify-center">
<Button
onClick={async () => {
if (onPasteQRCode) {
await onPasteQRCode();
}
}}
className="h-12 px-12 rounded-full"
size="lg"
>
Paste
</Button>
</div>
</DialogContent>
</Dialog>
);
}
+86
View File
@@ -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 (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-[100] p-4">
<Card className="w-full max-w-md border-0 shadow-lg bg-background">
<CardHeader className="relative">
<Button
onClick={onClose}
className="absolute top-2 right-2"
size="sm"
variant="ghost"
>
<X className="h-4 w-4" />
</Button>
<CardTitle className="flex items-center pr-8">
<AlertTriangle className="h-5 w-5 mr-2 text-destructive" />
Remove Mint
</CardTitle>
<CardDescription>
Are you sure you want to remove this mint from your wallet?
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="bg-muted p-4 rounded-lg border">
<div className="font-medium">{mintToRemove.name || new URL(mintToRemove.url).hostname}</div>
</div>
<div className="text-sm text-muted-foreground bg-muted/30 p-3 rounded space-y-2">
<div>⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.</div>
<div>💡 You can always add this mint back later if needed.</div>
</div>
<div className="flex gap-2 justify-end">
<Button
variant="outline"
onClick={onClose}
>
Cancel
</Button>
<Button
variant="destructive"
onClick={onConfirm}
disabled={isLoading}
>
{isLoading ? (
<>
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
Removing...
</>
) : (
<>
<X className="h-4 w-4 mr-2" />
Remove Mint
</>
)}
</Button>
</div>
</CardContent>
</Card>
</div>
);
}
+136
View File
@@ -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<void>;
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 (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
onClick={onClose}
>
<div
className="w-full max-w-md border-0 shadow-lg bg-background rounded-lg"
onClick={(e) => e.stopPropagation()}
>
<div className="relative p-6">
<button
onClick={onClose}
className="absolute top-4 right-4 p-2 hover:bg-muted rounded-md transition-colors"
>
<X className="h-4 w-4" />
</button>
<div className="flex items-center mb-4 pr-8">
<Key className="h-5 w-5 mr-2" />
<h2 className="text-lg font-semibold">Restore from Seed Phrase</h2>
</div>
<p className="text-muted-foreground mb-4">
Enter your seed phrase to restore tokens from the active mint.
</p>
{activeMintUrl && (
<div className="bg-muted p-3 rounded-md mb-4">
<p className="text-sm text-muted-foreground">
<strong>Active Mint:</strong> {mints.find(m => m.url === activeMintUrl)?.name || new URL(activeMintUrl).hostname}
</p>
</div>
)}
<div className="space-y-4">
<div>
<Label htmlFor="seed-phrase">Seed Phrase</Label>
<Input
id="seed-phrase"
type="text"
placeholder="Enter your 12-word seed phrase..."
value={seedPhraseInput}
onChange={(e) => setSeedPhraseInput(e.target.value)}
className="mt-1"
/>
</div>
<div className="bg-muted p-3 rounded-md">
<p className="text-xs text-muted-foreground">
<strong>Note:</strong> This will restore tokens from the provided seed phrase and add them to your current wallet balance.
</p>
</div>
</div>
<div className="mt-6">
<Button
onClick={handleRestore}
disabled={isRestoring || !seedPhraseInput.trim() || !activeMintUrl}
className="w-full"
>
{isRestoring ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Restoring...
</>
) : (
'Restore Tokens'
)}
</Button>
</div>
</div>
</div>
</div>
);
}
-546
View File
@@ -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<void>;
isRestoring: boolean;
mints: Array<{ url: string; name?: string }>;
activeMintUrl: string | null;
// QR Scanner Modal
showQRScanner: boolean;
setShowQRScanner: (show: boolean) => void;
stopScanning: () => Promise<void>;
qrError: string | null;
onPasteQRCode?: () => Promise<void>;
}
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 && (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
onClick={() => setShowProofBreakdown(false)}
>
<Card
className="w-full max-w-md border-0 shadow-lg bg-background"
onClick={(e) => e.stopPropagation()}
>
<CardHeader className="relative">
<Button
onClick={() => setShowProofBreakdown(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">
<Coins className="h-5 w-5 mr-2" />
Token Breakdown
</CardTitle>
<CardDescription>
{new URL(proofBreakdown.mintUrl).hostname}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="text-center py-2">
<div className="text-2xl font-bold text-primary">
{proofBreakdown.totalBalance.toLocaleString()} sats
</div>
<div className="text-sm text-muted-foreground">Total Balance</div>
</div>
<div className="space-y-2">
<div className="text-sm font-medium text-muted-foreground">Denominations:</div>
{Object.entries(proofBreakdown.denominations)
.sort(([a], [b]) => parseInt(a) - parseInt(b))
.map(([amount, count]) => (
<div key={amount} className="flex items-center justify-between p-2 bg-muted/30 rounded">
<div className="flex items-center gap-2">
<Coins className="h-4 w-4 text-muted-foreground" />
<span className="font-medium">{parseInt(amount).toLocaleString()} sats</span>
</div>
<Badge variant="secondary" className="bg-primary/10 text-primary">
× {count}
</Badge>
</div>
))}
</div>
<div className="text-xs text-muted-foreground bg-muted/30 p-3 rounded">
💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations.
</div>
</CardContent>
</Card>
</div>
)}
{/* Remove Mint Modal */}
{showRemoveMintModal && mintToRemove && (
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-[100] p-4">
<Card className="w-full max-w-md border-0 shadow-lg bg-background">
<CardHeader className="relative">
<Button
onClick={() => setShowRemoveMintModal(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">
<AlertTriangle className="h-5 w-5 mr-2 text-destructive" />
Remove Mint
</CardTitle>
<CardDescription>
Are you sure you want to remove this mint from your wallet?
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="bg-muted p-4 rounded-lg border">
<div className="font-medium">{mintToRemove.name || new URL(mintToRemove.url).hostname}</div>
</div>
<div className="text-sm text-muted-foreground bg-muted/30 p-3 rounded space-y-2">
<div>⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.</div>
<div>💡 You can always add this mint back later if needed.</div>
</div>
<div className="flex gap-2 justify-end">
<Button
variant="outline"
onClick={() => setShowRemoveMintModal(false)}
>
Cancel
</Button>
<Button
variant="destructive"
onClick={onConfirmRemoveMint}
disabled={isLoading}
>
{isLoading ? (
<>
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
Removing...
</>
) : (
<>
<X className="h-4 w-4 mr-2" />
Remove Mint
</>
)}
</Button>
</div>
</CardContent>
</Card>
</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}
onClose={() => 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 && (
<QRModal
isOpen={showInvoiceModal}
onClose={() => {
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 && (
<QRModal
isOpen={!!sentToken}
onClose={() => 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 && (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
onClick={() => setShowSeedPhraseInfo(false)}
>
<div
className="w-full max-w-md border-0 shadow-lg bg-background rounded-lg"
onClick={(e) => e.stopPropagation()}
>
<div className="relative p-6">
<button
onClick={() => setShowSeedPhraseInfo(false)}
className="absolute top-4 right-4 p-2 hover:bg-muted rounded-md transition-colors"
>
<X className="h-4 w-4" />
</button>
<div className="flex items-center mb-4 pr-8">
<Key className="h-5 w-5 mr-2" />
<h2 className="text-lg font-semibold">Restore from Seed Phrase</h2>
</div>
<p className="text-muted-foreground mb-4">
Enter your seed phrase to restore tokens from the active mint.
</p>
{activeMintUrl && (
<div className="bg-muted p-3 rounded-md mb-4">
<p className="text-sm text-muted-foreground">
<strong>Active Mint:</strong> {mints.find(m => m.url === activeMintUrl)?.name || new URL(activeMintUrl).hostname}
</p>
</div>
)}
<div className="space-y-4">
<div>
<Label htmlFor="seed-phrase">Seed Phrase</Label>
<Input
id="seed-phrase"
type="text"
placeholder="Enter your 12-word seed phrase..."
value={seedPhraseInput}
onChange={(e) => setSeedPhraseInput(e.target.value)}
className="mt-1"
/>
</div>
<div className="bg-muted p-3 rounded-md">
<p className="text-xs text-muted-foreground">
<strong>Note:</strong> This will restore tokens from the provided seed phrase and add them to your current wallet balance.
</p>
</div>
</div>
<div className="mt-6">
<Button
onClick={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('');
setShowSeedPhraseInfo(false);
} catch (error) {
toast({
variant: "destructive",
title: "Restore Failed",
description: error instanceof Error ? error.message : "Failed to restore from seed phrase",
});
}
}}
disabled={isRestoring || !seedPhraseInput.trim() || !activeMintUrl}
className="w-full"
>
{isRestoring ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Restoring...
</>
) : (
'Restore Tokens'
)}
</Button>
</div>
</div>
</div>
</div>
)}
{/* QR Scanner Modal */}
<Dialog open={showQRScanner} onOpenChange={async (open) => {
if (!open) {
setShowQRScanner(false);
await stopScanning();
}
}}>
<DialogContent className="max-w-[min(90vw,500px)] w-full p-4 sm:p-6">
{/* Header */}
<DialogHeader>
<DialogTitle>Scan QR Code</DialogTitle>
<VisuallyHidden.Root asChild>
<DialogDescription>
Position the QR code within the camera view to scan
</DialogDescription>
</VisuallyHidden.Root>
</DialogHeader>
{/* Camera container with square aspect ratio */}
<div className="relative w-full" style={{ aspectRatio: '1 / 1' }}>
<div
id="qr-reader"
className="w-full h-full rounded-xl overflow-hidden bg-muted"
/>
{/* Scanning area overlay frame */}
{/* <div className="absolute inset-0 pointer-events-none flex items-center justify-center">
<div className="w-4/5 h-4/5 border-4 border-white/30 rounded-xl shadow-lg" />
</div> */}
{/* Error message */}
{qrError && (
<div className="absolute inset-x-4 top-4 p-3 bg-destructive text-destructive-foreground rounded-lg text-center z-50 shadow-lg">
{qrError}
</div>
)}
</div>
{/* Paste Button */}
<div className="mt-4 flex justify-center">
<Button
onClick={async () => {
if (onPasteQRCode) {
await onPasteQRCode();
}
}}
className="h-12 px-12 rounded-full"
size="lg"
>
Paste
</Button>
</div>
</DialogContent>
</Dialog>
</>
);
}