From c8620015ab1f1fddc94ef3e127787c9f3adcead0 Mon Sep 17 00:00:00 2001 From: mroxso <24775431+mroxso@users.noreply.github.com> Date: Sun, 27 Apr 2025 22:31:47 +0200 Subject: [PATCH] Fix: Enhance pubkey extraction logic in ZapButtonListItem component (#103) Co-authored-by: highperfocused --- components/ZapButtonListItem.tsx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/components/ZapButtonListItem.tsx b/components/ZapButtonListItem.tsx index 854d6d7..46ad4bd 100644 --- a/components/ZapButtonListItem.tsx +++ b/components/ZapButtonListItem.tsx @@ -13,10 +13,27 @@ import { Avatar, AvatarImage } from "@/components/ui/avatar"; export default function ZapButtonListItem({ event }: { event: NostrEvent }) { let pubkey = event.pubkey; - for(let i = 0; i < event.tags.length; i++) { - if(event.tags[i][0] === 'P') { - pubkey = event.tags[i][1]; - break; + + // Try to extract pubkey from description tag if available + const descriptionTag = event.tags.find(tag => tag[0] === 'description'); + if (descriptionTag && descriptionTag[1]) { + try { + const descriptionEvent = JSON.parse(descriptionTag[1]); + if (descriptionEvent.pubkey) { + pubkey = descriptionEvent.pubkey; + } + } catch (e) { + console.error('Failed to parse description tag:', e); + } + } + + // Fallback to 'p' tag if description doesn't have a pubkey + if (pubkey === event.pubkey) { + for(let i = 0; i < event.tags.length; i++) { + if(event.tags[i][0] === 'P' || event.tags[i][0] === 'p') { + pubkey = event.tags[i][1]; + break; + } } }