From c15a89832b2fd8ab06b9ec655487cb50e8ded7c1 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Fri, 15 Feb 2019 13:32:08 -0500 Subject: [PATCH] Fix waitForTransaction delay (#424). --- src.ts/providers/base-provider.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src.ts/providers/base-provider.ts b/src.ts/providers/base-provider.ts index 42689f09..925efbd8 100644 --- a/src.ts/providers/base-provider.ts +++ b/src.ts/providers/base-provider.ts @@ -777,17 +777,19 @@ export class BaseProvider extends Provider { waitForTransaction(transactionHash: string, confirmations?: number): Promise { if (confirmations == null) { confirmations = 1; } - if (confirmations === 0) { - return this.getTransactionReceipt(transactionHash); - } - - return new Promise((resolve) => { - let handler = (receipt: TransactionReceipt) => { - if (receipt.confirmations < confirmations) { return; } - this.removeListener(transactionHash, handler); - resolve(receipt); + return this.getTransactionReceipt(transactionHash).then((receipt) => { + if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) { + return receipt; } - this.on(transactionHash, handler); + + return >(new Promise((resolve) => { + let handler = (receipt: TransactionReceipt) => { + if (receipt.confirmations < confirmations) { return; } + this.removeListener(transactionHash, handler); + resolve(receipt); + } + this.on(transactionHash, handler); + })); }); }