@orderly.network/hooks 2.5.2 → 2.5.3-alpha.1

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
@@ -61,9 +61,9 @@ var __export = (target, all) => {
61
61
  // src/version.ts
62
62
  if (typeof window !== "undefined") {
63
63
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
64
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.5.2";
64
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.5.3-alpha.1";
65
65
  }
66
- var version_default = "2.5.2";
66
+ var version_default = "2.5.3-alpha.1";
67
67
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
68
68
  var OrderlyContext = React.createContext({
69
69
  // configStore: new MemoryConfigStore(),
@@ -320,7 +320,7 @@ var useWS = () => {
320
320
  if ((nextState.status === types.AccountStatusEnum.EnableTrading || nextState.status === types.AccountStatusEnum.EnableTradingWithoutConnected) && account9.accountId) {
321
321
  websocketClient.openPrivate(account9.accountId);
322
322
  } else {
323
- websocketClient.closePrivate(1e3, "switch account");
323
+ websocketClient.closePrivate(3887, "switch account");
324
324
  }
325
325
  });
326
326
  if (typeof window !== "undefined") {
@@ -374,7 +374,7 @@ var useAccount = () => {
374
374
  const ws = useWS();
375
375
  const switchAccount = React.useCallback(
376
376
  async (accountId) => {
377
- ws.closePrivate(1e3, "switch account");
377
+ ws.closePrivate(3887, "switch account");
378
378
  return account9.switchAccount(accountId);
379
379
  },
380
380
  [account9]
@@ -480,6 +480,11 @@ var useBoolean = (initialValue = false) => {
480
480
  const toggle = React.useCallback(() => setValue((v) => !v), []);
481
481
  return [value, { setTrue, setFalse, toggle }];
482
482
  };
483
+ var useUpdatedRef = (val) => {
484
+ const latestRef = React.useRef(val);
485
+ latestRef.current = val;
486
+ return latestRef;
487
+ };
483
488
  var useMemoizedFn = (fn) => {
484
489
  const fnRef = React.useRef(fn);
485
490
  fnRef.current = React.useMemo(() => fn, [fn]);
@@ -774,8 +779,10 @@ function useWsStatus() {
774
779
  }
775
780
  }
776
781
  });
777
- return () => ws.off("websocket:status", () => {
778
- });
782
+ return () => {
783
+ ws.off("status:change", () => {
784
+ });
785
+ };
779
786
  }, []);
780
787
  return wsStatus;
781
788
  }
@@ -2132,14 +2139,24 @@ var OrderbookService = class _OrderbookService {
2132
2139
  const bidMap = /* @__PURE__ */ new Map();
2133
2140
  rawOrderBook.asks.forEach((ask) => askMap.set(ask[0], ask[1]));
2134
2141
  rawOrderBook.bids.forEach((bid) => bidMap.set(bid[0], bid[1]));
2135
- update.asks.forEach((ask) => ask[1] === 0 ? askMap.delete(ask[0]) : askMap.set(ask[0], ask[1]));
2136
- update.bids.forEach((bid) => bid[1] === 0 ? bidMap.delete(bid[0]) : bidMap.set(bid[0], bid[1]));
2137
- rawOrderBook.asks = Array.from(askMap.entries()).sort((a, b) => a[0] - b[0]);
2138
- rawOrderBook.bids = Array.from(bidMap.entries()).sort((a, b) => b[0] - a[0]);
2142
+ update.asks.forEach(
2143
+ (ask) => ask[1] === 0 ? askMap.delete(ask[0]) : askMap.set(ask[0], ask[1])
2144
+ );
2145
+ update.bids.forEach(
2146
+ (bid) => bid[1] === 0 ? bidMap.delete(bid[0]) : bidMap.set(bid[0], bid[1])
2147
+ );
2148
+ rawOrderBook.asks = Array.from(askMap.entries()).sort(
2149
+ (a, b) => a[0] - b[0]
2150
+ );
2151
+ rawOrderBook.bids = Array.from(bidMap.entries()).sort(
2152
+ (a, b) => b[0] - a[0]
2153
+ );
2139
2154
  rawOrderBook.ts = update.ts;
2140
2155
  }
2141
2156
  applyBufferedUpdatesToRawOrderBooks(symbol) {
2142
- this.bufferedOrderBookUpdates[symbol]?.forEach((update) => this.applyUpdateToRawOrderBook(symbol, update));
2157
+ this.bufferedOrderBookUpdates[symbol]?.forEach(
2158
+ (update) => this.applyUpdateToRawOrderBook(symbol, update)
2159
+ );
2143
2160
  }
2144
2161
  deleteBufferedOrderBookUpdates(symbol) {
2145
2162
  delete this.bufferedOrderBookUpdates[symbol];
@@ -2472,7 +2489,10 @@ var reduceOrderbook = (depth, level, padding, data) => {
2472
2489
  bids
2473
2490
  };
2474
2491
  };
