aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-12 00:14:09 +0800
committerFabio Berger <me@fabioberger.com>2017-11-12 00:14:09 +0800
commitc6f97f20fb7ada5135350c9120bfe203f78c0970 (patch)
tree9028936fd1ad8acb56625e0b4c633a88c18a5212
parentb66600338e0057baa6964328bdf337a905aa5ff9 (diff)
parent76b66872d8f797ee3b0efe0fa2ca914cf44ee46c (diff)
downloaddexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.tar
dexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.tar.gz
dexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.tar.bz2
dexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.tar.lz
dexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.tar.xz
dexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.tar.zst
dexon-sol-tools-c6f97f20fb7ada5135350c9120bfe203f78c0970.zip
Merge branch 'development' into orderWatcher
* development: 0.22.6 Add new changes to CHANGELOG use util fn no race, reject from interval cb and clear allow timeout for await transaction mined # Conflicts: # src/types.ts
-rw-r--r--CHANGELOG.md4
-rw-r--r--package-lock.json2
-rw-r--r--package.json2
-rw-r--r--src/0x.ts14
-rw-r--r--src/types.ts1
5 files changed, 20 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 156fb1222..029144b5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+v0.22.6 - _November 10, 2017_
+------------------------
+ * Add a timeout parameter to transaction awaiting (#206)
+
v0.22.5 - _November 7, 2017_
------------------------
* Re-publish v0.22.4 to fix publishing issue
diff --git a/package-lock.json b/package-lock.json
index c3c4962e7..6b4a97d87 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "0x.js",
- "version": "0.22.5",
+ "version": "0.22.6",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 4b23bf6e1..e7e21bdce 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "0x.js",
- "version": "0.22.5",
+ "version": "0.22.6",
"description": "A javascript library for interacting with the 0x protocol",
"keywords": [
"0x.js",
diff --git a/src/0x.ts b/src/0x.ts
index 59688e948..a1841eaa8 100644
--- a/src/0x.ts
+++ b/src/0x.ts
@@ -285,13 +285,24 @@ export class ZeroEx {
* Waits for a transaction to be mined and returns the transaction receipt.
* @param txHash Transaction hash
* @param pollingIntervalMs How often (in ms) should we check if the transaction is mined.
+ * @param timeoutMs How long (in ms) to poll for transaction mined until aborting.
* @return Transaction receipt with decoded log args.
*/
public async awaitTransactionMinedAsync(
- txHash: string, pollingIntervalMs: number = 1000): Promise<TransactionReceiptWithDecodedLogs> {
+ 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) {
+ intervalUtils.clearAsyncExcludingInterval(intervalId);
+ return reject(ZeroExError.TransactionMiningTimeout);
+ }
+
const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash);
if (!_.isNull(transactionReceipt)) {
intervalUtils.clearAsyncExcludingInterval(intervalId);
@@ -307,6 +318,7 @@ export class ZeroEx {
}
}, pollingIntervalMs);
});
+
return txReceiptPromise;
}
/*
diff --git a/src/types.ts b/src/types.ts
index 411ff3bfd..160b71fda 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -17,6 +17,7 @@ export enum ZeroExError {
NoNetworkId = 'NO_NETWORK_ID',
SubscriptionNotFound = 'SUBSCRIPTION_NOT_FOUND',
SubscriptionAlreadyPresent = 'SUBSCRIPTION_ALREADY_PRESENT',
+ TransactionMiningTimeout = 'TRANSACTION_MINING_TIMEOUT',
}
export enum InternalZeroExError {