aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-04-16 22:21:02 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-04-18 19:45:04 +0800
commit25744056993878392b67796286b4b41fda3489f5 (patch)
tree3222ea03ddba85ee95b4f781ced470383660a37f /packages/0x.js/src
parent3ba78553f01d79e26fb5c95040b64a86a7763b86 (diff)
downloaddexon-sol-tools-25744056993878392b67796286b4b41fda3489f5.tar.gz
dexon-sol-tools-25744056993878392b67796286b4b41fda3489f5.tar.zst
dexon-sol-tools-25744056993878392b67796286b4b41fda3489f5.zip
Fix expiration watcher comparator
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/order_watcher/expiration_watcher.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/packages/0x.js/src/order_watcher/expiration_watcher.ts b/packages/0x.js/src/order_watcher/expiration_watcher.ts
index 8b306bf3b..27ec7107d 100644
--- a/packages/0x.js/src/order_watcher/expiration_watcher.ts
+++ b/packages/0x.js/src/order_watcher/expiration_watcher.ts
@@ -22,8 +22,17 @@ export class ExpirationWatcher {
this._expirationMarginMs = expirationMarginIfExistsMs || DEFAULT_EXPIRATION_MARGIN_MS;
this._orderExpirationCheckingIntervalMs =
expirationMarginIfExistsMs || DEFAULT_ORDER_EXPIRATION_CHECKING_INTERVAL_MS;
- const scoreFunction = (orderHash: string) => this._expiration[orderHash].toNumber();
- const comparator = (lhs: string, rhs: string) => scoreFunction(lhs) - scoreFunction(rhs);
+ const comparator = (lhsOrderHash: string, rhsOrderHash: string) => {
+ const lhsExpiration = this._expiration[lhsOrderHash].toNumber();
+ const rhsExpiration = this._expiration[rhsOrderHash].toNumber();
+ if (lhsExpiration !== rhsExpiration) {
+ return lhsExpiration - rhsExpiration;
+ } else {
+ // HACK: If two orders have identical expirations, the order in which they are emitted by the
+ // ExpirationWatcher does not matter, so we emit them in alphabetical order by orderHash.
+ return lhsOrderHash.localeCompare(rhsOrderHash);
+ }
+ };
this._orderHashByExpirationRBTree = new RBTree(comparator);
}
public subscribe(callback: (orderHash: string) => void): void {