redesigned camera modal with paste button

This commit is contained in:
lemonknowsall committed 2025-10-27 16:00:15 -07:00
1 parent df6989baf9
commit 5687faa746
3 files changed
+65 -72

No files matched your search

+27 -13
View File
@@ -45,7 +45,7 @@ export function CashuWallet() {
const { user } = useCurrentUser(); const { user } = useCurrentUser();
const { getInvoice: getLightningInvoice, isLoading: isResolvingAddress } = useLightningAddress(); const { getInvoice: getLightningInvoice, isLoading: isResolvingAddress } = useLightningAddress();
const { toast } = useToast(); 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 { copy: copyToClipboard } = useCopyToClipboard();
const { hasNsecAccess } = useNsecAccess(); const { hasNsecAccess } = useNsecAccess();
@@ -336,20 +336,8 @@ export function CashuWallet() {
// Start/stop QR scanner when modal opens/closes // Start/stop QR scanner when modal opens/closes
useEffect(() => { useEffect(() => {
if (showQRScanner) { 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); startScanning(handleQRScanResult);
} else { } else {
// Restore body scroll
document.body.style.overflow = '';
document.body.style.position = '';
document.body.style.width = '';
document.body.style.height = '';
stopScanning(); stopScanning();
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // 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 // RENDER
// ============================================================================ // ============================================================================
@@ -594,6 +607,7 @@ export function CashuWallet() {
setShowQRScanner={setShowQRScanner} setShowQRScanner={setShowQRScanner}
stopScanning={stopScanning} stopScanning={stopScanning}
qrError={qrError} qrError={qrError}
onPasteQRCode={handlePasteQRCode}
/> />
{/* Bottom Drawer Modals */} {/* Bottom Drawer Modals */}
+36 -59
View File
@@ -5,6 +5,7 @@ import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label'; import { Label } from '@/components/ui/label';
import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft, Loader2 } from 'lucide-react'; import { X, Coins, AlertTriangle, RefreshCw, Key, ArrowRightLeft, Loader2 } from 'lucide-react';
import { QRModal } from '@/components/ui/qr-modal'; import { QRModal } from '@/components/ui/qr-modal';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { useToast } from '@/hooks/useToast'; import { useToast } from '@/hooks/useToast';
import { UTXO } from '@/lib/bitcoin'; import { UTXO } from '@/lib/bitcoin';
@@ -86,6 +87,7 @@ interface WalletModalProps {
setShowQRScanner: (show: boolean) => void; setShowQRScanner: (show: boolean) => void;
stopScanning: () => Promise<void>; stopScanning: () => Promise<void>;
qrError: string | null; qrError: string | null;
onPasteQRCode?: () => Promise<void>;
} }
export function WalletModals({ export function WalletModals({
@@ -124,6 +126,7 @@ export function WalletModals({
setShowQRScanner, setShowQRScanner,
stopScanning, stopScanning,
qrError, qrError,
onPasteQRCode,
}: WalletModalProps) { }: WalletModalProps) {
const { toast } = useToast(); const { toast } = useToast();
@@ -483,85 +486,59 @@ export function WalletModals({
</div> </div>
)} )}
{/* QR Scanner Modal - Full Screen Overlay */} {/* QR Scanner Modal */}
{showQRScanner && ( <Dialog open={showQRScanner} onOpenChange={(open) => {
<div if (!open) {
style={{ setShowQRScanner(false);
stopScanning();
}
}}>
<DialogContent
className="max-w-none w-screen h-screen !h-[100dvh] p-6 bg-background border-0 rounded-none !top-0 !left-0 !right-0 !bottom-0 !translate-x-0 !translate-y-0 flex flex-col"
style={{
position: 'fixed', position: 'fixed',
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
width: '100vw', transform: 'none',
height: '100dvh', maxWidth: '100vw',
zIndex: 9999, maxHeight: '100vh',
backgroundColor: '#000',
margin: 0,
padding: 0,
overflow: 'hidden'
}} }}
> >
{/* Close button */} {/* Camera view with rounded corners */}
<button
onClick={() => {
setShowQRScanner(false);
stopScanning();
}}
style={{
position: 'absolute',
top: '16px',
right: '16px',
zIndex: 10000,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
border: 'none',
borderRadius: '8px',
padding: '12px',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center'
}}
aria-label="Close scanner"
>
<X className="h-6 w-6 text-white" />
</button>
{/* Camera view */}
<div <div
id="qr-reader" id="qr-reader"
className="flex-1 rounded-2xl overflow-hidden"
style={{ style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
width: '100%', width: '100%',
height: '100%', height: '100%',
overflow: 'hidden'
}} }}
/> />
{/* Error message */} {/* Error message */}
{qrError && ( {qrError && (
<div <div className="absolute bottom-28 left-6 right-6 p-3 bg-destructive text-destructive-foreground rounded-lg text-center z-50">
style={{
position: 'absolute',
bottom: '80px',
left: '16px',
right: '16px',
padding: '12px',
backgroundColor: 'rgb(239, 68, 68)',
color: 'white',
borderRadius: '8px',
zIndex: 10000,
textAlign: 'center'
}}
>
{qrError} {qrError}
</div> </div>
)} )}
</div>
)} {/* Paste Button */}
<div className="mt-4 pb-safe flex justify-center">
<Button
onClick={async () => {
if (onPasteQRCode) {
await onPasteQRCode();
}
}}
className="rounded-full px-8"
size="lg"
>
Paste
</Button>
</div>
</DialogContent>
</Dialog>
</> </>
); );
} }
+2
View File
@@ -19,6 +19,7 @@ interface UseQRCodeReturn {
isScanning: boolean; isScanning: boolean;
startScanning: (onResult: (result: QRScanResult) => void) => Promise<void>; startScanning: (onResult: (result: QRScanResult) => void) => Promise<void>;
stopScanning: () => Promise<void>; stopScanning: () => Promise<void>;
classifyQRCode: (text: string) => QRScanResult;
} }
/** /**
@@ -184,5 +185,6 @@ export function useQRCode(): UseQRCodeReturn {
isScanning, isScanning,
startScanning, startScanning,
stopScanning, stopScanning,
classifyQRCode,
}; };
} }