From b9b9ef63598dea610b4be58716ae01d53cae8837 Mon Sep 17 00:00:00 2001 From: highperfocused Date: Tue, 6 May 2025 18:12:20 +0200 Subject: [PATCH] fix: Add error handling for decoding bolt11 tags in ZapButton and ZapButtonListItem components --- components/ZapButton.tsx | 11 +++++++++-- components/ZapButtonListItem.tsx | 11 ++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/components/ZapButton.tsx b/components/ZapButton.tsx index 5cf58d2..8fa8bf9 100644 --- a/components/ZapButton.tsx +++ b/components/ZapButton.tsx @@ -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; + } } }); }); diff --git a/components/ZapButtonListItem.tsx b/components/ZapButtonListItem.tsx index 46ad4bd..95f5d54 100644 --- a/components/ZapButtonListItem.tsx +++ b/components/ZapButtonListItem.tsx @@ -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; + } } });