mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +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]);
|
||||
|
||||
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: [email protected]
|
||||
if (/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(decodedText)) {
|
||||
return { type: 'lightning_address', value: decodedText };
|
||||
// Lightning address: [email protected] or lightning:[email protected]
|
||||
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 };
|
||||
|
||||
Reference in new issue
Block a user