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; }