From 1923273f6f24c804122acd10c06bd3a1ed53bf40 Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 8 May 2023 15:48:42 +0100 Subject: [PATCH] bug: handle nwc reply --- packages/app/src/Wallet/NostrWalletConnect.ts | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/app/src/Wallet/NostrWalletConnect.ts b/packages/app/src/Wallet/NostrWalletConnect.ts index f561bffa..e53696b6 100644 --- a/packages/app/src/Wallet/NostrWalletConnect.ts +++ b/packages/app/src/Wallet/NostrWalletConnect.ts @@ -117,9 +117,9 @@ export class NostrConnectWallet implements LNWallet { throw new WalletError(WalletErrorCode.GeneralError, "No pending command found"); } - const body = JSON.parse(await EventExt.decryptData(e.content, this.#config.secret, this.#config.walletPubkey)); - pending.resolve(body); + pending.resolve(e.content); this.#commandQueue.delete(replyTo[1]); + this.#conn?.CloseReq(sub); } async #rpc(method: string, params: Record) { @@ -135,12 +135,30 @@ export class NostrConnectWallet implements LNWallet { .tag(["p", this.#config.walletPubkey]); const evCommand = await eb.buildAndSign(this.#config.secret); + this.#conn.QueueReq( + [ + "REQ", + evCommand.id.slice(0, 12), + { + kinds: [23195], + authors: [this.#config.walletPubkey], + ["#e"]: [evCommand.id], + }, + ], + () => { + // ignored + } + ); await this.#conn.SendAsync(evCommand); - /*return await new Promise((resolve, reject) => { - this.#commandQueue.set(evCommand.id, { - resolve, reject - }) - })*/ - return {} as T; + return await new Promise((resolve, reject) => { + this.#commandQueue.set(evCommand.id, { + resolve: async (o: string) => { + const reply = JSON.parse(await EventExt.decryptData(o, this.#config.secret, this.#config.walletPubkey)); + console.debug("NWC", reply); + resolve(reply); + }, + reject, + }); + }); } }