@orderly.network/hooks 0.0.95 → 0.0.96

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.js CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var React2 = require('react');
3
+ var react = require('react');
4
4
  var useSWR = require('swr');
5
5
  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
9
  var types = require('@orderly.network/types');
10
+ var jsxRuntime = require('react/jsx-runtime');
10
11
  var utils = require('@orderly.network/utils');
11
12
  var useSWRSubscription = require('swr/subscription');
12
13
  var ramda = require('ramda');
@@ -17,7 +18,6 @@ var scanClient = require('@layerzerolabs/scan-client');
17
18
 
18
19
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
20
 
20
- var React2__default = /*#__PURE__*/_interopDefault(React2);
21
21
  var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
22
22
  var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
23
23
  var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
@@ -29,7 +29,7 @@ var __export = (target, all) => {
29
29
  for (var name in all)
30
30
  __defProp(target, name, { get: all[name], enumerable: true });
31
31
  };
32
- var OrderlyContext = React2.createContext({
32
+ var OrderlyContext = react.createContext({
33
33
  // configStore: new MemoryConfigStore(),
34
34
  });
35
35
  var OrderlyProvider = OrderlyContext.Provider;
@@ -37,7 +37,7 @@ var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?
37
37
 
38
38
  // src/useQuery.ts
39
39
  var useQuery = (query, options) => {
40
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
40
+ const { apiBaseUrl } = react.useContext(OrderlyContext);
41
41
  const { formatter, ...swrOptions } = options || {};
42
42
  if (typeof apiBaseUrl === "undefined") {
43
43
  throw new Error("please add OrderlyProvider to your app");
@@ -52,7 +52,7 @@ var useQuery = (query, options) => {
52
52
  );
53
53
  };
54
54
  var useLazyQuery = (query, options) => {
55
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
55
+ const { apiBaseUrl } = react.useContext(OrderlyContext);
56
56
  const { formatter, init, ...swrOptions } = options || {};
57
57
  if (typeof apiBaseUrl === "undefined") {
58
58
  throw new Error("please add OrderlyProvider to your app");
@@ -75,7 +75,7 @@ var useLazyQuery = (query, options) => {
75
75
  );
76
76
  };
77
77
  var useAccountInstance = () => {
78
- const { configStore, keyStore, contractManager, getWalletAdapter } = React2.useContext(OrderlyContext);
78
+ const { configStore, keyStore, contractManager, getWalletAdapter } = react.useContext(OrderlyContext);
79
79
  if (!configStore)
80
80
  throw new Error("configStore is not defined, please use OrderlyProvider");
81
81
  if (!keyStore) {
@@ -118,7 +118,7 @@ var fetcher2 = (url, options) => {
118
118
  return net.mutate(url, init);
119
119
  };
120
120
  var useMutation = (url, method = "POST", options) => {
121
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
121
+ const { apiBaseUrl } = react.useContext(OrderlyContext);
122
122
  let fullUrl = url;
123
123
  if (!url.startsWith("http")) {
124
124
  fullUrl = `${apiBaseUrl}${url}`;
@@ -164,7 +164,7 @@ var useMutation = (url, method = "POST", options) => {
164
164
  ];
165
165
  };
166
166
  var signatureMiddleware = (useSWRNext) => {
167
- const { apiBaseUrl } = React2.useContext(OrderlyContext);
167
+ const { apiBaseUrl } = react.useContext(OrderlyContext);
168
168
  return (key, fetcher3, config) => {
169
169
  try {
170
170
  const extendedFetcher = async (args) => {
@@ -198,7 +198,7 @@ var useAccount = () => {
198
198
  onWalletConnect,
199
199
  onWalletDisconnect,
200
200
  onSetChain
201
- } = React2.useContext(OrderlyContext);
201
+ } = react.useContext(OrderlyContext);
202
202
  if (!configStore)
203
203
  throw new Error("configStore is not defined, please use OrderlyProvider");
204
204
  if (!keyStore) {
@@ -207,26 +207,26 @@ var useAccount = () => {
207
207
  );
208
208
  }
209
209
  const account5 = useAccountInstance();
210
- const [state, setState] = React2.useState(account5.stateValue);
210
+ const [state, setState] = react.useState(account5.stateValue);
211
211
  const statusChangeHandler = (nextState) => {
212
212
  setState(() => nextState);
213
213
  };
214
- React2.useEffect(() => {
214
+ react.useEffect(() => {
215
215
  account5.on("change:status", statusChangeHandler);
216
216
  return () => {
217
217
  account5.off("change:status", statusChangeHandler);
218
218
  };
219
219
  }, []);
220
- const createOrderlyKey = React2.useCallback(
220
+ const createOrderlyKey = react.useCallback(
221
221
  async (remember) => {
222
222
  return account5.createOrderlyKey(remember ? 365 : 30);
223
223
  },
224
224
  [account5]
225
225
  );
226
- const createAccount = React2.useCallback(async () => {
226
+ const createAccount = react.useCallback(async () => {
227
227
  return account5.createAccount();
228
228
  }, [account5]);
229
- const connect = React2.useCallback(async () => {
229
+ const connect = react.useCallback(async () => {
230
230
  return onWalletConnect?.();
231
231
  }, [account5]);
232
232
  const disconnect = async () => {
@@ -268,10 +268,10 @@ var usePrivateQuery = (query, options) => {
268
268
  );
269
269
  };
270
270
  var useBoolean = (initialValue = false) => {
271
- const [value, setValue] = React2.useState(initialValue);
272
- const setTrue = React2.useCallback(() => setValue(true), []);
273
- const setFalse = React2.useCallback(() => setValue(false), []);
274
- const toggle = React2.useCallback(() => setValue((v) => !v), []);
271
+ const [value, setValue] = react.useState(initialValue);
272
+ const setTrue = react.useCallback(() => setValue(true), []);
273
+ const setFalse = react.useCallback(() => setValue(false), []);
274
+ const toggle = react.useCallback(() => setValue((v) => !v), []);
275
275
  return [value, { setTrue, setFalse, toggle }];
276
276
  };
277
277
 
@@ -280,8 +280,8 @@ var useTradingView = () => {
280
280
  return {};
281
281
  };
282
282
  var useTopicObserve = (topic) => {
283
- const [data, setData] = React2.useState();
284
- React2.useEffect(() => {
283
+ const [data, setData] = react.useState();
284
+ react.useEffect(() => {
285
285
  return () => {
286
286
  };
287
287
  }, []);
@@ -290,14 +290,14 @@ var useTopicObserve = (topic) => {
290
290
  };
291
291
  };
292
292
  var useAppState = () => {
293
- const { errors } = React2.useContext(OrderlyContext);
293
+ const { errors } = react.useContext(OrderlyContext);
294
294
  return {
295
295
  errors
296
296
  // ready,
297
297
  };
298
298
  };
299
299
  var usePreLoadData = () => {
300
- const { configStore } = React2.useContext(OrderlyContext);
300
+ const { configStore } = react.useContext(OrderlyContext);
301
301
  const { error: swapSupportError, data: swapSupportData } = useSWR__default.default(
302
302
  `${configStore.get("swapSupportApiUrl")}/swap_support`,
303
303
  (url) => fetch(url).then((res) => res.json()),
@@ -308,7 +308,7 @@ var usePreLoadData = () => {
308
308
  const { error: tokenError, data: tokenData } = useQuery("/v1/public/token", {
309
309
  revalidateOnFocus: false
310
310
  });
311
- const isDone = React2.useMemo(() => {
311
+ const isDone = react.useMemo(() => {
312
312
  return !!swapSupportData && !!tokenData;
313
313
  }, [swapSupportData, tokenData]);
314
314
  return {
@@ -338,7 +338,7 @@ function parseJSON(value) {
338
338
 
339
339
  // src/useSessionStorage.ts
340
340
  function useSessionStorage(key, initialValue) {
341
- const readValue = React2.useCallback(() => {
341
+ const readValue = react.useCallback(() => {
342
342
  if (typeof window === "undefined") {
343
343
  return initialValue;
344
344
  }
@@ -350,7 +350,7 @@ function useSessionStorage(key, initialValue) {
350
350
  return initialValue;
351
351
  }
352
352
  }, [initialValue, key]);
353
- const [storedValue, setStoredValue] = React2.useState(readValue);
353
+ const [storedValue, setStoredValue] = react.useState(readValue);
354
354
  const setValue = (value) => {
355
355
  if (typeof window == "undefined") {
356
356
  console.warn(
@@ -365,10 +365,10 @@ function useSessionStorage(key, initialValue) {
365
365
  console.warn(`Error setting sessionStorage key \u201C${key}\u201D:`, error);
366
366
  }
367
367
  };
368
- React2.useEffect(() => {
368
+ react.useEffect(() => {
369
369
  setStoredValue(readValue());
370
370
  }, []);
371
- React2.useEffect(() => {
371
+ react.useEffect(() => {
372
372
  if (typeof window == "undefined") {
373
373
  return;
374
374
  }
@@ -377,7 +377,7 @@ function useSessionStorage(key, initialValue) {
377
377
  window.removeEventListener("storage", handleStorageChange);
378
378
  };
379
379
  });
380
- const handleStorageChange = React2.useCallback(
380
+ const handleStorageChange = react.useCallback(
381
381
  (event) => {
382
382
  if (event?.key && event.key !== key) {
383
383
  return;
@@ -389,7 +389,7 @@ function useSessionStorage(key, initialValue) {
389
389
  return [storedValue, setValue];
390
390
  }
391
391
  function useLocalStorage(key, initialValue) {
392
- const readValue = React2.useCallback(() => {
392
+ const readValue = react.useCallback(() => {
393
393
  if (typeof window === "undefined") {
394
394
  return initialValue;
395
395
  }
@@ -401,8 +401,8 @@ function useLocalStorage(key, initialValue) {
401
401
  return initialValue;
402
402
  }
403
403
  }, [initialValue, key]);
404
- const [storedValue, setStoredValue] = React2.useState(readValue);
405
- const setValue = React2.useCallback(
404
+ const [storedValue, setStoredValue] = react.useState(readValue);
405
+ const setValue = react.useCallback(
406
406
  (value) => {
407
407
  if (typeof window === "undefined") {
408
408
  console.warn(
@@ -419,14 +419,14 @@ function useLocalStorage(key, initialValue) {
419
419
  },
420
420
  [storedValue]
421
421
  );
422
- React2.useEffect(() => {
422
+ react.useEffect(() => {
423
423
  setStoredValue(readValue());
424
424
  }, []);
425
425
  return [storedValue, setValue];
426
426
  }
427
427
  var useRunOnce = ({ fn, sessionKey }) => {
428
- const triggered = React2.useRef(false);
429
- React2.useEffect(() => {
428
+ const triggered = react.useRef(false);
429
+ react.useEffect(() => {
430
430
  const hasBeenTriggered = sessionKey ? sessionStorage.getItem(sessionKey) : triggered.current;
431
431
  if (!hasBeenTriggered) {
432
432
  fn();
@@ -438,17 +438,17 @@ var useRunOnce = ({ fn, sessionKey }) => {
438
438
  }, [fn, sessionKey]);
439
439
  return null;
440
440
  };
441
- var DataSourceContext = React2.createContext({});
441
+ var DataSourceContext = react.createContext({});
442
442
  var DataSourceProvider = (props) => {
443
443
  useAccountInstance();
444
444
  useConstant__default.default(() => {
445
445
  });
446
- return /* @__PURE__ */ React2__default.default.createElement(DataSourceContext.Provider, { value: {} }, props.children);
446
+ return /* @__PURE__ */ jsxRuntime.jsx(DataSourceContext.Provider, { value: {}, children: props.children });
447
447
  };
448
448
  var WS_NAME = "nativeWebsocketClient";
449
449
  var useWS = () => {
450
450
  useAccount();
451
- const { configStore } = React2.useContext(OrderlyContext);
451
+ const { configStore } = react.useContext(OrderlyContext);
452
452
  const ws = useConstant__default.default(() => {
453
453
  let websocketClient = core.SimpleDI.get(WS_NAME);
454
454
  const account5 = core.SimpleDI.get(core.Account.instanceName);
@@ -477,7 +477,7 @@ var useWS = () => {
477
477
  return ws;
478
478
  };
479
479
  var useConfig = () => {
480
- const { configStore } = React2.useContext(OrderlyContext);
480
+ const { configStore } = react.useContext(OrderlyContext);
481
481
  return configStore;
482
482
  };
483
483
  var useMarkPrice = (symbol) => {
@@ -532,9 +532,9 @@ var useTickerStream = (symbol) => {
532
532
  revalidateOnFocus: false
533
533
  }
534
534
  );
535
- const [ticker, setTicker] = React2.useState();
535
+ const [ticker, setTicker] = react.useState();
536
536
  const ws = useWS();
537
- React2.useEffect(() => {
537
+ react.useEffect(() => {
538
538
  const unsubscribe = ws.subscribe(
539
539
  // { event: "subscribe", topic: "markprices" },
540
540
  `${symbol}@ticker`,
@@ -560,7 +560,7 @@ var useTickerStream = (symbol) => {
560
560
  const { data: markPrice } = useMarkPrice(symbol);
561
561
  const { data: indexPrice } = useIndexPrice(symbol);
562
562
  const { data: openInterest } = useOpenInterest(symbol);
563
- const value = React2.useMemo(() => {
563
+ const value = react.useMemo(() => {
564
564
  if (!info)
565
565
  return null;
566
566
  if (!ticker)
@@ -764,23 +764,23 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
764
764
  if (!symbol) {
765
765
  throw new Error("useOrderbookStream requires a symbol");
766
766
  }
767
- const [requestData, setRequestData] = React2.useState(null);
768
- const [data, setData] = React2.useState(initial);
769
- const [isLoading, setIsLoading] = React2.useState(true);
770
- const [level, setLevel] = React2.useState(() => options?.level ?? 10);
767
+ const [requestData, setRequestData] = react.useState(null);
768
+ const [data, setData] = react.useState(initial);
769
+ const [isLoading, setIsLoading] = react.useState(true);
770
+ const [level, setLevel] = react.useState(() => options?.level ?? 10);
771
771
  const config = useSymbolsInfo()[symbol];
772
- const [depth, setDepth] = React2.useState();
773
- const depths = React2.useMemo(() => {
772
+ const [depth, setDepth] = react.useState();
773
+ const depths = react.useMemo(() => {
774
774
  const tick = config("quote_tick");
775
775
  return [tick, tick * 10, tick * 100, tick * 1e3];
776
776
  }, [config("quote_tick")]);
777
- React2.useEffect(() => {
777
+ react.useEffect(() => {
778
778
  setDepth(config("quote_tick"));
779
779
  }, [config("quote_tick")]);
780
780
  const ws = useWS();
781
781
  const ticker = useTickerStream(symbol);
782
782
  const eventEmitter = useEventEmitter();
783
- React2.useEffect(() => {
783
+ react.useEffect(() => {
784
784
  setIsLoading(true);
785
785
  let ignore = false;
786
786
  ws.onceSubscribe(
@@ -815,7 +815,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
815
815
  };
816
816
  }, [symbol, depth]);
817
817
  const { data: markPrice } = useMarkPrice(symbol);
818
- React2.useEffect(() => {
818
+ react.useEffect(() => {
819
819
  if (!requestData)
820
820
  return;
821
821
  let ignore = false;
@@ -840,14 +840,14 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
840
840
  subscription?.();
841
841
  };
842
842
  }, [symbol, requestData]);
843
- const onItemClick = React2.useCallback((item) => {
843
+ const onItemClick = react.useCallback((item) => {
844
844
  eventEmitter.emit("orderbook:item:click", item);
845
845
  }, []);
846
- const onDepthChange = React2.useCallback((depth2) => {
846
+ const onDepthChange = react.useCallback((depth2) => {
847
847
  setDepth(() => depth2);
848
848
  }, []);
849
- const prevMiddlePrice = React2.useRef(0);
850
- const middlePrice = React2.useMemo(() => {
849
+ const prevMiddlePrice = react.useRef(0);
850
+ const middlePrice = react.useMemo(() => {
851
851
  let asksFrist = 0, bidsFirst = 0;
852
852
  if (data.asks.length > 0) {
853
853
  asksFrist = data.asks[data.asks.length - 1][0];
@@ -859,7 +859,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
859
859
  return 0;
860
860
  return [asksFrist, bidsFirst, ticker["24h_close"]].sort()[1];
861
861
  }, [ticker, data]);
862
- React2.useEffect(() => {
862
+ react.useEffect(() => {
863
863
  prevMiddlePrice.current = middlePrice;
864
864
  }, [middlePrice]);
865
865
  const reducedData = reduceOrderbook(depth, level, {
@@ -1104,7 +1104,7 @@ var usePositionStream = (symbol, options) => {
1104
1104
  }
1105
1105
  });
1106
1106
  const { data: markPrices } = useMarkPricesStream();
1107
- const formatedPositions = React2.useMemo(() => {
1107
+ const formatedPositions = react.useMemo(() => {
1108
1108
  if (!data?.rows || !symbolInfo || !accountInfo)
1109
1109
  return null;
1110
1110
  const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows : data.rows.filter((item) => {
@@ -1170,7 +1170,7 @@ var usePositionStream = (symbol, options) => {
1170
1170
  }
1171
1171
  ];
1172
1172
  }, [data?.rows, symbolInfo, accountInfo, markPrices, symbol, holding]);
1173
- const [totalCollateral, totalValue, totalUnrealizedROI] = React2.useMemo(() => {
1173
+ const [totalCollateral, totalValue, totalUnrealizedROI] = react.useMemo(() => {
1174
1174
  if (!holding || !markPrices) {
1175
1175
  return [utils.zero, utils.zero, 0];
1176
1176
  }
@@ -1193,7 +1193,7 @@ var usePositionStream = (symbol, options) => {
1193
1193
  });
1194
1194
  return [totalCollateral2, totalValue2, totalUnrealizedROI2];
1195
1195
  }, [holding, formatedPositions, markPrices]);
1196
- const positionsRows = React2.useMemo(() => {
1196
+ const positionsRows = react.useMemo(() => {
1197
1197
  if (!formatedPositions)
1198
1198
  return null;
1199
1199
  if (!symbolInfo || !accountInfo)
@@ -1261,7 +1261,7 @@ var useHoldingStream = () => {
1261
1261
  }
1262
1262
  }
1263
1263
  );
1264
- const usdc = React2.useMemo(() => {
1264
+ const usdc = react.useMemo(() => {
1265
1265
  const usdc2 = data?.find((item) => item.token === "USDC");
1266
1266
  return usdc2;
1267
1267
  }, [data]);
@@ -1351,7 +1351,7 @@ var useOrderStream = ({
1351
1351
  formatter: (data) => data
1352
1352
  }
1353
1353
  );
1354
- const orders = React2.useMemo(() => {
1354
+ const orders = react.useMemo(() => {
1355
1355
  if (!ordersResponse.data) {
1356
1356
  return null;
1357
1357
  }
@@ -1362,10 +1362,10 @@ var useOrderStream = ({
1362
1362
  };
1363
1363
  });
1364
1364
  }, [ordersResponse.data, markPrices]);
1365
- const total = React2.useMemo(() => {
1365
+ const total = react.useMemo(() => {
1366
1366
  return ordersResponse.data?.[0]?.meta?.total || 0;
1367
1367
  }, [ordersResponse.data]);
1368
- React2.useEffect(() => {
1368
+ react.useEffect(() => {
1369
1369
  const unsubscribe = ws.privateSubscribe(
1370
1370
  {
1371
1371
  id: "executionreport_orders",
@@ -1426,15 +1426,16 @@ var useOrderStream = ({
1426
1426
  );
1427
1427
  return () => unsubscribe();
1428
1428
  }, []);
1429
- const cancelAllOrders = React2.useCallback(() => {
1429
+ const cancelAllOrders = react.useCallback(() => {
1430
1430
  }, [ordersResponse.data]);
1431
- const updateOrder = React2.useCallback((orderId, order2) => {
1431
+ const updateOrder = react.useCallback((orderId, order2) => {
1432
1432
  return doUpdateOrder({ ...order2, order_id: orderId });
1433
1433
  }, []);
1434
- const cancelOrder = React2.useCallback((orderId, symbol2) => {
1434
+ const cancelOrder = react.useCallback((orderId, symbol2) => {
1435
1435
  return doCancelOrder(null, {
1436
1436
  order_id: orderId,
1437
- symbol: symbol2
1437
+ symbol: symbol2,
1438
+ source: "mweb"
1438
1439
  }).then((res) => {
1439
1440
  if (res.success) ; else {
1440
1441
  throw new Error(res.message);
@@ -1503,13 +1504,13 @@ var useCollateral = (options = { dp: 6 }) => {
1503
1504
  const symbolInfo = useSymbolsInfo();
1504
1505
  const { data: markPrices } = useMarkPricesStream();
1505
1506
  const { usdc } = useHoldingStream();
1506
- const [totalCollateral, totalValue] = React2.useMemo(() => {
1507
+ const [totalCollateral, totalValue] = react.useMemo(() => {
1507
1508
  return [
1508
1509
  ramda.pathOr(utils.zero, [0, "totalCollateral"], positions2),
1509
1510
  ramda.pathOr(utils.zero, [0, "totalValue"], positions2)
1510
1511
  ];
1511
1512
  }, [positions2, markPrices]);
1512
- const totalInitialMarginWithOrders = React2.useMemo(() => {
1513
+ const totalInitialMarginWithOrders = react.useMemo(() => {
1513
1514
  if (!accountInfo || !symbolInfo || !markPrices) {
1514
1515
  return 0;
1515
1516
  }
@@ -1522,13 +1523,13 @@ var useCollateral = (options = { dp: 6 }) => {
1522
1523
  symbolInfo
1523
1524
  });
1524
1525
  }, [positions2, orders, markPrices, accountInfo, symbolInfo]);
1525
- const freeCollateral = React2.useMemo(() => {
1526
+ const freeCollateral = react.useMemo(() => {
1526
1527
  return futures.account.freeCollateral({
1527
1528
  totalCollateral,
1528
1529
  totalInitialMarginWithOrders
1529
1530
  });
1530
1531
  }, [totalCollateral, totalInitialMarginWithOrders]);
1531
- const availableBalance = React2.useMemo(() => {
1532
+ const availableBalance = react.useMemo(() => {
1532
1533
  return futures.account.availableBalance({
1533
1534
  USDCHolding: usdc?.holding ?? 0,
1534
1535
  unsettlementPnL: pathOr_unsettledPnLPathOr(positions2)
@@ -1550,7 +1551,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
1550
1551
  const symbolInfo = useSymbolsInfo();
1551
1552
  const { totalCollateral } = useCollateral();
1552
1553
  const { data: markPrices } = useMarkPricesStream();
1553
- const maxQty = React2.useMemo(() => {
1554
+ const maxQty = react.useMemo(() => {
1554
1555
  if (!symbol)
1555
1556
  return 0;
1556
1557
  const positions2 = positionsPath2(positionsData);
@@ -1787,11 +1788,11 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1787
1788
  const [doCreateOrder] = useMutation("/v1/order");
1788
1789
  const { freeCollateral } = useCollateral();
1789
1790
  const symbolInfo = useSymbolsInfo();
1790
- const baseDP = React2.useMemo(
1791
+ const baseDP = react.useMemo(
1791
1792
  () => utils.getPrecisionByNumber(symbolInfo[symbol]("base_tick", 0)),
1792
1793
  [symbolInfo]
1793
1794
  );
1794
- const quoteDP = React2.useMemo(() => {
1795
+ const quoteDP = react.useMemo(() => {
1795
1796
  return utils.getPrecisionByNumber(symbolInfo[symbol]("quote_tick", 0));
1796
1797
  }, [symbolInfo]);
1797
1798
  const { data: markPrice } = useMarkPrice(symbol);
@@ -1830,7 +1831,7 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
1830
1831
  });
1831
1832
  });
1832
1833
  };
1833
- const calculate = React2.useCallback(
1834
+ const calculate = react.useCallback(
1834
1835
  (values, field, value) => {
1835
1836
  const fieldHandler = getCalculateHandler(field);
1836
1837
  const newValues = ramda.compose(
@@ -1871,11 +1872,11 @@ var useFetures = () => {
1871
1872
  revalidateOnFocus: false
1872
1873
  }
1873
1874
  );
1874
- const [sortedData, setSortedData] = React2.useState(data);
1875
+ const [sortedData, setSortedData] = react.useState(data);
1875
1876
  useWS();
1876
- React2.useEffect(() => {
1877
+ react.useEffect(() => {
1877
1878
  }, []);
1878
- React2.useEffect(() => {
1879
+ react.useEffect(() => {
1879
1880
  if (data) {
1880
1881
  const sortedData2 = data.sort((a, b) => {
1881
1882
  return 0;
@@ -1883,9 +1884,9 @@ var useFetures = () => {
1883
1884
  setSortedData(sortedData2);
1884
1885
  }
1885
1886
  }, [data]);
1886
- const sortBy = React2.useCallback((key) => {
1887
+ const sortBy = react.useCallback((key) => {
1887
1888
  }, [data]);
1888
- const filterBy = React2.useCallback((key) => {
1889
+ const filterBy = react.useCallback((key) => {
1889
1890
  }, [data]);
1890
1891
  return {
1891
1892
  // ...data,
@@ -1948,7 +1949,7 @@ var useMarketsStream = () => {
1948
1949
  unsubscribe?.();
1949
1950
  };
1950
1951
  });
1951
- const value = React2.useMemo(() => {
1952
+ const value = react.useMemo(() => {
1952
1953
  if (!futures)
1953
1954
  return null;
1954
1955
  if (!tickers)
@@ -1975,7 +1976,7 @@ var useLeverage = () => {
1975
1976
  const { data, mutate: mutate2 } = usePrivateQuery("/v1/client/info");
1976
1977
  const [update] = useMutation("/v1/client/leverage");
1977
1978
  const { data: config } = useQuery("/v1/public/config");
1978
- const updateLeverage = React2.useCallback((data2) => {
1979
+ const updateLeverage = react.useCallback((data2) => {
1979
1980
  return update(data2).then((res) => {
1980
1981
  console.log(res);
1981
1982
  if (res.success) {
@@ -1998,7 +1999,7 @@ var useFundingRate = (symbol) => {
1998
1999
  if (!symbol) {
1999
2000
  throw new Error("useFuturesForSymbol requires a symbol");
2000
2001
  }
2001
- const [countDown, setCountDown] = React2.useState("00:00:00");
2002
+ const [countDown, setCountDown] = react.useState("00:00:00");
2002
2003
  const { data } = useQuery(
2003
2004
  `/v1/public/funding_rate/${symbol}`,
2004
2005
  {
@@ -2008,7 +2009,7 @@ var useFundingRate = (symbol) => {
2008
2009
  }
2009
2010
  }
2010
2011
  );
2011
- React2.useEffect(() => {
2012
+ react.useEffect(() => {
2012
2013
  if (!data)
2013
2014
  return;
2014
2015
  const { next_funding_time } = data;
@@ -2038,12 +2039,12 @@ var useMarketTradeStream = (symbol, options = {}) => {
2038
2039
  if (!symbol) {
2039
2040
  throw new Error("useTradeStream: symbol is required");
2040
2041
  }
2041
- const [trades, setTrades] = React2.useState([]);
2042
- const [isLoading, setIsLoading] = React2.useState(false);
2043
- React2.useState(() => symbol);
2042
+ const [trades, setTrades] = react.useState([]);
2043
+ const [isLoading, setIsLoading] = react.useState(false);
2044
+ react.useState(() => symbol);
2044
2045
  const { limit = 50 } = options;
2045
2046
  const ws = useWS();
2046
- React2.useEffect(() => {
2047
+ react.useEffect(() => {
2047
2048
  setIsLoading(true);
2048
2049
  setTrades(() => []);
2049
2050
  ws.onceSubscribe(
@@ -2064,7 +2065,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
2064
2065
  }
2065
2066
  );
2066
2067
  }, [symbol]);
2067
- React2.useEffect(() => {
2068
+ react.useEffect(() => {
2068
2069
  const unsubscript = ws.subscribe(
2069
2070
  {
2070
2071
  id: `${symbol}@trade`,
@@ -2094,7 +2095,7 @@ var useMarginRatio = () => {
2094
2095
  const [{ rows }] = usePositionStream();
2095
2096
  const { data: markPrices } = useMarkPricesStream();
2096
2097
  const { totalCollateral } = useCollateral();
2097
- const marginRatio = React2.useMemo(() => {
2098
+ const marginRatio = react.useMemo(() => {
2098
2099
  if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
2099
2100
  return 0;
2100
2101
  }
@@ -2105,7 +2106,7 @@ var useMarginRatio = () => {
2105
2106
  });
2106
2107
  return ratio;
2107
2108
  }, [rows, markPrices, totalCollateral]);
2108
- const currentLeverage = React2.useMemo(() => {
2109
+ const currentLeverage = react.useMemo(() => {
2109
2110
  return futures.account.currentLeverage(marginRatio);
2110
2111
  }, [marginRatio]);
2111
2112
  return { marginRatio, currentLeverage };
@@ -3128,9 +3129,9 @@ var isNativeTokenChecker = (address) => address === nativeTokenAddress;
3128
3129
  // src/orderly/useChains.ts
3129
3130
  var useChains = (networkId, options = {}) => {
3130
3131
  const { filter, pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
3131
- const { configStore, networkId: envNetworkId } = React2.useContext(OrderlyContext);
3132
+ const { configStore, networkId: envNetworkId } = react.useContext(OrderlyContext);
3132
3133
  const field = options?.pick;
3133
- const map2 = React2.useRef(
3134
+ const map2 = react.useRef(
3134
3135
  /* @__PURE__ */ new Map()
3135
3136
  );
3136
3137
  const { data, error: swapSupportError } = useSWR__default.default(
@@ -3158,7 +3159,7 @@ var useChains = (networkId, options = {}) => {
3158
3159
  dedupingInterval: 36e5
3159
3160
  }
3160
3161
  );
3161
- const chains = React2.useMemo(() => {
3162
+ const chains = react.useMemo(() => {
3162
3163
  if (!orderlyChains)
3163
3164
  return void 0;
3164
3165
  let orderlyChainsArr = [];
@@ -3270,7 +3271,7 @@ var useChains = (networkId, options = {}) => {
3270
3271
  };
3271
3272
  }
3272
3273
  }, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
3273
- const findByChainId = React2.useCallback(
3274
+ const findByChainId = react.useCallback(
3274
3275
  (chainId, field2) => {
3275
3276
  const chain = map2.current.get(chainId);
3276
3277
  if (chain) {
@@ -3297,7 +3298,7 @@ var useChains = (networkId, options = {}) => {
3297
3298
  };
3298
3299
  var useChain = (token) => {
3299
3300
  const { data, isLoading } = useQuery("/v1/public/token");
3300
- const chains = React2.useMemo(() => {
3301
+ const chains = react.useMemo(() => {
3301
3302
  if (!data)
3302
3303
  return null;
3303
3304
  let item = data.find((chain) => chain.token === token);
@@ -3316,9 +3317,9 @@ var useChain = (token) => {
3316
3317
  };
3317
3318
  var useWithdraw = () => {
3318
3319
  const { account: account5, state } = useAccount();
3319
- const [isLoading, setIsLoading] = React2.useState(false);
3320
+ const [isLoading, setIsLoading] = react.useState(false);
3320
3321
  const { unsettledPnL, availableBalance } = useCollateral();
3321
- const withdraw = React2.useCallback(
3322
+ const withdraw = react.useCallback(
3322
3323
  (inputs) => {
3323
3324
  return account5.assetsManager.withdraw(inputs).then((res) => {
3324
3325
  return res;
@@ -3327,7 +3328,7 @@ var useWithdraw = () => {
3327
3328
  [state]
3328
3329
  );
3329
3330
  const { usdc } = useHoldingStream();
3330
- const maxAmount = React2.useMemo(() => {
3331
+ const maxAmount = react.useMemo(() => {
3331
3332
  if (!usdc || !usdc.holding)
3332
3333
  return 0;
3333
3334
  if (unsettledPnL >= 0)
@@ -3337,18 +3338,18 @@ var useWithdraw = () => {
3337
3338
  return { withdraw, isLoading, maxAmount, availableBalance, unsettledPnL };
3338
3339
  };
3339
3340
  var useDeposit = (options) => {
3340
- const { onlyTestnet } = React2.useContext(OrderlyContext);
3341
- const [balanceRevalidating, setBalanceRevalidating] = React2.useState(false);
3342
- const [allowanceRevalidating, setAllowanceRevalidating] = React2.useState(false);
3341
+ const { onlyTestnet } = react.useContext(OrderlyContext);
3342
+ const [balanceRevalidating, setBalanceRevalidating] = react.useState(false);
3343
+ const [allowanceRevalidating, setAllowanceRevalidating] = react.useState(false);
3343
3344
  const [_, { findByChainId }] = useChains(void 0, {
3344
3345
  wooSwapEnabled: true
3345
3346
  });
3346
- const [balance, setBalance] = React2.useState("0");
3347
- const [allowance, setAllowance] = React2.useState("0");
3347
+ const [balance, setBalance] = react.useState("0");
3348
+ const [allowance, setAllowance] = react.useState("0");
3348
3349
  const { account: account5, state } = useAccount();
3349
- const prevAddress = React2.useRef();
3350
- const getBalanceListener = React2.useRef();
3351
- const dst = React2.useMemo(() => {
3350
+ const prevAddress = react.useRef();
3351
+ const getBalanceListener = react.useRef();
3352
+ const dst = react.useMemo(() => {
3352
3353
  const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3353
3354
  const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
3354
3355
  if (!chain) {
@@ -3363,11 +3364,11 @@ var useDeposit = (options) => {
3363
3364
  // chainId: 42161,
3364
3365
  };
3365
3366
  }, []);
3366
- const isNativeToken = React2.useMemo(
3367
+ const isNativeToken = react.useMemo(
3367
3368
  () => isNativeTokenChecker(options?.address || ""),
3368
3369
  [options?.address]
3369
3370
  );
3370
- const fetchBalanceHandler = React2.useCallback(
3371
+ const fetchBalanceHandler = react.useCallback(
3371
3372
  async (address, decimals) => {
3372
3373
  let balance2;
3373
3374
  if (!!address && isNativeTokenChecker(address)) {
@@ -3381,7 +3382,7 @@ var useDeposit = (options) => {
3381
3382
  },
3382
3383
  []
3383
3384
  );
3384
- const fetchBalance = React2.useCallback(
3385
+ const fetchBalance = react.useCallback(
3385
3386
  async (address, decimals) => {
3386
3387
  if (!address)
3387
3388
  return;
@@ -3400,7 +3401,7 @@ var useDeposit = (options) => {
3400
3401
  },
3401
3402
  [state, balanceRevalidating]
3402
3403
  );
3403
- const fetchBalances = React2.useCallback(async (tokens) => {
3404
+ const fetchBalances = react.useCallback(async (tokens) => {
3404
3405
  const tasks = [];
3405
3406
  for (const token of tokens) {
3406
3407
  if (isNativeTokenChecker(token.address)) {
@@ -3435,7 +3436,7 @@ var useDeposit = (options) => {
3435
3436
  const allowance2 = await account5.assetsManager.getAllowance(address);
3436
3437
  setAllowance(() => allowance2);
3437
3438
  };
3438
- const getVaultAddress = React2.useCallback(() => {
3439
+ const getVaultAddress = react.useCallback(() => {
3439
3440
  if (dst.chainId !== options?.srcChainId) {
3440
3441
  return options?.crossChainRouteAddress;
3441
3442
  } else {
@@ -3444,7 +3445,7 @@ var useDeposit = (options) => {
3444
3445
  }
3445
3446
  }
3446
3447
  }, [options, dst]);
3447
- React2.useEffect(() => {
3448
+ react.useEffect(() => {
3448
3449
  if (state.status < types.AccountStatusEnum.Connected)
3449
3450
  return;
3450
3451
  fetchBalance(options?.address, options?.decimals);
@@ -3467,7 +3468,7 @@ var useDeposit = (options) => {
3467
3468
  account5.address,
3468
3469
  dst
3469
3470
  ]);
3470
- const approve = React2.useCallback(
3471
+ const approve = react.useCallback(
3471
3472
  (amount) => {
3472
3473
  if (!options?.address) {
3473
3474
  throw new Error("address is required");
@@ -3482,7 +3483,7 @@ var useDeposit = (options) => {
3482
3483
  },
3483
3484
  [account5, getAllowance, options?.address]
3484
3485
  );
3485
- const deposit = React2.useCallback(
3486
+ const deposit = react.useCallback(
3486
3487
  (amount) => {
3487
3488
  return account5.assetsManager.deposit(amount).then((res) => {
3488
3489
  setAllowance((value) => new utils.Decimal(value).sub(amount).toString());
@@ -3503,7 +3504,7 @@ var useDeposit = (options) => {
3503
3504
  loopGetBalance();
3504
3505
  }, 3e3);
3505
3506
  };
3506
- React2.useEffect(() => {
3507
+ react.useEffect(() => {
3507
3508
  if (!options?.address) {
3508
3509
  return;
3509
3510
  }
@@ -3580,7 +3581,7 @@ var usePrivateDataObserver = () => {
3580
3581
  const ws = useWS();
3581
3582
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3582
3583
  const { state } = useAccount();
3583
- React2.useEffect(() => {
3584
+ react.useEffect(() => {
3584
3585
  if (!state.accountId)
3585
3586
  return;
3586
3587
  const key = ["/v1/positions", state.accountId];
@@ -3658,10 +3659,10 @@ var useFundingRateBySymbol = (symbol) => {
3658
3659
  return useQuery(`/public/funding_rate/${symbol}`);
3659
3660
  };
3660
3661
  var useWooSwapQuery = () => {
3661
- const { configStore } = React2.useContext(OrderlyContext);
3662
+ const { configStore } = react.useContext(OrderlyContext);
3662
3663
  const account5 = useAccountInstance();
3663
3664
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3664
- const query = React2.useCallback(
3665
+ const query = react.useCallback(
3665
3666
  (inputs) => {
3666
3667
  if (loading)
3667
3668
  return;
@@ -3702,17 +3703,17 @@ var useWooSwapQuery = () => {
3702
3703
  };
3703
3704
  };
3704
3705
  var useWooCrossSwapQuery = () => {
3705
- const { configStore } = React2.useContext(OrderlyContext);
3706
+ const { configStore } = react.useContext(OrderlyContext);
3706
3707
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3707
3708
  const account5 = useAccountInstance();
3708
- const dstValutDeposit = React2.useCallback(() => {
3709
+ const dstValutDeposit = react.useCallback(() => {
3709
3710
  return {
3710
3711
  accountId: account5.accountIdHashStr,
3711
3712
  brokerHash: core.utils.parseBrokerHash(configStore.get("brokerId")),
3712
3713
  tokenHash: core.utils.parseTokenHash("USDC")
3713
3714
  };
3714
3715
  }, [account5]);
3715
- const queryDestinationFee = React2.useCallback(
3716
+ const queryDestinationFee = react.useCallback(
3716
3717
  async (crossChainRouteAddress, dst) => {
3717
3718
  if (!account5.walletClient) {
3718
3719
  throw new Error("walletClient is not ready");
@@ -3729,7 +3730,7 @@ var useWooCrossSwapQuery = () => {
3729
3730
  },
3730
3731
  []
3731
3732
  );
3732
- const query = React2.useCallback(
3733
+ const query = react.useCallback(
3733
3734
  (inputs) => {
3734
3735
  if (loading)
3735
3736
  return;
@@ -3790,20 +3791,20 @@ var useWooCrossSwapQuery = () => {
3790
3791
  };
3791
3792
  var useCrossSwap = () => {
3792
3793
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
3793
- const [layerStatus, setLayerStatus] = React2.useState(
3794
+ const [layerStatus, setLayerStatus] = react.useState(
3794
3795
  "WAITTING" /* INITIALIZING */
3795
3796
  );
3796
3797
  const ee = useEventEmitter();
3797
- const [bridgeMessage, setBridgeMessage] = React2.useState();
3798
- const [status, setStatus] = React2.useState(
3798
+ const [bridgeMessage, setBridgeMessage] = react.useState();
3799
+ const [status, setStatus] = react.useState(
3799
3800
  types.WS_WalletStatusEnum.NO
3800
3801
  );
3801
- const txHashFromBridge = React2.useRef();
3802
+ const txHashFromBridge = react.useRef();
3802
3803
  const account5 = useAccountInstance();
3803
- const { networkId, configStore } = React2.useContext(OrderlyContext);
3804
- const client = React2.useRef(scanClient.createClient(networkId)).current;
3805
- const timer = React2.useRef();
3806
- React2.useEffect(() => {
3804
+ const { networkId, configStore } = react.useContext(OrderlyContext);
3805
+ const client = react.useRef(scanClient.createClient(networkId)).current;
3806
+ const timer = react.useRef();
3807
+ react.useEffect(() => {
3807
3808
  const handler = (data) => {
3808
3809
  const { side, transStatus, trxId } = data;
3809
3810
  if (side === "DEPOSIT" && trxId === txHashFromBridge.current) {
@@ -3815,7 +3816,7 @@ var useCrossSwap = () => {
3815
3816
  ee.off("wallet:changed", handler);
3816
3817
  };
3817
3818
  }, [txHashFromBridge.current]);
3818
- const checkLayerStatus = React2.useCallback((txHash) => {
3819
+ const checkLayerStatus = react.useCallback((txHash) => {
3819
3820
  const check = async (txHash2) => {
3820
3821
  try {
3821
3822
  const { messages } = await client.getMessagesBySrcTxHash(txHash2);
@@ -3847,14 +3848,14 @@ var useCrossSwap = () => {
3847
3848
  };
3848
3849
  check(txHash);
3849
3850
  }, []);
3850
- React2.useEffect(() => {
3851
+ react.useEffect(() => {
3851
3852
  return () => {
3852
3853
  if (timer.current) {
3853
3854
  clearTimeout(timer.current);
3854
3855
  }
3855
3856
  };
3856
3857
  }, []);
3857
- const dstValutDeposit = React2.useCallback(() => {
3858
+ const dstValutDeposit = react.useCallback(() => {
3858
3859
  return {
3859
3860
  accountId: account5.accountIdHashStr,
3860
3861
  brokerHash: core.utils.parseBrokerHash(configStore.get("brokerId")),
@@ -4190,13 +4191,13 @@ var woofiDexDepositorAbi = [
4190
4191
  var useSwap = () => {
4191
4192
  const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
4192
4193
  const account5 = useAccountInstance();
4193
- const { configStore } = React2.useContext(OrderlyContext);
4194
- const [status, setStatus] = React2.useState(
4194
+ const { configStore } = react.useContext(OrderlyContext);
4195
+ const [status, setStatus] = react.useState(
4195
4196
  types.WS_WalletStatusEnum.NO
4196
4197
  );
4197
- const txHash = React2.useRef();
4198
+ const txHash = react.useRef();
4198
4199
  const ee = useEventEmitter();
4199
- React2.useEffect(() => {
4200
+ react.useEffect(() => {
4200
4201
  const handler = (data) => {
4201
4202
  const { side, transStatus, trxId } = data;
4202
4203
  if (side === "DEPOSIT" && trxId === txHash.current) {
@@ -4208,7 +4209,7 @@ var useSwap = () => {
4208
4209
  ee.off("wallet:changed", handler);
4209
4210
  };
4210
4211
  }, [txHash.current]);
4211
- const dstValutDeposit = React2.useCallback(() => {
4212
+ const dstValutDeposit = react.useCallback(() => {
4212
4213
  const brokerId = configStore.get("brokerId");
4213
4214
  return {
4214
4215
  accountId: account5.accountIdHashStr,
@@ -4216,7 +4217,7 @@ var useSwap = () => {
4216
4217
  tokenHash: core.utils.parseTokenHash("USDC")
4217
4218
  };
4218
4219
  }, [account5]);
4219
- const swap = React2.useCallback(
4220
+ const swap = react.useCallback(
4220
4221
  async (woofiDexDepositorAdress, inputs, config) => {
4221
4222
  if (!account5.walletClient) {
4222
4223
  throw new Error("walletClient is undefined");