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 { 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 */}
+36 -59
View File
@@ -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<void>;
qrError: string | null;
onPasteQRCode?: () => Promise<void>;
}
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({
</div>
)}
{/* QR Scanner Modal - Full Screen Overlay */}
{showQRScanner && (
<div
style={{
{/* QR Scanner Modal */}
<Dialog open={showQRScanner} onOpenChange={(open) => {
if (!open) {
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',
top: 0,
left: 0,
right: 0,
bottom: 0,
width: '100vw',
height: '100dvh',
zIndex: 9999,
backgroundColor: '#000',
margin: 0,
padding: 0,
overflow: 'hidden'
transform: 'none',
maxWidth: '100vw',
maxHeight: '100vh',
}}
>
{/* Close button */}
<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 */}
{/* Camera view with rounded corners */}
<div
id="qr-reader"
className="flex-1 rounded-2xl overflow-hidden"
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
width: '100%',
height: '100%',
overflow: 'hidden'
}}
/>
{/* Error message */}
{qrError && (
<div
style={{
position: 'absolute',
bottom: '80px',
left: '16px',
right: '16px',
padding: '12px',
backgroundColor: 'rgb(239, 68, 68)',
color: 'white',
borderRadius: '8px',
zIndex: 10000,
textAlign: 'center'
}}
>
<div className="absolute bottom-28 left-6 right-6 p-3 bg-destructive text-destructive-foreground rounded-lg text-center z-50">
{qrError}
</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;
startScanning: (onResult: (result: QRScanResult) => void) => Promise<void>;
stopScanning: () => Promise<void>;
classifyQRCode: (text: string) => QRScanResult;
}
/**
@@ -184,5 +185,6 @@ export function useQRCode(): UseQRCodeReturn {
isScanning,
startScanning,
stopScanning,
classifyQRCode,
};
}