diff --git a/package.json b/package.json index a180dff..396eab8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.25", + "version": "0.17.26", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/Orion/bridge/swap.ts b/src/Orion/bridge/swap.ts index 4c4a631..62935fc 100644 --- a/src/Orion/bridge/swap.ts +++ b/src/Orion/bridge/swap.ts @@ -308,7 +308,7 @@ export default async function swap({ options?.logger?.('Redeem tx mined.'); options?.logger?.('Atomic swap completed.'); - if (options?.withdrawToWallet) { + if (options?.withdrawToWallet !== undefined && options.withdrawToWallet) { options.logger?.('Withdrawing to wallet...'); const unsignedWithdrawTx = await targetExchangeContract.populateTransaction.withdraw( targetChainAssetAddress, diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index ba0683f..6e9b870 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -11,7 +11,7 @@ import { import UnsubscriptionType from './UnsubscriptionType'; import type { SwapInfoBase, AssetPairUpdate, OrderbookItem, - Balance, Exchange, CFDBalance, FuturesTradeInfo, SwapInfo, + Balance, Exchange, CFDBalance, FuturesTradeInfo, SwapInfo, AnyJSON, } from '../../../types'; import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema'; import assetPairConfigSchema from './schemas/assetPairConfigSchema'; @@ -202,14 +202,14 @@ class OrionAggregatorWS { } } - private send(data: unknown) { - if (this.ws?.readyState === 1) { - const jsonData = JSON.stringify(data); + private send(jsonObject: AnyJSON) { + if (this.ws?.readyState === WebSocket.OPEN) { + const jsonData = JSON.stringify(jsonObject); this.ws.send(jsonData); this.logger?.(`Sent: ${jsonData}`); } else { setTimeout(() => { - this.send(data); + this.send(jsonObject); }, 50); } } @@ -228,7 +228,7 @@ class OrionAggregatorWS { const id = type === 'aobus' ? ((subscription as any).payload as string) // TODO: Refactor!!! : uuidv4(); - const subRequest: Partial> = {}; + const subRequest: AnyJSON = {}; subRequest['T'] = type; subRequest['id'] = id; @@ -259,7 +259,7 @@ class OrionAggregatorWS { this.send({ T: UNSUBSCRIBE, S: subscription, - d: details, + ...(details !== undefined) && { d: details }, }); if (subscription.includes('0x')) { // is wallet address (ADDRESS_UPDATE) diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 44999f1..62c9369 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid'; import priceFeedSubscriptions from './priceFeedSubscriptions'; import { tickerInfoSchema, candleSchema } from './schemas'; import priceSchema from './schemas/priceSchema'; +import type { AnyJSON } from '../../../types'; type TickerInfo = { pairName: string @@ -100,6 +101,17 @@ export default class PriceFeedSubscription { + this.send(jsonObject); + }, 50); + } + } + init() { this.isClosedIntentionally = false; @@ -139,12 +151,13 @@ export default class PriceFeedSubscription { - this.ws?.send('heartbeat'); + this.send('heartbeat'); }, 15000); } kill() { this.isClosedIntentionally = true; this.ws?.close(); + clearInterval(this.heartbeatInterval); } } diff --git a/src/types.ts b/src/types.ts index f49fa51..e90ef6c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ import type BigNumber from 'bignumber.js'; import type exchanges from './constants/exchanges'; import type subOrderStatuses from './constants/subOrderStatuses'; @@ -292,3 +293,12 @@ export type VerboseOrionUnitConfig = { } export type KnownEnv = typeof knownEnvs[number]; + +export type AnyJSON = string | number | boolean | null | JSONObject | JSONArray; + +// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style +interface JSONObject { + [x: string]: AnyJSON +} + +interface JSONArray extends Array {}