problem: we are querying zap providers too often

This commit is contained in:
gsovereignty
2024-08-18 00:00:47 +08:00
parent 197ba82c0c
commit ea0ea6777b
4 changed files with 24 additions and 16 deletions

View File

@@ -72,7 +72,7 @@
}
})
.catch((e) => {
if (e.pubkey && $currentUser && e.pubkey == $currentUser.pubkey) {
if (e && 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

@@ -6,6 +6,8 @@ import { sha256 } from 'js-sha256';
import { MapOfVotes, MeritRequest, Votes } from './merits';
import * as immutable from 'immutable';
import { BloomFilter } from 'bloomfilter';
import { zappers } from '@/stores/zappers';
import { get } from 'svelte/store';
export class Rocket {
Event: NDKEvent;
@@ -739,20 +741,24 @@ export function RocketATagFilter(rocket: NDKEvent): string {
export async function ValidateZapPublisher(rocket: NDKEvent, zap: NDKEvent): Promise<boolean> {
return new Promise((resolve, reject) => {
getAuthorizedZapper(rocket)
.then((pubkey) => {
if (pubkey == zap.pubkey) {
resolve(true);
} else {
reject();
}
})
.catch((e) => reject(e));
// let z = new NDKZap({ ndk: rocket.ndk!, zappedEvent: rocket, zappedUser: rocket.author });
// z.getZapEndpoint().then(x=>{
// console.log(x)
// resolve(true)
// }).catch(()=>{reject(false)})
let zapper = get(zappers).get(rocket.pubkey);
if (zapper && zapper == zap.pubkey) {
resolve(true);
} else {
getAuthorizedZapper(rocket)
.then((pubkey) => {
if (pubkey == zap.pubkey) {
zappers.update((existing) => {
existing.set(rocket.pubkey, pubkey);
return existing;
});
resolve(true);
} else {
reject();
}
})
.catch((e) => reject(e));
}
});
}

View File

@@ -163,7 +163,6 @@ export async function getAuthorizedZapper(rocket: NDKEvent): Promise<string> {
z.getZapEndpoint()
.then((url) => {
if (url) {
console.log(url);
url = url.trim().replace('/callback', '');
fetch(url).then((result) => {
result

View File

@@ -0,0 +1,3 @@
import { writable } from 'svelte/store';
export let zappers = writable(new Map<string, string>());