From 4620813645851cf437248596369c375d8ea0269d Mon Sep 17 00:00:00 2001 From: im-adithya Date: Thu, 19 Oct 2023 14:08:17 +0530 Subject: [PATCH] fix: use latest webln if available in globalThis after init --- src/lightning-address.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lightning-address.ts b/src/lightning-address.ts index a6503fe..49fc8a2 100644 --- a/src/lightning-address.ts +++ b/src/lightning-address.ts @@ -54,6 +54,10 @@ export default class LightningAddress { } } + getWebLN() { + return this.webln || globalThis.webln + } + async fetch() { if (this.options.proxy) { return this.fetchWithProxy(); @@ -186,7 +190,7 @@ export default class LightningAddress { boost, }, { - webln: this.webln, + webln: this.getWebLN(), }, ); } @@ -233,12 +237,13 @@ export default class LightningAddress { options: ZapOptions = {}, ): Promise { const invoice = this.zapInvoice(args, options); - if (!this.webln) { + const webln = this.getWebLN() + if (!webln) { // mainly for TS throw new Error("WebLN not available"); } - await this.webln.enable(); - const response = this.webln.sendPayment((await invoice).paymentRequest); + await webln.enable(); + const response = webln.sendPayment((await invoice).paymentRequest); return response; }