@orderly.network/hooks 1.0.9 → 1.0.10

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;
@@ -341,7 +341,6 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
341
341
  declare const useHoldingStream: () => {
342
342
  data: API.Holding[] | undefined;
343
343
  usdc: API.Holding | undefined;
344
- balance: any;
345
344
  isLoading: boolean;
346
345
  };
347
346
 
@@ -432,4 +431,4 @@ declare const useSwap: () => {
432
431
  status: WS_WalletStatusEnum;
433
432
  };
434
433
 
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 };
434
+ 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;
@@ -341,7 +341,6 @@ declare const useDeposit: (options?: useDepositOptions | undefined) => {
341
341
  declare const useHoldingStream: () => {
342
342
  data: API.Holding[] | undefined;
343
343
  usdc: API.Holding | undefined;
344
- balance: any;
345
344
  isLoading: boolean;
346
345
  };
347
346
 
@@ -432,4 +431,4 @@ declare const useSwap: () => {
432
431
  status: WS_WalletStatusEnum;
433
432
  };
434
433
 
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 };
434
+ 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,7 +437,7 @@ 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
  }
@@ -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,6 +3144,17 @@ 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
3159
  "/v1/public/token",
3094
3160
  {
@@ -3129,41 +3195,48 @@ var useChains = (networkId, options = {}) => {
3129
3195
  if (!options.filter(_chain))
3130
3196
  return;
3131
3197
  }
3198
+ if (_chain.chain_id === 421613) {
3199
+ const index = testnetArr.findIndex((item2) => item2.network_infos.chain_id === 421613);
3200
+ if (index > -1) {
3201
+ testnetArr[index] = _chain;
3202
+ }
3203
+ }
3132
3204
  map.current.set(chainId, _chain);
3133
3205
  orderlyChainsArr.push(_chain);
3134
3206
  });
