@agg-build/hooks 2.0.0 → 2.1.0

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
@@ -84,8 +84,8 @@ __export(src_exports, {
84
84
  MarketStatus: () => MarketStatus,
85
85
  MatchStatus: () => MatchStatus,
86
86
  MatchType: () => MatchType,
87
- QueryClient: () => import_react_query38.QueryClient,
88
- QueryClientProvider: () => import_react_query38.QueryClientProvider,
87
+ QueryClient: () => import_react_query39.QueryClient,
88
+ QueryClientProvider: () => import_react_query39.QueryClientProvider,
89
89
  RedeemRejectedError: () => RedeemRejectedError,
90
90
  TradeSide: () => TradeSide,
91
91
  TurnstileChallengeError: () => import_sdk4.TurnstileChallengeError,
@@ -179,7 +179,7 @@ __export(src_exports, {
179
179
  useOrderbookQuote: () => useOrderbookQuote,
180
180
  useOrders: () => useOrders,
181
181
  usePositions: () => usePositions,
182
- useQueryClient: () => import_react_query38.useQueryClient,
182
+ useQueryClient: () => import_react_query39.useQueryClient,
183
183
  useQuoteManaged: () => useQuoteManaged,
184
184
  useRampQuotes: () => useRampQuotes,
185
185
  useRampSession: () => useRampSession,
@@ -205,6 +205,7 @@ __export(src_exports, {
205
205
  useWithdrawEstimate: () => useWithdrawEstimate,
206
206
  useWithdrawFlow: () => useWithdrawFlow,
207
207
  useWithdrawManaged: () => useWithdrawManaged,
208
+ useWithdrawPreview: () => useWithdrawPreview,
208
209
  useWithdrawalLifecycle: () => useWithdrawalLifecycle,
209
210
  userActivityQueryKeys: () => userActivityQueryKeys
210
211
  });
@@ -332,7 +333,7 @@ var getVenueOrder = (venue) => {
332
333
  var sortVenues = (venues) => [...venues].sort((a, b) => getVenueOrder(a) - getVenueOrder(b));
333
334
 
334
335
  // src/index.ts
335
- var import_react_query38 = require("@tanstack/react-query");
336
+ var import_react_query39 = require("@tanstack/react-query");
336
337
 
337
338
  // src/candle-store.ts
338
339
  var import_sdk = require("@agg-build/sdk");
@@ -534,6 +535,8 @@ var enUsLabels = {
534
535
  errorPrefix: "Error",
535
536
  tabsAria: "Tabs",
536
537
  hiddenTabsAria: "Hidden tabs",
538
+ scrollTabsLeft: "Scroll tabs left",
539
+ scrollTabsRight: "Scroll tabs right",
537
540
  selectAria: "Select",
538
541
  lineChartAria: "Line chart",
539
542
  candlestickChartAria: "Candlestick chart",
@@ -696,6 +699,7 @@ var enUsLabels = {
696
699
  networkReserveTooltipLineTwo: "Any unused amount stays in your balance.",
697
700
  youReceive: "You'll receive",
698
701
  confirm: "Confirm withdrawal",
702
+ calculatingFees: "Calculating fees\u2026",
699
703
  successTitle: "Withdrawal submitted",
700
704
  successDescription: (tokenSymbol) => `Your ${tokenSymbol} withdrawal is being processed and will arrive shortly.`,
701
705
  // Terminal-state copy. The success step swaps `successTitle` /
@@ -1110,6 +1114,9 @@ var enUsLabels = {
1110
1114
  buyingOutcome: (label) => `Buying ${label}`,
1111
1115
  sellingOutcome: (label) => `Selling ${label}`,
1112
1116
  findingBestRoute: "Finding the best route...",
1117
+ findingBestOdds: "Finding best odds\u2026",
1118
+ updatingRoute: "Updating route\u2026",
1119
+ refreshingQuotes: "Refreshing quotes\u2026",
1113
1120
  checkingBalance: "Checking balance",
1114
1121
  submittingOrderProgress: "Submitting order...",
1115
1122
  orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
@@ -1450,7 +1457,8 @@ var defaultAggUiConfig = {
1450
1457
  enableNotifications: true
1451
1458
  },
1452
1459
  market: {
1453
- arbitrageThreshold: 0
1460
+ arbitrageThreshold: 0,
1461
+ maxMidpointIdsPerRequest: 75
1454
1462
  },
1455
1463
  chart: {
1456
1464
  defaultChartTimeRange: "1D",
@@ -1474,7 +1482,7 @@ var mergeAggUiSearchConfig = (config) => {
1474
1482
  };
1475
1483
  };
1476
1484
  var mergeAggUiConfig = (persisted, config) => {
1477
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T;
1485
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V;
1478
1486
  const locale = (_d = (_c = (_a = config == null ? void 0 : config.general) == null ? void 0 : _a.locale) != null ? _c : (_b = persisted.general) == null ? void 0 : _b.locale) != null ? _d : DEFAULT_LOCALE;
1479
1487
  const theme = (_h = (_g = (_e = config == null ? void 0 : config.general) == null ? void 0 : _e.theme) != null ? _g : (_f = persisted.general) == null ? void 0 : _f.theme) != null ? _h : defaultAggUiConfig.general.theme;
1480
1488
  const formatters = createFormatters(locale);
@@ -1499,19 +1507,20 @@ var mergeAggUiConfig = (persisted, config) => {
1499
1507
  enableNotifications: (_B = (_A = config == null ? void 0 : config.features) == null ? void 0 : _A.enableNotifications) != null ? _B : defaultAggUiConfig.features.enableNotifications
1500
1508
  },
1501
1509
  market: {
1502
- arbitrageThreshold: (_D = (_C = config == null ? void 0 : config.market) == null ? void 0 : _C.arbitrageThreshold) != null ? _D : defaultAggUiConfig.market.arbitrageThreshold
1510
+ arbitrageThreshold: (_D = (_C = config == null ? void 0 : config.market) == null ? void 0 : _C.arbitrageThreshold) != null ? _D : defaultAggUiConfig.market.arbitrageThreshold,
1511
+ maxMidpointIdsPerRequest: (_F = (_E = config == null ? void 0 : config.market) == null ? void 0 : _E.maxMidpointIdsPerRequest) != null ? _F : defaultAggUiConfig.market.maxMidpointIdsPerRequest
1503
1512
  },
1504
1513
  chart: {
1505
- defaultChartTimeRange: (_F = (_E = config == null ? void 0 : config.chart) == null ? void 0 : _E.defaultChartTimeRange) != null ? _F : defaultAggUiConfig.chart.defaultChartTimeRange,
1506
- selectedChartTimeRange: (_J = (_I = (_G = persisted.chart) == null ? void 0 : _G.selectedChartTimeRange) != null ? _I : (_H = config == null ? void 0 : config.chart) == null ? void 0 : _H.defaultChartTimeRange) != null ? _J : defaultAggUiConfig.chart.defaultChartTimeRange,
1514
+ defaultChartTimeRange: (_H = (_G = config == null ? void 0 : config.chart) == null ? void 0 : _G.defaultChartTimeRange) != null ? _H : defaultAggUiConfig.chart.defaultChartTimeRange,
1515
+ selectedChartTimeRange: (_L = (_K = (_I = persisted.chart) == null ? void 0 : _I.selectedChartTimeRange) != null ? _K : (_J = config == null ? void 0 : config.chart) == null ? void 0 : _J.defaultChartTimeRange) != null ? _L : defaultAggUiConfig.chart.defaultChartTimeRange,
1507
1516
  setSelectedChartTimeRange: defaultAggUiConfig.chart.setSelectedChartTimeRange
1508
1517
  },
1509
1518
  formatting: {
1510
- formatNumber: (_L = (_K = config == null ? void 0 : config.formatting) == null ? void 0 : _K.formatNumber) != null ? _L : formatters.formatNumber,
1511
- formatPercent: (_N = (_M = config == null ? void 0 : config.formatting) == null ? void 0 : _M.formatPercent) != null ? _N : formatters.formatPercent,
1512
- formatCurrency: (_P = (_O = config == null ? void 0 : config.formatting) == null ? void 0 : _O.formatCurrency) != null ? _P : formatters.formatCurrency,
1513
- formatCompactCurrency: (_R = (_Q = config == null ? void 0 : config.formatting) == null ? void 0 : _Q.formatCompactCurrency) != null ? _R : formatters.formatCompactCurrency,
1514
- formatDate: (_T = (_S = config == null ? void 0 : config.formatting) == null ? void 0 : _S.formatDate) != null ? _T : formatters.formatDate
1519
+ formatNumber: (_N = (_M = config == null ? void 0 : config.formatting) == null ? void 0 : _M.formatNumber) != null ? _N : formatters.formatNumber,
1520
+ formatPercent: (_P = (_O = config == null ? void 0 : config.formatting) == null ? void 0 : _O.formatPercent) != null ? _P : formatters.formatPercent,
1521
+ formatCurrency: (_R = (_Q = config == null ? void 0 : config.formatting) == null ? void 0 : _Q.formatCurrency) != null ? _R : formatters.formatCurrency,
1522
+ formatCompactCurrency: (_T = (_S = config == null ? void 0 : config.formatting) == null ? void 0 : _S.formatCompactCurrency) != null ? _T : formatters.formatCompactCurrency,
1523
+ formatDate: (_V = (_U = config == null ? void 0 : config.formatting) == null ? void 0 : _U.formatDate) != null ? _V : formatters.formatDate
1515
1524
  },
1516
1525
  search: mergeAggUiSearchConfig(config == null ? void 0 : config.search),
1517
1526
  walletActions: config == null ? void 0 : config.walletActions,
@@ -4412,6 +4421,13 @@ var isValidDestinationAddress = (address, chainId) => {
4412
4421
  if (chainId === SOLANA_CHAIN_ID) return SOLANA_ADDRESS_REGEX.test(address);
4413
4422
  return EVM_ADDRESS_REGEX.test(address);
4414
4423
  };
4424
+ var detectDestinationAddressKind = (address) => {
4425
+ const trimmed = address.trim();
4426
+ if (!trimmed) return null;
4427
+ if (EVM_ADDRESS_REGEX.test(trimmed)) return "evm";
4428
+ if (SOLANA_ADDRESS_REGEX.test(trimmed)) return "solana";
4429
+ return null;
4430
+ };
4415
4431
  var DEFAULT_WITHDRAW_SUMMARY = {
4416
4432
  amountReceived: "",
4417
4433
  network: "",
@@ -4449,7 +4465,7 @@ var parseTokenAmountToRaw = (amount, decimals) => {
4449
4465
  };
4450
4466
  var shortenAddress = (address) => address.length > 12 ? `${address.slice(0, 6)}...${address.slice(-4)}` : address;
4451
4467
  function useWithdrawFlow(options) {
4452
- var _a, _b;
4468
+ var _a, _b, _c, _d, _e;
4453
4469
  const { open, onOpenChange } = options;
4454
4470
  const { totalBalance } = useAggBalanceState();
4455
4471
  const { balances } = useManagedBalances({ enabled: open });
@@ -4470,31 +4486,42 @@ function useWithdrawFlow(options) {
4470
4486
  const [withdrawNetwork, setWithdrawNetwork] = (0, import_react13.useState)("");
4471
4487
  const [withdrawSummary, setWithdrawSummary] = (0, import_react13.useState)(DEFAULT_WITHDRAW_SUMMARY);
4472
4488
  const [withdrawalId, setWithdrawalId] = (0, import_react13.useState)(null);
4489
+ const [isMax, setIsMax] = (0, import_react13.useState)(false);
4490
+ const detectedAddressKind = (0, import_react13.useMemo)(
4491
+ () => detectDestinationAddressKind(withdrawDestination),
4492
+ [withdrawDestination]
4493
+ );
4473
4494
  const networkOptions = (0, import_react13.useMemo)(
4474
- () => (supportedChains != null ? supportedChains : []).filter((chain) => WITHDRAWAL_SUPPORTED_CHAIN_IDS.has(chain.chainId)).map((chain) => ({
4475
- value: String(chain.chainId),
4476
- label: chain.name
4477
- })),
4478
- [supportedChains]
4495
+ () => (supportedChains != null ? supportedChains : []).filter((chain) => WITHDRAWAL_SUPPORTED_CHAIN_IDS.has(chain.chainId)).map((chain) => {
4496
+ const value = String(chain.chainId);
4497
+ const isSolana = chain.chainId === SOLANA_CHAIN_ID;
4498
+ const disabled = detectedAddressKind === "solana" ? !isSolana : detectedAddressKind === "evm" ? isSolana : false;
4499
+ return { value, label: chain.name, disabled };
4500
+ }),
4501
+ [supportedChains, detectedAddressKind]
4502
+ );
4503
+ const firstEnabledNetwork = (_d = (_c = (_a = networkOptions.find((option) => !option.disabled)) == null ? void 0 : _a.value) != null ? _c : (_b = networkOptions[0]) == null ? void 0 : _b.value) != null ? _d : "";
4504
+ const isCurrentNetworkSelectable = networkOptions.some(
4505
+ (option) => option.value === withdrawNetwork && !option.disabled
4479
4506
  );
4480
- const resolvedWithdrawNetwork = withdrawNetwork || ((_a = networkOptions[0]) == null ? void 0 : _a.value) || "";
4507
+ const resolvedWithdrawNetwork = isCurrentNetworkSelectable ? withdrawNetwork : firstEnabledNetwork;
4481
4508
  (0, import_react13.useEffect)(() => {
4482
4509
  if (!networkOptions.length) return;
4483
- if (!withdrawNetwork || !networkOptions.some((option) => option.value === withdrawNetwork)) {
4484
- setWithdrawNetwork(networkOptions[0].value);
4510
+ if (!isCurrentNetworkSelectable && firstEnabledNetwork) {
4511
+ setWithdrawNetwork(firstEnabledNetwork);
4485
4512
  }
4486
- }, [networkOptions, withdrawNetwork]);
4513
+ }, [networkOptions, isCurrentNetworkSelectable, firstEnabledNetwork]);
4487
4514
  const tokenOptions = (0, import_react13.useMemo)(() => {
4488
- var _a2, _b2, _c;
4515
+ var _a2, _b2, _c2;
4489
4516
  const selectedChainId = Number(resolvedWithdrawNetwork);
4490
4517
  const supportedTokensForNetwork = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens) != null ? _b2 : [];
4491
4518
  const withdrawableSymbols = new Set(supportedTokensForNetwork.map((token) => token.symbol));
4492
- return ((_c = balances == null ? void 0 : balances.cash) != null ? _c : []).filter((cashEntry) => withdrawableSymbols.has(cashEntry.tokenSymbol)).map((cashEntry) => ({
4519
+ return ((_c2 = balances == null ? void 0 : balances.cash) != null ? _c2 : []).filter((cashEntry) => withdrawableSymbols.has(cashEntry.tokenSymbol)).map((cashEntry) => ({
4493
4520
  value: cashEntry.tokenSymbol,
4494
4521
  label: cashEntry.tokenSymbol
4495
4522
  }));
4496
4523
  }, [balances, resolvedWithdrawNetwork, supportedChains]);
4497
- const resolvedWithdrawToken = tokenOptions.some((option) => option.value === withdrawToken) ? withdrawToken : ((_b = tokenOptions[0]) == null ? void 0 : _b.value) || "";
4524
+ const resolvedWithdrawToken = tokenOptions.some((option) => option.value === withdrawToken) ? withdrawToken : ((_e = tokenOptions[0]) == null ? void 0 : _e.value) || "";
4498
4525
  (0, import_react13.useEffect)(() => {
4499
4526
  if (!tokenOptions.length) return;
4500
4527
  if (!tokenOptions.some((option) => option.value === withdrawToken)) {
@@ -4506,9 +4533,9 @@ function useWithdrawFlow(options) {
4506
4533
  [balances, resolvedWithdrawToken]
4507
4534
  );
4508
4535
  const selectedTokenDecimals = (0, import_react13.useMemo)(() => {
4509
- var _a2, _b2, _c, _d;
4536
+ var _a2, _b2, _c2, _d2;
4510
4537
  const selectedChainId = Number(resolvedWithdrawNetwork);
4511
- return (_d = (_c = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens.find((token) => token.symbol === resolvedWithdrawToken)) == null ? void 0 : _b2.decimals) != null ? _c : selectedCashEntry == null ? void 0 : selectedCashEntry.decimals) != null ? _d : 6;
4538
+ return (_d2 = (_c2 = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens.find((token) => token.symbol === resolvedWithdrawToken)) == null ? void 0 : _b2.decimals) != null ? _c2 : selectedCashEntry == null ? void 0 : selectedCashEntry.decimals) != null ? _d2 : 6;
4512
4539
  }, [
4513
4540
  resolvedWithdrawNetwork,
4514
4541
  resolvedWithdrawToken,
@@ -4533,6 +4560,7 @@ function useWithdrawFlow(options) {
4533
4560
  setWithdrawNetwork("");
4534
4561
  setWithdrawSummary(DEFAULT_WITHDRAW_SUMMARY);
4535
4562
  setWithdrawalId(null);
4563
+ setIsMax(false);
4536
4564
  }, []);
4537
4565
  const handleWithdrawOpenChange = (0, import_react13.useCallback)(
4538
4566
  (isOpen) => {
@@ -4572,19 +4600,19 @@ function useWithdrawFlow(options) {
4572
4600
  }
4573
4601
  return scaleBy(native, selectedTokenDecimals - selectedCashEntry.decimals);
4574
4602
  })();
4575
- if (BigInt(amountRaw) > balanceInDestFrame) {
4603
+ if (!isMax && BigInt(amountRaw) > balanceInDestFrame) {
4576
4604
  throw new Error("Withdrawal amount exceeds your available balance.");
4577
4605
  }
4578
4606
  }
4579
4607
  ws == null ? void 0 : ws.connect();
4580
4608
  yield new Promise((resolve, reject) => {
4581
4609
  withdrawMutation.mutate(
4582
- {
4610
+ __spreadValues({
4583
4611
  amountRaw,
4584
4612
  tokenSymbol: resolvedWithdrawToken,
4585
4613
  destinationAddress: trimmedDestination,
4586
4614
  destinationChainId
4587
- },
4615
+ }, isMax ? { max: true } : {}),
4588
4616
  {
4589
4617
  onSuccess: (data) => {
4590
4618
  setWithdrawalId(data.withdrawalId);
@@ -4601,6 +4629,7 @@ function useWithdrawFlow(options) {
4601
4629
  fees: "\u2014"
4602
4630
  });
4603
4631
  }), [
4632
+ isMax,
4604
4633
  resolvedWithdrawNetwork,
4605
4634
  resolvedWithdrawToken,
4606
4635
  selectedCashEntry,
@@ -4624,13 +4653,18 @@ function useWithdrawFlow(options) {
4624
4653
  selectedToken: resolvedWithdrawToken,
4625
4654
  selectedNetwork: resolvedWithdrawNetwork,
4626
4655
  purchaseSummary: withdrawSummary,
4627
- withdrawalId
4656
+ withdrawalId,
4657
+ isMax
4628
4658
  },
4629
4659
  onWithdrawDestinationChange: setWithdrawDestination,
4630
- onWithdrawAmountChange: setWithdrawAmount,
4660
+ onWithdrawAmountChange: (0, import_react13.useCallback)((v) => {
4661
+ setIsMax(false);
4662
+ setWithdrawAmount(v);
4663
+ }, []),
4631
4664
  onWithdrawTokenChange: setWithdrawToken,
4632
4665
  onWithdrawNetworkChange: setWithdrawNetwork,
4633
4666
  onMaxClick: (0, import_react13.useCallback)(() => {
4667
+ setIsMax(true);
4634
4668
  setWithdrawAmount(exactBalance === "0" ? "0" : exactBalance);
4635
4669
  }, [exactBalance]),
4636
4670
  onSelectWithdrawProvider: (0, import_react13.useCallback)(
@@ -4697,6 +4731,7 @@ var INITIAL_STATE2 = {
4697
4731
  status: null,
4698
4732
  requestedAmountRaw: null,
4699
4733
  completedAmountRaw: null,
4734
+ feeRaw: null,
4700
4735
  terminal: false,
4701
4736
  lastLeg: null,
4702
4737
  legs: [],
@@ -4727,16 +4762,17 @@ var mergeLegs = (prev, snapshot, delta) => {
4727
4762
  return next;
4728
4763
  };
4729
4764
  var restToLifecycleState = (response) => {
4730
- var _a, _b;
4765
+ var _a, _b, _c;
4731
4766
  return {
4732
4767
  pending: false,
4733
4768
  status: response.status,
4734
4769
  requestedAmountRaw: response.requested.amountRaw,
4735
4770
  completedAmountRaw: (_a = response.completedAmountRaw) != null ? _a : null,
4771
+ feeRaw: (_b = response.expected.feeRaw) != null ? _b : null,
4736
4772
  terminal: response.status === "completed" || response.status === "partial" || response.status === "failed",
4737
4773
  lastLeg: null,
4738
4774
  legs: response.legs.map(restLegToWsLeg),
4739
- errorMessage: (_b = response.errorMessage) != null ? _b : null,
4775
+ errorMessage: (_c = response.errorMessage) != null ? _c : null,
4740
4776
  // No server timestamp on the REST response — we use 0 as "older than any
4741
4777
  // WS timestamp" so a subsequent WS event always wins. Callers that read
4742
4778
  // `timestamp` should treat 0/null interchangeably as "unset".
@@ -4778,14 +4814,15 @@ function useWithdrawalLifecycle(withdrawalId) {
4778
4814
  return (msg) => {
4779
4815
  if (msg.withdrawalId !== withdrawalId) return;
4780
4816
  setState((prev) => {
4781
- var _a, _b, _c, _d;
4817
+ var _a, _b, _c, _d, _e;
4782
4818
  return {
4783
4819
  pending: false,
4784
4820
  status: msg.status,
4785
4821
  requestedAmountRaw: (_a = msg.requestedAmountRaw) != null ? _a : prev.requestedAmountRaw,
4786
4822
  completedAmountRaw: (_b = msg.completedAmountRaw) != null ? _b : prev.completedAmountRaw,
4823
+ feeRaw: (_c = msg.feeRaw) != null ? _c : null,
4787
4824
  terminal: msg.terminal,
4788
- lastLeg: (_c = msg.leg) != null ? _c : null,
4825
+ lastLeg: (_d = msg.leg) != null ? _d : null,
4789
4826
  // `legs[]` is the cumulative server-known truth. Snapshots
4790
4827
  // (`pending` / terminal rollup) carry a full `legs[]` and replace
4791
4828
  // it. Intermediate per-leg deltas carry only `leg` (no `legs[]`)
@@ -4793,7 +4830,7 @@ function useWithdrawalLifecycle(withdrawalId) {
4793
4830
  // (sourceChainId, destChainId, type) so the timeline UI doesn't
4794
4831
  // collapse to empty between snapshots.
4795
4832
  legs: mergeLegs(prev.legs, msg.legs, msg.leg),
4796
- errorMessage: (_d = msg.errorMessage) != null ? _d : null,
4833
+ errorMessage: (_e = msg.errorMessage) != null ? _e : null,
4797
4834
  timestamp: msg.timestamp
4798
4835
  };
4799
4836
  });
@@ -4813,6 +4850,37 @@ function useWithdrawalLifecycle(withdrawalId) {
4813
4850
  return { state, reset };
4814
4851
  }
4815
4852
 
4853
+ // src/withdraw/use-withdraw-preview.ts
4854
+ var import_react_query17 = require("@tanstack/react-query");
4855
+ function useWithdrawPreview({
4856
+ amountRaw,
4857
+ tokenSymbol,
4858
+ destinationChainId,
4859
+ destinationAddress,
4860
+ max
4861
+ }) {
4862
+ const client = useAggClient();
4863
+ const enabled = !!amountRaw && BigInt(amountRaw || "0") > BigInt(0) && !!tokenSymbol && !!destinationChainId && !!destinationAddress;
4864
+ return (0, import_react_query17.useQuery)({
4865
+ queryKey: [
4866
+ "withdraw-preview",
4867
+ tokenSymbol,
4868
+ amountRaw,
4869
+ destinationChainId,
4870
+ destinationAddress,
4871
+ max != null ? max : false
4872
+ ],
4873
+ enabled,
4874
+ staleTime: 15e3,
4875
+ queryFn: () => client.withdrawPreview(__spreadValues({
4876
+ amountRaw,
4877
+ tokenSymbol,
4878
+ destinationChainId,
4879
+ destinationAddress
4880
+ }, max ? { max: true } : {}))
4881
+ });
4882
+ }
4883
+
4816
4884
  // src/index.ts
4817
4885
  var import_sdk4 = require("@agg-build/sdk");
4818
4886
 
@@ -4930,7 +4998,7 @@ var requestAggAuthChooserOpen = () => {
4930
4998
  };
4931
4999
 
4932
5000
  // src/use-categories.ts
4933
- var import_react_query17 = require("@tanstack/react-query");
5001
+ var import_react_query18 = require("@tanstack/react-query");
4934
5002
  function useCategories(options) {
4935
5003
  var _a, _b, _c, _d, _e, _f;
4936
5004
  const client = useAggClient();
@@ -4938,7 +5006,7 @@ function useCategories(options) {
4938
5006
  const parentId = (_b = options == null ? void 0 : options.parentId) != null ? _b : null;
4939
5007
  const enabled = (_c = options == null ? void 0 : options.enabled) != null ? _c : true;
4940
5008
  const limit = (_d = options == null ? void 0 : options.limit) != null ? _d : 20;
4941
- const query = (0, import_react_query17.useInfiniteQuery)({
5009
+ const query = (0, import_react_query18.useInfiniteQuery)({
4942
5010
  queryKey: [queryKeyScope, "parent", parentId != null ? parentId : "__root__", limit],
4943
5011
  queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
4944
5012
  const res = yield client.getCategories(__spreadValues({
@@ -4970,7 +5038,7 @@ function useCategoryChildren(options) {
4970
5038
  const parentIds = Array.from(
4971
5039
  new Set(((_d = options == null ? void 0 : options.parentIds) != null ? _d : []).filter((parentId) => Boolean(parentId)))
4972
5040
  );
4973
- const queries = (0, import_react_query17.useQueries)({
5041
+ const queries = (0, import_react_query18.useQueries)({
4974
5042
  queries: parentIds.map((parentId) => ({
4975
5043
  queryKey: [queryKeyScope, "parent", parentId, limit],
4976
5044
  queryFn: () => __async(null, null, function* () {
@@ -5013,7 +5081,7 @@ function useDebouncedValue(value, delay) {
5013
5081
  }
5014
5082
 
5015
5083
  // src/use-execution-orders.ts
5016
- var import_react_query18 = require("@tanstack/react-query");
5084
+ var import_react_query19 = require("@tanstack/react-query");
5017
5085
  function useExecutionOrders(options = {}) {
5018
5086
  var _a, _b;
5019
5087
  const client = useAggClient();
@@ -5026,7 +5094,7 @@ function useExecutionOrders(options = {}) {
5026
5094
  enabled = true,
5027
5095
  refetchIntervalMs = false
5028
5096
  } = options;
5029
- const query = (0, import_react_query18.useInfiniteQuery)({
5097
+ const query = (0, import_react_query19.useInfiniteQuery)({
5030
5098
  // quoteId + orderId are part of the cache key — different filters
5031
5099
  // produce different result sets, so they have to vary the key.
5032
5100
  queryKey: [
@@ -5062,7 +5130,7 @@ function useExecutionOrders(options = {}) {
5062
5130
  }
5063
5131
 
5064
5132
  // src/use-user-activity.ts
5065
- var import_react_query19 = require("@tanstack/react-query");
5133
+ var import_react_query20 = require("@tanstack/react-query");
5066
5134
  var DEFAULT_PENDING_REFETCH_INTERVAL_MS = 15e3;
5067
5135
  var PENDING_ACTIVITY_STATUSES = /* @__PURE__ */ new Set([
5068
5136
  "pending",
@@ -5096,7 +5164,7 @@ function useUserActivity(options = {}) {
5096
5164
  enabled = true,
5097
5165
  pendingRefetchIntervalMs = DEFAULT_PENDING_REFETCH_INTERVAL_MS
5098
5166
  } = options;
5099
- const query = (0, import_react_query19.useInfiniteQuery)({
5167
+ const query = (0, import_react_query20.useInfiniteQuery)({
5100
5168
  queryKey: userActivityQueryKeys.feed(type, limit),
5101
5169
  queryFn: ({ pageParam }) => client.getUserActivity({
5102
5170
  type,
@@ -5113,7 +5181,7 @@ function useUserActivity(options = {}) {
5113
5181
  // flight (typically after a deposit / withdraw cache invalidation).
5114
5182
  // Without this the feed flashes to the skeleton mid-session, which
5115
5183
  // is worse UX than briefly showing slightly-stale rows.
5116
- placeholderData: import_react_query19.keepPreviousData,
5184
+ placeholderData: import_react_query20.keepPreviousData,
5117
5185
  refetchInterval: (q) => {
5118
5186
  if (pendingRefetchIntervalMs === false) return false;
5119
5187
  const data = q.state.data;
@@ -5158,12 +5226,12 @@ function useExternalId(options = {}) {
5158
5226
  }
5159
5227
 
5160
5228
  // src/use-execution-positions.ts
5161
- var import_react_query20 = require("@tanstack/react-query");
5229
+ var import_react_query21 = require("@tanstack/react-query");
5162
5230
  function useExecutionPositions(options = {}) {
5163
5231
  var _a, _b;
5164
5232
  const client = useAggClient();
5165
5233
  const { limit = 50, status, mode, enabled = true } = options;
5166
- const query = (0, import_react_query20.useInfiniteQuery)({
5234
+ const query = (0, import_react_query21.useInfiniteQuery)({
5167
5235
  queryKey: executionKeys.positions(null, limit, status != null ? status : null, mode != null ? mode : null),
5168
5236
  queryFn: ({ pageParam }) => client.getExecutionPositions(__spreadProps(__spreadValues({
5169
5237
  limit,
@@ -5194,7 +5262,7 @@ var import_react23 = require("react");
5194
5262
  var import_sdk3 = require("@agg-build/sdk");
5195
5263
 
5196
5264
  // src/use-market-chart.ts
5197
- var import_react_query21 = require("@tanstack/react-query");
5265
+ var import_react_query22 = require("@tanstack/react-query");
5198
5266
 
5199
5267
  // src/market-data/subscription.ts
5200
5268
  var import_react21 = require("react");
@@ -5279,7 +5347,7 @@ function useMarketChart(options) {
5279
5347
  orderbook: true,
5280
5348
  trades: true
5281
5349
  });
5282
- const queries = (0, import_react_query21.useQueries)({
5350
+ const queries = (0, import_react_query22.useQueries)({
5283
5351
  queries: outcomeIds.map((outcomeId) => ({
5284
5352
  // Cache key is intentionally time-free. The rolling window's
5285
5353
  // startTs/endTs advance on every bucket but the user expects the same
@@ -5314,7 +5382,7 @@ function useMarketChart(options) {
5314
5382
  gcTime: 60 * 6e4,
5315
5383
  refetchOnWindowFocus: false,
5316
5384
  retry: 1,
5317
- placeholderData: import_react_query21.keepPreviousData,
5385
+ placeholderData: import_react_query22.keepPreviousData,
5318
5386
  refetchInterval: refetchIntervalMs != null && refetchIntervalMs > 0 ? refetchIntervalMs : false,
5319
5387
  refetchIntervalInBackground: false
5320
5388
  }))
@@ -5557,7 +5625,7 @@ function useEventOrderbookData(venueMarkets, selectedMarketId) {
5557
5625
  }
5558
5626
 
5559
5627
  // src/use-live-market.ts
5560
- var import_react_query22 = require("@tanstack/react-query");
5628
+ var import_react_query23 = require("@tanstack/react-query");
5561
5629
  function outcomeOrderbookToState(response, marketId) {
5562
5630
  var _a, _b, _c, _d;
5563
5631
  const { venue, orderbook, midpoint, spread, seq, checksum, timestamp, venueMarketOutcomeId } = response;
@@ -5607,7 +5675,7 @@ function useLiveMarket(canonicalMarketId) {
5607
5675
  enabled: isLiveSubscriptionEnabled,
5608
5676
  orderbook: true
5609
5677
  });
5610
- const query = (0, import_react_query22.useQuery)({
5678
+ const query = (0, import_react_query23.useQuery)({
5611
5679
  queryKey: marketDataKeys.live(canonicalMarketId != null ? canonicalMarketId : "__disabled__"),
5612
5680
  queryFn: () => __async(null, null, function* () {
5613
5681
  return createMarketLiveState(canonicalMarketId != null ? canonicalMarketId : "__disabled__");
@@ -5619,7 +5687,7 @@ function useLiveMarket(canonicalMarketId) {
5619
5687
  isConnected: Boolean(isLiveSubscriptionEnabled && isConnected)
5620
5688
  })
5621
5689
  });
5622
- const seedQuery = (0, import_react_query22.useQuery)({
5690
+ const seedQuery = (0, import_react_query23.useQuery)({
5623
5691
  queryKey: ["live-market-seed", canonicalMarketId],
5624
5692
  queryFn: ({ signal }) => canonicalMarketId ? client.getOutcomeOrderbook(canonicalMarketId, { signal }) : Promise.resolve(null),
5625
5693
  enabled: Boolean(canonicalMarketId),
@@ -5640,7 +5708,7 @@ function useLiveMarket(canonicalMarketId) {
5640
5708
 
5641
5709
  // src/use-live-outcome-prices.ts
5642
5710
  var import_react26 = require("react");
5643
- var import_react_query23 = require("@tanstack/react-query");
5711
+ var import_react_query24 = require("@tanstack/react-query");
5644
5712
  var EMPTY_PRICES = /* @__PURE__ */ new Map();
5645
5713
  var buildMidpointFingerprint = (outcomeIds, queries) => {
5646
5714
  var _a, _b, _c;
@@ -5666,7 +5734,7 @@ function useLiveOutcomePrices(venueMarkets) {
5666
5734
  }
5667
5735
  return [...ids].sort();
5668
5736
  }, [venueMarkets]);
5669
- const queries = (0, import_react_query23.useQueries)({
5737
+ const queries = (0, import_react_query24.useQueries)({
5670
5738
  queries: outcomeIds.map((id) => ({
5671
5739
  queryKey: marketDataKeys.live(id),
5672
5740
  queryFn: () => createMarketLiveState(id),
@@ -5716,7 +5784,7 @@ function findLivePriceById(livePrices, id) {
5716
5784
 
5717
5785
  // src/use-live-best-prices.ts
5718
5786
  var import_react27 = require("react");
5719
- var import_react_query24 = require("@tanstack/react-query");
5787
+ var import_react_query25 = require("@tanstack/react-query");
5720
5788
  var EMPTY = /* @__PURE__ */ new Map();
5721
5789
  var extractOutcomeBestPrices = (state) => {
5722
5790
  var _a, _b;
@@ -5758,7 +5826,7 @@ function useLiveBestPrices(venueMarkets) {
5758
5826
  }
5759
5827
  return [...ids].sort();
5760
5828
  }, [venueMarkets]);
5761
- const queries = (0, import_react_query24.useQueries)({
5829
+ const queries = (0, import_react_query25.useQueries)({
5762
5830
  queries: outcomeIds.map((id) => ({
5763
5831
  queryKey: marketDataKeys.live(id),
5764
5832
  queryFn: () => createMarketLiveState(id),
@@ -5852,7 +5920,7 @@ function useLiveTrades(canonicalMarketId) {
5852
5920
  }
5853
5921
 
5854
5922
  // src/use-midpoints.ts
5855
- var import_react_query25 = require("@tanstack/react-query");
5923
+ var import_react_query26 = require("@tanstack/react-query");
5856
5924
  var import_react28 = require("react");
5857
5925
  var normalizeVenueMarketIds = (venueMarkets) => {
5858
5926
  var _a;
@@ -5982,16 +6050,21 @@ var extractBestPrices = (data, venueMarkets) => {
5982
6050
  }
5983
6051
  return { bestPrices, bestPriceVenuesByOutcomeId: venuesByOutcome };
5984
6052
  };
5985
- function useMidpoints(venueMarkets) {
6053
+ function useMidpoints(venueMarkets, options) {
6054
+ var _a;
5986
6055
  const client = useAggClient();
6056
+ const {
6057
+ market: { maxMidpointIdsPerRequest: configuredMaxMidpointIdsPerRequest }
6058
+ } = useAggUiConfig();
6059
+ const maxMidpointIdsPerRequest = (_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : configuredMaxMidpointIdsPerRequest;
5987
6060
  const ids = (0, import_react28.useMemo)(() => normalizeVenueMarketIds(venueMarkets), [venueMarkets]);
5988
6061
  const bestMidpointCandidateOutcomeIds = (0, import_react28.useMemo)(
5989
6062
  () => resolveBestMidpointCandidateOutcomeIds(venueMarkets),
5990
6063
  [venueMarkets]
5991
6064
  );
5992
- const { data, isLoading } = (0, import_react_query25.useQuery)({
5993
- queryKey: ["midpoints", ids],
5994
- queryFn: () => client.getMidpoints(ids, { bestPrice: true }),
6065
+ const { data, isLoading } = (0, import_react_query26.useQuery)({
6066
+ queryKey: ["midpoints", ids, maxMidpointIdsPerRequest],
6067
+ queryFn: () => client.getMidpoints(ids, { bestPrice: true, maxMidpointIdsPerRequest }),
5995
6068
  enabled: ids.length > 0,
5996
6069
  staleTime: Infinity,
5997
6070
  gcTime: 30 * 6e4,
@@ -6000,13 +6073,13 @@ function useMidpoints(venueMarkets) {
6000
6073
  refetchOnReconnect: false
6001
6074
  });
6002
6075
  const result = (0, import_react28.useMemo)(() => {
6003
- var _a, _b, _c, _d, _e;
6076
+ var _a2, _b, _c, _d, _e;
6004
6077
  const map = /* @__PURE__ */ new Map();
6005
6078
  const venueMap = /* @__PURE__ */ new Map();
6006
6079
  if (!(data == null ? void 0 : data.data) || !venueMarkets) return { map, venueMap };
6007
6080
  const itemByMarketId = new Map(data.data.map((item) => [item.venueMarketId, item]));
6008
6081
  for (const item of data.data) {
6009
- if (!((_a = item.outcomes) == null ? void 0 : _a.length)) continue;
6082
+ if (!((_a2 = item.outcomes) == null ? void 0 : _a2.length)) continue;
6010
6083
  for (const o of item.outcomes) {
6011
6084
  if (o.midpoint == null) continue;
6012
6085
  map.set(o.venueMarketOutcomeId, o.midpoint);
@@ -6145,10 +6218,10 @@ var useRollingChartWindow = (options) => {
6145
6218
  };
6146
6219
 
6147
6220
  // src/use-market-orderbook.ts
6148
- var import_react_query26 = require("@tanstack/react-query");
6221
+ var import_react_query27 = require("@tanstack/react-query");
6149
6222
  function useMarketOrderbook(options) {
6150
6223
  var _a, _b, _c, _d, _e, _f, _g;
6151
- const queryClient = (0, import_react_query26.useQueryClient)();
6224
+ const queryClient = (0, import_react_query27.useQueryClient)();
6152
6225
  const ws = useAggWebSocket();
6153
6226
  const isConnected = useAggWebSocketConnectionState();
6154
6227
  const {
@@ -6165,7 +6238,7 @@ function useMarketOrderbook(options) {
6165
6238
  enabled: enabled && !!selectedOutcomeId,
6166
6239
  orderbook: true
6167
6240
  });
6168
- const liveQueries = (0, import_react_query26.useQueries)({
6241
+ const liveQueries = (0, import_react_query27.useQueries)({
6169
6242
  queries: subscriptionIds.map((subscriptionId) => ({
6170
6243
  queryKey: marketDataKeys.live(subscriptionId),
6171
6244
  queryFn: () => createMarketLiveState(subscriptionId),
@@ -6289,7 +6362,7 @@ function useArbFeed() {
6289
6362
  }
6290
6363
 
6291
6364
  // src/use-order-book.ts
6292
- var import_react_query27 = require("@tanstack/react-query");
6365
+ var import_react_query28 = require("@tanstack/react-query");
6293
6366
  function useOrderBook(options) {
6294
6367
  const client = useAggClient();
6295
6368
  const { orderbooks, enabled = true, canonicalMarketId } = options;
@@ -6302,7 +6375,7 @@ function useOrderBook(options) {
6302
6375
  venueMarketOutcomeId: outcome.id
6303
6376
  })) : void 0
6304
6377
  });
6305
- const batchedResult = (0, import_react_query27.useQuery)({
6378
+ const batchedResult = (0, import_react_query28.useQuery)({
6306
6379
  queryKey: requestedVenueMarketIds.length ? ["orderbooks", requestedVenueMarketIds, null] : ["orderbooks", "__disabled__", null],
6307
6380
  queryFn: ({ signal }) => client.getOrderbooks(
6308
6381
  {
@@ -6315,7 +6388,7 @@ function useOrderBook(options) {
6315
6388
  gcTime: 5 * 6e4,
6316
6389
  refetchOnWindowFocus: false,
6317
6390
  retry: 1,
6318
- placeholderData: import_react_query27.keepPreviousData
6391
+ placeholderData: import_react_query28.keepPreviousData
6319
6392
  });
6320
6393
  const data = (() => {
6321
6394
  var _a, _b;
@@ -6370,7 +6443,7 @@ function useOrderBook(options) {
6370
6443
  }
6371
6444
 
6372
6445
  // src/use-orderbook-quote.ts
6373
- var import_react_query28 = require("@tanstack/react-query");
6446
+ var import_react_query29 = require("@tanstack/react-query");
6374
6447
  var QUOTE_DEBOUNCE_MS = 300;
6375
6448
  var createUnavailableOrderbookError = (message, code, retryable) => {
6376
6449
  const error = new Error(message);
@@ -6432,7 +6505,7 @@ function useOrderbookQuote(options) {
6432
6505
  const { marketId, side, size, enabled = true } = options;
6433
6506
  const debouncedSize = useDebouncedValue(size, QUOTE_DEBOUNCE_MS);
6434
6507
  const shouldFetch = enabled && !!marketId && debouncedSize > 0;
6435
- const query = (0, import_react_query28.useQuery)({
6508
+ const query = (0, import_react_query29.useQuery)({
6436
6509
  queryKey: marketId ? marketDataKeys.orderbookQuote(marketId, side, debouncedSize) : ["market-data", "orderbook-quote", "__disabled__"],
6437
6510
  queryFn: () => __async(null, null, function* () {
6438
6511
  var _a2, _b, _c, _d;
@@ -6463,7 +6536,7 @@ function useOrderbookQuote(options) {
6463
6536
  staleTime: 1e4,
6464
6537
  gcTime: 5 * 6e4,
6465
6538
  retry: 1,
6466
- placeholderData: import_react_query28.keepPreviousData
6539
+ placeholderData: import_react_query29.keepPreviousData
6467
6540
  });
6468
6541
  return {
6469
6542
  data: (_a = query.data) != null ? _a : null,
@@ -6474,12 +6547,12 @@ function useOrderbookQuote(options) {
6474
6547
  }
6475
6548
 
6476
6549
  // src/use-orders.ts
6477
- var import_react_query29 = require("@tanstack/react-query");
6550
+ var import_react_query30 = require("@tanstack/react-query");
6478
6551
  function useOrders(options = {}) {
6479
6552
  var _a, _b, _c, _d;
6480
6553
  const client = useAggClient();
6481
6554
  const { userId, status, limit = 50, offset = 0, enabled = true } = options;
6482
- const query = (0, import_react_query29.useQuery)({
6555
+ const query = (0, import_react_query30.useQuery)({
6483
6556
  queryKey: ["orders", userId != null ? userId : "me", status != null ? status : "all", limit, offset],
6484
6557
  queryFn: () => client.getOrders({
6485
6558
  userId,
@@ -6496,13 +6569,13 @@ function useOrders(options = {}) {
6496
6569
  }
6497
6570
 
6498
6571
  // src/use-search.ts
6499
- var import_react_query30 = require("@tanstack/react-query");
6572
+ var import_react_query31 = require("@tanstack/react-query");
6500
6573
  var import_react32 = require("react");
6501
6574
  function useSearch(options) {
6502
6575
  var _a, _b, _c;
6503
6576
  const client = (0, import_react32.useContext)(AggClientContext);
6504
- const queryClient = (0, import_react32.useContext)(import_react_query30.QueryClientContext);
6505
- const [fallbackQueryClient] = (0, import_react32.useState)(() => new import_react_query30.QueryClient());
6577
+ const queryClient = (0, import_react32.useContext)(import_react_query31.QueryClientContext);
6578
+ const [fallbackQueryClient] = (0, import_react32.useState)(() => new import_react_query31.QueryClient());
6506
6579
  const { q, type, categoryIds, limit = 20, enabled = true, deep = false } = options;
6507
6580
  const isEnabled = enabled && q.length > 0;
6508
6581
  (0, import_react32.useEffect)(() => {
@@ -6515,7 +6588,7 @@ function useSearch(options) {
6515
6588
  if (isEnabled && !client) {
6516
6589
  throw new Error("useSearch must be used within an <AggProvider>");
6517
6590
  }
6518
- const query = (0, import_react_query30.useInfiniteQuery)(
6591
+ const query = (0, import_react_query31.useInfiniteQuery)(
6519
6592
  {
6520
6593
  // deep is part of the key — TanStack treats deep vs light as
6521
6594
  // independent queries so users can have both modes cached side-by-side.
@@ -6540,7 +6613,7 @@ function useSearch(options) {
6540
6613
  if (!lastPage.hasMore) return void 0;
6541
6614
  return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
6542
6615
  },
6543
- placeholderData: import_react_query30.keepPreviousData,
6616
+ placeholderData: import_react_query31.keepPreviousData,
6544
6617
  enabled: isEnabled && !!client
6545
6618
  },
6546
6619
  queryClient != null ? queryClient : fallbackQueryClient
@@ -6645,7 +6718,7 @@ function useMarketSearch(options) {
6645
6718
  }
6646
6719
 
6647
6720
  // src/use-smart-route.ts
6648
- var import_react_query31 = require("@tanstack/react-query");
6721
+ var import_react_query32 = require("@tanstack/react-query");
6649
6722
  var SMART_ROUTE_STALE_TIME_MS = 2e4;
6650
6723
  function useSmartRoute(options) {
6651
6724
  var _a, _b;
@@ -6667,7 +6740,7 @@ function useSmartRoute(options) {
6667
6740
  staleTimeMs = SMART_ROUTE_STALE_TIME_MS
6668
6741
  } = options;
6669
6742
  const resolvedVenueMarketOutcomeId = (_a = venueMarketOutcomeId != null ? venueMarketOutcomeId : venueMarketId) != null ? _a : outcomeId;
6670
- const query = (0, import_react_query31.useQuery)({
6743
+ const query = (0, import_react_query32.useQuery)({
6671
6744
  queryKey: [
6672
6745
  "smart-route",
6673
6746
  resolvedVenueMarketOutcomeId,
@@ -6704,25 +6777,34 @@ function useSmartRoute(options) {
6704
6777
  gcTime: 6e4,
6705
6778
  refetchOnWindowFocus: false,
6706
6779
  retry: 1,
6707
- placeholderData: import_react_query31.keepPreviousData
6780
+ placeholderData: import_react_query32.keepPreviousData
6708
6781
  });
6709
6782
  const error = query.error;
6783
+ let loadingReason = null;
6784
+ if (query.isFetching) {
6785
+ if (query.isLoading) {
6786
+ loadingReason = query.data != null ? "updating-route" : "finding-best-odds";
6787
+ } else {
6788
+ loadingReason = "refreshing-quotes";
6789
+ }
6790
+ }
6710
6791
  return {
6711
6792
  data: (_b = query.data) != null ? _b : null,
6712
6793
  isLoading: query.isLoading,
6713
6794
  isFetching: query.isFetching,
6714
6795
  error: error instanceof Error ? error : error ? new Error(String(error)) : null,
6715
- refetch: query.refetch
6796
+ refetch: query.refetch,
6797
+ loadingReason
6716
6798
  };
6717
6799
  }
6718
6800
 
6719
6801
  // src/use-user-holdings.ts
6720
- var import_react_query32 = require("@tanstack/react-query");
6802
+ var import_react_query33 = require("@tanstack/react-query");
6721
6803
  function useUserHoldings(options) {
6722
6804
  var _a, _b;
6723
6805
  const client = useAggClient();
6724
6806
  const { venue, venueMarketId, venueEventId, enabled = true } = options;
6725
- const query = (0, import_react_query32.useInfiniteQuery)({
6807
+ const query = (0, import_react_query33.useInfiniteQuery)({
6726
6808
  queryKey: ["user-holdings", venue, venueMarketId, venueEventId],
6727
6809
  queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
6728
6810
  return client.getUserHoldings({
@@ -6751,12 +6833,12 @@ function useUserHoldings(options) {
6751
6833
  var import_react35 = require("react");
6752
6834
 
6753
6835
  // src/use-venue-event.ts
6754
- var import_react_query33 = require("@tanstack/react-query");
6836
+ var import_react_query34 = require("@tanstack/react-query");
6755
6837
  function useVenueEvent(options) {
6756
6838
  var _a;
6757
6839
  const client = useAggClient();
6758
6840
  const { eventId, enabled = true } = options;
6759
- const query = (0, import_react_query33.useQuery)({
6841
+ const query = (0, import_react_query34.useQuery)({
6760
6842
  queryKey: ["venue-event", eventId],
6761
6843
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
6762
6844
  return client.getVenueEventById(eventId, { signal });
@@ -6775,13 +6857,13 @@ function useVenueEvent(options) {
6775
6857
  }
6776
6858
 
6777
6859
  // src/use-venue-markets.ts
6778
- var import_react_query34 = require("@tanstack/react-query");
6860
+ var import_react_query35 = require("@tanstack/react-query");
6779
6861
  var import_react34 = require("react");
6780
6862
  function useVenueMarkets(options) {
6781
6863
  var _a, _b, _c, _d, _e;
6782
6864
  const client = (0, import_react34.useContext)(AggClientContext);
6783
- const queryClient = (0, import_react34.useContext)(import_react_query34.QueryClientContext);
6784
- const [fallbackQueryClient] = (0, import_react34.useState)(() => new import_react_query34.QueryClient());
6865
+ const queryClient = (0, import_react34.useContext)(import_react_query35.QueryClientContext);
6866
+ const [fallbackQueryClient] = (0, import_react34.useState)(() => new import_react_query35.QueryClient());
6785
6867
  const venue = options == null ? void 0 : options.venue;
6786
6868
  const venueEventId = options == null ? void 0 : options.venueEventId;
6787
6869
  const search = options == null ? void 0 : options.search;
@@ -6802,7 +6884,7 @@ function useVenueMarkets(options) {
6802
6884
  if (enabled && !client) {
6803
6885
  throw new Error("useVenueMarkets must be used within an <AggProvider>");
6804
6886
  }
6805
- const query = (0, import_react_query34.useInfiniteQuery)(
6887
+ const query = (0, import_react_query35.useInfiniteQuery)(
6806
6888
  {
6807
6889
  queryKey: [
6808
6890
  "venue-markets",
@@ -6886,13 +6968,13 @@ function useEnrichedVenueEvent(options) {
6886
6968
  }
6887
6969
 
6888
6970
  // src/use-venue-events.ts
6889
- var import_react_query35 = require("@tanstack/react-query");
6971
+ var import_react_query36 = require("@tanstack/react-query");
6890
6972
  var import_react36 = require("react");
6891
6973
  function useVenueEvents(options) {
6892
6974
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
6893
6975
  const client = (0, import_react36.useContext)(AggClientContext);
6894
- const queryClient = (0, import_react36.useContext)(import_react_query35.QueryClientContext);
6895
- const [fallbackQueryClient] = (0, import_react36.useState)(() => new import_react_query35.QueryClient());
6976
+ const queryClient = (0, import_react36.useContext)(import_react_query36.QueryClientContext);
6977
+ const [fallbackQueryClient] = (0, import_react36.useState)(() => new import_react_query36.QueryClient());
6896
6978
  const venues = options == null ? void 0 : options.venues;
6897
6979
  const search = options == null ? void 0 : options.search;
6898
6980
  const categoryIds = options == null ? void 0 : options.categoryIds;
@@ -6918,7 +7000,7 @@ function useVenueEvents(options) {
6918
7000
  if (enabled && !client) {
6919
7001
  throw new Error("useVenueEvents must be used within an <AggProvider>");
6920
7002
  }
6921
- const query = (0, import_react_query35.useInfiniteQuery)(
7003
+ const query = (0, import_react_query36.useInfiniteQuery)(
6922
7004
  {
6923
7005
  queryKey: [
6924
7006
  queryKeyScope,
@@ -6963,7 +7045,7 @@ function useVenueEvents(options) {
6963
7045
  return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
6964
7046
  },
6965
7047
  // TODO: RMIK - Comment out to show skeletons on category switch
6966
- placeholderData: import_react_query35.keepPreviousData,
7048
+ placeholderData: import_react_query36.keepPreviousData,
6967
7049
  enabled: enabled && !!client
6968
7050
  },
6969
7051
  queryClient != null ? queryClient : fallbackQueryClient
@@ -7005,26 +7087,12 @@ function useVenueEvents(options) {
7005
7087
  }
7006
7088
 
7007
7089
  // src/use-venue-market-midpoints.ts
7008
- var import_react_query36 = require("@tanstack/react-query");
7009
- var MAX_VENUE_MARKET_IDS_PER_REQUEST = 200;
7090
+ var import_react_query37 = require("@tanstack/react-query");
7010
7091
  var normalizeVenueMarketIds2 = (venueMarketIds) => {
7011
7092
  return [
7012
7093
  ...new Set(venueMarketIds.map((venueMarketId) => venueMarketId.trim()).filter(Boolean))
7013
7094
  ].sort((left, right) => left.localeCompare(right));
7014
7095
  };
7015
- var chunkVenueMarketIds = (venueMarketIds) => {
7016
- if (venueMarketIds.length === 0) return [];
7017
- const chunks = [];
7018
- for (let index = 0; index < venueMarketIds.length; index += MAX_VENUE_MARKET_IDS_PER_REQUEST) {
7019
- chunks.push(venueMarketIds.slice(index, index + MAX_VENUE_MARKET_IDS_PER_REQUEST));
7020
- }
7021
- return chunks;
7022
- };
7023
- var mergeMidpointResponses = (responses) => {
7024
- return {
7025
- data: responses.flatMap((response) => response.data)
7026
- };
7027
- };
7028
7096
  var mapMidpointsByVenueMarketId = (rows) => {
7029
7097
  const mappedMidpoints = /* @__PURE__ */ new Map();
7030
7098
  rows.forEach((row) => {
@@ -7037,32 +7105,33 @@ var mapMidpointsByVenueMarketId = (rows) => {
7037
7105
  return mappedMidpoints;
7038
7106
  };
7039
7107
  function useVenueMarketMidpoints(options) {
7040
- var _a, _b, _c;
7108
+ var _a, _b, _c, _d;
7041
7109
  const client = useAggClient();
7110
+ const {
7111
+ market: { maxMidpointIdsPerRequest: configuredMaxMidpointIdsPerRequest }
7112
+ } = useAggUiConfig();
7042
7113
  const enabled = (_a = options.enabled) != null ? _a : true;
7043
7114
  const requestedVenueMarketIds = normalizeVenueMarketIds2(options.venueMarketIds);
7044
- const query = (0, import_react_query36.useQuery)({
7045
- queryKey: requestedVenueMarketIds.length ? ["venue-market-midpoints", requestedVenueMarketIds] : ["venue-market-midpoints", "__disabled__"],
7115
+ const maxMidpointIdsPerRequest = (_b = options.maxMidpointIdsPerRequest) != null ? _b : configuredMaxMidpointIdsPerRequest;
7116
+ const query = (0, import_react_query37.useQuery)({
7117
+ queryKey: requestedVenueMarketIds.length ? ["venue-market-midpoints", requestedVenueMarketIds, maxMidpointIdsPerRequest] : ["venue-market-midpoints", "__disabled__"],
7046
7118
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
7047
- const venueMarketIdChunks = chunkVenueMarketIds(requestedVenueMarketIds);
7048
- if (venueMarketIdChunks.length === 0) {
7119
+ if (requestedVenueMarketIds.length === 0) {
7049
7120
  return { data: [] };
7050
7121
  }
7051
- const chunkResponses = yield Promise.all(
7052
- venueMarketIdChunks.map((venueMarketIds) => {
7053
- return client.getMidpoints({ venueMarketIds, bestPrice: true }, { signal });
7054
- })
7122
+ return client.getMidpoints(
7123
+ { venueMarketIds: requestedVenueMarketIds, bestPrice: true },
7124
+ { signal, maxMidpointIdsPerRequest }
7055
7125
  );
7056
- return mergeMidpointResponses(chunkResponses);
7057
7126
  }),
7058
7127
  enabled: enabled && requestedVenueMarketIds.length > 0,
7059
7128
  staleTime: 1e4,
7060
7129
  gcTime: 5 * 6e4,
7061
7130
  refetchOnWindowFocus: false,
7062
7131
  retry: 1,
7063
- placeholderData: import_react_query36.keepPreviousData
7132
+ placeholderData: import_react_query37.keepPreviousData
7064
7133
  });
7065
- const midpointRows = (_c = (_b = query.data) == null ? void 0 : _b.data) != null ? _c : [];
7134
+ const midpointRows = (_d = (_c = query.data) == null ? void 0 : _c.data) != null ? _d : [];
7066
7135
  const midpointsByVenueMarketId = mapMidpointsByVenueMarketId(midpointRows);
7067
7136
  return __spreadProps(__spreadValues({}, query), {
7068
7137
  midpointRows,
@@ -7164,8 +7233,13 @@ var buildCachedMidpointEntries = (requestedVenueMarketIds, rows) => {
7164
7233
  }
7165
7234
  return nextCacheEntries;
7166
7235
  };
7167
- function useViewportMidpoints(visibleMarkets) {
7236
+ function useViewportMidpoints(visibleMarkets, options) {
7237
+ var _a;
7168
7238
  const client = useAggClient();
7239
+ const {
7240
+ market: { maxMidpointIdsPerRequest: configuredMaxMidpointIdsPerRequest }
7241
+ } = useAggUiConfig();
7242
+ const maxMidpointIdsPerRequest = (_a = options == null ? void 0 : options.maxMidpointIdsPerRequest) != null ? _a : configuredMaxMidpointIdsPerRequest;
7169
7243
  const [cache, setCache] = (0, import_react37.useState)(() => /* @__PURE__ */ new Map());
7170
7244
  const inFlightRef = (0, import_react37.useRef)(/* @__PURE__ */ new Set());
7171
7245
  const visibleRef = (0, import_react37.useRef)(visibleMarkets);
@@ -7179,10 +7253,10 @@ function useViewportMidpoints(visibleMarkets) {
7179
7253
  if (!toFetch.length) return;
7180
7254
  let cancelled = false;
7181
7255
  for (const id of toFetch) inFlightRef.current.add(id);
7182
- client.getMidpoints(toFetch, { bestPrice: true }).then((resp) => {
7183
- var _a;
7256
+ client.getMidpoints(toFetch, { bestPrice: true, maxMidpointIdsPerRequest }).then((resp) => {
7257
+ var _a2;
7184
7258
  if (cancelled) return;
7185
- const nextCacheEntries = buildCachedMidpointEntries(toFetch, (_a = resp.data) != null ? _a : []);
7259
+ const nextCacheEntries = buildCachedMidpointEntries(toFetch, (_a2 = resp.data) != null ? _a2 : []);
7186
7260
  setCache((prev) => {
7187
7261
  const next = new Map(prev);
7188
7262
  for (const [venueMarketId, entry] of nextCacheEntries) {
@@ -7197,15 +7271,15 @@ function useViewportMidpoints(visibleMarkets) {
7197
7271
  return () => {
7198
7272
  cancelled = true;
7199
7273
  };
7200
- }, [visibleFp, cache]);
7274
+ }, [visibleFp, cache, maxMidpointIdsPerRequest]);
7201
7275
  const { prices, venueByOutcomeId } = (0, import_react37.useMemo)(() => {
7202
- var _a, _b, _c, _d;
7276
+ var _a2, _b, _c, _d;
7203
7277
  const map = /* @__PURE__ */ new Map();
7204
7278
  const venueMap = /* @__PURE__ */ new Map();
7205
7279
  for (const market of visibleMarkets) {
7206
7280
  const entry = cache.get(market.id);
7207
7281
  if (!entry) continue;
7208
- const ownVenue = (_a = entry.venue) != null ? _a : market.venue;
7282
+ const ownVenue = (_a2 = entry.venue) != null ? _a2 : market.venue;
7209
7283
  for (const outcome of market.venueMarketOutcomes) {
7210
7284
  let best = (_b = entry.ownOutcomes.get(outcome.id)) != null ? _b : null;
7211
7285
  let bestVenue = best != null ? ownVenue : null;
@@ -7304,12 +7378,12 @@ function useVisibleIds(options = {}) {
7304
7378
  }
7305
7379
 
7306
7380
  // src/use-app-config.ts
7307
- var import_react_query37 = require("@tanstack/react-query");
7381
+ var import_react_query38 = require("@tanstack/react-query");
7308
7382
  var FIVE_MINUTES = 5 * 60 * 1e3;
7309
7383
  var APP_CONFIG_QUERY_KEY = ["agg", "app-config"];
7310
7384
  function useAppConfig() {
7311
7385
  const client = useAggClient();
7312
- const query = (0, import_react_query37.useQuery)({
7386
+ const query = (0, import_react_query38.useQuery)({
7313
7387
  queryKey: APP_CONFIG_QUERY_KEY,
7314
7388
  queryFn: () => client.getAppConfig(),
7315
7389
  staleTime: FIVE_MINUTES
@@ -7321,8 +7395,8 @@ function useAppConfig() {
7321
7395
  });
7322
7396
  }
7323
7397
  function useCachedAppConfig() {
7324
- const queryClient = (0, import_react_query37.useQueryClient)();
7325
- const query = (0, import_react_query37.useQuery)({
7398
+ const queryClient = (0, import_react_query38.useQueryClient)();
7399
+ const query = (0, import_react_query38.useQuery)({
7326
7400
  queryKey: APP_CONFIG_QUERY_KEY,
7327
7401
  enabled: false,
7328
7402
  initialData: () => queryClient.getQueryData(APP_CONFIG_QUERY_KEY),
@@ -7482,6 +7556,7 @@ var toAppConfigResult = (query) => {
7482
7556
  useWithdrawEstimate,
7483
7557
  useWithdrawFlow,
7484
7558
  useWithdrawManaged,
7559
+ useWithdrawPreview,
7485
7560
  useWithdrawalLifecycle,
7486
7561
  userActivityQueryKeys
7487
7562
  });