@orderly.network/hooks 1.1.3-alpha.8 → 1.1.3

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.mjs CHANGED
@@ -13,16 +13,16 @@ import { useDebouncedCallback } from 'use-debounce';
13
13
  export * from 'use-debounce';
14
14
  import { Decimal, zero, getPrecisionByNumber, timeConvertString, isTestnet } from '@orderly.network/utils';
15
15
  import useSWRSubscription from 'swr/subscription';
16
- import { pathOr, propOr, compose, head, prop, mergeDeepRight, pick, includes, omit, min } from 'ramda';
16
+ import { pathOr, propOr, pick, compose, head, prop, mergeDeepRight, includes, omit, min } from 'ramda';
17
17
  import { positions, account, order } from '@orderly.network/perp';
18
18
  import { createClient } from '@layerzerolabs/scan-client';
19
19
 
20
20
  // src/version.ts
21
21
  if (typeof window !== "undefined") {
22
22
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
23
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.3-alpha.8";
23
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.3";
24
24
  }
25
- var version_default = "1.1.3-alpha.8";
25
+ var version_default = "1.1.3";
26
26
  var fetcher = (url, init = {}, queryOptions) => get(url, init, queryOptions?.formatter);
27
27
  var OrderlyContext = createContext({
28
28
  // configStore: new MemoryConfigStore(),
@@ -449,10 +449,16 @@ var useWS = () => {
449
449
  });
450
450
  return ws;
451
451
  };