2475
- var INIT_DATA = { asks: [], bids: [] };
2492
+ var INIT_DATA = {
2493
+ asks: [],
2494
+ bids: []
2495
+ };
2476
2496
  var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
2477
2497
  if (!symbol) {
2478
2498
  throw new types.SDKError("Symbol is required");
@@ -2489,8 +2509,9 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
2489
2509
  const prevMiddlePrice = React.useRef(0);
2490
2510
  const depths = React.useMemo(() => {
2491
2511
  const tick = config("quote_tick");
2492
- if (typeof tick === "undefined")
2512
+ if (typeof tick === "undefined") {
2493
2513
  return [];
2514
+ }
2494
2515
  try {
2495
2516
  const base = new utils.Decimal(tick);
2496
2517
  return [
@@ -2598,8 +2619,9 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
2598
2619
  if (data.bids.length > 0) {
2599
2620
  bidsFirst = data.bids[0][0];
2600
2621
  }
2601
- if (isNaN(asksFrist) || isNaN(bidsFirst) || !ticker)
2622
+ if (isNaN(asksFrist) || isNaN(bidsFirst) || !ticker) {
2602
2623
  return 0;
2624
+ }
2603
2625
  return [asksFrist, bidsFirst, ticker["24h_close"]].sort()[1];
2604
2626
  }, [ticker?.["24h_close"], data]);
2605
2627
  React.useEffect(() => {
@@ -3278,8 +3300,17 @@ var useMarkPricesStream = () => {
3278
3300
 
3279
3301
  // src/orderly/useIndexPricesStream.ts
3280
3302
  var useIndexPricesStream = () => {
3281
- const data = useIndexPriceStore((state) => state.indexPrices);
3282
- return { data };
3303
+ const indexPrices = useIndexPriceStore((state) => state.indexPrices);
3304
+ const getIndexPrice = (token) => {
3305
+ if (token === "USDC") {
3306
+ return 1;
3307
+ }
3308
+ return indexPrices[`PERP_${token}_USDC`] ?? 0;
3309
+ };
3310
+ return {
3311
+ data: indexPrices,
3312
+ getIndexPrice: useMemoizedFn(getIndexPrice)
3313
+ };
3283
3314
  };
3284
3315
  var generateLeverageLevers = (max3) => {
3285
3316
  const min3 = 1;
@@ -3349,14 +3380,14 @@ var useComputedLTV = (options = {}) => {
3349
3380
  const isUSDC = token?.toUpperCase() === "USDC";
3350
3381
  const tokensInfo = useTokensInfo();
3351
3382
  const { usdc, data: holdingList = [] } = useHoldingStream();
3352
- const { data: indexPrices } = useIndexPricesStream();
3383
+ const { getIndexPrice } = useIndexPricesStream();
3353
3384
  const { unsettledPnL } = useCollateral();
3354
3385
  const usdcBalance = React.useMemo(() => {
3355
3386
  if (isUSDC && input) {
3356
3387
  return new utils.Decimal(usdc?.holding ?? 0).add(input).toNumber();
3357
3388
  }
3358
3389
  return usdc?.holding ?? 0;
3359
- }, [usdc?.holding, input, token, isUSDC]);
3390
+ }, [usdc?.holding, input, isUSDC]);
3360
3391
  const getAdjustedQty = React.useCallback(
3361
3392
  (item) => {
3362
3393
  if (input && item.token === token) {
@@ -3371,19 +3402,20 @@ var useComputedLTV = (options = {}) => {
3371
3402
  usdcBalance,
3372
3403
  upnl: unsettledPnL,
3373
3404
  assets: holdingList.filter((h) => h.token.toUpperCase() !== "USDC").map((item) => {
3374
- const indexPrice = indexPrices[`PERP_${item.token}_USDC`] ?? 0;
3405
+ const indexPrice = getIndexPrice(item.token);
3375
3406
  const findToken = tokensInfo?.find((i) => i.token === item.token);
3376
3407
  const qty = getAdjustedQty(item);
3408
+ const weight = collateralRatio({
3409
+ baseWeight: findToken?.base_weight ?? 0,
3410
+ discountFactor: findToken?.discount_factor ?? 0,
3411
+ collateralCap: findToken?.user_max_qty ?? qty,
3412
+ collateralQty: qty,
3413
+ indexPrice
3414
+ });
3377
3415
  return {
3378
3416
  qty,
3379
3417
  indexPrice,
3380
- weight: collateralRatio({
3381
- baseWeight: findToken?.base_weight ?? 0,
3382
- discountFactor: findToken?.discount_factor ?? 0,
3383
- collateralCap: findToken?.user_max_qty ?? qty,
3384
- collateralQty: qty,
3385
- indexPrice
3386
- })
3418
+ weight: weight.toNumber()
3387
3419
  };
3388
3420
  })
3389
3421
  });
@@ -3391,8 +3423,8 @@ var useComputedLTV = (options = {}) => {
3391
3423
  usdcBalance,
3392
3424
  unsettledPnL,
3393
3425
  holdingList,
3394
- indexPrices,
3395
3426
  tokensInfo,
3427
+ getIndexPrice,
3396
3428
  getAdjustedQty
3397
3429
  ]);
3398
3430
  if (new utils.Decimal(usdcBalance).add(new utils.Decimal(unsettledPnL)).gte(utils.zero)) {
@@ -4582,22 +4614,19 @@ var useHoldingStream = () => {
4582
4614
 
4583
4615
  // src/orderly/useMaxWithdrawal.ts
4584
4616
  var { maxWithdrawalUSDC, maxWithdrawalOtherCollateral, collateralRatio: collateralRatio2 } = perp.account;
4585
- function useMaxWithdrawal(token) {
4586
- const { unsettledPnL, freeCollateral } = useCollateral();
4617
+ var useMaxWithdrawal = (token) => {
4618
+ const { unsettledPnL } = useCollateral();
4619
+ const { freeCollateral } = useAppStore((state) => state.portfolio);
4587
4620
  const tokenInfo = useTokenInfo(token);
4588
- const { data: indexPrices } = useIndexPricesStream();
4621
+ const { getIndexPrice } = useIndexPricesStream();
4622
+ const indexPriceRef = useUpdatedRef(getIndexPrice(token));
4589
4623
  const { usdc, data: holdings = [] } = useHoldingStream();
4590
4624
  const holding = React.useMemo(() => {
4591
- return holdings?.find((item) => item?.token === token);
4625
+ return holdings.find(
4626
+ (item) => item.token?.toUpperCase() === token.toUpperCase()
4627
+ );
4592
4628
  }, [holdings, token]);
4593
4629
  const usdcBalance = usdc?.holding ?? 0;
4594
- const indexPrice = React.useMemo(() => {
4595
- if (token === "USDC") {
4596
- return 1;
4597
- }
4598
- const symbol = `PERP_${token}_USDC`;
4599
- return indexPrices[symbol] ?? 0;
4600
- }, [token, indexPrices]);
4601
4630
  const memoizedCollateralRatio = React.useMemo(() => {
4602
4631
  const { base_weight = 0, discount_factor = 0 } = tokenInfo || {};
4603
4632
  const holdingQty = holding?.holding ?? 0;
@@ -4606,41 +4635,53 @@ function useMaxWithdrawal(token) {
4606
4635
  discountFactor: discount_factor,
4607
4636
  collateralQty: holdingQty,
4608
4637
  collateralCap: tokenInfo?.user_max_qty ?? holdingQty,
4609
- indexPrice
4638
+ indexPrice: indexPriceRef.current
4610
4639
  });
4611
- }, [holdings, tokenInfo, indexPrice, token, holding]);
4640
+ }, [tokenInfo, holding?.holding, indexPriceRef]);
4612
4641
  const maxAmount = React.useMemo(() => {
4642
+ if (!token) {
4643
+ return 0;
4644
+ }
4645
+ let quantity = 0;
4613
4646
  if (token === "USDC") {
4614
- return maxWithdrawalUSDC({
4647
+ quantity = maxWithdrawalUSDC({
4615
4648
  USDCBalance: usdcBalance,
4616
4649
  freeCollateral,
4617
4650
  upnl: unsettledPnL ?? 0
4618
4651
  });
4652
+ } else {
4653
+ quantity = maxWithdrawalOtherCollateral({
4654
+ USDCBalance: usdcBalance,
4655
+ collateralQty: holding?.holding ?? 0,
4656
+ freeCollateral,
4657
+ indexPrice: indexPriceRef.current,
4658
+ weight: memoizedCollateralRatio
4659
+ }).toNumber();
4619
4660
  }
4620
- return maxWithdrawalOtherCollateral({
4621
- collateralQty: holding?.holding ?? 0,
4622
- freeCollateral,
4623
- indexPrice,
4624
- weight: memoizedCollateralRatio
4625
- });
4661
+ if (Number.isNaN(quantity)) {
4662
+ return 0;
4663
+ }
4664
+ if (tokenInfo?.decimals === void 0) {
4665
+ return quantity;
4666
+ }
4667
+ return new utils.Decimal(quantity || 0).todp(tokenInfo.decimals, utils.Decimal.ROUND_DOWN).toNumber();
4626
4668
  }, [
4669
+ token,
4670
+ tokenInfo?.decimals,
4627
4671
  usdcBalance,
4628
4672
  freeCollateral,
4629
4673
  unsettledPnL,
4630
- memoizedCollateralRatio,
4631
- holdings,
4632
- indexPrice,
4633
- token,
4634
- holding
4674
+ holding?.holding,
4675
+ indexPriceRef,
4676
+ memoizedCollateralRatio
4635
4677
  ]);
4636
4678
  return maxAmount;
4637
- }
4679
+ };
4638
4680
 
4639
4681
  // src/orderly/useWithdraw.ts
4640
4682
  var useWithdraw = (options) => {
4641
- const { srcChainId, token, decimals } = options;
4683
+ const { srcChainId, token = "", decimals } = options;
4642
4684
  const { account: account9, state } = useAccount();
4643
- const [isLoading, setIsLoading] = React.useState(false);
4644
4685
  const { unsettledPnL, availableBalance, freeCollateral } = useCollateral();
4645
4686
  const networkId = useConfig("networkId");
4646
4687
  const [_, { findByChainId }] = useChains(void 0);
@@ -4700,12 +4741,16 @@ var useWithdraw = (options) => {
4700
4741
  throw err;
4701
4742
  });
4702
4743
  },
4703
- [state, targetChain, state, decimals]
4744
+ [
4745
+ account9.assetsManager,
4746
+ decimals,
4747
+ state?.connectWallet?.name,
4748
+ targetChain?.network_infos.name
4749
+ ]
4704
4750
  );
4705
4751
  return {
4706
4752
  dst,
4707
4753
  withdraw,
4708
- isLoading,
4709
4754
  maxAmount,
4710
4755
  unsettledPnL,
4711
4756
  availableBalance,
@@ -4723,6 +4768,7 @@ var useDeposit = (options) => {
4723
4768
  const [depositFeeRevalidating, setDepositFeeRevalidating] = React.useState(false);
4724
4769
  const [balance, setBalance] = React.useState("0");
4725
4770
  const [allowance, setAllowance] = React.useState("0");
4771
+ const balanceRef = React.useRef("");
4726
4772
  const { account: account9, state } = useAccount();
4727
4773
  const { track: track2 } = useTrack();
4728
4774
  const prevAddress = React.useRef();
@@ -4771,19 +4817,6 @@ var useDeposit = (options) => {
4771
4817
  },
4772
4818
  []
4773
4819
  );
4774
- const fetchBalance = React.useCallback(
4775
- async (address, decimals) => {
4776
- if (!address)
4777
- return;
4778
- try {
4779
- const balance2 = await fetchBalanceHandler(address, decimals);
4780
- setBalance(() => balance2);
4781
- } catch (e) {
4782
- setBalance(() => "0");
4783
- }
4784
- },
4785
- [state]
4786
- );
4787
4820
  const fetchBalances = React.useCallback(async (tokens) => {
4788
4821
  const tasks = [];
4789
4822
  for (const token of tokens) {
@@ -4851,7 +4884,8 @@ var useDeposit = (options) => {
4851
4884
  ]);
4852
4885
  const queryBalance = useDebounce.useDebouncedCallback(
4853
4886
  (address, decimals) => {
4854
- fetchBalance(address, decimals).finally(() => {
4887
+ fetchBalanceHandler(address, decimals).then((balance2) => {
4888
+ setBalance(balance2);
4855
4889
  setBalanceRevalidating(false);
4856
4890
  });
4857
4891
  },
@@ -4996,11 +5030,14 @@ var useDeposit = (options) => {
4996
5030
  isNativeToken,
4997
5031
  vaultAddress
4998
5032
  ]);
4999
- const loopGetBalance = async () => {
5033
+ const loopGetBalance = async (timeout) => {
5000
5034
  if (getBalanceListener.current) {
5001
5035
  clearTimeout(getBalanceListener.current);
5002
5036
  }
5003
- const time = account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3;
5037
+ const time = timeout ?? (account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3);
5038
+ if (balanceRef.current === "") {
5039
+ setBalanceRevalidating(true);
5040
+ }
5004
5041
  getBalanceListener.current = setTimeout(async () => {
5005
5042
  try {
5006
5043
  const balance2 = await fetchBalanceHandler(
@@ -5008,8 +5045,14 @@ var useDeposit = (options) => {
5008
5045
  options.decimals
5009
5046
  );
5010
5047
  setBalance(balance2);
5048
+ balanceRef.current = balance2;
5011
5049
  loopGetBalance();
5012
5050
  } catch (err) {
5051
+ loopGetBalance(1e3);
5052
+ } finally {
5053
+ if (balanceRef.current !== "") {
5054
+ setBalanceRevalidating(false);
5055
+ }
5013
5056
  }
5014
5057
  }, time);
5015
5058
  };
@@ -5049,7 +5092,7 @@ var useDeposit = (options) => {
5049
5092
  if (!options.address) {
5050
5093
  return;
5051
5094
  }
5052
- loopGetBalance();
5095
+ loopGetBalance(0);
5053
5096
  return () => {
5054
5097
  if (getBalanceListener.current) {
5055
5098
  clearTimeout(getBalanceListener.current);
@@ -5165,7 +5208,7 @@ var useSubAccountMutation = (url, method = "POST", options) => {
5165
5208
 
5166
5209
  // src/orderly/useTransfer.ts
5167
5210
  var useTransfer = (options) => {
5168
- const { fromAccountId, token } = options || {};
5211
+ const { fromAccountId, token = "" } = options || {};
5169
5212
  const { unsettledPnL, holding } = useCollateral();
5170
5213
  const [doTransfer, { isMutating: submitting }] = useSubAccountMutation(
5171
5214
  "/v1/internal_transfer",
@@ -5223,6 +5266,74 @@ var useWalletSubscription = (options) => {
5223
5266
  }
5224
5267
  );
5225
5268
  };
5269
+ var useBalanceSubscription = (options) => {
5270
+ const ws = useWS();
5271
+ const { state } = useAccount();
5272
+ return useSWRSubscription__default.default(
5273
+ state.accountId ? ["balance", state.accountId] : null,
5274
+ (_, { next }) => {
5275
+ const unsubscribe = ws.privateSubscribe(
5276
+ {
5277
+ id: "balance",
5278
+ event: "subscribe",
5279
+ topic: "balance",
5280
+ ts: Date.now()
5281
+ },
5282
+ {
5283
+ onMessage: (data) => {
5284
+ options?.onMessage?.(data);
5285
+ next(null, data);
5286
+ }
5287
+ }
5288
+ );
5289
+ return () => unsubscribe();
5290
+ }
5291
+ );
5292
+ };
5293
+ var useWalletTopic = (options) => {
5294
+ const ws = useWS();
5295
+ const { state } = useAccount();
5296
+ React.useEffect(() => {
5297
+ if (!state.accountId)
5298
+ return;
5299
+ const unsubscribe = ws.privateSubscribe(
5300
+ {
5301
+ id: "wallet",
5302
+ event: "subscribe",
5303
+ topic: "wallet",
5304
+ ts: Date.now()
5305
+ },
5306
+ {
5307
+ onMessage: (data) => {
5308
+ options.onMessage(data);
5309
+ }
5310
+ }
5311
+ );
5312
+ return () => unsubscribe?.();
5313
+ }, [state.accountId]);
5314
+ };
5315
+ var useBalanceTopic = (options) => {
5316
+ const ws = useWS();
5317
+ const { state } = useAccount();
5318
+ React.useEffect(() => {
5319
+ if (!state.accountId)
5320
+ return;
5321
+ const unsubscribe = ws.privateSubscribe(
5322
+ {
5323
+ id: "balance",
5324
+ event: "subscribe",
5325
+ topic: "balance",
5326
+ ts: Date.now()
5327
+ },
5328
+ {
5329
+ onMessage: (data) => {
5330
+ options.onMessage(data);
5331
+ }
5332
+ }
5333
+ );
5334
+ return () => unsubscribe?.();
5335
+ }, [state.accountId]);
5336
+ };
5226
5337
  var useSettleSubscription = (options) => {
5227
5338
  const ws = useWS();
5228
5339
  const { state } = useAccount();
@@ -7031,7 +7142,7 @@ var useSubAccountWS = (options) => {
7031
7142
  websocketClient.current.openPrivate(accountId);
7032
7143
  }
7033
7144
  return () => {
7034
- websocketClient.current.closePrivate(1e3, "switch account");
7145
+ websocketClient.current.closePrivate(3887, "switch account");
7035
7146
  };
7036
7147
  }, [accountId, state.status]);
7037
7148
  return websocketClient.current;
@@ -7236,17 +7347,17 @@ function useSubAccountMaxWithdrawal(options) {
7236
7347
  });
7237
7348
  }
7238
7349
  return maxWithdrawalOtherCollateral2({
7350
+ USDCBalance: usdcBalance,
7239
7351
  collateralQty: holding?.holding ?? 0,
7240
7352
  freeCollateral,
7241
7353
  indexPrice,
7242
7354
  weight: memoizedCollateralRatio
7243
- });
7355
+ }).toNumber();
7244
7356
  }, [
7245
7357
  usdcBalance,
7246
7358
  freeCollateral,
7247
7359
  unsettledPnL,
7248
7360
  memoizedCollateralRatio,
7249
- holdings,
7250
7361
  indexPrice,
7251
7362
  token,
7252
7363
  holding
@@ -7752,28 +7863,36 @@ var useSymbolLeverage = (symbol) => {
7752
7863
  }, [maxAccountLeverage, maxSymbolLeverage]);
7753
7864
  return maxLeverage;
7754
7865
  };
7755
- var AssetHistoryStatusEnum = /* @__PURE__ */ ((AssetHistoryStatusEnum2) => {
7756
- AssetHistoryStatusEnum2["NEW"] = "NEW";
7757
- AssetHistoryStatusEnum2["CONFIRM"] = "CONFIRM";
7758
- AssetHistoryStatusEnum2["PROCESSING"] = "PROCESSING";
7759
- AssetHistoryStatusEnum2["COMPLETED"] = "COMPLETED";
7760
- AssetHistoryStatusEnum2["FAILED"] = "FAILED";
7761
- AssetHistoryStatusEnum2["PENDING_REBALANCE"] = "PENDING_REBALANCE";
7762
- return AssetHistoryStatusEnum2;
7763
- })(AssetHistoryStatusEnum || {});
7764
- var useAssetsHistory = (options) => {
7765
- const { page = 1, pageSize = 10 } = options;
7866
+ var useAssetsHistory = (options, config) => {
7766
7867
  const ee = useEventEmitter();
7767
7868
  const getKey = () => {
7869
+ const {
7870
+ page = 1,
7871
+ pageSize = 10,
7872
+ token,
7873
+ side,
7874
+ status,
7875
+ startTime,
7876
+ endTime
7877
+ } = options;
7768
7878
  const searchParams = new URLSearchParams();
7769
7879
  searchParams.set("page", page.toString());
7770
7880
  searchParams.set("size", pageSize.toString());
7771
- if (options.side && options.side !== "All")
7772
- searchParams.set("side", options.side);
7773
- if (options.startTime)
7774
- searchParams.set("start_t", options.startTime);
7775
- if (options.endTime)
7776
- searchParams.set("end_t", options.endTime);
7881
+ if (token) {
7882
+ searchParams.set("token", token);
7883
+ }
7884
+ if (side && side !== "All") {
7885
+ searchParams.set("side", side);
7886
+ }
7887
+ if (status) {
7888
+ searchParams.set("status", status);
7889
+ }
7890
+ if (startTime) {
7891
+ searchParams.set("start_t", startTime.toString());
7892
+ }
7893
+ if (endTime) {
7894
+ searchParams.set("end_t", endTime.toString());
7895
+ }
7777
7896
  return `/v1/asset/history?${searchParams.toString()}`;
7778
7897
  };
7779
7898
  const { data, isLoading, mutate: mutate5 } = usePrivateQuery(
@@ -7786,7 +7905,10 @@ var useAssetsHistory = (options) => {
7786
7905
  );
7787
7906
  const updateList = useDebounce.useDebouncedCallback(
7788
7907
  (data2) => {
7789
- mutate5();
7908
+ const isUpdate = typeof config?.shouldUpdateOnWalletChanged === "function" ? config.shouldUpdateOnWalletChanged(data2) : true;
7909
+ if (isUpdate) {
7910
+ mutate5();
7911
+ }
7790
7912
  },
7791
7913
  // delay in ms
7792
7914
  300
@@ -7798,7 +7920,7 @@ var useAssetsHistory = (options) => {
7798
7920
  };
7799
7921
  }, []);
7800
7922
  return [
7801
- data?.rows || [],
7923
+ data?.rows || types.EMPTY_LIST,
7802
7924
  {
7803
7925
  meta: data?.meta,
7804
7926
  isLoading
@@ -7960,7 +8082,7 @@ var useTransferHistory = (parmas) => {
7960
8082
  }
7961
8083
  return `/v1/internal_transfer_history?${search.toString()}`;
7962
8084
  }, [page, size, fromId, toId, dataRange, main_sub_only]);
7963
- const { data, isLoading } = usePrivateQuery(
8085
+ const { data, isLoading, mutate: mutate5 } = usePrivateQuery(
7964
8086
  memoizedQueryKey,
7965
8087
  {
7966
8088
  // initialSize: 1,
@@ -7975,7 +8097,7 @@ var useTransferHistory = (parmas) => {
7975
8097
  }
7976
8098
  return data.rows;
7977
8099
  }, [data, infos]);
7978
- return [parsedData, { meta: data?.meta, isLoading }];
8100
+ return [parsedData, { meta: data?.meta, isLoading, mutate: mutate5 }];
7979
8101
  };
7980
8102
  var MaintenanceStatus = /* @__PURE__ */ ((MaintenanceStatus2) => {
7981
8103
  MaintenanceStatus2[MaintenanceStatus2["None"] = 0] = "None";
@@ -8301,6 +8423,8 @@ var usePublicDataObserver = () => {
8301
8423
  );
8302
8424
  const { updateMarket } = useMarketStore((state) => state.actions);
8303
8425
  const setTokensInfo = useTokensInfoStore((state) => state.setTokensInfo);
8426
+ const { dataAdapter } = React.useContext(OrderlyContext);
8427
+ const resolveList = typeof dataAdapter?.symbolList === "function" ? dataAdapter.symbolList : (oriVal) => oriVal;
8304
8428
  useQuery(`/v1/public/info`, {
8305
8429
  ...publicQueryOptions,
8306
8430
  onSuccess(data) {
@@ -8351,6 +8475,13 @@ var usePublicDataObserver = () => {
8351
8475
  return [];
8352
8476
  }
8353
8477
  updateMarket(data);
8478
+ },
8479
+ formatter(data) {
8480
+ const rowsData = data.rows;
8481
+ if (Array.isArray(rowsData)) {
8482
+ return resolveList(rowsData);
8483
+ }
8484
+ return resolveList(data);
8354
8485
  }
8355
8486
  });
8356
8487
  useQuery(`/v1/public/token`, {
@@ -8365,8 +8496,9 @@ var usePublicDataObserver = () => {
8365
8496
  });
8366
8497
  };
8367
8498
  function getEstFundingRate(data) {
8368
- if (!data)
8499
+ if (!data) {
8369
8500
  return;
8501
+ }
8370
8502
  const { next_funding_time, est_funding_rate } = data;
8371
8503
  if (Date.now() > next_funding_time) {
8372
8504
  return null;
@@ -8490,7 +8622,8 @@ var OrderlyConfigProvider = (props) => {
8490
8622
  chainFilter,
8491
8623
  customChains,
8492
8624
  enableSwapDeposit = false,
8493
- chainTransformer
8625
+ chainTransformer,
8626
+ dataAdapter
8494
8627
  } = props;
8495
8628
  if (typeof configStore !== "undefined" && !configStore.get("brokerId")) {
8496
8629
  throw new types.SDKError(
@@ -8541,28 +8674,35 @@ var OrderlyConfigProvider = (props) => {
8541
8674
  }
8542
8675
  return chainFilter;
8543
8676
  }, [props.chainFilter, innerConfigStore]);
8677
+ const memoizedValue = React.useMemo(() => {
8678
+ return {
8679
+ configStore: innerConfigStore,
8680
+ keyStore: innerKeyStore,
8681
+ networkId: innerConfigStore.get("networkId") || networkId,
8682
+ filteredChains,
8683
+ walletAdapters: innerWalletAdapters,
8684
+ customChains,
8685
+ enableSwapDeposit,
8686
+ defaultOrderbookTickSizes,
8687
+ chainTransformer,
8688
+ dataAdapter
8689
+ };
8690
+ }, [
8691
+ innerConfigStore,
8692
+ innerKeyStore,
8693
+ networkId,
8694
+ filteredChains,
8695
+ innerWalletAdapters,
8696
+ customChains,
8697
+ enableSwapDeposit,
8698
+ defaultOrderbookTickSizes,
8699
+ dataAdapter,
8700
+ chainTransformer
8701
+ ]);
8544
8702
  if (!account9) {
8545
8703
  return null;
8546
8704
  }
8547
- return /* @__PURE__ */ jsxRuntime.jsx(
8548
- OrderlyProvider,
8549
- {
8550
- value: {
8551
- configStore: innerConfigStore,
8552
- keyStore: innerKeyStore,
8553
- // getWalletAdapter: innerGetWalletAdapter,
8554
- networkId: innerConfigStore.get("networkId") || networkId,
8555
- filteredChains,
8556
- walletAdapters: innerWalletAdapters,
8557
- // apiBaseUrl,
8558
- customChains,
8559
- enableSwapDeposit,
8560
- chainTransformer,
8561
- defaultOrderbookTickSizes
8562
- },
8563
- children: /* @__PURE__ */ jsxRuntime.jsx(StatusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(DataCenterProvider, { children: props.children }) })
8564
- }
8565
- );
8705
+ return /* @__PURE__ */ jsxRuntime.jsx(OrderlyProvider, { value: memoizedValue, children: /* @__PURE__ */ jsxRuntime.jsx(StatusProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(DataCenterProvider, { children: props.children }) }) });
8566
8706
  };
8567
8707
  var needNumberOnlyFields = [
8568
8708
  "order_quantity",
@@ -9927,6 +10067,7 @@ var utils_exports = {};
9927
10067
  __export(utils_exports, {
9928
10068
  calcTPSL_ROI: () => calcTPSL_ROI,
9929
10069
  cleanStringStyle: () => cleanStringStyle,
10070
+ fetcher: () => fetcher,
9930
10071
  findPositionTPSLFromOrders: () => findPositionTPSLFromOrders,
9931
10072
  findTPSLFromOrder: () => findTPSLFromOrder,
9932
10073
  findTPSLFromOrders: () => findTPSLFromOrders,
@@ -16346,12 +16487,15 @@ var useOrderEntity = (order, options) => {
16346
16487
  symbolInfo
16347
16488
  };
16348
16489
  };
16349
- var canUnblockRegions = ["United States"];
16490
+ var defaultRestrictedIps = [];
16491
+ var defaultRestrictedRegions = [];
16492
+ var defaultUnblockRegions = [];
16350
16493
  var useRestrictedInfo = (options) => {
16351
16494
  const {
16352
16495
  enableDefault = false,
16353
- customRestrictedIps = [],
16354
- customRestrictedRegions = [],
16496
+ customRestrictedIps = defaultRestrictedIps,
16497
+ customRestrictedRegions = defaultRestrictedRegions,
16498
+ customUnblockRegions = defaultUnblockRegions,
16355
16499
  content
16356
16500
  } = options || {};
16357
16501
  const [ip, setIp] = React.useState("");
@@ -16377,7 +16521,7 @@ var useRestrictedInfo = (options) => {
16377
16521
  const combinedInvalidRegions = [
16378
16522
  ...formattedCustomRegions,
16379
16523
  ...enableDefault ? [...invalidCountries, ...invalidCities] : []
16380
- ];
16524
+ ].filter((item) => !!item);
16381
16525
  const allInvalidAreas2 = [
16382
16526
  enableDefault ? invalid_web_country : "",
16383
16527
  enableDefault ? invalid_web_city : "",
@@ -16386,15 +16530,20 @@ var useRestrictedInfo = (options) => {
16386
16530
  const { city, region, ip: ip2 } = ipInfo;
16387
16531
  const formattedCity = formatRegion(city);
16388
16532
  const formattedRegion = formatRegion(region);
16389
- const showRestricted = accessRestricted && (combinedInvalidRegions.includes(formattedCity) || combinedInvalidRegions.includes(formattedRegion) || customRestrictedIps.includes(ip2));
16390
- for (const item of canUnblockRegions) {
16391
- if (formatRegion(item) === formatRegion(region)) {
16392
- setCanUnblock(true);
16533
+ const isRestricted = formattedCity && combinedInvalidRegions.includes(formattedCity) || formattedRegion && combinedInvalidRegions.includes(formattedRegion) || ip2 && customRestrictedIps.includes(ip2);
16534
+ let canUnblock2 = false;
16535
+ if (isRestricted) {
16536
+ for (const item of customUnblockRegions) {
16537
+ if (formatRegion(item) === formatRegion(region)) {
16538
+ canUnblock2 = true;
16539
+ }
16393
16540
  }
16394
16541
  }
16542
+ const restrictedOpen2 = canUnblock2 ? isRestricted && accessRestricted !== false : isRestricted;
16395
16543
  setIp(ip2);
16396
16544
  setAllInvalidAreas(allInvalidAreas2);
16397
- setRestrictedOpen(showRestricted);
16545
+ setRestrictedOpen(!!restrictedOpen2);
16546
+ setCanUnblock(canUnblock2);
16398
16547
  } catch (error) {
16399
16548
  }
16400
16549
  }, [
@@ -16405,6 +16554,7 @@ var useRestrictedInfo = (options) => {
16405
16554
  // it will lead to infinite re-render when these values change, so we don't need to watch these
16406
16555
  // customRestrictedIps,
16407
16556
  // customRestrictedRegions,
16557
+ // customUnblockRegions,
16408
16558
  ]);
16409
16559
  return {
16410
16560
  ip,
@@ -16531,7 +16681,6 @@ Object.defineProperty(exports, "useConstant", {
16531
16681
  enumerable: true,
16532
16682
  get: function () { return useConstant__default.default; }
16533
16683
  });
16534
- exports.AssetHistoryStatusEnum = AssetHistoryStatusEnum;
16535
16684
  exports.DefaultLayoutConfig = DefaultLayoutConfig;
16536
16685
  exports.DistributionId = DistributionId;
16537
16686
  exports.ENVType = ENVType2;
@@ -16560,6 +16709,8 @@ exports.useAccountRewardsHistory = useAccountRewardsHistory;
16560
16709
  exports.useAllBrokers = useAllBrokers;
16561
16710
  exports.useApiKeyManager = useApiKeyManager;
16562
16711
  exports.useAssetsHistory = useAssetsHistory;
16712
+ exports.useBalanceSubscription = useBalanceSubscription;
16713
+ exports.useBalanceTopic = useBalanceTopic;
16563
16714
  exports.useBoolean = useBoolean;
16564
16715
  exports.useChain = useChain;
16565
16716
  exports.useChains = useChains;
@@ -16654,10 +16805,12 @@ exports.useTrackingInstance = useTrackingInstance;
16654
16805
  exports.useTradingRewardsStatus = useTradingRewardsStatus;
16655
16806
  exports.useTransfer = useTransfer;
16656
16807
  exports.useTransferHistory = useTransferHistory;
16808
+ exports.useUpdatedRef = useUpdatedRef;
16657
16809
  exports.useWS = useWS;
16658
16810
  exports.useWalletConnector = useWalletConnector;
16659
16811
  exports.useWalletRewardsHistory = useWalletRewardsHistory;
16660
16812
  exports.useWalletSubscription = useWalletSubscription;
16813
+ exports.useWalletTopic = useWalletTopic;
16661
16814
  exports.useWithdraw = useWithdraw;
16662
16815
  exports.useWsStatus = useWsStatus;
16663
16816
  exports.utils = utils_exports;