diff --git a/src/hooks/useQRCode.ts b/src/hooks/useQRCode.ts index b379cb9..e5482b6 100644 --- a/src/hooks/useQRCode.ts +++ b/src/hooks/useQRCode.ts @@ -71,18 +71,20 @@ export function useQRCode(): UseQRCodeReturn { }, [toast]); const classifyQRCode = useCallback((decodedText: string): QRScanResult => { - // Lightning invoice: lnbc... (case insensitive) - if (/^lnbc[a-z0-9]+$/i.test(decodedText)) { - return { type: 'lightning_invoice', value: decodedText }; + // Lightning invoice: lnbc... or lightning:lnbc... (case insensitive) + const lightningInvoiceMatch = decodedText.match(/^(?:lightning:)?(lnbc[a-z0-9]+)$/i); + if (lightningInvoiceMatch) { + return { type: 'lightning_invoice', value: lightningInvoiceMatch[1] }; } - // Lightning address: name@domain.tld - if (/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(decodedText)) { - return { type: 'lightning_address', value: decodedText }; + // Lightning address: name@domain.tld or lightning:name@domain.tld + const lightningAddressMatch = decodedText.match(/^(?:lightning:)?([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/); + if (lightningAddressMatch) { + return { type: 'lightning_address', value: lightningAddressMatch[1] }; } // Cashu token: cashu... - if (/^cashu[A-Za-z0-9+/=]+$/.test(decodedText)) { + if (/^cashu[A-Za-z0-9+/=-]+$/.test(decodedText)) { return { type: 'cashu_token', value: decodedText }; } @@ -91,9 +93,10 @@ export function useQRCode(): UseQRCodeReturn { return { type: 'bitcoin_address', value: decodedText }; } - // Nostr npub: npub1... - if (/^npub1[a-z0-9]{58}$/.test(decodedText)) { - return { type: 'npub', value: decodedText }; + // Nostr npub: npub1... or nostr:npub1... + const npubMatch = decodedText.match(/^(?:nostr:)?(npub1[a-z0-9]{58})$/); + if (npubMatch) { + return { type: 'npub', value: npubMatch[1] }; } return { type: 'unknown', value: decodedText };