From 5687faa7464c9f4dc0f099bd36fe5aca9582ee31 Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Mon, 27 Oct 2025 16:00:15 -0700 Subject: [PATCH] redesigned camera modal with paste button --- src/components/wallet/CashuWallet.tsx | 40 +++++++---- src/components/wallet/WalletModals.tsx | 95 ++++++++++---------------- src/hooks/useQRCode.ts | 2 + 3 files changed, 65 insertions(+), 72 deletions(-) diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index fe11eb0..82a89c3 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -45,7 +45,7 @@ export function CashuWallet() { const { user } = useCurrentUser(); const { getInvoice: getLightningInvoice, isLoading: isResolvingAddress } = useLightningAddress(); const { toast } = useToast(); - const { generateQRCode, isScanning, startScanning, stopScanning, error: qrError } = useQRCode(); + const { generateQRCode, isScanning, startScanning, stopScanning, error: qrError, classifyQRCode } = useQRCode(); const { copy: copyToClipboard } = useCopyToClipboard(); const { hasNsecAccess } = useNsecAccess(); @@ -336,20 +336,8 @@ export function CashuWallet() { // Start/stop QR scanner when modal opens/closes useEffect(() => { if (showQRScanner) { - // Lock body scroll on mobile - document.body.style.overflow = 'hidden'; - document.body.style.position = 'fixed'; - document.body.style.width = '100%'; - document.body.style.height = '100%'; - startScanning(handleQRScanResult); } else { - // Restore body scroll - document.body.style.overflow = ''; - document.body.style.position = ''; - document.body.style.width = ''; - document.body.style.height = ''; - stopScanning(); } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -458,6 +446,31 @@ export function CashuWallet() { } }; + // Handle paste from clipboard + const handlePasteQRCode = async () => { + try { + const text = await navigator.clipboard.readText(); + if (!text || !text.trim()) { + toast({ + variant: "destructive", + title: "Clipboard Empty", + description: "No text found in clipboard", + }); + return; + } + + const result = classifyQRCode(text.trim()); + await handleQRScanResult(result); + } catch (err) { + toast({ + variant: "destructive", + title: "Paste Failed", + description: "Could not read from clipboard", + }); + console.error('Error pasting from clipboard:', err); + } + }; + // ============================================================================ // RENDER // ============================================================================ @@ -594,6 +607,7 @@ export function CashuWallet() { setShowQRScanner={setShowQRScanner} stopScanning={stopScanning} qrError={qrError} + onPasteQRCode={handlePasteQRCode} /> {/* Bottom Drawer Modals */} diff --git a/src/components/wallet/WalletModals.tsx b/src/components/wallet/WalletModals.tsx index 336d1c8..dd5e528 100644 --- a/src/components/wallet/WalletModals.tsx +++ b/src/components/wallet/WalletModals.tsx @@ -5,6 +5,7 @@ import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft, Loader2 } from 'lucide-react'; import { QRModal } from '@/components/ui/qr-modal'; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { nip19 } from 'nostr-tools'; import { useToast } from '@/hooks/useToast'; import { UTXO } from '@/lib/bitcoin'; @@ -86,6 +87,7 @@ interface WalletModalProps { setShowQRScanner: (show: boolean) => void; stopScanning: () => Promise; qrError: string | null; + onPasteQRCode?: () => Promise; } export function WalletModals({ @@ -124,6 +126,7 @@ export function WalletModals({ setShowQRScanner, stopScanning, qrError, + onPasteQRCode, }: WalletModalProps) { const { toast } = useToast(); @@ -483,85 +486,59 @@ export function WalletModals({ )} - {/* QR Scanner Modal - Full Screen Overlay */} - {showQRScanner && ( -
{ + if (!open) { + setShowQRScanner(false); + stopScanning(); + } + }}> + - {/* Close button */} - - - {/* Camera view */} + {/* Camera view with rounded corners */}
{/* Error message */} {qrError && ( -
+
{qrError}
)} -
- )} + + {/* Paste Button */} +
+ +
+ + ); } diff --git a/src/hooks/useQRCode.ts b/src/hooks/useQRCode.ts index e5482b6..a712d50 100644 --- a/src/hooks/useQRCode.ts +++ b/src/hooks/useQRCode.ts @@ -19,6 +19,7 @@ interface UseQRCodeReturn { isScanning: boolean; startScanning: (onResult: (result: QRScanResult) => void) => Promise; stopScanning: () => Promise; + classifyQRCode: (text: string) => QRScanResult; } /** @@ -184,5 +185,6 @@ export function useQRCode(): UseQRCodeReturn { isScanning, startScanning, stopScanning, + classifyQRCode, }; }