From 11de694b6f485be8e3228b476ff20c0691061b93 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Mon, 6 Jun 2022 11:17:04 +0400 Subject: [PATCH] Fixed re-subscribe bug --- README.md | 2 ++ package.json | 2 +- src/services/OrionAggregator/ws/index.ts | 19 ++++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8ea482e..ffc79b2 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,8 @@ const exchangeContract = Exchange__factory.connect( const orderIsOk = await exchangeContract.validateOrder(signedOrder); +if (!orderIsOk) throw new Error("Order invalid"); + const { orderId } = await simpleFetch(orionUnit.orionAggregator.placeOrder)( signedOrder, false // True if you want place order to "internal" orderbook. If you do not want your order to be executed on CEXes or DEXes, but could be filled with the another "internal" order(s). diff --git a/package.json b/package.json index 17f16f9..cb26930 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.12.0", + "version": "0.12.1", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 913dfe7..343d6bc 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -139,6 +139,8 @@ const exclusiveSubscriptions = [ ] as const; type WsMessage = string | ArrayBufferLike | Blob | ArrayBufferView; + +const isSubType = (subType: string): subType is keyof Subscription => Object.values(SubscriptionType).some((t) => t === subType); class OrionAggregatorWS { private ws: WebSocket | undefined; @@ -264,14 +266,17 @@ class OrionAggregatorWS { this.ws.onopen = () => { // Re-subscribe to all subscriptions if (isReconnect) { - Object.entries(this.subscriptions).forEach(([type, subscription]) => { - this.send({ - T: type, - ...('payload' in subscription) && { - S: subscription.payload, - }, + Object.keys(this.subscriptions) + .filter(isSubType) + .forEach((subType) => { + const subscriptions = this.subscriptions[subType]; + if (subscriptions) { + Object.keys(subscriptions).forEach((subKey) => { + const sub = subscriptions[subKey]; + if (sub) this.subscribe(subType, sub); + }); + } }); - }); } }; this.ws.onmessage = (e) => {