From f318fd9cf1303fe2770f400cbce14c778f77e454 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 15 Feb 2019 13:42:12 -0500 Subject: [PATCH] Added fastRetry to polling for JsonRpcSigner to improve polling for sent transactions (#402). --- src.ts/providers/json-rpc-provider.ts | 2 +- src.ts/utils/web.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src.ts/providers/json-rpc-provider.ts b/src.ts/providers/json-rpc-provider.ts index 4560754a2..65dc7485f 100644 --- a/src.ts/providers/json-rpc-provider.ts +++ b/src.ts/providers/json-rpc-provider.ts @@ -158,7 +158,7 @@ export class JsonRpcSigner extends Signer { if (tx === null) { return undefined; } return this.provider._wrapTransaction(tx, hash); }); - }, { onceBlock: this.provider }).catch((error: Error) => { + }, { fastRetry: 250, onceBlock: this.provider }).catch((error: Error) => { (error).transactionHash = hash; throw error; }); diff --git a/src.ts/utils/web.ts b/src.ts/utils/web.ts index 734570c0c..957cc651a 100644 --- a/src.ts/utils/web.ts +++ b/src.ts/utils/web.ts @@ -28,7 +28,8 @@ export type PollOptions = { floor?: number, ceiling?: number, interval?: number, - onceBlock?: OnceBlockable + onceBlock?: OnceBlockable, + fastRetry?: number }; @@ -208,6 +209,8 @@ export function poll(func: () => Promise, options?: PollOptions): Promise Promise, options?: PollOptions): Promise options.ceiling) { timeout = options.ceiling; } + // Fast Timeout, means we quickly try again the first time + if (fastTimeout) { + attempt--; + timeout = fastTimeout; + fastTimeout = null; + } + setTimeout(check, timeout); }