452
+ var WsNetworkStatus = /* @__PURE__ */ ((WsNetworkStatus2) => {
453
+ WsNetworkStatus2["Connected"] = "connected";
454
+ WsNetworkStatus2["Unstable"] = "unstable";
455
+ WsNetworkStatus2["Disconnected"] = "disconnected";
456
+ return WsNetworkStatus2;
457
+ })(WsNetworkStatus || {});
452
458
  function useWsStatus() {
453
459
  const ws = useWS();
454
460
  const [wsStatus, setWsStatus] = useState(
455
- ws.client.public.readyState ? "connected" : "disconnected"
461
+ ws.client.public.readyState ? "connected" /* Connected */ : "disconnected" /* Disconnected */
456
462
  );
457
463
  const connectCount = useRef(0);
458
464
  useEffect(() => {
@@ -462,16 +468,16 @@ function useWsStatus() {
462
468
  switch (type) {
463
469
  case "open":
464
470
  connectCount.current = 0;
465
- setWsStatus("connected");
471
+ setWsStatus("connected" /* Connected */);
466
472
  break;
467
473
  case "close":
468
474
  connectCount.current = 0;
469
- setWsStatus("disconnected");
475
+ setWsStatus("disconnected" /* Disconnected */);
470
476
  break;
471
477
  case "reconnecting":
472
478
  connectCount.current++;
473
- if (connectCount.current >= 2) {
474
- setWsStatus("unstable");
479
+ if (connectCount.current >= 3) {
480
+ setWsStatus("unstable" /* Unstable */);
475
481
  }
476
482
  break;
477
483
  }
@@ -499,7 +505,8 @@ var usePrivateDataObserver = (options) => {
499
505
  "positions"
500
506
  );
501
507
  map.forEach((getKey, key) => {
502
- if (orderStatus === "history" && key === "orders" || orderStatus === "positions" && key === "orders:NEW" || key.includes(orderStatus)) {
508
+ if (orderStatus === "history" && key === "orders" || orderStatus === "positions" && key === "orders:NEW" || key.includes("INCOMPLETE") || // always update pending list
509
+ key.includes(orderStatus)) {
503
510
  mutate2(
504
511
  unstable_serialize((index, prevData) => [
505
512
  getKey(index, prevData),
@@ -696,16 +703,18 @@ var useWalletConnector = () => {
696
703
  };
697
704
  var useMarkPrice = (symbol) => {
698
705
  const ws = useWS();
699
- return useSWRSubscription(`${symbol}@markprice`, (key, { next }) => {
706
+ const [price, setPrice] = useState(0);
707
+ useEffect(() => {
700
708
  const unsubscribe = ws.subscribe(`${symbol}@markprice`, {
701
709
  onMessage: (message) => {
702
- next(null, message.price);
710
+ setPrice(message.price);
703
711
  }
704
712
  });
705
713
  return () => {
706
714
  unsubscribe?.();
707
715
  };
708
- });
716
+ }, [symbol]);
717
+ return { data: price };
709
718
  };
710
719
  var useIndexPrice = (symbol) => {
711
720
  symbol = symbol.replace("PERP", "SPOT");
@@ -871,7 +880,7 @@ var reduceItems = (depth, level, data, asks = false) => {
871
880
  const result = [];
872
881
  if (typeof depth !== "undefined") {
873
882
  const prices = /* @__PURE__ */ new Map();
874
- for (let i = 0; i < min(level, data.length); i++) {
883
+ for (let i = 0; i < data.length; i++) {
875
884
  const [price, quantity] = data[i];
876
885
  if (isNaN(price) || isNaN(quantity))
877
886
  continue;
@@ -1109,6 +1118,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
1109
1118
  var needNumberOnlyFields = [
1110
1119
  "order_quantity",
1111
1120
  "order_price",
1121
+ "trigger_price",
1112
1122
  "total"
1113
1123
  ];
1114
1124
  var cleanStringStyle = (str) => {
@@ -1193,13 +1203,13 @@ function quantityInputHandle(inputs) {
1193
1203
  }
1194
1204
  if (values.order_type === OrderType.MARKET || values.order_type === OrderType.STOP_MARKET) {
1195
1205
  const price = markPrice;
1196
- values.total = quantity.mul(price).todp(2).toNumber();
1206
+ values.total = quantity.mul(price).todp(2).toString();
1197
1207
  }
1198
1208
  if (values.order_type === OrderType.LIMIT || values.order_type === OrderType.STOP_LIMIT) {
1199
1209
  if (values.order_price) {
1200
1210
  const price = Number(values.order_price);
1201
1211
  const total = quantity.mul(price);
1202
- values.total = total.todp(2).toNumber();
1212
+ values.total = total.todp(2).toString();
1203
1213
  } else {
1204
1214
  values.total = "";
1205
1215
  }
@@ -1228,13 +1238,13 @@ function totalInputHandle(inputs) {
1228
1238
  const totalDP = total.dp();
1229
1239
  if (totalDP > config.quoteDP) {
1230
1240
  total = total.toDecimalPlaces(config.quoteDP);
1231
- values.total = total.toNumber();
1241
+ values.total = total.toString();
1232
1242
  }
1233
1243
  const quantity = total.div(price);
1234
1244
  return [
1235
1245
  {
1236
1246
  ...values,
1237
- order_quantity: quantity.toDecimalPlaces(Math.min(config.baseDP, quantity.dp())).toNumber()
1247
+ order_quantity: quantity.toDecimalPlaces(Math.min(config.baseDP, quantity.dp())).toString()
1238
1248
  },
1239
1249
  input,
1240
1250
  value,
@@ -1702,7 +1712,8 @@ var useOrderStream = (params) => {
1702
1712
  // onError: (err) => {
1703
1713
  // console.error("fetch failed::::", err);
1704
1714
  // },
1705
- formatter: (data) => data
1715
+ formatter: (data) => data,
1716
+ revalidateOnFocus: false
1706
1717
  });
1707
1718
  const flattenOrders = useMemo(() => {
1708
1719
  if (!ordersResponse.data) {
@@ -2337,7 +2348,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2337
2348
  const diffOrderEntry = (prev, current) => {
2338
2349
  if (!prev)
2339
2350
  return null;
2340
- let key, value;
2351
+ let key, value, preValue;
2341
2352
  const keys = Object.keys(current);
2342
2353
  for (let i = 0; i < keys.length; i++) {
2343
2354
  const k = keys[i];
@@ -2348,12 +2359,13 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2348
2359
  if (preveValue !== currentValue) {
2349
2360
  key = k;
2350
2361
  value = currentValue;
2362
+ preValue = preveValue;
2351
2363
  break;
2352
2364
  }
2353
2365
  }
2354
2366
  if (!key)
2355
2367
  return null;
2356
- return { key, value };
2368
+ return { key, value, preValue };
2357
2369
  };
2358
2370
  const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
2359
2371
  const parseString2Number = (order3, key) => {
@@ -2364,12 +2376,34 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2364
2376
  }
2365
2377
  order3[key] = order3[key].replace(/,/g, "");
2366
2378
  };
2379
+ const needParse = useMemo(() => {
2380
+ if (typeof symbolOrOrder === "string") {
2381
+ return null;
2382
+ }
2383
+ return pick([
2384
+ "order_price",
2385
+ "side",
2386
+ "order_quantity",
2387
+ "visible_quantity",
2388
+ "order_type",
2389
+ "order_type_ext",
2390
+ "symbol",
2391
+ "total",
2392
+ "reduce_only",
2393
+ "trigger_price"
2394
+ ])(
2395
+ //@ts-ignore
2396
+ symbolOrOrder
2397
+ );
2398
+ }, [symbolOrOrder]);
2367
2399
  const parsedData = useMemo(() => {
2368
2400
  if (typeof symbolOrOrder === "string") {
2369
2401
  return null;
2370
2402
  }
2371
2403
  if (typeof symbolOrOrder.order_quantity === "string") {
2372
2404
  parseString2Number(symbolOrOrder, "order_quantity");
2405
+ } else if (typeof symbolOrOrder.order_quantity === "number") {
2406
+ symbolOrOrder.order_quantity = new Decimal(symbolOrOrder.order_quantity).toDecimalPlaces(baseDP).toString();
2373
2407
  }
2374
2408
  if (typeof symbolOrOrder.order_price === "string") {
2375
2409
  parseString2Number(symbolOrOrder, "order_price");
@@ -2380,11 +2414,18 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2380
2414
  if (typeof symbolOrOrder.trigger_price === "string") {
2381
2415
  parseString2Number(symbolOrOrder, "trigger_price");
2382
2416
  }
2383
- if (typeof symbolOrOrder.order_quantity === "number") {
2384
- symbolOrOrder.order_quantity = new Decimal(symbolOrOrder.order_quantity).toDecimalPlaces(baseDP).toString();
2385
- }
2386
2417
  return symbolOrOrder;
2387
- }, [symbolOrOrder]);
2418
+ }, [
2419
+ needParse?.order_price,
2420
+ needParse?.order_quantity,
2421
+ needParse?.total,
2422
+ needParse?.trigger_price,
2423
+ needParse?.order_type,
2424
+ needParse?.order_type_ext,
2425
+ needParse?.symbol,
2426
+ needParse?.reduce_only,
2427
+ needParse?.side
2428
+ ]);
2388
2429
  const createOrder = (values) => {
2389
2430
  if (!values.symbol) {
2390
2431
  throw new SDKError("symbol is error");
@@ -2506,19 +2547,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2506
2547
  prevOrderData.current = parsedData;
2507
2548
  orderDataCache.current = values;
2508
2549
  return values;
2509
- }, [
2510
- parsedData?.order_price,
2511
- parsedData?.side,
2512
- parsedData?.order_quantity,
2513
- parsedData?.visible_quantity,
2514
- parsedData?.order_type,
2515
- parsedData?.order_type_ext,
2516
- parsedData?.symbol,
2517
- parsedData?.total,
2518
- parsedData?.reduce_only,
2519
- parsedData?.trigger_price,
2520
- markPrice
2521
- ]);
2550
+ }, [parsedData, markPrice]);
2522
2551
  useEffect(() => {
2523
2552
  if (!markPrice)
2524
2553
  return;
@@ -4046,7 +4075,7 @@ var woofiDexCrossChainRouterAbi = [
4046
4075
  var nativeTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
4047
4076
  var isNativeTokenChecker = (address) => address === nativeTokenAddress;
4048
4077
  var useChains = (networkId, options = {}) => {
4049
- const { pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
4078
+ const { pick: pick4, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
4050
4079
  const { configStore } = useContext(OrderlyContext);
4051
4080
  const field = options?.pick;
4052
4081
  const filterFun = useRef(options?.filter);
@@ -5256,6 +5285,6 @@ var useSwap = () => {
5256
5285
  };
5257
5286
  };
5258
5287
 
5259
- export { MarketsType, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusContext, StatusProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarkets, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolPriceRange, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery, useWsStatus, version_default as version };
5288
+ export { MarketsType, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusContext, StatusProvider, WalletConnectorContext, WsNetworkStatus, cleanStringStyle, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarkets, useMarketsStream, useMaxQty, useMediaQuery, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolPriceRange, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery, useWsStatus, version_default as version };
5260
5289
  //# sourceMappingURL=out.js.map
5261
5290
  //# sourceMappingURL=index.mjs.map