From 85db532e6a4c0e1c03ebf971aadae56639c81f80 Mon Sep 17 00:00:00 2001 From: gsovereignty Date: Sat, 17 Aug 2024 21:24:50 +0800 Subject: [PATCH] problem: some zap providers don't implement the API properly --- src/components/ProductPurchases.svelte | 25 +++++++++++++++++-------- src/lib/event_helpers/rockets.ts | 2 +- src/lib/helpers.ts | 10 +++++++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/components/ProductPurchases.svelte b/src/components/ProductPurchases.svelte index b756adb..6f2410b 100644 --- a/src/components/ProductPurchases.svelte +++ b/src/components/ProductPurchases.svelte @@ -3,6 +3,7 @@ import { Product, Rocket, ValidateZapPublisher, ZapPurchase } from '@/event_helpers/rockets'; import { unixToRelativeTime } from '@/helpers'; import { ndk } from '@/ndk'; + import { currentUser } from '@/stores/session'; import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components'; import { onDestroy } from 'svelte'; import { derived, writable } from 'svelte/store'; @@ -61,14 +62,22 @@ zapsNotInRocket.subscribe((z) => { z.forEach((z) => { - ValidateZapPublisher(rocket.Event, z.ZapReceipt).then((result) => { - if (result) { - validPubkeys.update((existing) => { - existing.add(z.ZapReceipt.pubkey); - return existing; - }); - } - }); + ValidateZapPublisher(rocket.Event, z.ZapReceipt) + .then((result) => { + if (result) { + validPubkeys.update((existing) => { + existing.add(z.ZapReceipt.pubkey); + return existing; + }); + } + }) + .catch((e) => { + if (e.pubkey && $currentUser && e.pubkey == $currentUser.pubkey) { + alert( + 'Nostrocket could not validate that the zap receipts published on your behalf are legitimate, this usually means we could not query your lightning service provider API. Consider switching to a lightning service provider that is known to work (e.g. getAlby).' + ); + } + }); }); }); diff --git a/src/lib/event_helpers/rockets.ts b/src/lib/event_helpers/rockets.ts index eda7879..0d4671d 100644 --- a/src/lib/event_helpers/rockets.ts +++ b/src/lib/event_helpers/rockets.ts @@ -747,7 +747,7 @@ export async function ValidateZapPublisher(rocket: NDKEvent, zap: NDKEvent): Pro reject(); } }) - .catch(reject); + .catch((e) => reject(e)); // let z = new NDKZap({ ndk: rocket.ndk!, zappedEvent: rocket, zappedUser: rocket.author }); // z.getZapEndpoint().then(x=>{ // console.log(x) diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 08be4ca..73f9b64 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -163,6 +163,7 @@ export async function getAuthorizedZapper(rocket: NDKEvent): Promise { z.getZapEndpoint() .then((url) => { if (url) { + console.log(url); url = url.trim().replace('/callback', ''); fetch(url).then((result) => { result @@ -170,13 +171,16 @@ export async function getAuthorizedZapper(rocket: NDKEvent): Promise { .then((j) => { resolve(j.nostrPubkey); }) - .catch(reject); + .catch((e) => reject(e)); }); } else { - reject(); + reject({ + reason: 'could not get zap endpoint for ' + z.zappedUser.pubkey, + pubkey: z.zappedUser.pubkey + }); } }) - .catch(reject); + .catch((e) => reject(e)); }); }