aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/0x.ts19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/0x.ts b/src/0x.ts
index 2208e5ec8..0ac95fccd 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -294,9 +294,19 @@ export class ZeroEx {
*/
public async awaitTransactionMinedAsync(
txHash: string, pollingIntervalMs = 1000, timeoutMs?: number): Promise<TransactionReceiptWithDecodedLogs> {
+ let timeoutExceeded = false;
+ if (timeoutMs) {
+ setTimeout(() => timeoutExceeded = true, timeoutMs);
+ }
+
const txReceiptPromise = new Promise(
(resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => {
const intervalId = intervalUtils.setAsyncExcludingInterval(async () => {
+ if (timeoutExceeded) {
+ clearInterval(intervalId);
+ return reject(ZeroExError.TransactionMiningTimeout);
+ }
+
const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash);
if (!_.isNull(transactionReceipt)) {
intervalUtils.clearAsyncExcludingInterval(intervalId);
@@ -313,15 +323,6 @@ export class ZeroEx {
}, pollingIntervalMs);
});
- if (timeoutMs) {
- return Promise.race([
- txReceiptPromise,
- new Promise<TransactionReceiptWithDecodedLogs>((resolve, reject) => {
- setTimeout(() => reject(ZeroExError.TransactionMiningTimeout), timeoutMs);
- })
- ]);
- }
-
return txReceiptPromise;
}
/*