From d30be10568ecdc3d99b3d70fe0d9d372dfe56d41 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 24 Jul 2023 10:12:39 +0700 Subject: [PATCH] fix zap --- src/utils/hooks/usePublish.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/hooks/usePublish.tsx b/src/utils/hooks/usePublish.tsx index d9daf3d6..7a758c18 100644 --- a/src/utils/hooks/usePublish.tsx +++ b/src/utils/hooks/usePublish.tsx @@ -39,15 +39,20 @@ export function usePublish() { return event; }; - const createZap = async (event: NostrEvent, amount: number) => { - if (!privkey) throw new Error('Private key not found'); + const createZap = async (event: NostrEvent, amount: number, message?: string) => { + // @ts-expect-error, lumeevent to nostrevent + event.id = event.event_id; + // @ts-expect-error, lumeevent to nostrevent + if (typeof event.content !== 'string') event.content = event.content.original; if (typeof event.tags === 'string') event.tags = destr(event.tags); - - const signer = new NDKPrivateKeySigner(privkey); - ndk.signer = signer; + if (!privkey) throw new Error('Private key not found'); + if (!ndk.signer) { + const signer = new NDKPrivateKeySigner(privkey); + ndk.signer = signer; + } const ndkEvent = new NDKEvent(ndk, event); - const res = await ndkEvent.zap(amount, 'test zap from lume'); + const res = await ndkEvent.zap(amount, message ?? 'test zap from lume'); return res; };