@orderly.network/hooks 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -3,11 +3,11 @@ export { SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration } from 'swr/mutation';
4
4
  import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
5
  import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
6
- import { WebSocketClient, WS } from '@orderly.network/net';
7
6
  export { useEventCallback, useObservable } from 'rxjs-hooks';
8
7
  export { default as useConstant } from 'use-constant';
9
8
  import * as react from 'react';
10
9
  import { FC, PropsWithChildren } from 'react';
10
+ import { WS } from '@orderly.network/net';
11
11
  import * as swr__internal from 'swr/_internal';
12
12
  import * as swr_subscription from 'swr/subscription';
13
13
 
@@ -59,8 +59,6 @@ declare const useAppState: () => {
59
59
  exchangeState: ExchangeStatusEnum;
60
60
  };
61
61
 
62
- declare const useWebSocketClient: () => WebSocketClient;
63
-
64
62
  declare const DataSourceProvider: FC<PropsWithChildren>;
65
63
 
66
64
  declare const useWS: () => WS;
@@ -285,4 +283,4 @@ declare namespace index {
285
283
  };
286
284
  }
287
285
 
288
- export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS, useWebSocketClient };
286
+ export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
package/dist/index.d.ts CHANGED
@@ -3,11 +3,11 @@ export { SWRConfiguration, default as useSWR } from 'swr';
3
3
  import { SWRMutationConfiguration } from 'swr/mutation';
4
4
  import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, WSMessage } from '@orderly.network/core';
5
5
  import { SystemStateEnum, ExchangeStatusEnum, OrderSide, OrderEntity, API } from '@orderly.network/types';
6
- import { WebSocketClient, WS } from '@orderly.network/net';
7
6
  export { useEventCallback, useObservable } from 'rxjs-hooks';
8
7
  export { default as useConstant } from 'use-constant';
9
8
  import * as react from 'react';
10
9
  import { FC, PropsWithChildren } from 'react';
10
+ import { WS } from '@orderly.network/net';
11
11
  import * as swr__internal from 'swr/_internal';
12
12
  import * as swr_subscription from 'swr/subscription';
13
13
 
@@ -59,8 +59,6 @@ declare const useAppState: () => {
59
59
  exchangeState: ExchangeStatusEnum;
60
60
  };
61
61
 
62
- declare const useWebSocketClient: () => WebSocketClient;
63
-
64
62
  declare const DataSourceProvider: FC<PropsWithChildren>;
65
63
 
66
64
  declare const useWS: () => WS;
@@ -285,4 +283,4 @@ declare namespace index {
285
283
  };
286
284
  }
287
285
 
288
- export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS, useWebSocketClient };
286
+ export { DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAppState, useChains, useCollateral, useFetures, useFundingRate$1 as useFundingRate, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePrivateObserve, usePrivateQuery, useQuery, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradeStream, useTradingView, useWS };
package/dist/index.js CHANGED
@@ -6,10 +6,10 @@ var net = require('@orderly.network/net');
6
6
  var useSWRMutation = require('swr/mutation');
7
7
  var useConstant = require('use-constant');
8
8
  var core = require('@orderly.network/core');
9
- var rxjsHooks = require('rxjs-hooks');
10
9
  var types = require('@orderly.network/types');
11
10
  var rxjs = require('rxjs');
12
11
  var operators = require('rxjs/operators');
12
+ var rxjsHooks = require('rxjs-hooks');
13
13
  var ramda = require('ramda');
14
14
  var useSWRSubscription = require('swr/subscription');
15
15
  var utils = require('@orderly.network/utils');
@@ -231,10 +231,16 @@ var useAccount = () => {
231
231
  }
232
232
  return account5;
233
233
  });
234
- const state = rxjsHooks.useObservable(
235
- () => account4.state$,
236
- account4.stateValue
237
- );
234
+ const [state, setState] = React.useState(account4.stateValue);
235
+ const statusChangeHandler = (nextState) => {
236
+ setState(() => nextState);
237
+ };
238
+ React.useEffect(() => {
239
+ account4.on("change:status", statusChangeHandler);
240
+ return () => {
241
+ account4.off("change:status", statusChangeHandler);
242
+ };
243
+ }, []);
238
244
  const login = React.useCallback(
239
245
  (address) => {
240
246
  account4.login(address);
@@ -355,27 +361,6 @@ var useAppState = () => {
355
361
  }
356
362
  );
357
363
  };
358
- var WS_NAME = "websocketClient";
359
- var useWebSocketClient = () => {
360
- const ws = useConstant__default.default(() => {
361
- let websocketClient = core.SimpleDI.get(WS_NAME);
362
- if (!websocketClient) {
363
- websocketClient = new net.WebSocketClient({
364
- accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
365
- networkId: "testnet",
366
- onSigntureRequest: (accountId) => __async(void 0, null, function* () {
367
- const signer = core.getMockSigner();
368
- const timestamp = (/* @__PURE__ */ new Date()).getTime();
369
- const result = yield signer.signText(timestamp.toString());
370
- return __spreadProps(__spreadValues({}, result), { timestamp });
371
- })
372
- });
373
- core.SimpleDI.registerByName(WS_NAME, websocketClient);
374
- }
375
- return websocketClient;
376
- });
377
- return ws;
378
- };
379
364
  var DataSourceContext = React.createContext({});
