diff --git a/src/NWCClient.ts b/src/NWCClient.ts index 78e59ce..96d52b2 100644 --- a/src/NWCClient.ts +++ b/src/NWCClient.ts @@ -68,6 +68,11 @@ export type Nip47PayResponse = { preimage: string; }; +type Nip47TimeoutValues = { + replyTimeout?: number; + publishTimeout?: number; +}; + export type Nip47MultiPayInvoiceRequest = { invoices: (Nip47PayInvoiceRequest & WithOptionalId)[]; }; @@ -545,6 +550,7 @@ export class NWCClient { "get_info", {}, (result) => !!result.methods, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -559,6 +565,7 @@ export class NWCClient { "get_budget", {}, (result) => result !== undefined, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -573,6 +580,7 @@ export class NWCClient { "get_balance", {}, (result) => result.balance !== undefined, + { replyTimeout: 10000 }, ); return result; } catch (error) { @@ -722,6 +730,7 @@ export class NWCClient { "list_transactions", request, (response) => !!response.transactions, + { replyTimeout: 10000 }, ); return result; @@ -820,6 +829,7 @@ export class NWCClient { nip47Method: Nip47SingleMethod, params: unknown, resultValidator: (result: T) => boolean, + timeoutValues?: Nip47TimeoutValues, ): Promise { await this._checkConnected(); await this._checkCompatibility(); @@ -868,7 +878,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); @@ -931,7 +944,10 @@ export class NWCClient { ), ); } - const publishTimeoutCheck = setTimeout(publishTimeout, 5000); + const publishTimeoutCheck = setTimeout( + publishTimeout, + timeoutValues?.publishTimeout || 5000, + ); try { await this.relay.publish(event); @@ -956,6 +972,7 @@ export class NWCClient { params: unknown, numPayments: number, resultValidator: (result: T) => boolean, + timeoutValues?: Nip47TimeoutValues, ): Promise<(T & { dTag: string })[]> { await this._checkConnected(); await this._checkCompatibility(); @@ -1005,7 +1022,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); @@ -1087,7 +1107,10 @@ export class NWCClient { ), ); } - const publishTimeoutCheck = setTimeout(publishTimeout, 5000); + const publishTimeoutCheck = setTimeout( + publishTimeout, + timeoutValues?.publishTimeout || 5000, + ); try { await this.relay.publish(event);