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 { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance';
import { useNsecAccess } from '@/hooks/useNsecAccess';
import { decodeBolt11Amount } from '@/lib/bolt11Decoder';
import { nostrPubkeyToBitcoinAddress } from '@/lib/bitcoin';
import { QRModal } from '@/components/ui/qr-modal';
import { WalletHeader } from './WalletHeader';
@@ -367,11 +368,12 @@ export function CashuWallet() {
setLightningInvoice(result.value);
setPendingInvoice(result.value);
// Decode invoice amount
setDecodedInvoiceAmount(100); // Placeholder - would need actual decoding
const amount = decodeBolt11Amount(result.value);
setDecodedInvoiceAmount(amount);
setShowSendModal(true);
toast({
title: "Lightning Invoice Scanned",
description: "Invoice ready to pay",
description: amount ? `${amount} sats` : "Invoice ready to pay",
});
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 {
mode: 'tokens' | 'lightning' | 'bitcoin';
operation: 'send' | 'receive';
@@ -180,7 +186,7 @@ export function TransactionCard({
<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="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>
<button
onClick={() => {
@@ -215,7 +221,7 @@ export function TransactionCard({
<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="font-bold text-primary">Sending:</span>{' '}
<span className="font-semibold text-foreground">{pendingLightningAddress}</span>
<span className="font-semibold text-foreground">{truncateAddress(pendingLightningAddress)}</span>
</span>
<button
onClick={() => {
+23 -17
View File
@@ -492,30 +492,36 @@ export function WalletModals({
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 */}
<div className="absolute inset-0">
<div className="fixed inset-0">
<div id="qr-reader" className="w-full h-full"></div>
</div>
{/* Dark overlay with centered square cutout */}
<div className="absolute inset-0 pointer-events-none">
{/* Top overlay */}
<div className="absolute top-0 left-0 right-0 h-[calc(50vh-150px)] bg-black/60"></div>
{/* Bottom overlay */}
<div className="absolute bottom-0 left-0 right-0 h-[calc(50vh-150px)] bg-black/60"></div>
{/* Left overlay */}
<div className="absolute top-[calc(50vh-150px)] bottom-[calc(50vh-150px)] left-0 right-[calc(50vw+150px)] bg-black/60"></div>
{/* Right overlay */}
<div className="absolute top-[calc(50vh-150px)] bottom-[calc(50vh-150px)] left-[calc(50vw+150px)] right-0 bg-black/60"></div>
{/* Centered square boundary box */}
<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>
{/* Dark overlay with centered square cutout using SVG mask */}
<svg className="fixed inset-0 w-full h-full pointer-events-none" style={{ zIndex: 10 }}>
<defs>
<mask id="qr-scanner-mask">
<rect width="100%" height="100%" fill="white" />
<rect
x="calc(50% - 150px)"
y="calc(50% - 150px)"
width="300"
height="300"
rx="8"
fill="black"
/>
</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 */}
{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}
</div>
)}