380
365
  var DataSourceProvider = (props) => {
381
366
  console.log("render DataSourceProvider");
@@ -384,15 +369,19 @@ var DataSourceProvider = (props) => {
384
369
  });
385
370
  return /* @__PURE__ */ React__default.default.createElement(DataSourceContext.Provider, { value: {} }, props.children);
386
371
  };
387
- var WS_NAME2 = "nativeWebsocketClient";
372
+ var WS_NAME = "nativeWebsocketClient";
388
373
  var useWS = () => {
374
+ useAccount();
375
+ const { configStore } = React.useContext(OrderlyContext);
389
376
  const ws = useConstant__default.default(() => {
390
- let websocketClient = core.SimpleDI.get(WS_NAME2);
377
+ let websocketClient = core.SimpleDI.get(WS_NAME);
391
378
  const account4 = core.SimpleDI.get(core.Account.instanceName);
392
379
  if (!websocketClient) {
393
380
  websocketClient = new net.WS({
394
381
  // accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
395
382
  networkId: "testnet",
383
+ publicUrl: configStore.get("publicWsUrl"),
384
+ privateUrl: configStore.get("privateWsUrl"),
396
385
  onSigntureRequest: (accountId) => __async(void 0, null, function* () {
397
386
  const signer = account4.signer;
398
387
  const timestamp = (/* @__PURE__ */ new Date()).getTime();
@@ -400,7 +389,7 @@ var useWS = () => {
400
389
  return __spreadProps(__spreadValues({}, result), { timestamp });
401
390
  })
402
391
  });
403
- core.SimpleDI.registerByName(WS_NAME2, websocketClient);
392
+ core.SimpleDI.registerByName(WS_NAME, websocketClient);
404
393
  }
405
394
  return websocketClient;
406
395
  });
@@ -649,8 +638,6 @@ function createGetter(data, depth = 2) {
649
638
  }
650
639
  });
651
640
  }
652
-
653
- // src/orderly/useSymbolsInfo.ts
654
641
  var useSymbolsInfo = () => {
655
642
  const { data = {} } = useQuery(`/v1/public/info`, {
656
643
  focusThrottleInterval: 1e3 * 60 * 60 * 24,
@@ -664,7 +651,11 @@ var useSymbolsInfo = () => {
664
651
  for (let index = 0; index < data2.rows.length; index++) {
665
652
  const item = data2.rows[index];
666
653
  const arr = item.symbol.split("_");
654
+ const base_dp = utils.getPrecisionByNumber(item.base_tick);
655
+ const quote_dp = utils.getPrecisionByNumber(item.quote_tick);
667
656
  obj[item.symbol] = __spreadProps(__spreadValues({}, item), {
657
+ base_dp,
658
+ quote_dp,
668
659
  base: arr[1],
669
660
  quote: arr[2],
670
661
  type: arr[0],
@@ -1361,6 +1352,29 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1361
1352
  symbolConfig: symbolInfo[symbol]()
1362
1353
  };
1363
1354
  };
1355
+ var WS_NAME2 = "websocketClient";
1356
+ var useWebSocketClient = () => {
1357
+ const ws = useConstant__default.default(() => {
1358
+ let websocketClient = core.SimpleDI.get(WS_NAME2);
1359
+ if (!websocketClient) {
1360
+ websocketClient = new net.WebSocketClient({
1361
+ accountId: "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY",
1362
+ networkId: "testnet",
1363
+ onSigntureRequest: (accountId) => __async(void 0, null, function* () {
1364
+ const signer = core.getMockSigner();
1365
+ const timestamp = (/* @__PURE__ */ new Date()).getTime();
1366
+ const result = yield signer.signText(timestamp.toString());
1367
+ return __spreadProps(__spreadValues({}, result), { timestamp });
1368
+ })
1369
+ });
1370
+ core.SimpleDI.registerByName(WS_NAME2, websocketClient);
1371
+ }
1372
+ return websocketClient;
1373
+ });
1374
+ return ws;
1375
+ };
1376
+
1377
+ // src/orderly/useFetures.ts
1364
1378
  var useFetures = () => {
1365
1379
  const { data, isLoading, error } = useQuery(
1366
1380
  `/v1/public/futures`,
@@ -1739,6 +1753,5 @@ exports.useTopicObserve = useTopicObserve;
1739
1753
  exports.useTradeStream = useTradeStream;
1740
1754
  exports.useTradingView = useTradingView;
1741
1755
  exports.useWS = useWS;
1742
- exports.useWebSocketClient = useWebSocketClient;
1743
1756
  //# sourceMappingURL=out.js.map
1744
1757
  //# sourceMappingURL=index.js.map