@orderly.network/hooks 1.1.3-alpha.9 → 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.9";
23
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.3";
24
24
  }
25
- var version_default = "1.1.3-alpha.9";
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;
@@ -1194,13 +1203,13 @@ function quantityInputHandle(inputs) {
1194
1203
  }
1195
1204
  if (values.order_type === OrderType.MARKET || values.order_type === OrderType.STOP_MARKET) {
1196
1205
  const price = markPrice;
1197
- values.total = quantity.mul(price).todp(2).toNumber();
1206
+ values.total = quantity.mul(price).todp(2).toString();
1198
1207
  }
1199
1208
  if (values.order_type === OrderType.LIMIT || values.order_type === OrderType.STOP_LIMIT) {
1200
1209
  if (values.order_price) {
1201
1210
  const price = Number(values.order_price);
1202
1211
  const total = quantity.mul(price);
1203
- values.total = total.todp(2).toNumber();
1212
+ values.total = total.todp(2).toString();
1204
1213
  } else {
1205
1214
  values.total = "";
1206
1215
  }
@@ -1229,13 +1238,13 @@ function totalInputHandle(inputs) {
1229
1238
  const totalDP = total.dp();
1230
1239
  if (totalDP > config.quoteDP) {
1231
1240
  total = total.toDecimalPlaces(config.quoteDP);
1232
- values.total = total.toNumber();
1241
+ values.total = total.toString();
1233
1242
  }
1234
1243
  const quantity = total.div(price);
1235
1244
  return [
1236
1245
  {
1237
1246
  ...values,
1238
- order_quantity: quantity.toDecimalPlaces(Math.min(config.baseDP, quantity.dp())).toNumber()
1247
+ order_quantity: quantity.toDecimalPlaces(Math.min(config.baseDP, quantity.dp())).toString()
1239
1248
  },
1240
1249
  input,
1241
1250
  value,
@@ -1703,7 +1712,8 @@ var useOrderStream = (params) => {
1703
1712
  // onError: (err) => {
1704
1713
  // console.error("fetch failed::::", err);
1705
1714
  // },
1706
- formatter: (data) => data
1715
+ formatter: (data) => data,
1716
+ revalidateOnFocus: false
1707
1717
  });
1708
1718
  const flattenOrders = useMemo(() => {
1709
1719
  if (!ordersResponse.data) {
@@ -2338,7 +2348,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2338
2348
  const diffOrderEntry = (prev, current) => {
2339
2349
  if (!prev)
2340
2350
  return null;
2341
- let key, value;
2351
+ let key, value, preValue;
2342
2352
  const keys = Object.keys(current);
2343
2353
  for (let i = 0; i < keys.length; i++) {
2344
2354
  const k = keys[i];
@@ -2349,12 +2359,13 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2349
2359
  if (preveValue !== currentValue) {
2350
2360
  key = k;
2351
2361
  value = currentValue;
2362
+ preValue = preveValue;
2352
2363
  break;
2353
2364
  }
2354
2365
  }
2355
2366
  if (!key)
2356
2367
  return null;
2357
- return { key, value };
2368
+ return { key, value, preValue };
2358
2369
  };
2359
2370
  const maxQty = useMaxQty(symbol, sideValue, isReduceOnly);
2360
2371
  const parseString2Number = (order3, key) => {
@@ -2365,12 +2376,34 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2365
2376
  }
2366
2377
  order3[key] = order3[key].replace(/,/g, "");
2367
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]);
2368
2399
  const parsedData = useMemo(() => {
2369
2400
  if (typeof symbolOrOrder === "string") {
2370
2401
  return null;
2371
2402
  }
2372
2403
  if (typeof symbolOrOrder.order_quantity === "string") {
2373
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();
2374
2407
  }
2375
2408
  if (typeof symbolOrOrder.order_price === "string") {
2376
2409
  parseString2Number(symbolOrOrder, "order_price");
@@ -2381,14 +2414,18 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2381
2414
  if (typeof symbolOrOrder.trigger_price === "string") {
2382
2415
  parseString2Number(symbolOrOrder, "trigger_price");
2383
2416
  }
2384
- if (typeof symbolOrOrder.trigger_price === "string") {
2385
- symbolOrOrder.trigger_price = symbolOrOrder.trigger_price.replace(/,/g, "");
2386
- }
2387
- if (typeof symbolOrOrder.order_quantity === "number") {
2388
- symbolOrOrder.order_quantity = new Decimal(symbolOrOrder.order_quantity).toDecimalPlaces(baseDP).toString();
2389
- }
2390
2417
  return symbolOrOrder;
2391
- }, [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
+ ]);
2392
2429
  const createOrder = (values) => {
2393
2430
  if (!values.symbol) {
2394
2431
  throw new SDKError("symbol is error");
@@ -2510,19 +2547,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2510
2547
  prevOrderData.current = parsedData;
2511
2548
  orderDataCache.current = values;
2512
2549
  return values;
2513
- }, [
2514
- parsedData?.order_price,
2515
- parsedData?.side,
2516
- parsedData?.order_quantity,
2517
- parsedData?.visible_quantity,
2518
- parsedData?.order_type,
2519
- parsedData?.order_type_ext,
2520
- parsedData?.symbol,
2521
- parsedData?.total,
2522
- parsedData?.reduce_only,
2523
- parsedData?.trigger_price,
2524
- markPrice
2525
- ]);
2550
+ }, [parsedData, markPrice]);
2526
2551
  useEffect(() => {
2527
2552
  if (!markPrice)
2528
2553
  return;
@@ -4050,7 +4075,7 @@ var woofiDexCrossChainRouterAbi = [
4050
4075
  var nativeTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
4051
4076
  var isNativeTokenChecker = (address) => address === nativeTokenAddress;
4052
4077
  var useChains = (networkId, options = {}) => {
4053
- const { pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
4078
+ const { pick: pick4, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
4054
4079
  const { configStore } = useContext(OrderlyContext);
4055
4080
  const field = options?.pick;
4056
4081
  const filterFun = useRef(options?.filter);
@@ -5260,6 +5285,6 @@ var useSwap = () => {
5260
5285
  };
5261
5286
  };
5262
5287
 
5263
- export { MarketsType, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, StatusContext, StatusProvider, WalletConnectorContext, 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 };
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 };
5264
5289
  //# sourceMappingURL=out.js.map
5265
5290
  //# sourceMappingURL=index.mjs.map