Skip to content

Commit c544b99

Browse files
committed
fix: connect on every nwc request to ensure reconnect happens
1 parent d60a958 commit c544b99

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@getalby/sdk",
3-
"version": "3.2.1",
3+
"version": "3.2.2",
44
"description": "The SDK to integrate with Nostr Wallet Connect and the Alby API",
55
"repository": "https://github.com/getAlby/js-sdk.git",
66
"bugs": "https://github.com/getAlby/js-sdk/issues",

src/webln/NostrWeblnProvider.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
242242
}
243243

244244
async enable() {
245-
if (this.connected) {
246-
return Promise.resolve();
247-
}
248-
await this.relay.connect();
245+
return Promise.resolve();
249246
}
250247

251248
close() {
@@ -271,7 +268,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
271268
// WebLN compatible response
272269
// TODO: use NIP-47 get_info call
273270
async getInfo(): Promise<GetInfoResponse> {
274-
this.checkConnected();
271+
await this.checkConnected();
275272

276273
const supports = ["lightning", "nostr"];
277274
const version = "Alby JS SDK";
@@ -312,8 +309,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
312309
}
313310
}
314311

315-
getBalance() {
316-
this.checkConnected();
312+
async getBalance() {
313+
await this.checkConnected();
317314

318315
return this.executeNip47Request<GetBalanceResponse, { balance: number }>(
319316
"get_balance",
@@ -327,8 +324,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
327324
);
328325
}
329326

330-
sendPayment(invoice: string) {
331-
this.checkConnected();
327+
async sendPayment(invoice: string) {
328+
await this.checkConnected();
332329

333330
return this.executeNip47Request<SendPaymentResponse, Nip47PayResponse>(
334331
"pay_invoice",
@@ -340,8 +337,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
340337
);
341338
}
342339

343-
keysend(args: KeysendArgs) {
344-
this.checkConnected();
340+
async keysend(args: KeysendArgs) {
341+
await this.checkConnected();
345342

346343
return this.executeNip47Request<SendPaymentResponse, Nip47PayResponse>(
347344
"pay_keysend",
@@ -369,8 +366,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
369366
throw new Error("Method not implemented.");
370367
}
371368

372-
makeInvoice(args: string | number | RequestInvoiceArgs) {
373-
this.checkConnected();
369+
async makeInvoice(args: string | number | RequestInvoiceArgs) {
370+
await this.checkConnected();
374371

375372
const requestInvoiceArgs: RequestInvoiceArgs | undefined =
376373
typeof args === "object" ? (args as RequestInvoiceArgs) : undefined;
@@ -394,8 +391,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
394391
);
395392
}
396393

397-
lookupInvoice(args: LookupInvoiceArgs) {
398-
this.checkConnected();
394+
async lookupInvoice(args: LookupInvoiceArgs) {
395+
await this.checkConnected();
399396

400397
return this.executeNip47Request<LookupInvoiceResponse, Nip47Transaction>(
401398
"lookup_invoice",
@@ -412,8 +409,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
412409
);
413410
}
414411

415-
listTransactions(args: ListTransactionsArgs) {
416-
this.checkConnected();
412+
async listTransactions(args: ListTransactionsArgs) {
413+
await this.checkConnected();
417414

418415
// maybe we can tailor the response to our needs
419416
return this.executeNip47Request<
@@ -527,12 +524,11 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
527524
});
528525
}
529526

530-
private checkConnected() {
531-
if (!this.connected) {
532-
throw new Error(
533-
"please call enable() and await the promise before calling this function",
534-
);
527+
private async checkConnected() {
528+
if (!this.secret) {
529+
throw new Error("Missing secret key");
535530
}
531+
await this.relay.connect();
536532
}
537533

538534
private executeNip47Request<T, R>(

0 commit comments

Comments
 (0)