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.
This commit is contained in:
parent
3c832e2706
commit
ab3a8ab296
1 changed files with 30 additions and 2 deletions
|
|
@ -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
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue