Add SubscriptionAlreadyPresent error
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
OnOrderStateChangeCallback,
|
||||
ExchangeEvents,
|
||||
TokenEvents,
|
||||
ZeroExError,
|
||||
} from '../types';
|
||||
import {Web3Wrapper} from '../web3_wrapper';
|
||||
|
||||
@@ -85,6 +86,9 @@ export class OrderStateWatcher {
|
||||
*/
|
||||
public subscribe(callback: OnOrderStateChangeCallback, numConfirmations: number): void {
|
||||
assert.isFunction('callback', callback);
|
||||
if (!_.isUndefined(this._callbackAsync)) {
|
||||
throw new Error(ZeroExError.SubscriptionAlreadyPresent);
|
||||
}
|
||||
this._callbackAsync = callback;
|
||||
this._eventWatcher.subscribe(this._onMempoolEventCallbackAsync.bind(this), numConfirmations);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ export enum ZeroExError {
|
||||
OutOfGas = 'OUT_OF_GAS',
|
||||
NoNetworkId = 'NO_NETWORK_ID',
|
||||
SubscriptionNotFound = 'SUBSCRIPTION_NOT_FOUND',
|
||||
SubscriptionAlreadyPresent = 'SUBSCRIPTION_ALREADY_PRESENT',
|
||||
}
|
||||
|
||||
export enum InternalZeroExError {
|
||||
|
||||
@@ -23,6 +23,7 @@ describe('EventWatcher', () => {
|
||||
let stubs: Sinon.SinonStub[] = [];
|
||||
let eventWatcher: EventWatcher;
|
||||
let web3Wrapper: Web3Wrapper;
|
||||
const numConfirmations = 0;
|
||||
const logA = {
|
||||
address: '0x71d271f8b14adef568f8f28f1587ce7271ac4ca5',
|
||||
blockHash: null,
|
||||
@@ -87,7 +88,7 @@ describe('EventWatcher', () => {
|
||||
done();
|
||||
}
|
||||
};
|
||||
eventWatcher.subscribe(callback);
|
||||
eventWatcher.subscribe(callback, numConfirmations);
|
||||
});
|
||||
it('correctly computes the difference and emits only changes', (done: DoneCallback) => {
|
||||
const initialLogs: Web3.LogEntry[] = [logA, logB];
|
||||
@@ -121,6 +122,6 @@ describe('EventWatcher', () => {
|
||||
done();
|
||||
}
|
||||
};
|
||||
eventWatcher.subscribe(callback);
|
||||
eventWatcher.subscribe(callback, numConfirmations);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user