problem: some zap providers don't implement the API properly

This commit is contained in:
gsovereignty
2024-08-17 21:24:50 +08:00
parent 4ada91cb4b
commit 85db532e6a
3 changed files with 25 additions and 12 deletions

View File

@@ -3,6 +3,7 @@
import { Product, Rocket, ValidateZapPublisher, ZapPurchase } from '@/event_helpers/rockets'; import { Product, Rocket, ValidateZapPublisher, ZapPurchase } from '@/event_helpers/rockets';
import { unixToRelativeTime } from '@/helpers'; import { unixToRelativeTime } from '@/helpers';
import { ndk } from '@/ndk'; import { ndk } from '@/ndk';
import { currentUser } from '@/stores/session';
import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components'; import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components';
import { onDestroy } from 'svelte'; import { onDestroy } from 'svelte';
import { derived, writable } from 'svelte/store'; import { derived, writable } from 'svelte/store';
@@ -61,14 +62,22 @@
zapsNotInRocket.subscribe((z) => { zapsNotInRocket.subscribe((z) => {
z.forEach((z) => { z.forEach((z) => {
ValidateZapPublisher(rocket.Event, z.ZapReceipt).then((result) => { ValidateZapPublisher(rocket.Event, z.ZapReceipt)
if (result) { .then((result) => {
validPubkeys.update((existing) => { if (result) {
existing.add(z.ZapReceipt.pubkey); validPubkeys.update((existing) => {
return 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).'
);
}
});
}); });
}); });

View File

@@ -747,7 +747,7 @@ export async function ValidateZapPublisher(rocket: NDKEvent, zap: NDKEvent): Pro
reject(); reject();
} }
}) })
.catch(reject); .catch((e) => reject(e));
// let z = new NDKZap({ ndk: rocket.ndk!, zappedEvent: rocket, zappedUser: rocket.author }); // let z = new NDKZap({ ndk: rocket.ndk!, zappedEvent: rocket, zappedUser: rocket.author });
// z.getZapEndpoint().then(x=>{ // z.getZapEndpoint().then(x=>{
// console.log(x) // console.log(x)

View File

@@ -163,6 +163,7 @@ export async function getAuthorizedZapper(rocket: NDKEvent): Promise<string> {
z.getZapEndpoint() z.getZapEndpoint()
.then((url) => { .then((url) => {
if (url) { if (url) {
console.log(url);
url = url.trim().replace('/callback', ''); url = url.trim().replace('/callback', '');
fetch(url).then((result) => { fetch(url).then((result) => {
result result
@@ -170,13 +171,16 @@ export async function getAuthorizedZapper(rocket: NDKEvent): Promise<string> {
.then((j) => { .then((j) => {
resolve(j.nostrPubkey); resolve(j.nostrPubkey);
}) })
.catch(reject); .catch((e) => reject(e));
}); });
} else { } else {
reject(); reject({
reason: 'could not get zap endpoint for ' + z.zappedUser.pubkey,
pubkey: z.zappedUser.pubkey
});
} }
}) })
.catch(reject); .catch((e) => reject(e));
}); });
} }