mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
add code prefix
This commit is contained in:
1 parent
1b285ff53f
commit
fde64074ed
1 file changed
+13
-10
+13
-10
@@ -71,18 +71,20 @@ export function useQRCode(): UseQRCodeReturn {
|
|||||||
}, [toast]);
|
}, [toast]);
|
||||||
|
|
||||||
const classifyQRCode = useCallback((decodedText: string): QRScanResult => {
|
const classifyQRCode = useCallback((decodedText: string): QRScanResult => {
|
||||||
// Lightning invoice: lnbc... (case insensitive)
|
// Lightning invoice: lnbc... or lightning:lnbc... (case insensitive)
|
||||||
if (/^lnbc[a-z0-9]+$/i.test(decodedText)) {
|
const lightningInvoiceMatch = decodedText.match(/^(?:lightning:)?(lnbc[a-z0-9]+)$/i);
|
||||||
return { type: 'lightning_invoice', value: decodedText };
|
if (lightningInvoiceMatch) {
|
||||||
|
return { type: 'lightning_invoice', value: lightningInvoiceMatch[1] };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lightning address: [email protected]
|
// Lightning address: [email protected] or lightning:[email protected]
|
||||||
if (/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(decodedText)) {
|
const lightningAddressMatch = decodedText.match(/^(?:lightning:)?([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/);
|
||||||
return { type: 'lightning_address', value: decodedText };
|
if (lightningAddressMatch) {
|
||||||
|
return { type: 'lightning_address', value: lightningAddressMatch[1] };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cashu token: cashu...
|
// 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 };
|
return { type: 'cashu_token', value: decodedText };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,9 +93,10 @@ export function useQRCode(): UseQRCodeReturn {
|
|||||||
return { type: 'bitcoin_address', value: decodedText };
|
return { type: 'bitcoin_address', value: decodedText };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nostr npub: npub1...
|
// Nostr npub: npub1... or nostr:npub1...
|
||||||
if (/^npub1[a-z0-9]{58}$/.test(decodedText)) {
|
const npubMatch = decodedText.match(/^(?:nostr:)?(npub1[a-z0-9]{58})$/);
|
||||||
return { type: 'npub', value: decodedText };
|
if (npubMatch) {
|
||||||
|
return { type: 'npub', value: npubMatch[1] };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { type: 'unknown', value: decodedText };
|
return { type: 'unknown', value: decodedText };
|
||||||
|
|||||||
Reference in new issue
Block a user