NBunker: add waitReady property

This commit is contained in:
Alex Gleason 2024-10-29 15:44:36 -05:00
parent cfd4908e8d
commit 9faf9942a9
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 13 additions and 1 deletions

View File

@ -37,6 +37,8 @@ function logInNostr(signer: NostrSigner, relay: NRelay1) {
}, },
}); });
await bunker.waitReady;
const token = await dispatch(obtainOAuthToken({ const token = await dispatch(obtainOAuthToken({
grant_type: 'nostr_bunker', grant_type: 'nostr_bunker',
pubkey: bunkerPubkey, pubkey: bunkerPubkey,

View File

@ -58,7 +58,14 @@ export class NBunker {
private controller = new AbortController(); private controller = new AbortController();
private authorizedPubkeys = new Set<string>(); private authorizedPubkeys = new Set<string>();
/** Wait for the bunker to be ready before sending requests. */
public waitReady: Promise<void>;
private setReady!: () => void;
constructor(private opts: NBunkerOpts) { constructor(private opts: NBunkerOpts) {
this.waitReady = new Promise((resolve) => {
this.setReady = resolve;
});
this.open(); this.open();
} }
@ -73,7 +80,10 @@ export class NBunker {
{ kinds: [24133], '#p': [bunkerPubkey], limit: 0 }, { kinds: [24133], '#p': [bunkerPubkey], limit: 0 },
]; ];
for await (const msg of relay.req(filters, { signal })) { const sub = relay.req(filters, { signal });
this.setReady();
for await (const msg of sub) {
if (msg[0] === 'EVENT') { if (msg[0] === 'EVENT') {
const [,, event] = msg; const [,, event] = msg;