ln decoder for qr code scan and mobile qr modal fix

This commit is contained in:
lemonknowsall committed 2025-10-27 14:42:19 -07:00
1 parent fde64074ed
commit 0925bb9f1c
3 files changed
+35 -21

No files matched your search

+4 -2
View File
@@ -12,6 +12,7 @@ import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions';
import { useHistoryManager } from '@/hooks/cashu/useHistoryManager'; import { useHistoryManager } from '@/hooks/cashu/useHistoryManager';
import { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance'; import { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance';
import { useNsecAccess } from '@/hooks/useNsecAccess'; import { useNsecAccess } from '@/hooks/useNsecAccess';
import { decodeBolt11Amount } from '@/lib/bolt11Decoder';
import { nostrPubkeyToBitcoinAddress } from '@/lib/bitcoin'; import { nostrPubkeyToBitcoinAddress } from '@/lib/bitcoin';
import { QRModal } from '@/components/ui/qr-modal'; import { QRModal } from '@/components/ui/qr-modal';
import { WalletHeader } from './WalletHeader'; import { WalletHeader } from './WalletHeader';
@@ -367,11 +368,12 @@ export function CashuWallet() {
setLightningInvoice(result.value); setLightningInvoice(result.value);
setPendingInvoice(result.value); setPendingInvoice(result.value);
// Decode invoice amount // Decode invoice amount
setDecodedInvoiceAmount(100); // Placeholder - would need actual decoding const amount = decodeBolt11Amount(result.value);
setDecodedInvoiceAmount(amount);
setShowSendModal(true); setShowSendModal(true);
toast({ toast({
title: "Lightning Invoice Scanned", title: "Lightning Invoice Scanned",
description: "Invoice ready to pay", description: amount ? `${amount} sats` : "Invoice ready to pay",
}); });
break; break;
} }
+8 -2
View File
@@ -17,6 +17,12 @@ const getOperationMessage = (operation: string, mode: string): string => {
} }
}; };
// Helper function to truncate long addresses (show first 12, last 12 with ellipsis in middle)
const truncateAddress = (address: string): string => {
if (address.length <= 26) return address; // "first 12" + "..." + "last 12" = 26
return address.slice(0, 12) + '...' + address.slice(-12);
};
interface TransactionCardProps { interface TransactionCardProps {
mode: 'tokens' | 'lightning' | 'bitcoin'; mode: 'tokens' | 'lightning' | 'bitcoin';
operation: 'send' | 'receive'; operation: 'send' | 'receive';
@@ -180,7 +186,7 @@ export function TransactionCard({
<div className="flex items-center justify-center gap-2"> <div className="flex items-center justify-center gap-2">
<span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md"> <span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md">
<span className="font-bold text-primary">Sending to:</span>{' '} <span className="font-bold text-primary">Sending to:</span>{' '}
<span className="font-semibold text-foreground">{pendingBitcoinRecipient}</span> <span className="font-semibold text-foreground">{truncateAddress(pendingBitcoinRecipient)}</span>
</span> </span>
<button <button
onClick={() => { onClick={() => {
@@ -215,7 +221,7 @@ export function TransactionCard({
<div className="flex items-center justify-center gap-2"> <div className="flex items-center justify-center gap-2">
<span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md"> <span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md">
<span className="font-bold text-primary">Sending:</span>{' '} <span className="font-bold text-primary">Sending:</span>{' '}
<span className="font-semibold text-foreground">{pendingLightningAddress}</span> <span className="font-semibold text-foreground">{truncateAddress(pendingLightningAddress)}</span>
</span> </span>
<button <button
onClick={() => { onClick={() => {
+23 -17
View File
@@ -492,30 +492,36 @@ export function WalletModals({
stopScanning(); stopScanning();
} }
}}> }}>
<DialogContent className="max-w-full h-screen flex flex-col items-center justify-center p-0 bg-black border-0 [&>button]:text-white [&>button]:hover:bg-black/70"> <DialogContent className="max-w-full w-screen h-screen flex flex-col items-center justify-center p-0 bg-black border-0 [&>button]:fixed [&>button]:top-4 [&>button]:right-4 [&>button]:z-50 [&>button]:text-white [&>button]:hover:bg-black/70">
{/* Full-screen camera container */} {/* Full-screen camera container */}
<div className="absolute inset-0"> <div className="fixed inset-0">
<div id="qr-reader" className="w-full h-full"></div> <div id="qr-reader" className="w-full h-full"></div>
</div> </div>
{/* Dark overlay with centered square cutout */} {/* Dark overlay with centered square cutout using SVG mask */}
<div className="absolute inset-0 pointer-events-none"> <svg className="fixed inset-0 w-full h-full pointer-events-none" style={{ zIndex: 10 }}>
{/* Top overlay */} <defs>
<div className="absolute top-0 left-0 right-0 h-[calc(50vh-150px)] bg-black/60"></div> <mask id="qr-scanner-mask">
{/* Bottom overlay */} <rect width="100%" height="100%" fill="white" />
<div className="absolute bottom-0 left-0 right-0 h-[calc(50vh-150px)] bg-black/60"></div> <rect
{/* Left overlay */} x="calc(50% - 150px)"
<div className="absolute top-[calc(50vh-150px)] bottom-[calc(50vh-150px)] left-0 right-[calc(50vw+150px)] bg-black/60"></div> y="calc(50% - 150px)"
{/* Right overlay */} width="300"
<div className="absolute top-[calc(50vh-150px)] bottom-[calc(50vh-150px)] left-[calc(50vw+150px)] right-0 bg-black/60"></div> height="300"
rx="8"
{/* Centered square boundary box */} fill="black"
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[300px] h-[300px] border-2 border-white rounded-lg"></div> />
</div> </mask>
</defs>
<rect width="100%" height="100%" fill="rgba(0, 0, 0, 0.6)" mask="url(#qr-scanner-mask)" />
</svg>
{/* Centered square boundary box */}
<div className="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[300px] h-[300px] border-2 border-white rounded-lg pointer-events-none" style={{ zIndex: 20 }}></div>
{/* Error message */} {/* Error message */}
{qrError && ( {qrError && (
<div className="absolute top-20 left-4 right-4 p-3 bg-destructive text-destructive-foreground rounded z-50"> <div className="fixed top-20 left-4 right-4 p-3 bg-destructive text-destructive-foreground rounded" style={{ zIndex: 50 }}>
{qrError} {qrError}
</div> </div>
)} )}