aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/order_watcher/event_watcher.ts8
-rw-r--r--test/order_state_watcher_test.ts5
2 files changed, 7 insertions, 6 deletions
diff --git a/src/order_watcher/event_watcher.ts b/src/order_watcher/event_watcher.ts
index f71b14afb..4cb741617 100644
--- a/src/order_watcher/event_watcher.ts
+++ b/src/order_watcher/event_watcher.ts
@@ -10,7 +10,7 @@ const DEFAULT_EVENT_POLLING_INTERVAL = 200;
export class EventWatcher {
private _web3Wrapper: Web3Wrapper;
private _pollingIntervalMs: number;
- private _intervalId: NodeJS.Timer;
+ private _intervalIdIfExists?: NodeJS.Timer;
private _lastEvents: Web3.LogEntry[] = [];
private _callbackIfExistsAsync?: EventWatcherCallback;
private _numConfirmations: number;
@@ -23,14 +23,16 @@ export class EventWatcher {
}
public subscribe(callback: EventWatcherCallback): void {
this._callbackIfExistsAsync = callback;
- this._intervalId = intervalUtils.setAsyncExcludingInterval(
+ this._intervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
this._pollForMempoolEventsAsync.bind(this), this._pollingIntervalMs,
);
}
public unsubscribe(): void {
delete this._callbackIfExistsAsync;
this._lastEvents = [];
- intervalUtils.clearAsyncExcludingInterval(this._intervalId);
+ if (!_.isUndefined(this._intervalIdIfExists)) {
+ intervalUtils.clearAsyncExcludingInterval(this._intervalIdIfExists);
+ }
}
private async _pollForMempoolEventsAsync(): Promise<void> {
const pendingEvents = await this._getEventsAsync();
diff --git a/test/order_state_watcher_test.ts b/test/order_state_watcher_test.ts
index 4701f39d4..72b481ad3 100644
--- a/test/order_state_watcher_test.ts
+++ b/test/order_state_watcher_test.ts
@@ -42,7 +42,6 @@ describe('OrderStateWatcher', () => {
let web3Wrapper: Web3Wrapper;
let signedOrder: SignedOrder;
const fillableAmount = new BigNumber(5);
- const numConfirmations = 0;
before(async () => {
web3 = web3Factory.create();
zeroEx = new ZeroEx(web3.currentProvider);
@@ -217,7 +216,7 @@ describe('OrderStateWatcher', () => {
expect(invalidOrderState.error).to.be.equal(ExchangeContractErrs.OrderRemainingFillAmountZero);
done();
});
- zeroEx.orderStateWatcher.subscribe(callback, numConfirmations);
+ zeroEx.orderStateWatcher.subscribe(callback);
const shouldThrowOnInsufficientBalanceOrAllowance = true;
await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount);
@@ -244,7 +243,7 @@ describe('OrderStateWatcher', () => {
expect(orderRelevantState.canceledTakerTokenAmount).to.be.bignumber.equal(cancelAmountInBaseUnits);
done();
});
- zeroEx.orderStateWatcher.subscribe(callback, numConfirmations);
+ zeroEx.orderStateWatcher.subscribe(callback);
await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmountInBaseUnits);
})().catch(done);
});