@@ -242,10 +242,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
242
242
}
243
243
244
244
async enable ( ) {
245
- if ( this . connected ) {
246
- return Promise . resolve ( ) ;
247
- }
248
- await this . relay . connect ( ) ;
245
+ return Promise . resolve ( ) ;
249
246
}
250
247
251
248
close ( ) {
@@ -271,7 +268,7 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
271
268
// WebLN compatible response
272
269
// TODO: use NIP-47 get_info call
273
270
async getInfo ( ) : Promise < GetInfoResponse > {
274
- this . checkConnected ( ) ;
271
+ await this . checkConnected ( ) ;
275
272
276
273
const supports = [ "lightning" , "nostr" ] ;
277
274
const version = "Alby JS SDK" ;
@@ -312,8 +309,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
312
309
}
313
310
}
314
311
315
- getBalance ( ) {
316
- this . checkConnected ( ) ;
312
+ async getBalance ( ) {
313
+ await this . checkConnected ( ) ;
317
314
318
315
return this . executeNip47Request < GetBalanceResponse , { balance : number } > (
319
316
"get_balance" ,
@@ -327,8 +324,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
327
324
) ;
328
325
}
329
326
330
- sendPayment ( invoice : string ) {
331
- this . checkConnected ( ) ;
327
+ async sendPayment ( invoice : string ) {
328
+ await this . checkConnected ( ) ;
332
329
333
330
return this . executeNip47Request < SendPaymentResponse , Nip47PayResponse > (
334
331
"pay_invoice" ,
@@ -340,8 +337,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
340
337
) ;
341
338
}
342
339
343
- keysend ( args : KeysendArgs ) {
344
- this . checkConnected ( ) ;
340
+ async keysend ( args : KeysendArgs ) {
341
+ await this . checkConnected ( ) ;
345
342
346
343
return this . executeNip47Request < SendPaymentResponse , Nip47PayResponse > (
347
344
"pay_keysend" ,
@@ -369,8 +366,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
369
366
throw new Error ( "Method not implemented." ) ;
370
367
}
371
368
372
- makeInvoice ( args : string | number | RequestInvoiceArgs ) {
373
- this . checkConnected ( ) ;
369
+ async makeInvoice ( args : string | number | RequestInvoiceArgs ) {
370
+ await this . checkConnected ( ) ;
374
371
375
372
const requestInvoiceArgs : RequestInvoiceArgs | undefined =
376
373
typeof args === "object" ? ( args as RequestInvoiceArgs ) : undefined ;
@@ -394,8 +391,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
394
391
) ;
395
392
}
396
393
397
- lookupInvoice ( args : LookupInvoiceArgs ) {
398
- this . checkConnected ( ) ;
394
+ async lookupInvoice ( args : LookupInvoiceArgs ) {
395
+ await this . checkConnected ( ) ;
399
396
400
397
return this . executeNip47Request < LookupInvoiceResponse , Nip47Transaction > (
401
398
"lookup_invoice" ,
@@ -412,8 +409,8 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
412
409
) ;
413
410
}
414
411
415
- listTransactions ( args : ListTransactionsArgs ) {
416
- this . checkConnected ( ) ;
412
+ async listTransactions ( args : ListTransactionsArgs ) {
413
+ await this . checkConnected ( ) ;
417
414
418
415
// maybe we can tailor the response to our needs
419
416
return this . executeNip47Request <
@@ -527,12 +524,11 @@ export class NostrWebLNProvider implements WebLNProvider, Nip07Provider {
527
524
} ) ;
528
525
}
529
526
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" ) ;
535
530
}
531
+ await this . relay . connect ( ) ;
536
532
}
537
533
538
534
private executeNip47Request < T , R > (
0 commit comments