Files
hypergolic/src/lib/event_helpers/products.ts
2024-08-04 16:34:37 +08:00

24 lines
692 B
TypeScript

import type { NDKEvent } from "@nostr-dev-kit/ndk";
import type NDKSvelte from "@nostr-dev-kit/ndk-svelte";
export async function fetchEvent(id:string, ndk:NDKSvelte):Promise<NDKEvent> {
return new Promise((resolve)=>{
ndk.fetchEvent(id).then((e) => {
if (e) {
resolve(e)
} else {
let _p = ndk.storeSubscribe([{ ids: [id] }], { subId: id, closeOnEose: true });
_p.subscribe((x) => {
if (x[0]) {
let e = x[0]
_p.unsubscribe();
resolve(e)
}
});
}
});
})
}