fix: Add error handling for decoding bolt11 tags in ZapButton and ZapButtonListItem components

This commit is contained in:
2025-05-06 18:12:20 +02:00
parent 524c7855a2
commit b9b9ef6359
2 changed files with 17 additions and 5 deletions

View File

@@ -126,8 +126,15 @@ export default function ZapButton({ event }: { event: any }) {
events.forEach((event) => {
event.tags.forEach((tag) => {
if (tag[0] === 'bolt11') {
let decoded = lightningPayReq.decode(tag[1]);
sats = sats + decoded.satoshis;
try {
lightningPayReq.decode(tag[1]);
let decoded = lightningPayReq.decode(tag[1]);
sats = sats + decoded.satoshis;
} catch (e) {
console.error("Error decoding bolt11 tag:", e);
console.log(tag[1]);
return null;
}
}
});
});

View File

@@ -49,9 +49,14 @@ export default function ZapButtonListItem({ event }: { event: NostrEvent }) {
var lightningPayReq = require('bolt11');
event.tags.forEach((tag) => {
if (tag[0] === 'bolt11') {
let decoded = lightningPayReq.decode(tag[1]);
// console.log(decoded.satoshis);
sats = decoded.satoshis;
try {
let decoded = lightningPayReq.decode(tag[1]);
// console.log(decoded.satoshis);
sats = decoded.satoshis;
} catch (e) {
console.error("Error decoding bolt11 tag:", e);
return null;
}
}
});