3135
3207
  });
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]);
3208
+ let testnetArr = [
3209
+ //@ts-ignore
3210
+ {
3211
+ network_infos: {
3212
+ name: "Arbitrum Goerli",
3213
+ shortName: "Arbitrum Goerli",
3214
+ public_rpc_url: "https://goerli-rollup.arbitrum.io/rpc",
3215
+ chain_id: 421613,
3216
+ currency_symbol: "ETH",
3217
+ bridge_enable: true,
3218
+ mainnet: false,
3219
+ explorer_base_url: "https://goerli.arbiscan.io/",
3220
+ est_txn_mins: null,
3221
+ woofi_dex_cross_chain_router: "",
3222
+ woofi_dex_depositor: ""
3223
+ },
3224
+ token_infos: [
3225
+ {
3226
+ symbol: "USDC",
3227
+ address: "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63",
3228
+ decimals: 6,
3229
+ swap_enable: false,
3230
+ woofi_dex_precision: 2
3231
+ }
3232
+ ]
3143
3233
  }
3144
- return arr;
3145
- } else {
3234
+ ];
3235
+ let mainnetArr = [];
3236
+ map.current.set(421613, testnetArr[0]);
3237
+ if (wooSwapEnabled) {
3146
3238
  if (!data || !data.data)
3147
3239
  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
3240
  Object.keys(data.data).forEach((key) => {
3168
3241
  const chain = data.data[key];
3169
3242
  const item = ramda.mergeDeepRight(chain, {
@@ -3189,27 +3262,65 @@ var useChains = (networkId, options = {}) => {
3189
3262
  testnetArr.push(item);
3190
3263
  }
3191
3264
  });
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;
3265
+ } else {
3266
+ if (!chainInfos)
3267
+ return void 0;
3268
+ orderlyChainsArr.forEach((chain) => {
3269
+ let _chain = chain;
3270
+ const networkInfo = chainInfos.find((item) => {
3271
+ console.log(item.chain_id, chain.network_infos.chain_id);
3272
+ return item.chain_id == chain.network_infos.chain_id;
3273
+ });
3274
+ if (networkInfo) {
3275
+ const { name, public_rpc_url, chain_id, currency_symbol, explorer_base_url } = networkInfo;
3276
+ _chain.network_infos = {
3277
+ ..._chain.network_infos,
3278
+ name,
3279
+ shortName: name,
3280
+ public_rpc_url,
3281
+ currency_symbol,
3282
+ bridge_enable: true,
3283
+ mainnet: true,
3284
+ explorer_base_url,
3285
+ est_txn_mins: null,
3286
+ woofi_dex_cross_chain_router: "",
3287
+ woofi_dex_depositor: ""
3288
+ };
3289
+ }
3290
+ map.current.set(_chain.network_infos.chain_id, _chain);
3291
+ if (_chain.network_infos.chain_id === 421613) {
3292
+ const index = testnetArr.findIndex((item) => item.network_infos.chain_id === 421613);
3293
+ if (index > -1) {
3294
+ testnetArr[index] = _chain;
3295
+ }
3296
+ }
3297
+ if (typeof options?.filter === "function") {
3298
+ if (!options.filter(_chain))
3299
+ return;
3300
+ }
3301
+ mainnetArr.push(_chain);
3197
3302
  });
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
3303
  }
3304
+ mainnetArr.sort((a, b) => {
3305
+ return a.network_infos.bridgeless ? -1 : 1;
3306
+ });
3307
+ testnetArr.sort((a, b) => {
3308
+ return a.network_infos.bridgeless ? -1 : 1;
3309
+ });
3310
+ if (!!field) {
3311
+ testnetArr = testnetArr.map((item) => item[field]);
3312
+ mainnetArr = mainnetArr.map((item) => item[field]);
3313
+ }
3314
+ if (networkId === "mainnet") {
3315
+ return mainnetArr;
3316
+ }
3317
+ if (networkId === "testnet") {
3318
+ return testnetArr;
3319
+ }
3320
+ return {
3321
+ testnet: testnetArr,
3322
+ mainnet: mainnetArr
3323
+ };
3213
3324
  }, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
3214
3325
  const findByChainId = React.useCallback(
3215
3326
  (chainId, field2) => {
@@ -3278,11 +3389,11 @@ var useWithdraw = () => {
3278
3389
  return { withdraw, isLoading, maxAmount, availableBalance, unsettledPnL };
3279
3390
  };
3280
3391
  var useDeposit = (options) => {
3281
- const { onlyTestnet } = React.useContext(OrderlyContext);
3392
+ const { onlyTestnet, enableSwapDeposit } = React.useContext(OrderlyContext);
3282
3393
  const [balanceRevalidating, setBalanceRevalidating] = React.useState(false);
3283
3394
  const [allowanceRevalidating, setAllowanceRevalidating] = React.useState(false);
3284
3395
  const [_, { findByChainId }] = useChains(void 0, {
3285
- wooSwapEnabled: true
3396
+ wooSwapEnabled: enableSwapDeposit
3286
3397
  });
3287
3398
  const [balance, setBalance] = React.useState("0");
3288
3399
  const [allowance, setAllowance] = React.useState("0");
@@ -3290,7 +3401,7 @@ var useDeposit = (options) => {
3290
3401
  const prevAddress = React.useRef();
3291
3402
  const getBalanceListener = React.useRef();
3292
3403
  const dst = React.useMemo(() => {
3293
- const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3404
+ const chain = onlyTestnet || 421613 == options?.srcChainId ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
3294
3405
  const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
3295
3406
  if (!chain) {
3296
3407
  throw new Error("dst chain not found");
@@ -3510,17 +3621,6 @@ var usePrivateDataObserver = () => {
3510
3621
  const ws = useWS();
3511
3622
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3512
3623
  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
3624
  React.useEffect(() => {
3525
3625
  if (!state.accountId)
3526
3626
  return;
@@ -3528,7 +3628,6 @@ var usePrivateDataObserver = () => {
3528
3628
  const unsubscribe = ws.privateSubscribe("position", {
3529
3629
  onMessage: (data) => {
3530
3630
  const { positions: nextPostions } = data;
3531
- console.log("ws-----data-----", data);
3532
3631
  mutate2(key, (prevPositions) => {
3533
3632
  if (!!prevPositions) {
3534
3633
  return {
@@ -4216,7 +4315,6 @@ exports.useMutation = useMutation;
4216
4315
  exports.useOrderEntry = useOrderEntry;
4217
4316
  exports.useOrderStream = useOrderStream;
4218
4317
  exports.useOrderbookStream = useOrderbookStream;
4219
- exports.useOrderlyContext = useOrderlyContext;
4220
4318
  exports.usePositionStream = usePositionStream;
4221
4319
  exports.usePreLoadData = usePreLoadData;
4222
4320
  exports.usePrivateDataObserver = usePrivateDataObserver;