diff --git a/src/NWCClient.ts b/src/NWCClient.ts index 68cfb29..b3a7fa2 100644 --- a/src/NWCClient.ts +++ b/src/NWCClient.ts @@ -67,6 +67,11 @@ export type Nip47PayResponse = { preimage: string; }; +type Nip47TimeoutValues = { + replyTimeout?: number; + publishTimeout?: number; +}; + export type Nip47MultiPayInvoiceRequest = { invoices: (Nip47PayInvoiceRequest & WithOptionalId)[]; }; @@ -544,6 +549,7 @@ export class NWCClient { "get_info", {}, (result) => !!result.methods, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -558,6 +564,7 @@ export class NWCClient { "get_budget", {}, (result) => result !== undefined, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -572,6 +579,7 @@ export class NWCClient { "get_balance", {}, (result) => result.balance !== undefined, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -721,6 +729,7 @@ export class NWCClient { "list_transactions", request, (response) => !!response.transactions, + { replyTimeout: 10000 }, ); return result; @@ -819,6 +828,7 @@ export class NWCClient { nip47Method: Nip47SingleMethod, params: unknown, resultValidator: (result: T) => boolean, + timeoutValues?: Nip47TimeoutValues, ): Promise { await this._checkConnected(); await this._checkCompatibility(); @@ -867,7 +877,10 @@ export class NWCClient { ); } - const replyTimeoutCheck = setTimeout(replyTimeout, 60000); + const replyTimeoutCheck = setTimeout( + replyTimeout, + timeoutValues?.replyTimeout || 60000, + ); sub.onevent = async (event) => { // console.log(`Received reply event: `, event); @@ -930,7 +943,10 @@ export class NWCClient { ), ); } - const publishTimeoutCheck = setTimeout(publishTimeout, 5000); + const publishTimeoutCheck = setTimeout( + publishTimeout, + timeoutValues?.publishTimeout || 5000, + ); try { await this.relay.publish(event);