@orderly.network/hooks 1.0.9 → 1.0.11

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
@@ -9,9 +9,8 @@ import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKey
9
9
  export { default as useConstant } from 'use-constant';
10
10
  import { WS } from '@orderly.network/net';
11
11
  import * as react from 'react';
12
- import { PropsWithChildren } from 'react';
12
+ import react__default, { PropsWithChildren } from 'react';
13
13
  import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
14
- import * as react_jsx_runtime from 'react/jsx-runtime';
15
14
  import * as swr_subscription from 'swr/subscription';
16
15
  import { Decimal } from '@orderly.network/utils';
17
16
  export * from 'use-debounce';
@@ -96,10 +95,10 @@ interface OrderlyConfigContextState {
96
95
  getWalletAdapter: getWalletAdapterFunc;
97
96
  networkId: NetworkId;
98
97
  onlyTestnet?: boolean;
98
+ enableSwapDeposit?: boolean;
99
99
  }
100
100
  declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
101
101
  declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
102
- declare const useOrderlyContext: () => OrderlyConfigContextState;
103
102
 
104
103
  declare type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
105
104
  [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
@@ -110,8 +109,9 @@ interface ConfigProviderProps {
110
109
  getWalletAdapter?: getWalletAdapterFunc;
111
110
  brokerId: string;
112
111
  networkId: NetworkId;
112
+ enableSwapDeposit?: boolean;
113
113
  }
114
- declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
114
+ declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react__default.JSX.Element | null;
115
115
 
116
116
  declare type ConnectedChain = {
117
117
  id: string;
@@ -318,6 +318,10 @@ declare type useDepositOptions = {
318
318
  networkId?: NetworkId;
319
319
  srcChainId?: number;
320
320
  srcToken?: string;
321
+ /**
322
+ * @hidden
323
+ */
324
+ wooSwapEnabled?: boolean;
321
325
  };
322
326
  declare const useDeposit: (options?: useDepositOptions | undefined) => {
323
327
  dst: {
@@ -341,7 +345,6 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
341
345
  declare const useHoldingStream: () => {
342
346
  data: API.Holding[] | undefined;
343
347
  usdc: API.Holding | undefined;
344
- balance: any;
345
348
  isLoading: boolean;
346
349
  };
347
350
 
@@ -432,4 +435,4 @@ declare const useSwap: () => {
432
435
  status: WS_WalletStatusEnum;
433
436
  };
434
437
 
435
- export { ConfigProviderProps, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, useOrderlyContext, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
438
+ export { ConfigProviderProps, OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
package/dist/index.d.ts CHANGED
@@ -9,9 +9,8 @@ import { AccountState, Account, EventEmitter, ConfigKey, ConfigStore, OrderlyKey
9
9
  export { default as useConstant } from 'use-constant';
10
10
  import { WS } from '@orderly.network/net';
11
11
  import * as react from 'react';
12
- import { PropsWithChildren } from 'react';
12
+ import react__default, { PropsWithChildren } from 'react';
13
13
  import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
14
- import * as react_jsx_runtime from 'react/jsx-runtime';
15
14
  import * as swr_subscription from 'swr/subscription';
16
15
  import { Decimal } from '@orderly.network/utils';
17
16
  export * from 'use-debounce';
@@ -96,10 +95,10 @@ interface OrderlyConfigContextState {
96
95
  getWalletAdapter: getWalletAdapterFunc;
97
96
  networkId: NetworkId;
98
97
  onlyTestnet?: boolean;
98
+ enableSwapDeposit?: boolean;
99
99
  }
100
100
  declare const OrderlyContext: react.Context<OrderlyConfigContextState>;
101
101
  declare const OrderlyProvider: react.Provider<OrderlyConfigContextState>;
102
- declare const useOrderlyContext: () => OrderlyConfigContextState;
103
102
 
104
103
  declare type RequireAtLeastOne<T, R extends keyof T = keyof T> = Omit<T, R> & {
105
104
  [K in R]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<R, K>>>;
@@ -110,8 +109,9 @@ interface ConfigProviderProps {
110
109
  getWalletAdapter?: getWalletAdapterFunc;
111
110
  brokerId: string;
112
111
  networkId: NetworkId;
112
+ enableSwapDeposit?: boolean;
113
113
  }
114
- declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react_jsx_runtime.JSX.Element | null;
114
+ declare const OrderlyConfigProvider: (props: PropsWithChildren<RequireAtLeastOne<ConfigProviderProps, "brokerId" | "configStore">>) => react__default.JSX.Element | null;
115
115
 
116
116
  declare type ConnectedChain = {
117
117
  id: string;
@@ -318,6 +318,10 @@ declare type useDepositOptions = {
318
318
  networkId?: NetworkId;
319
319
  srcChainId?: number;
320
320
  srcToken?: string;
321
+ /**
322
+ * @hidden
323
+ */
324
+ wooSwapEnabled?: boolean;
321
325
  };
322
326
  declare const useDeposit: (options?: useDepositOptions | undefined) => {
323
327
  dst: {
@@ -341,7 +345,6 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
341
345
  declare const useHoldingStream: () => {
342
346
  data: API.Holding[] | undefined;
343
347
  usdc: API.Holding | undefined;
344
- balance: any;
345
348
  isLoading: boolean;
346
349
  };
347
350
 
@@ -432,4 +435,4 @@ declare const useSwap: () => {
432
435
  status: WS_WalletStatusEnum;
433
436
  };
434
437
 
435
- export { ConfigProviderProps, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, useOrderlyContext, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
438
+ export { ConfigProviderProps, OrderlyConfigContextState, OrderlyConfigProvider, OrderlyContext, OrderlyProvider, WalletConnectorContext, useAccount, useAccountInfo, useAccountInstance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateInfiniteQuery, usePrivateQuery, useQuery, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useWS, useWalletConnector, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
package/dist/index.js CHANGED
@@ -8,7 +8,6 @@ var useConstant4 = require('use-constant');
8
8
  var core = require('@orderly.network/core');
9
9
  var types = require('@orderly.network/types');
10
10
  var useSWRInfinite = require('swr/infinite');
11
- var jsxRuntime = require('react/jsx-runtime');
12
11
  var utils = require('@orderly.network/utils');
13
12
  var useSWRSubscription = require('swr/subscription');
14
13
  var ramda = require('ramda');
@@ -31,9 +30,6 @@ var OrderlyContext = React.createContext({
31
30
  // configStore: new MemoryConfigStore(),
32
31
  });
33
32
  var OrderlyProvider = OrderlyContext.Provider;
34
- var useOrderlyContext = () => {
35
- return React.useContext(OrderlyContext);
36
- };
37
33
 
38
34
  // src/useConfig.ts
39
35
  var useConfig = (key, defaultValue) => {
@@ -289,22 +285,15 @@ var useBoolean = (initialValue = false) => {
289
285
  return [value, { setTrue, setFalse, toggle }];
290
286
  };
291
287
  var usePreLoadData = () => {
292
- const { configStore } = React.useContext(OrderlyContext);
293
- const { error: swapSupportError, data: swapSupportData } = useSWR__default.default(
294
- `${configStore.get("swapSupportApiUrl")}/swap_support`,
295
- (url) => fetch(url).then((res) => res.json()),
296
- {
297
- revalidateOnFocus: false
298
- }
299
- );
288
+ React.useContext(OrderlyContext);
300
289
  const { error: tokenError, data: tokenData } = useQuery("/v1/public/token", {
301
290
  revalidateOnFocus: false
302
291
  });
303
292
  const isDone = React.useMemo(() => {
304
- return !!swapSupportData && !!tokenData;
305
- }, [swapSupportData, tokenData]);
293
+ return !!tokenData;
294
+ }, [tokenData]);
306
295
  return {
307
- error: swapSupportError || tokenError,
296
+ error: tokenError,
308
297
  done: isDone
309
298
  };
310
299
  };
@@ -448,12 +437,12 @@ var useWS = () => {
448
437
  };
449
438
  var OrderlyConfigProvider = (props) => {
450
439
  const [account5, setAccount] = React__default.default.useState(null);
451
- const { configStore, keyStore, getWalletAdapter, brokerId, networkId } = props;
440
+ const { configStore, keyStore, getWalletAdapter, brokerId, networkId, enableSwapDeposit } = props;
452
441
  if (!brokerId && typeof configStore === "undefined") {
453
442
  console.error("[OrderlyConfigProvider]: brokerId is required");
454
443
  }
455
444
  const innerConfigStore = useConstant4__default.default(() => {
456
- return configStore || new core.MemoryConfigStore({ brokerId });
445
+ return configStore || new core.DefaultConfigStore({ brokerId, networkId });
457
446
  });
458
447
  const innerKeyStore = useConstant4__default.default(() => {
459
448
  return keyStore || new core.LocalStorageStore(networkId);
@@ -476,17 +465,19 @@ var OrderlyConfigProvider = (props) => {
476
465
  if (!account5) {
477
466
  return null;
478
467
  }
479
- return /* @__PURE__ */ jsxRuntime.jsx(
468
+ return /* @__PURE__ */ React__default.default.createElement(
480
469
  OrderlyProvider,
481
470
  {
482
471
  value: {
483
472
  configStore: innerConfigStore,
484
473
  keyStore: innerKeyStore,
485
474
  getWalletAdapter: innerGetWalletAdapter,
486
- networkId
487
- },
488
- children: props.children
489
- }
475
+ networkId,
476
+ enableSwapDeposit
477
+ // apiBaseUrl,
478
+ }
479
+ },
480
+ props.children
490
481
  );
491
482
  };
492
483
  var WalletConnectorContext = React.createContext({});
@@ -1103,8 +1094,8 @@ var usePositionStream = (symbol, options) => {
1103
1094
  const fundingRates = useFundingRates();
1104
1095
  const {
1105
1096
  data,
1106
- error
1107
- // mutate: updatePositions,
1097
+ error,
1098
+ mutate: updatePositions
1108
1099
  } = usePrivateQuery(`/v1/positions`, {
1109
1100
  // revalidateOnFocus: false,
1110
1101
  // revalidateOnReconnect: false,
@@ -1116,6 +1107,10 @@ var usePositionStream = (symbol, options) => {
1116
1107
  onError: (err) => {
1117
1108
  }
1118
1109
  });
1110
+ usePositionUpdateStream((positions2) => {
1111
+ console.log("position message", positions2);
1112
+ updatePositions();
1113
+ });
1119
1114
  const { data: markPrices } = useMarkPricesStream();
1120
1115
  const formatedPositions = React.useMemo(() => {
1121
1116
  if (!data?.rows || !symbolInfo || !accountInfo)
@@ -1264,6 +1259,41 @@ var pathOr_unsettledPnLPathOr = ramda.pathOr(0, [
1264
1259
  "aggregated",
1265
1260
  "unsettledPnL"
1266
1261
  ]);
1262
+ var usePositionUpdateStream = (callback) => {
1263
+ const ws = useWS();
1264
+ const positionList = React.useRef({});
1265
+ return useSWRSubscription__default.default("positionUpdate", (key, { next }) => {
1266
+ const unsubscribe = ws.privateSubscribe(
1267
+ // { event: "subscribe", topic: "markprices" },
1268
+ "position",
1269
+ {
1270
+ onMessage: (message) => {
1271
+ const { positions: positions2 } = message;
1272
+ let update = false;
1273
+ for (const p in positions2) {
1274
+ const { symbol, positionQty } = positions2[p];
1275
+ if (positionList.current[symbol] !== positionQty) {
1276
+ update = true;
1277
+ positionList.current[symbol] = positionQty;
1278
+ }
1279
+ }
1280
+ if (update) {
1281
+ callback(positions2.current);
1282
+ }
1283
+ next(null, positionList);
1284
+ },
1285
+ // onUnsubscribe: () => {
1286
+ // return "markprices";
1287
+ // },
1288
+ onError: (error) => {
1289
+ }
1290
+ }
1291
+ );
1292
+ return () => {
1293
+ unsubscribe?.();
1294
+ };
1295
+ });
1296
+ };
1267
1297
  var useHoldingStream = () => {
1268
1298
  const ws = useWS();
1269
1299
  const { data, isLoading, mutate: mutate2 } = usePrivateQuery(
@@ -1278,7 +1308,7 @@ var useHoldingStream = () => {
1278
1308
  const usdc2 = data?.find((item) => item.token === "USDC");
1279
1309
  return usdc2;
1280
1310
  }, [data]);
1281
- const { data: balance } = useSWRSubscription__default.default("holding", (_, { next }) => {
1311
+ useSWRSubscription__default.default("holding", (_, { next }) => {
1282
1312
  const unsubscribe = ws.privateSubscribe(
1283
1313
  {
1284
1314
  id: "balance",
@@ -1310,7 +1340,6 @@ var useHoldingStream = () => {
1310
1340
  return {
1311
1341
  data,
1312
1342
  usdc,
1313
- balance,
1314
1343
  isLoading
1315
1344
  };
1316
1345
  };
@@ -1541,11 +1570,37 @@ var useCollateral = (options = { dp: 6 }) => {
1541
1570
  var positionsPath2 = ramda.pathOr([], [0, "rows"]);
1542
1571
  var useMaxQty = (symbol, side, reduceOnly = false) => {
1543
1572
  const positionsData = usePositionStream();
1544
- const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
1545
1573
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1546
1574
  const symbolInfo = useSymbolsInfo();
1547
1575
  const { totalCollateral } = useCollateral();
1548
1576
  const { data: markPrices } = useMarkPricesStream();
1577
+ const {
1578
+ data: orders,
1579
+ error,
1580
+ mutate: updateOrder
1581
+ } = usePrivateQuery(`/v1/orders?status=NEW&size=99`, {
1582
+ formatter: (data) => data.rows,
1583
+ onError: (err) => {
1584
+ }
1585
+ });
1586
+ const ws = useWS();
1587
+ React.useEffect(() => {
1588
+ const unsubscribe = ws.privateSubscribe(
1589
+ {
1590
+ id: "executionreport_orders",
1591
+ event: "subscribe",
1592
+ topic: "executionreport",
1593
+ ts: Date.now()
1594
+ },
1595
+ {
1596
+ onMessage: (data) => {
1597
+ console.log("refresh orders", data);
1598
+ updateOrder();
1599
+ }
1600
+ }
1601
+ );
1602
+ return () => unsubscribe();
1603
+ }, []);
1549
1604
  const maxQty = React.useMemo(() => {
1550
1605
  if (!symbol)
1551
1606
  return 0;
@@ -3089,8 +3144,20 @@ var useChains = (networkId, options = {}) => {
3089
3144
  ...swrOptions
3090
3145
  }
3091
3146
  );
3147
+ const { data: chainInfos, error: chainInfoErr } = useQuery(
3148
+ "/v1/public/chain_info",
3149
+ {
3150
+ revalidateIfStale: false,
3151
+ revalidateOnFocus: false,
3152
+ revalidateOnReconnect: false,
3153
+ revalidateOnMount: true,
3154
+ dedupingInterval: 36e5,
3155
+ formatter: (data2) => data2.rows
3156
+ }
3157
+ );
3092
3158
  const { data: orderlyChains, error: tokenError } = useQuery(
3093
- "/v1/public/token",
3159
+ // wooSwapEnabled ? "/v1/public/token" :
3160
+ "https://api-evm.orderly.org/v1/public/token",
3094
3161
  {
3095
3162
  revalidateIfStale: false,
3096
3163
  revalidateOnFocus: false,
@@ -3129,41 +3196,48 @@ var useChains = (networkId, options = {}) => {
3129
3196
  if (!options.filter(_chain))
3130
3197
  return;
3131
3198
  }
3199
+ if (_chain.chain_id === 421613) {
3200
+ const index = testnetArr.findIndex((item2) => item2.network_infos.chain_id === 421613);
3201
+ if (index > -1) {
3202
+ testnetArr[index] = _chain;
3203
+ }
3204
+ }
3132
3205
  map.current.set(chainId, _chain);
3133
3206
  orderlyChainsArr.push(_chain);
3134
3207
  });
3135
3208
  });
3136
- if (!wooSwapEnabled) {
3137
- let arr = orderlyChainsArr;
3138
- if (typeof options?.filter === "function") {
3139
- arr = orderlyChainsArr.filter(options.filter);
3140
- }
3141
- if (!!field) {
3142
- arr = arr.map((item) => item[field]);
3209
+ let testnetArr = [
3210
+ //@ts-ignore
3211
+ {
3212
+ network_infos: {
3213
+ name: "Arbitrum Goerli",
3214
+ shortName: "Arbitrum Goerli",
3215
+ public_rpc_url: "https://goerli-rollup.arbitrum.io/rpc",
3216
+ chain_id: 421613,
3217
+ currency_symbol: "ETH",
3218
+ bridge_enable: true,
3219
+ mainnet: false,
3220
+ explorer_base_url: "https://goerli.arbiscan.io/",
3221
+ est_txn_mins: null,
3222
+ woofi_dex_cross_chain_router: "",
3223
+ woofi_dex_depositor: ""
3224
+ },
3225
+ token_infos: [
3226
+ {
3227
+ symbol: "USDC",
3228
+ address: "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63",
3229
+ decimals: 6,
3230
+ swap_enable: false,
3231
+ woofi_dex_precision: 2
3232
+ }
3233
+ ]
3143
3234
  }
3144
- return arr;
3145
- } else {
3235
+ ];
3236
+ let mainnetArr = [];
3237
+ map.current.set(421613, testnetArr[0]);
3238
+ if (wooSwapEnabled) {
3146
3239
  if (!data || !data.data)
3147
3240
  return data;
3148
- let testnetArr = [
3149
- //@ts-ignore
3150
- {
3151
- network_infos: {
3152
- name: "Arbitrum Goerli",
3153
- shortName: "Arbitrum Goerli",
3154
- public_rpc_url: "https://goerli-rollup.arbitrum.io/rpc",
3155
- chain_id: 421613,
3156
- currency_symbol: "ETH",
3157
- bridge_enable: true,
3158
- mainnet: false,
3159
- explorer_base_url: "https://goerli.arbiscan.io/",
3160
- est_txn_mins: null,
3161
- woofi_dex_cross_chain_router: "",
3162
- woofi_dex_depositor: ""
3163
- }
3164
- }
3165
- ];
3166
- let mainnetArr = [];
3167
3241
  Object.keys(data.data).forEach((key) => {
3168
3242
  const chain = data.data[key];
3169
3243
  const item = ramda.mergeDeepRight(chain, {
@@ -3189,27 +3263,65 @@ var useChains = (networkId, options = {}) => {
3189
3263
  testnetArr.push(item);
3190
3264
  }
3191
3265
  });
3192
- mainnetArr.sort((a, b) => {
3193
- return a.network_infos.bridgeless ? -1 : 1;
3194
- });
3195
- testnetArr.sort((a, b) => {
3196
- return a.network_infos.bridgeless ? -1 : 1;
3266
+ } else {
3267
+ if (!chainInfos)
3268
+ return void 0;
3269
+ orderlyChainsArr.forEach((chain) => {
3270
+ let _chain = chain;
3271
+ const networkInfo = chainInfos.find((item) => {
3272
+ console.log(item.chain_id, chain.network_infos.chain_id);
3273
+ return item.chain_id == chain.network_infos.chain_id;
3274
+ });
3275
+ if (networkInfo) {
3276
+ const { name, public_rpc_url, chain_id, currency_symbol, explorer_base_url } = networkInfo;
3277
+ _chain.network_infos = {
3278
+ ..._chain.network_infos,
3279
+ name,
3280
+ shortName: name,
3281
+ public_rpc_url,
3282
+ currency_symbol,
3283
+ bridge_enable: true,
3284
+ mainnet: true,
3285
+ explorer_base_url,
3286
+ est_txn_mins: null,
3287
+ woofi_dex_cross_chain_router: "",
3288
+ woofi_dex_depositor: ""
3289
+ };
3290
+ }
3291
+ map.current.set(_chain.network_infos.chain_id, _chain);
3292
+ if (_chain.network_infos.chain_id === 421613) {
3293
+ const index = testnetArr.findIndex((item) => item.network_infos.chain_id === 421613);
3294
+ if (index > -1) {
3295
+ testnetArr[index] = _chain;
3296
+ }
3297
+ }
3298
+ if (typeof options?.filter === "function") {
3299
+ if (!options.filter(_chain))
3300
+ return;
3301
+ }
3302
+ mainnetArr.push(_chain);
3197
3303
  });
3198
- if (!!field) {
3199
- testnetArr = testnetArr.map((item) => item[field]);
3200
- mainnetArr = mainnetArr.map((item) => item[field]);
3201
- }
3202
- if (networkId === "mainnet") {
3203
- return mainnetArr;
3204
- }
3205
- if (networkId === "testnet") {
3206
- return testnetArr;
3207
- }
3208
- return {
3209
- testnet: testnetArr,
3210
- mainnet: mainnetArr
3211
- };
3212
3304
  }
3305
+ mainnetArr.sort((a, b) => {
3306
+ return a.network_infos.bridgeless ? -1 : 1;
3307
+ });
3308
+ testnetArr.sort((a, b) => {
3309
+ return a.network_infos.bridgeless ? -1 : 1;
3310
+ });
3311
+ if (!!field) {
3312
+ testnetArr = testnetArr.map((item) => item[field]);
3313
+ mainnetArr = mainnetArr.map((item) => item[field]);
3314
+ }
3315
+ if (networkId === "mainnet") {
3316
+ return mainnetArr;
3317
+ }
3318
+ if (networkId === "testnet") {
3319
+ return testnetArr;
3320
+ }
3321
+ return {
3322
+ testnet: testnetArr,
3323
+ mainnet: mainnetArr
3324
+ };
3213
3325
  }, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
3214
3326
  const findByChainId = React.useCallback(
3215
3327
  (chainId, field2) => {
@@ -3278,11 +3390,12 @@ var useWithdraw = () => {
3278
3390
  return { withdraw, isLoading, maxAmount, availableBalance, unsettledPnL };
3279
3391
  };
3280
3392
  var useDeposit = (options) => {
3281
- const { onlyTestnet } = React.useContext(OrderlyContext);
3393
+ const { onlyTestnet, enableSwapDeposit } = React.useContext(OrderlyContext);
3394
+ const networkId = useConfig("networkId");
3282
3395
  const [balanceRevalidating, setBalanceRevalidating] = React.useState(false);
3283
3396
  const [allowanceRevalidating, setAllowanceRevalidating] = React.useState(false);
3284
3397
  const [_, { findByChainId }] = useChains(void 0, {
3285
- wooSwapEnabled: true
3398
+ wooSwapEnabled: enableSwapDeposit
3286
3399
  });
3287
3400
  const [balance, setBalance] = React.useState("0");
3288
3401
  const [allowance, setAllowance] = React.useState("0");
@@ -3290,8 +3403,10 @@ var useDeposit = (options) => {
3290
3403
  const prevAddress = React.useRef();
3291
3404
  const getBalanceListener = React.useRef();
3292
3405
  const dst = React.useMemo(() => {
3293
- const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3294
- const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
3406
+ const chain = networkId === "testnet" ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3407
+ const USDC = chain?.token_infos.find(
3408
+ (token) => token.symbol === "USDC"
3409
+ );
3295
3410
  if (!chain) {
3296
3411
  throw new Error("dst chain not found");
3297
3412
  }
@@ -3303,7 +3418,7 @@ var useDeposit = (options) => {
3303
3418
  network: chain.network_infos.shortName
3304
3419
  // chainId: 42161,
3305
3420
  };
3306
- }, []);
3421
+ }, [networkId]);
3307
3422
  const isNativeToken = React.useMemo(
3308
3423
  () => isNativeTokenChecker(options?.address || ""),
3309
3424
  [options?.address]
@@ -3510,17 +3625,6 @@ var usePrivateDataObserver = () => {
3510
3625
  const ws = useWS();
3511
3626
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3512
3627
  const { state } = useAccount();
3513
- React.useEffect(() => {
3514
- console.log("----!!!usePrivateDataObserver!!!----");
3515
- }, []);
3516
- React.useEffect(() => {
3517
- const unsubscribe = ws.privateSubscribe("executionreport", {
3518
- onMessage: (data) => {
3519
- console.log(data);
3520
- }
3521
- });
3522
- return () => unsubscribe?.();
3523
- }, [state.accountId]);
3524
3628
  React.useEffect(() => {
3525
3629
  if (!state.accountId)
3526
3630
  return;
@@ -3528,7 +3632,6 @@ var usePrivateDataObserver = () => {
3528
3632
  const unsubscribe = ws.privateSubscribe("position", {
3529
3633
  onMessage: (data) => {
3530
3634
  const { positions: nextPostions } = data;
3531
- console.log("ws-----data-----", data);
3532
3635
  mutate2(key, (prevPositions) => {
3533
3636
  if (!!prevPositions) {
3534
3637
  return {
@@ -4216,7 +4319,6 @@ exports.useMutation = useMutation;
4216
4319
  exports.useOrderEntry = useOrderEntry;
4217
4320
  exports.useOrderStream = useOrderStream;
4218
4321
  exports.useOrderbookStream = useOrderbookStream;
4219
- exports.useOrderlyContext = useOrderlyContext;
4220
4322
  exports.usePositionStream = usePositionStream;
4221
4323
  exports.usePreLoadData = usePreLoadData;
4222
4324
  exports.usePrivateDataObserver = usePrivateDataObserver;