From 0b98b29198e80ba6ebc26b511508c8cd03145ddd Mon Sep 17 00:00:00 2001 From: padreug Date: Thu, 18 Sep 2025 22:54:46 +0200 Subject: [PATCH] Implement payment request normalization in SendDialog - Added a new function to normalize payment requests by stripping URI prefixes (lightning: and lnurl:) and handling BIP-21 Bitcoin URIs with Lightning fallback. - Updated the destination parsing logic to utilize the normalization function, ensuring consistent handling of various payment formats. - Enhanced the payment submission process by using the normalized destination for sending payments. These changes improve the robustness of payment handling in the SendDialog, providing better support for different payment request formats. --- src/modules/wallet/components/SendDialog.vue | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/modules/wallet/components/SendDialog.vue b/src/modules/wallet/components/SendDialog.vue index 20631e3..b963988 100644 --- a/src/modules/wallet/components/SendDialog.vue +++ b/src/modules/wallet/components/SendDialog.vue @@ -93,6 +93,30 @@ function parseBolt11Invoice(bolt11: string): ParsedInvoice | null { } } +function normalizePaymentRequest(request: string): string { + let normalized = request.trim() + const req = normalized.toLowerCase() + + // Handle Lightning URI prefix stripping (following LNbits implementation) + if (req.startsWith('lightning:')) { + normalized = normalized.slice(10) // Remove "lightning:" (10 chars) + } else if (req.startsWith('lnurl:')) { + normalized = normalized.slice(6) // Remove "lnurl:" (6 chars) + } else if (req.includes('lightning=lnurl1')) { + // Extract LNURL from lightning parameter + normalized = normalized.split('lightning=')[1].split('&')[0] + } else if (req.includes('lightning=')) { + // Handle BIP-21 Bitcoin URIs with Lightning fallback + normalized = normalized.split('lightning=')[1] + // Remove any additional query parameters + if (normalized.includes('&')) { + normalized = normalized.split('&')[0] + } + } + + return normalized.trim() +} + function parsePaymentDestination(destination: string) { // Clear previous parsing results parsedInvoice.value = null @@ -101,7 +125,8 @@ function parsePaymentDestination(destination: string) { if (!destination.trim()) return - const cleanDest = destination.trim() + // Normalize the destination by stripping URI prefixes + const cleanDest = normalizePaymentRequest(destination) if (isBolt11(cleanDest)) { paymentType.value = 'bolt11' @@ -198,8 +223,11 @@ const effectiveAmount = computed(() => { // Methods const onSubmit = form.handleSubmit(async (formValues) => { try { + // Use normalized destination (stripped of URI prefixes) + const normalizedDestination = normalizePaymentRequest(formValues.destination) + const success = await walletService.sendPayment({ - destination: formValues.destination, + destination: normalizedDestination, amount: effectiveAmount.value, // Use computed effective amount comment: formValues.comment || undefined })