aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-11 23:13:42 +0800
committerFabio Berger <me@fabioberger.com>2017-11-11 23:13:42 +0800
commit0fe5c5dac33ec11bc3517f16f1fd613d720c8b8d (patch)
treef5de75d542c7249dac2d992f75221788e266048c
parent037e992de457fc9f5012576719470d6b4f2b118d (diff)
downloaddexon-sol-tools-0fe5c5dac33ec11bc3517f16f1fd613d720c8b8d.tar.gz
dexon-sol-tools-0fe5c5dac33ec11bc3517f16f1fd613d720c8b8d.tar.zst
dexon-sol-tools-0fe5c5dac33ec11bc3517f16f1fd613d720c8b8d.zip
Remove keys from dependentOrderHashes if empty
-rw-r--r--src/order_watcher/order_state_watcher.ts12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/order_watcher/order_state_watcher.ts b/src/order_watcher/order_state_watcher.ts
index f7e3a38a0..f06e32a32 100644
--- a/src/order_watcher/order_state_watcher.ts
+++ b/src/order_watcher/order_state_watcher.ts
@@ -87,8 +87,7 @@ export class OrderStateWatcher {
return; // noop
}
delete this._orderByOrderHash[orderHash];
- this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress].delete(orderHash);
- // We currently do not remove the maker/makerToken keys from the mapping when all orderHashes removed
+ this.removeFromDependentOrderHashes(signedOrder.maker, signedOrder.makerTokenAddress, orderHash);
}
/**
* Starts an orderStateWatcher subscription. The callback will be called every time a watched order's
@@ -191,4 +190,13 @@ export class OrderStateWatcher {
}
this._dependentOrderHashes[signedOrder.maker][signedOrder.makerTokenAddress].add(orderHash);
}
+ private removeFromDependentOrderHashes(makerAddress: string, makerTokenAddress: string, orderHash: string) {
+ this._dependentOrderHashes[makerAddress][makerTokenAddress].delete(orderHash);
+ if (this._dependentOrderHashes[makerAddress][makerTokenAddress].size === 0) {
+ delete this._dependentOrderHashes[makerAddress][makerTokenAddress];
+ }
+ if (_.isEmpty(this._dependentOrderHashes[makerAddress])) {
+ delete this._dependentOrderHashes[makerAddress];
+ }
+ }
}