mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-06 00:37:23 +00:00
fixed npubx.cash payments
This commit is contained in:
1 parent
6d35028424
commit
7390dd6c19
1 file changed
+100
-9
@@ -79,21 +79,49 @@ export function useLightningAddress(): UseLightningAddressReturn {
|
|||||||
// Step 1: Fetch LNURL-pay info
|
// Step 1: Fetch LNURL-pay info
|
||||||
const lnurlEndpoint = `https://${domain}/.well-known/lnurlp/${username}`;
|
const lnurlEndpoint = `https://${domain}/.well-known/lnurlp/${username}`;
|
||||||
|
|
||||||
|
console.log('Resolving Lightning address:', {
|
||||||
|
lightningAddress,
|
||||||
|
lnurlEndpoint,
|
||||||
|
amountSats
|
||||||
|
});
|
||||||
|
|
||||||
const lnurlResponse = await fetch(lnurlEndpoint, {
|
const lnurlResponse = await fetch(lnurlEndpoint, {
|
||||||
headers: { 'Accept': 'application/json' },
|
headers: { 'Accept': 'application/json' },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!lnurlResponse.ok) {
|
if (!lnurlResponse.ok) {
|
||||||
throw new Error(`Failed to resolve Lightning address: ${lnurlResponse.status}`);
|
console.error('LNURL Endpoint Error:', {
|
||||||
|
lightningAddress,
|
||||||
|
lnurlEndpoint,
|
||||||
|
status: lnurlResponse.status,
|
||||||
|
statusText: lnurlResponse.statusText
|
||||||
|
});
|
||||||
|
throw new Error(`Failed to resolve Lightning address: ${lnurlResponse.status} ${lnurlResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const lnurlData: LNURLPayResponse = await lnurlResponse.json();
|
const lnurlData: LNURLPayResponse = await lnurlResponse.json();
|
||||||
|
|
||||||
if (lnurlData.status !== 'OK') {
|
console.log('LNURL Response:', {
|
||||||
|
lightningAddress,
|
||||||
|
lnurlData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (lnurlData.status && lnurlData.status !== 'OK') {
|
||||||
|
console.error('LNURL Status Error:', {
|
||||||
|
lightningAddress,
|
||||||
|
status: lnurlData.status,
|
||||||
|
response: lnurlData
|
||||||
|
});
|
||||||
throw new Error('LNURL endpoint returned error status');
|
throw new Error('LNURL endpoint returned error status');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lnurlData.tag !== 'payRequest') {
|
if (lnurlData.tag !== 'payRequest') {
|
||||||
|
console.error('LNURL Tag Error:', {
|
||||||
|
lightningAddress,
|
||||||
|
expectedTag: 'payRequest',
|
||||||
|
actualTag: lnurlData.tag,
|
||||||
|
response: lnurlData
|
||||||
|
});
|
||||||
throw new Error(`Unexpected LNURL tag: ${lnurlData.tag}`);
|
throw new Error(`Unexpected LNURL tag: ${lnurlData.tag}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,11 +129,32 @@ export function useLightningAddress(): UseLightningAddressReturn {
|
|||||||
const minSats = lnurlData.minSendable / 1000;
|
const minSats = lnurlData.minSendable / 1000;
|
||||||
const maxSats = lnurlData.maxSendable / 1000;
|
const maxSats = lnurlData.maxSendable / 1000;
|
||||||
|
|
||||||
|
console.log('Amount validation:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
minSats,
|
||||||
|
maxSats,
|
||||||
|
minSendable: lnurlData.minSendable,
|
||||||
|
maxSendable: lnurlData.maxSendable
|
||||||
|
});
|
||||||
|
|
||||||
if (amountSats < minSats) {
|
if (amountSats < minSats) {
|
||||||
|
console.error('Amount below minimum:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
minSats,
|
||||||
|
maxSats
|
||||||
|
});
|
||||||
throw new Error(`Amount ${amountSats} sats is below minimum ${minSats} sats`);
|
throw new Error(`Amount ${amountSats} sats is below minimum ${minSats} sats`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amountSats > maxSats) {
|
if (amountSats > maxSats) {
|
||||||
|
console.error('Amount exceeds maximum:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
minSats,
|
||||||
|
maxSats
|
||||||
|
});
|
||||||
throw new Error(`Amount ${amountSats} sats exceeds maximum ${maxSats} sats`);
|
throw new Error(`Amount ${amountSats} sats exceeds maximum ${maxSats} sats`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,26 +168,68 @@ export function useLightningAddress(): UseLightningAddressReturn {
|
|||||||
callbackUrl.searchParams.set('comment', comment);
|
callbackUrl.searchParams.set('comment', comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('Requesting invoice:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
amountMsats,
|
||||||
|
callbackUrl: callbackUrl.toString(),
|
||||||
|
comment
|
||||||
|
});
|
||||||
|
|
||||||
const invoiceResponse = await fetch(callbackUrl.toString(), {
|
const invoiceResponse = await fetch(callbackUrl.toString(), {
|
||||||
headers: { 'Accept': 'application/json' },
|
headers: { 'Accept': 'application/json' },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!invoiceResponse.ok) {
|
if (!invoiceResponse.ok) {
|
||||||
throw new Error(`Failed to get invoice: ${invoiceResponse.status}`);
|
console.error('Invoice Request Error:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
callbackUrl: callbackUrl.toString(),
|
||||||
|
status: invoiceResponse.status,
|
||||||
|
statusText: invoiceResponse.statusText
|
||||||
|
});
|
||||||
|
throw new Error(`Failed to get invoice: ${invoiceResponse.status} ${invoiceResponse.statusText}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoiceData: LNURLInvoiceResponse = await invoiceResponse.json();
|
const invoiceData: LNURLInvoiceResponse = await invoiceResponse.json();
|
||||||
|
|
||||||
if (invoiceData.status !== 'OK') {
|
console.log('Invoice Response:', {
|
||||||
throw new Error(invoiceData.reason || 'Invoice generation failed');
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
invoiceData
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if we have a valid invoice (some providers return invoice directly without status field)
|
||||||
|
if (invoiceData.pr) {
|
||||||
|
console.log('Invoice generated successfully:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
invoiceLength: invoiceData.pr.length
|
||||||
|
});
|
||||||
|
setIsLoading(false);
|
||||||
|
return invoiceData.pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!invoiceData.pr) {
|
// If no invoice but has status field, check for errors
|
||||||
throw new Error('No invoice returned from provider');
|
if (invoiceData.status && invoiceData.status !== 'OK') {
|
||||||
|
const errorReason = invoiceData.reason || 'Invoice generation failed';
|
||||||
|
console.error('LNURL Invoice Error:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
status: invoiceData.status,
|
||||||
|
reason: errorReason,
|
||||||
|
response: invoiceData
|
||||||
|
});
|
||||||
|
throw new Error(`Invoice generation failed: ${errorReason}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(false);
|
// If we get here, no invoice was provided
|
||||||
return invoiceData.pr;
|
console.error('LNURL Invoice Missing PR:', {
|
||||||
|
lightningAddress,
|
||||||
|
amountSats,
|
||||||
|
response: invoiceData
|
||||||
|
});
|
||||||
|
throw new Error('No invoice returned from provider');
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
||||||
|
|||||||
Reference in new issue
Block a user