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
42d16908e1
commit
0b98b29198
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) {
|
function parsePaymentDestination(destination: string) {
|
||||||
// Clear previous parsing results
|
// Clear previous parsing results
|
||||||
parsedInvoice.value = null
|
parsedInvoice.value = null
|
||||||
|
|
@ -101,7 +125,8 @@ function parsePaymentDestination(destination: string) {
|
||||||
|
|
||||||
if (!destination.trim()) return
|
if (!destination.trim()) return
|
||||||
|
|
||||||
const cleanDest = destination.trim()
|
// Normalize the destination by stripping URI prefixes
|
||||||
|
const cleanDest = normalizePaymentRequest(destination)
|
||||||
|
|
||||||
if (isBolt11(cleanDest)) {
|
if (isBolt11(cleanDest)) {
|
||||||
paymentType.value = 'bolt11'
|
paymentType.value = 'bolt11'
|
||||||
|
|
@ -198,8 +223,11 @@ const effectiveAmount = computed(() => {
|
||||||
// Methods
|
// Methods
|
||||||
const onSubmit = form.handleSubmit(async (formValues) => {
|
const onSubmit = form.handleSubmit(async (formValues) => {
|
||||||
try {
|
try {
|
||||||
|
// Use normalized destination (stripped of URI prefixes)
|
||||||
|
const normalizedDestination = normalizePaymentRequest(formValues.destination)
|
||||||
|
|
||||||
const success = await walletService.sendPayment({
|
const success = await walletService.sendPayment({
|
||||||
destination: formValues.destination,
|
destination: normalizedDestination,
|
||||||
amount: effectiveAmount.value, // Use computed effective amount
|
amount: effectiveAmount.value, // Use computed effective amount
|
||||||
comment: formValues.comment || undefined
|
comment: formValues.comment || undefined
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue