Skip to content

Commit

Permalink
fix: use latest webln if available in globalThis after init
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Oct 19, 2023
1 parent 9662648 commit 4620813
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lightning-address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default class LightningAddress {
}
}

getWebLN() {
return this.webln || globalThis.webln
}

async fetch() {
if (this.options.proxy) {
return this.fetchWithProxy();
Expand Down Expand Up @@ -186,7 +190,7 @@ export default class LightningAddress {
boost,
},
{
webln: this.webln,
webln: this.getWebLN(),
},
);
}
Expand Down Expand Up @@ -233,12 +237,13 @@ export default class LightningAddress {
options: ZapOptions = {},
): Promise<SendPaymentResponse> {
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;
}

Expand Down

0 comments on commit 4620813

Please sign in to comment.