@agg-build/hooks 1.2.0 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -82,8 +82,10 @@ __export(src_exports, {
82
82
  MarketStatus: () => MarketStatus,
83
83
  MatchStatus: () => MatchStatus,
84
84
  MatchType: () => MatchType,
85
- QueryClient: () => import_react_query36.QueryClient,
86
- QueryClientProvider: () => import_react_query36.QueryClientProvider,
85
+ QueryClient: () => import_react_query37.QueryClient,
86
+ QueryClientProvider: () => import_react_query37.QueryClientProvider,
87
+ RedeemRejectedError: () => RedeemRejectedError,
88
+ TradeSide: () => TradeSide,
87
89
  TurnstileChallengeError: () => import_sdk4.TurnstileChallengeError,
88
90
  Venue: () => Venue,
89
91
  computeClosedPositionTotals: () => computeClosedPositionTotals,
@@ -98,9 +100,13 @@ __export(src_exports, {
98
100
  getWalletAddressFromUserProfile: () => getWalletAddressFromUserProfile,
99
101
  invalidateBalanceQueries: () => invalidateBalanceQueries,
100
102
  invalidatePositionQueries: () => invalidatePositionQueries,
103
+ invalidateUserActivityQueries: () => invalidateUserActivityQueries,
104
+ invalidateUserMoneyState: () => invalidateUserMoneyState,
105
+ mergeBestPricesPreferringLive: () => mergeBestPricesPreferringLive,
101
106
  optimizedImageUrl: () => optimizedImageUrl,
102
107
  parseEmail: () => parseEmail,
103
108
  parseEmailStrict: () => parseEmailStrict,
109
+ rangeToSeconds: () => rangeToSeconds,
104
110
  requestAggAuthChooserOpen: () => requestAggAuthChooserOpen,
105
111
  resolveAggUiLabels: () => resolveAggUiLabels,
106
112
  resolveDefaultTradingMarket: () => resolveDefaultMarket,
@@ -108,6 +114,7 @@ __export(src_exports, {
108
114
  resolveMarketTradingState: () => resolveMarketTradingState,
109
115
  resolveMarketWinningOutcome: () => resolveMarketWinningOutcome,
110
116
  resolveOrderEligibility: () => resolveOrderEligibility,
117
+ resolveRollingWindow: () => resolveRollingWindow,
111
118
  resolveTradingStateKind: () => resolveTradingStateKind,
112
119
  sortVenues: () => sortVenues,
113
120
  timeRangeToInterval: () => timeRangeToInterval,
@@ -138,6 +145,7 @@ __export(src_exports, {
138
145
  useGeoBlock: () => useGeoBlock,
139
146
  useLabels: () => useLabels,
140
147
  useLinkAccount: () => useLinkAccount,
148
+ useLiveBestPrices: () => useLiveBestPrices,
141
149
  useLiveCandleOverlay: () => useLiveCandleOverlay,
142
150
  useLiveCandles: () => useLiveCandles,
143
151
  useLiveMarket: () => useLiveMarket,
@@ -147,6 +155,7 @@ __export(src_exports, {
147
155
  useManagedBalances: () => useManagedBalances,
148
156
  useMarketChart: () => useMarketChart,
149
157
  useMarketOrderbook: () => useMarketOrderbook,
158
+ useMarketSearch: () => useMarketSearch,
150
159
  useMidpoints: () => useMidpoints,
151
160
  useOnBalanceUpdate: () => useOnBalanceUpdate,
152
161
  useOnOrderSubmitted: () => useOnOrderSubmitted,
@@ -156,17 +165,21 @@ __export(src_exports, {
156
165
  useOrderbookQuote: () => useOrderbookQuote,
157
166
  useOrders: () => useOrders,
158
167
  usePositions: () => usePositions,
159
- useQueryClient: () => import_react_query36.useQueryClient,
168
+ useQueryClient: () => import_react_query37.useQueryClient,
160
169
  useQuoteManaged: () => useQuoteManaged,
161
170
  useRampQuotes: () => useRampQuotes,
162
171
  useRampSession: () => useRampSession,
163
172
  useRedeem: () => useRedeem,
164
173
  useRedeemEligibleCount: () => useRedeemEligibleCount,
174
+ useRedeemLifecycle: () => useRedeemLifecycle,
175
+ useRedeemLifecycles: () => useRedeemLifecycles,
176
+ useRollingChartWindow: () => useRollingChartWindow,
165
177
  useSdkLabels: () => useSdkLabels,
166
178
  useSdkUiConfig: () => useSdkUiConfig,
167
179
  useSearch: () => useSearch,
168
180
  useSmartRoute: () => useSmartRoute,
169
181
  useSyncBalances: () => useSyncBalances,
182
+ useTradableVenues: () => useTradableVenues,
170
183
  useUserActivity: () => useUserActivity,
171
184
  useUserHoldings: () => useUserHoldings,
172
185
  useVenueEvent: () => useVenueEvent,
@@ -175,9 +188,11 @@ __export(src_exports, {
175
188
  useVenueMarkets: () => useVenueMarkets,
176
189
  useViewportMidpoints: () => useViewportMidpoints,
177
190
  useVisibleIds: () => useVisibleIds,
191
+ useWithdrawEstimate: () => useWithdrawEstimate,
178
192
  useWithdrawFlow: () => useWithdrawFlow,
179
193
  useWithdrawManaged: () => useWithdrawManaged,
180
- useWithdrawalLifecycle: () => useWithdrawalLifecycle
194
+ useWithdrawalLifecycle: () => useWithdrawalLifecycle,
195
+ userActivityQueryKeys: () => userActivityQueryKeys
181
196
  });
182
197
  module.exports = __toCommonJS(src_exports);
183
198
 
@@ -303,7 +318,7 @@ var getVenueOrder = (venue) => {
303
318
  var sortVenues = (venues) => [...venues].sort((a, b) => getVenueOrder(a) - getVenueOrder(b));
304
319
 
305
320
  // src/index.ts
306
- var import_react_query36 = require("@tanstack/react-query");
321
+ var import_react_query37 = require("@tanstack/react-query");
307
322
 
308
323
  // src/candle-store.ts
309
324
  var import_sdk = require("@agg-build/sdk");
@@ -437,7 +452,7 @@ var createAuthCallbackSession = (tokens) => {
437
452
  };
438
453
  };
439
454
  var executeWalletAuthFlow = (input) => __async(null, null, function* () {
440
- var _a, _b;
455
+ var _a, _b, _c, _d;
441
456
  const address = input.options.address.trim();
442
457
  const chain = (_a = input.options.chain) != null ? _a : "ethereum";
443
458
  const provider = chain === "solana" ? "siws" : "siwe";
@@ -460,14 +475,14 @@ var executeWalletAuthFlow = (input) => __async(null, null, function* () {
460
475
  uri: location.uri,
461
476
  nonce: startResult.nonce,
462
477
  chainId: typeof input.options.chainId === "string" ? input.options.chainId : "mainnet",
463
- statement: input.options.statement
478
+ statement: (_c = startResult.statement) != null ? _c : input.options.statement
464
479
  }) : input.client.buildSiweMessage({
465
480
  domain: location.domain,
466
481
  address,
467
482
  uri: location.uri,
468
483
  nonce: startResult.nonce,
469
484
  chainId: typeof input.options.chainId === "number" ? input.options.chainId : void 0,
470
- statement: input.options.statement
485
+ statement: (_d = startResult.statement) != null ? _d : input.options.statement
471
486
  });
472
487
  const signature = yield input.options.signMessage(message);
473
488
  const result = yield input.client.verify({ message, signature });
@@ -648,6 +663,12 @@ var enUsLabels = {
648
663
  max: "Max",
649
664
  tokenLabel: "Receive token",
650
665
  networkLabel: "Receive network",
666
+ estimatedFees: "Est. fees",
667
+ networkReserve: "Network reserve",
668
+ networkReserveTooltipAria: "Network reserve details",
669
+ networkReserveTooltipLineOne: "This reserve helps cover network and bridge costs.",
670
+ networkReserveTooltipLineTwo: "Any unused amount stays in your balance.",
671
+ youReceive: "You'll receive",
651
672
  confirm: "Confirm withdrawal",
652
673
  successTitle: "Withdrawal submitted",
653
674
  successDescription: (tokenSymbol) => `Your ${tokenSymbol} withdrawal is being processed and will arrive shortly.`,
@@ -656,12 +677,16 @@ var enUsLabels = {
656
677
  // terminal status — otherwise a finished withdrawal would keep showing
657
678
  // "submitted / processing" forever and force the user to hard-refresh.
658
679
  successTitleCompleted: "Withdrawal complete",
659
- successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol} withdrawal has been delivered.`,
680
+ successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol} has been successfully sent to your wallet.`,
660
681
  successTitlePartial: "Withdrawal partially completed",
661
- successDescriptionPartial: (tokenSymbol) => `Some legs of your ${tokenSymbol} withdrawal completed; see details below.`,
682
+ successDescriptionPartial: () => "Part of your withdrawal was completed successfully, but the remaining funds failed to transfer and were returned to your balance.",
662
683
  successTitleFailed: "Withdrawal failed",
663
- successDescriptionFailed: (tokenSymbol) => `Your ${tokenSymbol} withdrawal could not be completed.`,
684
+ successDescriptionFailed: () => "We couldn't complete your withdrawal. Your funds were returned to your balance.",
685
+ retry: "Try Again",
686
+ close: "Close",
687
+ loadingDescription: "This may take a few minutes. You can safely close this window and check the status later in your activity.",
664
688
  summary: {
689
+ requestedWithdrawal: "Requested withdrawal",
665
690
  // The response is `pricingStatus: "unquoted"` — we don't know net
666
691
  // output until on-chain settlement. Calling this "Amount received"
667
692
  // would imply receipt before the lifecycle has confirmed. Keep it
@@ -679,6 +704,12 @@ var enUsLabels = {
679
704
  completed: "Withdrawal complete.",
680
705
  partial: "Withdrawal partially completed \u2014 see details below.",
681
706
  failed: "Withdrawal failed.",
707
+ loadingSteps: {
708
+ preparing: "Preparing funds",
709
+ bridging: "Bridging between networks",
710
+ sending: "Sending to your wallet",
711
+ confirming: "Waiting for network confirmation"
712
+ },
682
713
  steps: {
683
714
  bridge: (sourceChainName, destChainName) => `Bridging from ${sourceChainName} to ${destChainName}`,
684
715
  transfer: (destChainName) => `Transferring on ${destChainName}`
@@ -734,10 +765,37 @@ var enUsLabels = {
734
765
  externalWallet: "Deposit from external wallet",
735
766
  card: "Deposit with card"
736
767
  },
768
+ depositStatusTitles: {
769
+ connectedWallet: {
770
+ pending: "Processing deposit from connected wallet",
771
+ completed: "Successful deposit from connected wallet",
772
+ failed: "Failed deposit from connected wallet",
773
+ canceled: "Canceled deposit from connected wallet"
774
+ },
775
+ externalWallet: {
776
+ pending: "Processing deposit from external wallet",
777
+ completed: "Successful deposit from external wallet",
778
+ failed: "Failed deposit from external wallet",
779
+ canceled: "Canceled deposit from external wallet"
780
+ },
781
+ card: {
782
+ pending: "Processing deposit with card",
783
+ completed: "Successful deposit with card",
784
+ failed: "Failed deposit with card",
785
+ canceled: "Canceled deposit with card"
786
+ }
787
+ },
788
+ withdrawalStatusTitles: {
789
+ pending: "Processing withdrawal",
790
+ completed: "Successful withdrawal",
791
+ failed: "Failed withdrawal",
792
+ canceled: "Canceled withdrawal"
793
+ },
737
794
  // Activity-row title for any withdrawal regardless of lifecycle
738
- // state (pending / completed / failed) — render the asset rather
739
- // than implying success. The ActivityRow renders a separate status
740
- // chip when the row is failed.
795
+ // state — render the asset rather than implying success. The
796
+ // ActivityRow renders a separate status chip when the row is
797
+ // failed. Retained for partner overrides that still want a
798
+ // status-agnostic title.
741
799
  withdrawalTitle: (tokenSymbol) => `Withdraw ${tokenSymbol}`
742
800
  },
743
801
  positions: {
@@ -958,6 +1016,7 @@ var enUsLabels = {
958
1016
  noMarketSelected: "Select a market to place an order.",
959
1017
  noOrderbooks: "No live orderbooks are available for this market right now.",
960
1018
  quoteUnavailable: "Quote temporarily unavailable. Please try again.",
1019
+ quoteBalanceMismatch: "Quote balance mismatch. Try a different amount.",
961
1020
  selectedVenueUnavailable: "The venue you selected is no longer available on this route. Review the updated options and try again.",
962
1021
  engineUnavailable: "The routing engine is temporarily unavailable. Please try again in a moment.",
963
1022
  insufficientInputAmount: "Trade amount is too small to cover bridging and execution costs. Increase your spend or deposit funds on the destination chain.",
@@ -995,6 +1054,7 @@ var enUsLabels = {
995
1054
  buyingOutcome: (label) => `Buying ${label}`,
996
1055
  sellingOutcome: (label) => `Selling ${label}`,
997
1056
  findingBestRoute: "Finding the best route...",
1057
+ checkingBalance: "Checking balance",
998
1058
  submittingOrderProgress: "Submitting order...",
999
1059
  orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
1000
1060
  executingOnVenue: (venueLabel) => `Executing on ${venueLabel}...`,
@@ -1253,6 +1313,7 @@ var defaultAggUiSearchConfig = {
1253
1313
  var defaultAggUiConfig = {
1254
1314
  enableLogs: false,
1255
1315
  enableWebsocketsLogs: false,
1316
+ enableDebug: false,
1256
1317
  general: {
1257
1318
  locale: DEFAULT_LOCALE,
1258
1319
  theme: "light",
@@ -1290,7 +1351,7 @@ var mergeAggUiSearchConfig = (config) => {
1290
1351
  };
1291
1352
  };
1292
1353
  var mergeAggUiConfig = (persisted, config) => {
1293
- 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;
1354
+ 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;
1294
1355
  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;
1295
1356
  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;
1296
1357
  const formatters = createFormatters(locale);
@@ -1298,32 +1359,33 @@ var mergeAggUiConfig = (persisted, config) => {
1298
1359
  return {
1299
1360
  enableLogs: (_i = config == null ? void 0 : config.enableLogs) != null ? _i : defaultAggUiConfig.enableLogs,
1300
1361
  enableWebsocketsLogs: (_j = config == null ? void 0 : config.enableWebsocketsLogs) != null ? _j : defaultAggUiConfig.enableWebsocketsLogs,
1362
+ enableDebug: (_k = config == null ? void 0 : config.enableDebug) != null ? _k : defaultAggUiConfig.enableDebug,
1301
1363
  general: {
1302
1364
  locale,
1303
1365
  theme,
1304
- rootClassName: (_l = (_k = config == null ? void 0 : config.general) == null ? void 0 : _k.rootClassName) != null ? _l : defaultAggUiConfig.general.rootClassName,
1305
- labels: mergeAggUiLabels(defaultLabels, (_m = config == null ? void 0 : config.general) == null ? void 0 : _m.labels)
1366
+ rootClassName: (_m = (_l = config == null ? void 0 : config.general) == null ? void 0 : _l.rootClassName) != null ? _m : defaultAggUiConfig.general.rootClassName,
1367
+ labels: mergeAggUiLabels(defaultLabels, (_n = config == null ? void 0 : config.general) == null ? void 0 : _n.labels)
1306
1368
  },
1307
1369
  features: {
1308
- enableAnimations: (_o = (_n = config == null ? void 0 : config.features) == null ? void 0 : _n.enableAnimations) != null ? _o : defaultAggUiConfig.features.enableAnimations,
1309
- enableLiveUpdates: (_q = (_p = config == null ? void 0 : config.features) == null ? void 0 : _p.enableLiveUpdates) != null ? _q : defaultAggUiConfig.features.enableLiveUpdates,
1310
- showFeesBreakdown: (_s = (_r = config == null ? void 0 : config.features) == null ? void 0 : _r.showFeesBreakdown) != null ? _s : defaultAggUiConfig.features.showFeesBreakdown,
1311
- enableGradients: (_u = (_t = config == null ? void 0 : config.features) == null ? void 0 : _t.enableGradients) != null ? _u : defaultAggUiConfig.features.enableGradients
1370
+ enableAnimations: (_p = (_o = config == null ? void 0 : config.features) == null ? void 0 : _o.enableAnimations) != null ? _p : defaultAggUiConfig.features.enableAnimations,
1371
+ enableLiveUpdates: (_r = (_q = config == null ? void 0 : config.features) == null ? void 0 : _q.enableLiveUpdates) != null ? _r : defaultAggUiConfig.features.enableLiveUpdates,
1372
+ showFeesBreakdown: (_t = (_s = config == null ? void 0 : config.features) == null ? void 0 : _s.showFeesBreakdown) != null ? _t : defaultAggUiConfig.features.showFeesBreakdown,
1373
+ enableGradients: (_v = (_u = config == null ? void 0 : config.features) == null ? void 0 : _u.enableGradients) != null ? _v : defaultAggUiConfig.features.enableGradients
1312
1374
  },
1313
1375
  market: {
1314
- arbitrageThreshold: (_w = (_v = config == null ? void 0 : config.market) == null ? void 0 : _v.arbitrageThreshold) != null ? _w : defaultAggUiConfig.market.arbitrageThreshold
1376
+ arbitrageThreshold: (_x = (_w = config == null ? void 0 : config.market) == null ? void 0 : _w.arbitrageThreshold) != null ? _x : defaultAggUiConfig.market.arbitrageThreshold
1315
1377
  },
1316
1378
  chart: {
1317
- defaultChartTimeRange: (_y = (_x = config == null ? void 0 : config.chart) == null ? void 0 : _x.defaultChartTimeRange) != null ? _y : defaultAggUiConfig.chart.defaultChartTimeRange,
1318
- selectedChartTimeRange: (_C = (_B = (_z = persisted.chart) == null ? void 0 : _z.selectedChartTimeRange) != null ? _B : (_A = config == null ? void 0 : config.chart) == null ? void 0 : _A.defaultChartTimeRange) != null ? _C : defaultAggUiConfig.chart.defaultChartTimeRange,
1379
+ defaultChartTimeRange: (_z = (_y = config == null ? void 0 : config.chart) == null ? void 0 : _y.defaultChartTimeRange) != null ? _z : defaultAggUiConfig.chart.defaultChartTimeRange,
1380
+ selectedChartTimeRange: (_D = (_C = (_A = persisted.chart) == null ? void 0 : _A.selectedChartTimeRange) != null ? _C : (_B = config == null ? void 0 : config.chart) == null ? void 0 : _B.defaultChartTimeRange) != null ? _D : defaultAggUiConfig.chart.defaultChartTimeRange,
1319
1381
  setSelectedChartTimeRange: defaultAggUiConfig.chart.setSelectedChartTimeRange
1320
1382
  },
1321
1383
  formatting: {
1322
- formatNumber: (_E = (_D = config == null ? void 0 : config.formatting) == null ? void 0 : _D.formatNumber) != null ? _E : formatters.formatNumber,
1323
- formatPercent: (_G = (_F = config == null ? void 0 : config.formatting) == null ? void 0 : _F.formatPercent) != null ? _G : formatters.formatPercent,
1324
- formatCurrency: (_I = (_H = config == null ? void 0 : config.formatting) == null ? void 0 : _H.formatCurrency) != null ? _I : formatters.formatCurrency,
1325
- formatCompactCurrency: (_K = (_J = config == null ? void 0 : config.formatting) == null ? void 0 : _J.formatCompactCurrency) != null ? _K : formatters.formatCompactCurrency,
1326
- formatDate: (_M = (_L = config == null ? void 0 : config.formatting) == null ? void 0 : _L.formatDate) != null ? _M : formatters.formatDate
1384
+ formatNumber: (_F = (_E = config == null ? void 0 : config.formatting) == null ? void 0 : _E.formatNumber) != null ? _F : formatters.formatNumber,
1385
+ formatPercent: (_H = (_G = config == null ? void 0 : config.formatting) == null ? void 0 : _G.formatPercent) != null ? _H : formatters.formatPercent,
1386
+ formatCurrency: (_J = (_I = config == null ? void 0 : config.formatting) == null ? void 0 : _I.formatCurrency) != null ? _J : formatters.formatCurrency,
1387
+ formatCompactCurrency: (_L = (_K = config == null ? void 0 : config.formatting) == null ? void 0 : _K.formatCompactCurrency) != null ? _L : formatters.formatCompactCurrency,
1388
+ formatDate: (_N = (_M = config == null ? void 0 : config.formatting) == null ? void 0 : _M.formatDate) != null ? _N : formatters.formatDate
1327
1389
  },
1328
1390
  search: mergeAggUiSearchConfig(config == null ? void 0 : config.search),
1329
1391
  walletActions: config == null ? void 0 : config.walletActions,
@@ -1625,6 +1687,26 @@ var shouldInvalidateBalancesForOrderEvent = (event, currentUserId) => {
1625
1687
  if (!currentUserId) return true;
1626
1688
  return event.userId === currentUserId;
1627
1689
  };
1690
+ var userActivityQueryKeys = {
1691
+ all: () => ["user-activity"]
1692
+ };
1693
+ var invalidateUserActivityQueries = (queryClient, options) => {
1694
+ var _a;
1695
+ const strategy = (_a = options == null ? void 0 : options.strategy) != null ? _a : "remove";
1696
+ if (strategy === "remove") {
1697
+ queryClient.removeQueries({ queryKey: userActivityQueryKeys.all() });
1698
+ return;
1699
+ }
1700
+ queryClient.invalidateQueries({
1701
+ queryKey: userActivityQueryKeys.all(),
1702
+ refetchType: "all"
1703
+ });
1704
+ };
1705
+ var invalidateUserMoneyState = (queryClient, options) => {
1706
+ invalidateBalanceQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
1707
+ invalidatePositionQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
1708
+ invalidateUserActivityQueries(queryClient, { strategy: options == null ? void 0 : options.activityStrategy });
1709
+ };
1628
1710
 
1629
1711
  // src/core/providers/balance-provider.tsx
1630
1712
  var import_jsx_runtime2 = require("react/jsx-runtime");
@@ -1633,6 +1715,7 @@ var CHAIN_LABELS = {
1633
1715
  10: "Optimism",
1634
1716
  56: "BNB",
1635
1717
  137: "Polygon",
1718
+ 1337: "Hyperliquid",
1636
1719
  8453: "Base",
1637
1720
  42161: "Arbitrum",
1638
1721
  43114: "Avalanche",
@@ -1672,7 +1755,9 @@ function AggBalanceProvider({ children }) {
1672
1755
  return client.getManagedBalances();
1673
1756
  }),
1674
1757
  enabled: Boolean(client && isAuthenticated),
1675
- staleTime: 1e4
1758
+ staleTime: 60 * 1e3,
1759
+ refetchOnWindowFocus: "always",
1760
+ refetchOnReconnect: "always"
1676
1761
  });
1677
1762
  const managedBalancesData = balancesQuery.data;
1678
1763
  const managedBalances = (0, import_react3.useMemo)(
@@ -1832,6 +1917,7 @@ var import_react6 = require("react");
1832
1917
  var import_react_query2 = require("@tanstack/react-query");
1833
1918
 
1834
1919
  // src/market-data/chart-cache.ts
1920
+ var MAX_CACHE_RETENTION_SECONDS = 7 * 30 * 24 * 60 * 60 + 14 * 24 * 60 * 60;
1835
1921
  var getIntervalSeconds = (interval) => {
1836
1922
  switch (interval) {
1837
1923
  case "1m":
@@ -1850,12 +1936,41 @@ var createVenueData = (venue, outcomeIds = []) => ({
1850
1936
  candles: [],
1851
1937
  liveCandle: null,
1852
1938
  lineValue: void 0,
1853
- lastTrade: null
1939
+ lastTrade: null,
1940
+ lastUpdateTs: null
1854
1941
  });
1942
+ var pruneCandlesBefore = (candles, cutoffTs) => {
1943
+ if (cutoffTs <= 0) return candles;
1944
+ let firstKeptIndex = 0;
1945
+ while (firstKeptIndex < candles.length && candles[firstKeptIndex].time < cutoffTs) {
1946
+ firstKeptIndex += 1;
1947
+ }
1948
+ if (firstKeptIndex === 0) return candles;
1949
+ return candles.slice(firstKeptIndex);
1950
+ };
1951
+ var promoteClosedLiveCandle = (candles, liveCandle, expectedCandleTime) => {
1952
+ if (!liveCandle || liveCandle.time >= expectedCandleTime) {
1953
+ return { candles, promoted: false };
1954
+ }
1955
+ if (candles.some((candle) => candle.time === liveCandle.time)) {
1956
+ return { candles, promoted: false };
1957
+ }
1958
+ return { candles: sortCandles([...candles, liveCandle]), promoted: true };
1959
+ };
1960
+ var resolveMaxLastUpdateTs = (venues) => {
1961
+ let max = null;
1962
+ for (const venueData of Object.values(venues)) {
1963
+ if (venueData.lastUpdateTs != null && (max == null || venueData.lastUpdateTs > max)) {
1964
+ max = venueData.lastUpdateTs;
1965
+ }
1966
+ }
1967
+ return max;
1968
+ };
1855
1969
  var sortCandles = (candles) => {
1856
1970
  return [...candles].sort((left, right) => left.time - right.time);
1857
1971
  };
1858
1972
  var createMarketChartData = (params) => {
1973
+ var _a;
1859
1974
  const candles = sortCandles(
1860
1975
  params.response.data.map((candle) => ({
1861
1976
  time: Math.floor(candle.t / 1e3),
@@ -1868,6 +1983,7 @@ var createMarketChartData = (params) => {
1868
1983
  }))
1869
1984
  );
1870
1985
  const lastCandle = candles[candles.length - 1];
1986
+ const lastUpdateTs = (_a = lastCandle == null ? void 0 : lastCandle.time) != null ? _a : null;
1871
1987
  const venues = {
1872
1988
  [params.response.venue]: {
1873
1989
  venue: params.response.venue,
@@ -1875,7 +1991,8 @@ var createMarketChartData = (params) => {
1875
1991
  candles,
1876
1992
  liveCandle: null,
1877
1993
  lineValue: lastCandle == null ? void 0 : lastCandle.close,
1878
- lastTrade: null
1994
+ lastTrade: null,
1995
+ lastUpdateTs
1879
1996
  }
1880
1997
  };
1881
1998
  return {
@@ -1885,7 +2002,8 @@ var createMarketChartData = (params) => {
1885
2002
  interval: params.interval,
1886
2003
  startTs: params.startTs,
1887
2004
  endTs: params.endTs,
1888
- venues
2005
+ venues,
2006
+ lastUpdateTs
1889
2007
  };
1890
2008
  };
1891
2009
  var mergeMarketChartData = (params) => {
@@ -1919,9 +2037,75 @@ var mergeMarketChartData = (params) => {
1919
2037
  interval: params.interval,
1920
2038
  startTs: params.startTs,
1921
2039
  endTs: params.endTs,
1922
- venues
2040
+ venues,
2041
+ lastUpdateTs: resolveMaxLastUpdateTs(venues)
1923
2042
  };
1924
2043
  };
2044
+ var applyMidpointToMarketChart = (data, update) => {
2045
+ var _a;
2046
+ if (!data || !Number.isFinite(update.midpoint)) {
2047
+ return data;
2048
+ }
2049
+ const targetVenueEntry = Object.entries(data.venues).find(
2050
+ ([, venueData]) => venueData.outcomeIds.includes(update.outcomeId)
2051
+ );
2052
+ if (!targetVenueEntry && data.marketId !== update.outcomeId) {
2053
+ return data;
2054
+ }
2055
+ const [targetVenueName, currentVenue] = targetVenueEntry != null ? targetVenueEntry : [
2056
+ data.primaryVenue,
2057
+ (_a = data.venues[data.primaryVenue]) != null ? _a : createVenueData(data.primaryVenue, [update.outcomeId])
2058
+ ];
2059
+ const intervalSeconds = getIntervalSeconds(data.interval);
2060
+ const expectedCandleTime = update.timestamp - update.timestamp % intervalSeconds;
2061
+ let liveCandle = currentVenue.liveCandle;
2062
+ const { candles: promotedCandles } = promoteClosedLiveCandle(
2063
+ currentVenue.candles,
2064
+ liveCandle,
2065
+ expectedCandleTime
2066
+ );
2067
+ const nextCandles = pruneCandlesBefore(
2068
+ promotedCandles,
2069
+ update.timestamp - MAX_CACHE_RETENTION_SECONDS
2070
+ );
2071
+ if (liveCandle && liveCandle.time === expectedCandleTime) {
2072
+ if (liveCandle.source === "trade") {
2073
+ liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
2074
+ close: update.midpoint
2075
+ });
2076
+ } else {
2077
+ liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
2078
+ close: update.midpoint,
2079
+ high: Math.max(liveCandle.high, update.midpoint),
2080
+ low: Math.min(liveCandle.low, update.midpoint),
2081
+ source: "midpoint"
2082
+ });
2083
+ }
2084
+ } else {
2085
+ liveCandle = {
2086
+ time: expectedCandleTime,
2087
+ open: update.midpoint,
2088
+ high: update.midpoint,
2089
+ low: update.midpoint,
2090
+ close: update.midpoint,
2091
+ volume: 0,
2092
+ source: "midpoint"
2093
+ };
2094
+ }
2095
+ const nextVenues = __spreadProps(__spreadValues({}, data.venues), {
2096
+ [targetVenueName]: __spreadProps(__spreadValues({}, currentVenue), {
2097
+ outcomeIds: currentVenue.outcomeIds.includes(update.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, update.outcomeId],
2098
+ candles: nextCandles,
2099
+ liveCandle,
2100
+ lineValue: update.midpoint,
2101
+ lastUpdateTs: update.timestamp
2102
+ })
2103
+ });
2104
+ return __spreadProps(__spreadValues({}, data), {
2105
+ venues: nextVenues,
2106
+ lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
2107
+ });
2108
+ };
1925
2109
  var applyTradeToMarketChart = (data, trade) => {
1926
2110
  var _a, _b, _c;
1927
2111
  if (!data || data.marketId !== trade.outcomeId) {
@@ -1931,6 +2115,15 @@ var applyTradeToMarketChart = (data, trade) => {
1931
2115
  const intervalSeconds = getIntervalSeconds(data.interval);
1932
2116
  const expectedCandleTime = trade.timestamp - trade.timestamp % intervalSeconds;
1933
2117
  let liveCandle = currentVenue.liveCandle;
2118
+ const { candles: promotedCandles } = promoteClosedLiveCandle(
2119
+ currentVenue.candles,
2120
+ liveCandle,
2121
+ expectedCandleTime
2122
+ );
2123
+ const nextCandles = pruneCandlesBefore(
2124
+ promotedCandles,
2125
+ trade.timestamp - MAX_CACHE_RETENTION_SECONDS
2126
+ );
1934
2127
  if (liveCandle && liveCandle.time === expectedCandleTime) {
1935
2128
  liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
1936
2129
  close: trade.price,
@@ -1950,16 +2143,20 @@ var applyTradeToMarketChart = (data, trade) => {
1950
2143
  source: "trade"
1951
2144
  };
1952
2145
  }
1953
- return __spreadProps(__spreadValues({}, data), {
1954
- venues: __spreadProps(__spreadValues({}, data.venues), {
1955
- [trade.venue]: __spreadProps(__spreadValues({}, currentVenue), {
1956
- outcomeIds: currentVenue.outcomeIds.includes(trade.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, trade.outcomeId],
1957
- liveCandle,
1958
- lineValue: (_c = liveCandle == null ? void 0 : liveCandle.close) != null ? _c : trade.price,
1959
- lastTrade: trade
1960
- })
2146
+ const nextVenues = __spreadProps(__spreadValues({}, data.venues), {
2147
+ [trade.venue]: __spreadProps(__spreadValues({}, currentVenue), {
2148
+ outcomeIds: currentVenue.outcomeIds.includes(trade.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, trade.outcomeId],
2149
+ candles: nextCandles,
2150
+ liveCandle,
2151
+ lineValue: (_c = liveCandle == null ? void 0 : liveCandle.close) != null ? _c : trade.price,
2152
+ lastTrade: trade,
2153
+ lastUpdateTs: trade.timestamp
1961
2154
  })
1962
2155
  });
2156
+ return __spreadProps(__spreadValues({}, data), {
2157
+ venues: nextVenues,
2158
+ lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
2159
+ });
1963
2160
  };
1964
2161
 
1965
2162
  // src/market-data/live-cache.ts
@@ -2150,7 +2347,15 @@ var marketDataKeys = {
2150
2347
  orderbook: (marketId, selectionKey, depth) => ["market-data", "orderbook", marketId, selectionKey != null ? selectionKey : null, depth != null ? depth : null],
2151
2348
  orderbookPrefix: (marketId) => marketId == null ? ["market-data", "orderbook"] : ["market-data", "orderbook", marketId],
2152
2349
  orderbookQuote: (marketId, side, size) => ["market-data", "orderbook-quote", marketId, side, size],
2153
- chart: (marketId, interval, startTs, endTs, countBack) => ["market-data", "chart", marketId, interval, startTs, endTs, countBack != null ? countBack : null],
2350
+ /**
2351
+ * Stable per `{marketId, interval, rangeKey}`. Deliberately excludes the
2352
+ * concrete `startTs`/`endTs` of the rolling window — those advance every
2353
+ * candle bucket, and including them would mint a fresh key on every
2354
+ * rollover, defeating React Query's cache on tab/page revisits. The
2355
+ * current window is passed to `queryFn` via closure instead, and
2356
+ * `refetchInterval` advances the data under the stable key.
2357
+ */
2358
+ chart: (marketId, interval, rangeKey, countBack) => ["market-data", "chart", marketId, interval, rangeKey, countBack != null ? countBack : null],
2154
2359
  chartPrefix: (marketId, interval) => {
2155
2360
  if (!marketId) return ["market-data", "chart"];
2156
2361
  if (!interval) return ["market-data", "chart", marketId];
@@ -2395,6 +2600,9 @@ function AggWebSocketProvider({ children }) {
2395
2600
  const invalidatePositionCaches = (0, import_react6.useCallback)(() => {
2396
2601
  invalidatePositionQueries(queryClient);
2397
2602
  }, [queryClient]);
2603
+ const invalidateActivityCaches = (0, import_react6.useCallback)(() => {
2604
+ invalidateUserActivityQueries(queryClient);
2605
+ }, [queryClient]);
2398
2606
  const callbacks = (0, import_react6.useMemo)(
2399
2607
  () => ({
2400
2608
  onSnapshot: (marketId, book) => {
@@ -2413,6 +2621,14 @@ function AggWebSocketProvider({ children }) {
2413
2621
  syncLiveQuery(marketId, (previous) => withLiveOrderbook(previous, book, "snapshot"));
2414
2622
  if (book.midpoint != null) {
2415
2623
  getOrCreateBuilder(marketId).addMidpoint(book.midpoint, book.timestamp);
2624
+ syncChartQueries(
2625
+ marketId,
2626
+ (_queryKey, previous) => applyMidpointToMarketChart(previous, {
2627
+ outcomeId: marketId,
2628
+ midpoint: book.midpoint,
2629
+ timestamp: book.timestamp
2630
+ })
2631
+ );
2416
2632
  }
2417
2633
  },
2418
2634
  onDelta: (marketId, book) => {
@@ -2458,6 +2674,14 @@ function AggWebSocketProvider({ children }) {
2458
2674
  });
2459
2675
  if (book.midpoint != null) {
2460
2676
  getOrCreateBuilder(marketId).addMidpoint(book.midpoint, book.timestamp);
2677
+ syncChartQueries(
2678
+ marketId,
2679
+ (_queryKey, previous) => applyMidpointToMarketChart(previous, {
2680
+ outcomeId: marketId,
2681
+ midpoint: book.midpoint,
2682
+ timestamp: book.timestamp
2683
+ })
2684
+ );
2461
2685
  }
2462
2686
  },
2463
2687
  onTrade: (trade) => {
@@ -2495,6 +2719,7 @@ function AggWebSocketProvider({ children }) {
2495
2719
  onBalanceUpdate: (msg) => {
2496
2720
  if (isClientAuthenticated) {
2497
2721
  invalidateBalanceCaches();
2722
+ invalidateActivityCaches();
2498
2723
  }
2499
2724
  for (const listener of balanceUpdateListenersRef.current) {
2500
2725
  listener(msg);
@@ -2560,6 +2785,7 @@ function AggWebSocketProvider({ children }) {
2560
2785
  [
2561
2786
  client,
2562
2787
  enableWebsocketsLogs,
2788
+ invalidateActivityCaches,
2563
2789
  invalidateBalanceCaches,
2564
2790
  invalidatePositionCaches,
2565
2791
  isClientAuthenticated,
@@ -2696,9 +2922,26 @@ var resolveTradingStateKind = (status) => {
2696
2922
  return "closed";
2697
2923
  };
2698
2924
  var resolveMarketWinningOutcome = (market) => {
2699
- var _a;
2925
+ var _a, _b, _c, _d;
2700
2926
  if (!market) return null;
2701
- return (_a = market.venueMarketOutcomes.find((outcome) => outcome.winner === true)) != null ? _a : null;
2927
+ const localWinningOutcome = (_a = market.venueMarketOutcomes.find((outcome) => outcome.winner === true)) != null ? _a : null;
2928
+ if (localWinningOutcome) return localWinningOutcome;
2929
+ const matchedVenueMarkets = (_b = market.matchedVenueMarkets) != null ? _b : [];
2930
+ if (!matchedVenueMarkets.length) return null;
2931
+ for (const outcome of market.venueMarketOutcomes) {
2932
+ const matchedRefs = (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : [];
2933
+ for (const ref of matchedRefs) {
2934
+ const matchedMarket = matchedVenueMarkets.find((item) => item.id === ref.venueMarketId);
2935
+ if (!matchedMarket) continue;
2936
+ const matchedOutcome = (_d = matchedMarket.venueMarketOutcomes) == null ? void 0 : _d.find(
2937
+ (item) => item.id === ref.venueMarketOutcomeId
2938
+ );
2939
+ if ((matchedOutcome == null ? void 0 : matchedOutcome.winner) === true) {
2940
+ return outcome;
2941
+ }
2942
+ }
2943
+ }
2944
+ return null;
2702
2945
  };
2703
2946
  var AFFIRMATIVE_WINNER_LABELS = /* @__PURE__ */ new Set(["yes", "up", "buy", "long", "true"]);
2704
2947
  var isAffirmativeWinnerLabel = (label) => {
@@ -2886,51 +3129,50 @@ function findOutcomeAcrossMarkets(event, outcomeId) {
2886
3129
  }
2887
3130
  return null;
2888
3131
  }
3132
+ var TradeSide = {
3133
+ Buy: "buy",
3134
+ Sell: "sell"
3135
+ };
2889
3136
  function tradingReducer(state, action) {
2890
- var _a, _b;
3137
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2891
3138
  switch (action.type) {
2892
3139
  case "INITIALIZE_EVENT": {
2893
3140
  if (!action.event) {
2894
- return { event: null, market: null, outcome: null };
3141
+ return { event: null, market: null, outcome: null, tradeSide: TradeSide.Buy };
2895
3142
  }
2896
- const market = resolveDefaultMarket(action.event);
2897
3143
  return {
2898
3144
  event: action.event,
2899
- market,
2900
- outcome: resolveDefaultOutcome(market)
3145
+ market: null,
3146
+ outcome: null,
3147
+ tradeSide: TradeSide.Buy
2901
3148
  };
2902
3149
  }
2903
3150
  case "SYNC_EVENT": {
2904
- const nextEvent = action.event;
2905
- const preservedMarket = state.market ? findMarketById(nextEvent, state.market.id) : null;
2906
- if (preservedMarket) {
2907
- const preservedMarketState = resolveMarketTradingState(preservedMarket);
2908
- if (preservedMarketState.isTradingDisabled) {
2909
- const tradableAlternative = resolveDefaultMarket(nextEvent);
2910
- if (tradableAlternative && resolveMarketTradingState(tradableAlternative).isOpen) {
2911
- return {
2912
- event: nextEvent,
2913
- market: tradableAlternative,
2914
- outcome: resolveDefaultOutcome(tradableAlternative)
2915
- };
2916
- }
2917
- }
2918
- const preservedOutcome = state.outcome ? findOutcomeById(preservedMarket, state.outcome.id) : null;
3151
+ const previousMarketId = (_b = (_a = state.market) == null ? void 0 : _a.id) != null ? _b : null;
3152
+ const previousOutcomeId = (_d = (_c = state.outcome) == null ? void 0 : _c.id) != null ? _d : null;
3153
+ const syncedMarket = previousMarketId ? findMarketById(action.event, previousMarketId) : null;
3154
+ if (!syncedMarket || resolveMarketTradingState(syncedMarket).isTradingDisabled) {
2919
3155
  return {
2920
- event: nextEvent,
2921
- market: preservedMarket,
2922
- outcome: preservedOutcome != null ? preservedOutcome : resolveDefaultOutcome(preservedMarket)
3156
+ event: action.event,
3157
+ market: null,
3158
+ outcome: null,
3159
+ tradeSide: (_e = state.tradeSide) != null ? _e : TradeSide.Buy
2923
3160
  };
2924
3161
  }
2925
- const defaultMarket = resolveDefaultMarket(nextEvent);
3162
+ const syncedOutcome = previousOutcomeId ? findOutcomeById(syncedMarket, previousOutcomeId) : null;
2926
3163
  return {
2927
- event: nextEvent,
2928
- market: defaultMarket,
2929
- outcome: resolveDefaultOutcome(defaultMarket)
3164
+ event: action.event,
3165
+ market: syncedMarket,
3166
+ outcome: syncedOutcome,
3167
+ tradeSide: (_f = state.tradeSide) != null ? _f : TradeSide.Buy
2930
3168
  };
2931
3169
  }
3170
+ case "SET_TRADE_SIDE": {
3171
+ if (((_g = state.tradeSide) != null ? _g : TradeSide.Buy) === action.tradeSide) return state;
3172
+ return __spreadProps(__spreadValues({}, state), { tradeSide: action.tradeSide });
3173
+ }
2932
3174
  case "SELECT_MARKET": {
2933
- const market = (_b = (_a = findMarketById(state.event, action.marketId)) != null ? _a : action.market) != null ? _b : null;
3175
+ const market = (_i = (_h = findMarketById(state.event, action.marketId)) != null ? _h : action.market) != null ? _i : null;
2934
3176
  if (!market) return state;
2935
3177
  if (resolveMarketTradingState(market).kind === "resolved") return state;
2936
3178
  return __spreadProps(__spreadValues({}, state), {
@@ -2939,6 +3181,9 @@ function tradingReducer(state, action) {
2939
3181
  });
2940
3182
  }
2941
3183
  case "SELECT_OUTCOME": {
3184
+ if (((_j = state.outcome) == null ? void 0 : _j.id) === action.outcomeId) {
3185
+ return state;
3186
+ }
2942
3187
  if (state.market) {
2943
3188
  const outcomeInCurrentMarket = findOutcomeById(state.market, action.outcomeId);
2944
3189
  if (outcomeInCurrentMarket) {
@@ -2990,7 +3235,8 @@ function logAction(actionType, payload, prev, next, enableLogs) {
2990
3235
  var initialState = {
2991
3236
  event: null,
2992
3237
  market: null,
2993
- outcome: null
3238
+ outcome: null,
3239
+ tradeSide: TradeSide.Buy
2994
3240
  };
2995
3241
  var EventTradingContext = (0, import_react7.createContext)(void 0);
2996
3242
  var useEventTradingContext = () => {
@@ -3000,9 +3246,15 @@ var EventTradingProvider = ({
3000
3246
  children,
3001
3247
  enableLogs = false
3002
3248
  }) => {
3249
+ var _a, _b;
3003
3250
  const [state, rawDispatch] = (0, import_react7.useReducer)(tradingReducer, initialState);
3004
3251
  const stateRef = (0, import_react7.useRef)(state);
3252
+ const pendingAtomicSelectionRef = (0, import_react7.useRef)(null);
3005
3253
  stateRef.current = state;
3254
+ const pendingAtomicSelection = pendingAtomicSelectionRef.current;
3255
+ if (pendingAtomicSelection && ((_a = state.market) == null ? void 0 : _a.id) === pendingAtomicSelection.marketId && ((_b = state.outcome) == null ? void 0 : _b.id) === pendingAtomicSelection.outcomeId) {
3256
+ pendingAtomicSelectionRef.current = null;
3257
+ }
3006
3258
  const dispatch = (0, import_react7.useCallback)(
3007
3259
  (action) => {
3008
3260
  const prev = stateRef.current;
@@ -3025,24 +3277,45 @@ var EventTradingProvider = ({
3025
3277
  [dispatch]
3026
3278
  );
3027
3279
  const selectOutcome = (0, import_react7.useCallback)(
3028
- (outcomeId) => dispatch({ type: "SELECT_OUTCOME", outcomeId }),
3280
+ (outcomeId) => {
3281
+ var _a2, _b2;
3282
+ if (((_a2 = stateRef.current.outcome) == null ? void 0 : _a2.id) === outcomeId) return;
3283
+ if (((_b2 = pendingAtomicSelectionRef.current) == null ? void 0 : _b2.outcomeId) === outcomeId) return;
3284
+ dispatch({ type: "SELECT_OUTCOME", outcomeId });
3285
+ },
3029
3286
  [dispatch]
3030
3287
  );
3031
3288
  const selectMarketAndOutcome = (0, import_react7.useCallback)(
3032
- (marketId, outcomeId) => dispatch({ type: "SELECT_MARKET_AND_OUTCOME", marketId, outcomeId }),
3289
+ (marketId, outcomeId) => {
3290
+ var _a2, _b2, _c, _d;
3291
+ if (((_a2 = stateRef.current.market) == null ? void 0 : _a2.id) === marketId && ((_b2 = stateRef.current.outcome) == null ? void 0 : _b2.id) === outcomeId) {
3292
+ return;
3293
+ }
3294
+ if (((_c = pendingAtomicSelectionRef.current) == null ? void 0 : _c.marketId) === marketId && ((_d = pendingAtomicSelectionRef.current) == null ? void 0 : _d.outcomeId) === outcomeId) {
3295
+ return;
3296
+ }
3297
+ pendingAtomicSelectionRef.current = { marketId, outcomeId };
3298
+ dispatch({ type: "SELECT_MARKET_AND_OUTCOME", marketId, outcomeId });
3299
+ },
3300
+ [dispatch]
3301
+ );
3302
+ const setTradeSide = (0, import_react7.useCallback)(
3303
+ (tradeSide) => dispatch({ type: "SET_TRADE_SIDE", tradeSide }),
3033
3304
  [dispatch]
3034
3305
  );
3035
3306
  const value = (0, import_react7.useMemo)(
3036
3307
  () => {
3037
- var _a, _b, _c, _d, _e, _f, _g, _h;
3308
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
3038
3309
  return {
3039
3310
  selectedEvent: state.event,
3040
3311
  selectedMarket: state.market,
3041
3312
  selectedOutcome: state.outcome,
3042
- selectedEventId: (_b = (_a = state.event) == null ? void 0 : _a.id) != null ? _b : null,
3313
+ selectedEventId: (_b2 = (_a2 = state.event) == null ? void 0 : _a2.id) != null ? _b2 : null,
3043
3314
  selectedMarketId: (_d = (_c = state.market) == null ? void 0 : _c.id) != null ? _d : null,
3044
3315
  selectedOutcomeId: (_f = (_e = state.outcome) == null ? void 0 : _e.id) != null ? _f : null,
3045
3316
  selectedVenue: (_h = (_g = state.market) == null ? void 0 : _g.venue) != null ? _h : null,
3317
+ tradeSide: (_i = state.tradeSide) != null ? _i : TradeSide.Buy,
3318
+ setTradeSide,
3046
3319
  initializeFromEvent,
3047
3320
  syncEvent,
3048
3321
  selectMarket,
@@ -3050,7 +3323,15 @@ var EventTradingProvider = ({
3050
3323
  selectMarketAndOutcome
3051
3324
  };
3052
3325
  },
3053
- [state, initializeFromEvent, syncEvent, selectMarket, selectOutcome, selectMarketAndOutcome]
3326
+ [
3327
+ state,
3328
+ initializeFromEvent,
3329
+ syncEvent,
3330
+ selectMarket,
3331
+ selectOutcome,
3332
+ selectMarketAndOutcome,
3333
+ setTradeSide
3334
+ ]
3054
3335
  );
3055
3336
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EventTradingContext.Provider, { value, children });
3056
3337
  };
@@ -3253,7 +3534,7 @@ function useRampSession() {
3253
3534
  }
3254
3535
 
3255
3536
  // src/withdraw/use-withdraw-flow.ts
3256
- var import_react11 = require("react");
3537
+ var import_react13 = require("react");
3257
3538
 
3258
3539
  // src/execution/use-quote-managed.ts
3259
3540
  var import_react_query6 = require("@tanstack/react-query");
@@ -3293,7 +3574,7 @@ function useWithdrawManaged(options) {
3293
3574
  mutationFn: (params) => client.withdrawManaged(params),
3294
3575
  onSuccess: (data) => {
3295
3576
  var _a;
3296
- invalidateBalanceQueries(queryClient);
3577
+ invalidateUserMoneyState(queryClient);
3297
3578
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
3298
3579
  },
3299
3580
  onError: options == null ? void 0 : options.onError
@@ -3405,7 +3686,7 @@ function useSyncBalances(options) {
3405
3686
  mutationFn: () => client.syncManagedBalances(),
3406
3687
  onSuccess: () => {
3407
3688
  var _a;
3408
- invalidateBalanceQueries(queryClient);
3689
+ invalidateUserMoneyState(queryClient);
3409
3690
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
3410
3691
  },
3411
3692
  onError: options == null ? void 0 : options.onError
@@ -3487,6 +3768,12 @@ function useExecutionProgress({
3487
3768
  event: mappedEvent,
3488
3769
  filledAmountRaw: msg.filledAmountRaw,
3489
3770
  remainingAmountRaw: msg.remainingAmountRaw,
3771
+ actualSharesRaw: msg.actualSharesRaw,
3772
+ actualToWinRaw: msg.actualToWinRaw,
3773
+ quotedSharesRaw: msg.quotedSharesRaw,
3774
+ quotedToWinRaw: msg.quotedToWinRaw,
3775
+ executionPriceRaw: msg.executionPriceRaw,
3776
+ quotedPriceRaw: msg.quotedPriceRaw,
3490
3777
  errorReason: event === "bridge_ws_subscribe_failed" ? (_a = msg.errorReason) != null ? _a : "Bridge event subscription failed." : msg.errorReason,
3491
3778
  timestamp: msg.timestamp
3492
3779
  };
@@ -3565,15 +3852,29 @@ function useExecutionProgress({
3565
3852
  });
3566
3853
  return;
3567
3854
  }
3855
+ const buildFailedProgress = (prev) => {
3856
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3857
+ const seq = (_b2 = (_a2 = msg.sequence) != null ? _a2 : prev == null ? void 0 : prev.currentSequence) != null ? _b2 : 0;
3858
+ const stepType = (_d = (_c2 = msg.stepType) != null ? _c2 : prev == null ? void 0 : prev.currentStepType) != null ? _d : null;
3859
+ const baseStepTypes = (_e = prev == null ? void 0 : prev.stepTypes) != null ? _e : {};
3860
+ const stepTypes = seq && stepType ? __spreadProps(__spreadValues({}, baseStepTypes), { [seq]: stepType }) : baseStepTypes;
3861
+ return {
3862
+ dagRunId: (_g = (_f = msg.dagRunId) != null ? _f : prev == null ? void 0 : prev.dagRunId) != null ? _g : "",
3863
+ totalSteps: (_i = (_h = msg.totalSteps) != null ? _h : prev == null ? void 0 : prev.totalSteps) != null ? _i : 0,
3864
+ currentSequence: seq,
3865
+ currentStepType: stepType,
3866
+ completedSequences: (_j = prev == null ? void 0 : prev.completedSequences) != null ? _j : [],
3867
+ stepTypes,
3868
+ status: "failed",
3869
+ errorReason: (_l = (_k = msg.errorReason) != null ? _k : prev == null ? void 0 : prev.errorReason) != null ? _l : null
3870
+ };
3871
+ };
3872
+ if (event === "step_failed") {
3873
+ setDagProgress((prev) => buildFailedProgress(prev));
3874
+ return;
3875
+ }
3568
3876
  if (event === "dag_failed") {
3569
- setDagProgress((prev) => {
3570
- var _a2;
3571
- if (!prev) return prev;
3572
- return __spreadProps(__spreadValues({}, prev), {
3573
- status: "failed",
3574
- errorReason: (_a2 = msg.errorReason) != null ? _a2 : null
3575
- });
3576
- });
3877
+ setDagProgress((prev) => buildFailedProgress(prev));
3577
3878
  return;
3578
3879
  }
3579
3880
  }, []);
@@ -3598,7 +3899,7 @@ function useExecutionProgress({
3598
3899
  }
3599
3900
  };
3600
3901
  const reconcile = () => __async(null, null, function* () {
3601
- var _a, _b, _c;
3902
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3602
3903
  if (cancelled || pollInFlightRef.current) return;
3603
3904
  const pending = orderIds.filter((id) => !terminalOrderIdsRef.current.has(id));
3604
3905
  if (pending.length === 0) {
@@ -3630,7 +3931,13 @@ function useExecutionProgress({
3630
3931
  venue: (_a = order.venue) != null ? _a : "",
3631
3932
  event: mapped,
3632
3933
  filledAmountRaw: (_b = order.filledAmountRaw) != null ? _b : void 0,
3633
- errorReason: (_c = order.errorMessage) != null ? _c : void 0,
3934
+ actualSharesRaw: (_c = order.actualSharesRaw) != null ? _c : void 0,
3935
+ actualToWinRaw: (_d = order.actualToWinRaw) != null ? _d : void 0,
3936
+ quotedSharesRaw: (_e = order.quotedSharesRaw) != null ? _e : void 0,
3937
+ quotedToWinRaw: (_f = order.quotedToWinRaw) != null ? _f : void 0,
3938
+ executionPriceRaw: (_g = order.executionPrice) != null ? _g : void 0,
3939
+ quotedPriceRaw: (_h = order.quotedPriceRaw) != null ? _h : void 0,
3940
+ errorReason: (_i = order.errorMessage) != null ? _i : void 0,
3634
3941
  timestamp: new Date(order.updatedAt).getTime() || Date.now()
3635
3942
  });
3636
3943
  }
@@ -3710,11 +4017,27 @@ var computeClosedPositionTotals = (group) => {
3710
4017
 
3711
4018
  // src/execution/use-redeem.ts
3712
4019
  var import_react_query13 = require("@tanstack/react-query");
4020
+ var RedeemRejectedError = class extends Error {
4021
+ constructor(message, response) {
4022
+ super(message);
4023
+ this.name = "RedeemRejectedError";
4024
+ this.response = response;
4025
+ }
4026
+ };
4027
+ var isLegRejected = (status) => status === "ineligible" || status === "rejected";
3713
4028
  var useRedeem = () => {
3714
4029
  const client = useAggClient();
3715
4030
  const queryClient = (0, import_react_query13.useQueryClient)();
3716
4031
  return (0, import_react_query13.useMutation)({
3717
- mutationFn: (body) => client.redeem(body),
4032
+ mutationFn: (body) => __async(null, null, function* () {
4033
+ const response = yield client.redeem(body);
4034
+ if (response.results.length > 0 && response.results.every((r) => isLegRejected(r.status))) {
4035
+ const reasons = response.results.map((r) => r.reason).filter((r) => Boolean(r));
4036
+ const message = reasons.length > 0 ? reasons.join("; ") : "Redeem rejected";
4037
+ throw new RedeemRejectedError(message, response);
4038
+ }
4039
+ return response;
4040
+ }),
3718
4041
  onSuccess: () => {
3719
4042
  queryClient.invalidateQueries({ queryKey: executionKeys.positionsPrefix() });
3720
4043
  queryClient.invalidateQueries({ queryKey: executionKeys.balances() });
@@ -3765,6 +4088,144 @@ var useRedeemEligibleCount = () => {
3765
4088
  return (_a = query.data) != null ? _a : 0;
3766
4089
  };
3767
4090
 
4091
+ // src/execution/use-redeem-lifecycle.ts
4092
+ var import_react12 = require("react");
4093
+
4094
+ // src/execution/use-redeem-lifecycles.ts
4095
+ var import_react11 = require("react");
4096
+ var computeDerivedState = (legs, expectedCount) => {
4097
+ const legCount = Object.keys(legs).length;
4098
+ let allTerminal = legCount === expectedCount;
4099
+ let allConfirmed = allTerminal;
4100
+ let anyFailed = false;
4101
+ let errorMessage = null;
4102
+ for (const leg of Object.values(legs)) {
4103
+ if (leg.status === "submitted") allTerminal = false;
4104
+ if (leg.status !== "confirmed") allConfirmed = false;
4105
+ if (leg.status === "failed") {
4106
+ anyFailed = true;
4107
+ if (errorMessage === null && leg.errorMessage) errorMessage = leg.errorMessage;
4108
+ }
4109
+ }
4110
+ return {
4111
+ terminal: allTerminal,
4112
+ allConfirmed: allTerminal && allConfirmed,
4113
+ anyFailed,
4114
+ errorMessage
4115
+ };
4116
+ };
4117
+ var seedState = (input) => {
4118
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
4119
+ const legs = {};
4120
+ for (const id of (_a = input.preFailedOutcomeIds) != null ? _a : []) {
4121
+ legs[id] = {
4122
+ status: "failed",
4123
+ txHash: null,
4124
+ errorMessage: (_c = (_b = input.preFailedReasons) == null ? void 0 : _b[id]) != null ? _c : null
4125
+ };
4126
+ }
4127
+ for (const id of (_d = input.preConfirmedOutcomeIds) != null ? _d : []) {
4128
+ legs[id] = {
4129
+ status: "confirmed",
4130
+ txHash: (_f = (_e = input.preConfirmedTxHashes) == null ? void 0 : _e[id]) != null ? _f : null,
4131
+ errorMessage: null
4132
+ };
4133
+ }
4134
+ const expectedCount = input.expectedOutcomeIds.length + ((_h = (_g = input.preFailedOutcomeIds) == null ? void 0 : _g.length) != null ? _h : 0) + ((_j = (_i = input.preConfirmedOutcomeIds) == null ? void 0 : _i.length) != null ? _j : 0);
4135
+ const derived = computeDerivedState(legs, expectedCount);
4136
+ return {
4137
+ pending: !derived.terminal,
4138
+ terminal: derived.terminal,
4139
+ allConfirmed: derived.allConfirmed,
4140
+ anyFailed: derived.anyFailed,
4141
+ errorMessage: derived.errorMessage,
4142
+ legs
4143
+ };
4144
+ };
4145
+ function useRedeemLifecycles(inputs) {
4146
+ const inputsByRedeemId = (0, import_react11.useMemo)(() => {
4147
+ const map = {};
4148
+ for (const input of inputs) {
4149
+ map[input.redeemId] = input;
4150
+ }
4151
+ return map;
4152
+ }, [inputs]);
4153
+ const [stateMap, setStateMap] = (0, import_react11.useState)(() => {
4154
+ const next = {};
4155
+ for (const [id, input] of Object.entries(inputsByRedeemId)) {
4156
+ next[id] = seedState(input);
4157
+ }
4158
+ return next;
4159
+ });
4160
+ (0, import_react11.useEffect)(() => {
4161
+ setStateMap((prev) => {
4162
+ let changed = false;
4163
+ const next = {};
4164
+ for (const [id, input] of Object.entries(inputsByRedeemId)) {
4165
+ const existing = prev[id];
4166
+ if (existing) {
4167
+ next[id] = existing;
4168
+ } else {
4169
+ next[id] = seedState(input);
4170
+ changed = true;
4171
+ }
4172
+ }
4173
+ if (Object.keys(next).length !== Object.keys(prev).length) changed = true;
4174
+ return changed ? next : prev;
4175
+ });
4176
+ }, [inputsByRedeemId]);
4177
+ useOnRedeemEvent(
4178
+ (0, import_react11.useMemo)(() => {
4179
+ if (Object.keys(inputsByRedeemId).length === 0) return null;
4180
+ return (event) => {
4181
+ const input = inputsByRedeemId[event.redeemId];
4182
+ if (!input) return;
4183
+ setStateMap((prev) => {
4184
+ var _a, _b, _c, _d;
4185
+ const existing = prev[event.redeemId];
4186
+ if (!existing) return prev;
4187
+ const nextLegs = __spreadProps(__spreadValues({}, existing.legs), {
4188
+ [event.venueMarketOutcomeId]: {
4189
+ status: event.status,
4190
+ txHash: event.txHash,
4191
+ errorMessage: event.errorMessage
4192
+ }
4193
+ });
4194
+ const expectedCount = input.expectedOutcomeIds.length + ((_b = (_a = input.preFailedOutcomeIds) == null ? void 0 : _a.length) != null ? _b : 0) + ((_d = (_c = input.preConfirmedOutcomeIds) == null ? void 0 : _c.length) != null ? _d : 0);
4195
+ const derived = computeDerivedState(nextLegs, expectedCount);
4196
+ const nextState = {
4197
+ pending: !derived.terminal,
4198
+ terminal: derived.terminal,
4199
+ allConfirmed: derived.allConfirmed,
4200
+ anyFailed: derived.anyFailed,
4201
+ errorMessage: derived.errorMessage,
4202
+ legs: nextLegs
4203
+ };
4204
+ return __spreadProps(__spreadValues({}, prev), { [event.redeemId]: nextState });
4205
+ });
4206
+ };
4207
+ }, [inputsByRedeemId])
4208
+ );
4209
+ return stateMap;
4210
+ }
4211
+
4212
+ // src/execution/use-redeem-lifecycle.ts
4213
+ var INITIAL_STATE = {
4214
+ pending: true,
4215
+ terminal: false,
4216
+ allConfirmed: false,
4217
+ anyFailed: false,
4218
+ errorMessage: null,
4219
+ legs: {}
4220
+ };
4221
+ function useRedeemLifecycle(input) {
4222
+ var _a;
4223
+ const inputs = (0, import_react12.useMemo)(() => input ? [input] : [], [input]);
4224
+ const map = useRedeemLifecycles(inputs);
4225
+ if (!input) return INITIAL_STATE;
4226
+ return (_a = map[input.redeemId]) != null ? _a : INITIAL_STATE;
4227
+ }
4228
+
3768
4229
  // src/withdraw/use-withdraw-flow.ts
3769
4230
  var EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
3770
4231
  var SOLANA_ADDRESS_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
@@ -3780,7 +4241,9 @@ var WITHDRAWAL_SUPPORTED_CHAIN_IDS = /* @__PURE__ */ new Set([
3780
4241
  // Base
3781
4242
  56,
3782
4243
  // BNB
3783
- SOLANA_CHAIN_ID
4244
+ SOLANA_CHAIN_ID,
4245
+ 1337
4246
+ // Hyperliquid
3784
4247
  ]);
3785
4248
  var isValidDestinationAddress = (address, chainId) => {
3786
4249
  if (chainId === SOLANA_CHAIN_ID) return SOLANA_ADDRESS_REGEX.test(address);
@@ -3831,20 +4294,20 @@ function useWithdrawFlow(options) {
3831
4294
  const withdrawMutation = useWithdrawManaged();
3832
4295
  const syncBalances = useSyncBalances();
3833
4296
  const ws = useAggWebSocket();
3834
- (0, import_react11.useEffect)(() => {
4297
+ (0, import_react13.useEffect)(() => {
3835
4298
  if (!open) return;
3836
4299
  syncBalances.mutate(void 0, {
3837
4300
  onError: () => {
3838
4301
  }
3839
4302
  });
3840
4303
  }, [open]);
3841
- const [withdrawDestination, setWithdrawDestination] = (0, import_react11.useState)("");
3842
- const [withdrawAmount, setWithdrawAmount] = (0, import_react11.useState)("");
3843
- const [withdrawToken, setWithdrawToken] = (0, import_react11.useState)("USDC");
3844
- const [withdrawNetwork, setWithdrawNetwork] = (0, import_react11.useState)("");
3845
- const [withdrawSummary, setWithdrawSummary] = (0, import_react11.useState)(DEFAULT_WITHDRAW_SUMMARY);
3846
- const [withdrawalId, setWithdrawalId] = (0, import_react11.useState)(null);
3847
- const networkOptions = (0, import_react11.useMemo)(
4304
+ const [withdrawDestination, setWithdrawDestination] = (0, import_react13.useState)("");
4305
+ const [withdrawAmount, setWithdrawAmount] = (0, import_react13.useState)("");
4306
+ const [withdrawToken, setWithdrawToken] = (0, import_react13.useState)("USDC");
4307
+ const [withdrawNetwork, setWithdrawNetwork] = (0, import_react13.useState)("");
4308
+ const [withdrawSummary, setWithdrawSummary] = (0, import_react13.useState)(DEFAULT_WITHDRAW_SUMMARY);
4309
+ const [withdrawalId, setWithdrawalId] = (0, import_react13.useState)(null);
4310
+ const networkOptions = (0, import_react13.useMemo)(
3848
4311
  () => (supportedChains != null ? supportedChains : []).filter((chain) => WITHDRAWAL_SUPPORTED_CHAIN_IDS.has(chain.chainId)).map((chain) => ({
3849
4312
  value: String(chain.chainId),
3850
4313
  label: chain.name
@@ -3852,13 +4315,13 @@ function useWithdrawFlow(options) {
3852
4315
  [supportedChains]
3853
4316
  );
3854
4317
  const resolvedWithdrawNetwork = withdrawNetwork || ((_a = networkOptions[0]) == null ? void 0 : _a.value) || "";
3855
- (0, import_react11.useEffect)(() => {
4318
+ (0, import_react13.useEffect)(() => {
3856
4319
  if (!networkOptions.length) return;
3857
4320
  if (!withdrawNetwork || !networkOptions.some((option) => option.value === withdrawNetwork)) {
3858
4321
  setWithdrawNetwork(networkOptions[0].value);
3859
4322
  }
3860
4323
  }, [networkOptions, withdrawNetwork]);
3861
- const tokenOptions = (0, import_react11.useMemo)(() => {
4324
+ const tokenOptions = (0, import_react13.useMemo)(() => {
3862
4325
  var _a2, _b2, _c;
3863
4326
  const selectedChainId = Number(resolvedWithdrawNetwork);
3864
4327
  const supportedTokensForNetwork = (_b2 = (_a2 = supportedChains == null ? void 0 : supportedChains.find((chain) => chain.chainId === selectedChainId)) == null ? void 0 : _a2.tokens) != null ? _b2 : [];
@@ -3869,17 +4332,17 @@ function useWithdrawFlow(options) {
3869
4332
  }));
3870
4333
  }, [balances, resolvedWithdrawNetwork, supportedChains]);
3871
4334
  const resolvedWithdrawToken = tokenOptions.some((option) => option.value === withdrawToken) ? withdrawToken : ((_b = tokenOptions[0]) == null ? void 0 : _b.value) || "";
3872
- (0, import_react11.useEffect)(() => {
4335
+ (0, import_react13.useEffect)(() => {
3873
4336
  if (!tokenOptions.length) return;
3874
4337
  if (!tokenOptions.some((option) => option.value === withdrawToken)) {
3875
4338
  setWithdrawToken(tokenOptions[0].value);
3876
4339
  }
3877
4340
  }, [tokenOptions, withdrawToken]);
3878
- const selectedCashEntry = (0, import_react11.useMemo)(
4341
+ const selectedCashEntry = (0, import_react13.useMemo)(
3879
4342
  () => balances == null ? void 0 : balances.cash.find((cashEntry) => cashEntry.tokenSymbol === resolvedWithdrawToken),
3880
4343
  [balances, resolvedWithdrawToken]
3881
4344
  );
3882
- const selectedTokenDecimals = (0, import_react11.useMemo)(() => {
4345
+ const selectedTokenDecimals = (0, import_react13.useMemo)(() => {
3883
4346
  var _a2, _b2, _c, _d;
3884
4347
  const selectedChainId = Number(resolvedWithdrawNetwork);
3885
4348
  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;
@@ -3889,18 +4352,18 @@ function useWithdrawFlow(options) {
3889
4352
  selectedCashEntry == null ? void 0 : selectedCashEntry.decimals,
3890
4353
  supportedChains
3891
4354
  ]);
3892
- const exactBalance = (0, import_react11.useMemo)(() => {
4355
+ const exactBalance = (0, import_react13.useMemo)(() => {
3893
4356
  if (!selectedCashEntry) return "0";
3894
4357
  return formatRawTokenAmount(selectedCashEntry.totalRaw, selectedCashEntry.decimals);
3895
4358
  }, [selectedCashEntry]);
3896
- const balanceDisplay = (0, import_react11.useMemo)(() => {
4359
+ const balanceDisplay = (0, import_react13.useMemo)(() => {
3897
4360
  if (!selectedCashEntry) return `0.00 ${resolvedWithdrawToken || withdrawToken}`;
3898
4361
  return `${formatRawTokenAmountForDisplay(
3899
4362
  selectedCashEntry.totalRaw,
3900
4363
  selectedCashEntry.decimals
3901
4364
  )} ${resolvedWithdrawToken}`;
3902
4365
  }, [resolvedWithdrawToken, selectedCashEntry, withdrawToken]);
3903
- const resetFlowState = (0, import_react11.useCallback)(() => {
4366
+ const resetFlowState = (0, import_react13.useCallback)(() => {
3904
4367
  setWithdrawDestination("");
3905
4368
  setWithdrawAmount("");
3906
4369
  setWithdrawToken("USDC");
@@ -3908,17 +4371,17 @@ function useWithdrawFlow(options) {
3908
4371
  setWithdrawSummary(DEFAULT_WITHDRAW_SUMMARY);
3909
4372
  setWithdrawalId(null);
3910
4373
  }, []);
3911
- const handleWithdrawOpenChange = (0, import_react11.useCallback)(
4374
+ const handleWithdrawOpenChange = (0, import_react13.useCallback)(
3912
4375
  (isOpen) => {
3913
4376
  if (!isOpen) resetFlowState();
3914
4377
  onOpenChange(isOpen);
3915
4378
  },
3916
4379
  [onOpenChange, resetFlowState]
3917
4380
  );
3918
- (0, import_react11.useEffect)(() => {
4381
+ (0, import_react13.useEffect)(() => {
3919
4382
  if (!open) resetFlowState();
3920
4383
  }, [open, resetFlowState]);
3921
- const handleWithdrawProvider = (0, import_react11.useCallback)(() => __async(null, null, function* () {
4384
+ const handleWithdrawProvider = (0, import_react13.useCallback)(() => __async(null, null, function* () {
3922
4385
  var _a2, _b2;
3923
4386
  const destinationChainId = Number(resolvedWithdrawNetwork);
3924
4387
  const trimmedDestination = withdrawDestination.trim();
@@ -4004,25 +4467,73 @@ function useWithdrawFlow(options) {
4004
4467
  onWithdrawAmountChange: setWithdrawAmount,
4005
4468
  onWithdrawTokenChange: setWithdrawToken,
4006
4469
  onWithdrawNetworkChange: setWithdrawNetwork,
4007
- onMaxClick: (0, import_react11.useCallback)(() => {
4470
+ onMaxClick: (0, import_react13.useCallback)(() => {
4008
4471
  setWithdrawAmount(exactBalance === "0" ? "0" : exactBalance);
4009
4472
  }, [exactBalance]),
4010
- onSelectWithdrawProvider: (0, import_react11.useCallback)(
4473
+ onSelectWithdrawProvider: (0, import_react13.useCallback)(
4011
4474
  (_providerId) => __async(null, null, function* () {
4012
4475
  return handleWithdrawProvider();
4013
4476
  }),
4014
4477
  [handleWithdrawProvider]
4015
4478
  ),
4016
- onDoneWithdraw: (0, import_react11.useCallback)(() => handleWithdrawOpenChange(false), [handleWithdrawOpenChange])
4479
+ onDoneWithdraw: (0, import_react13.useCallback)(() => handleWithdrawOpenChange(false), [handleWithdrawOpenChange])
4017
4480
  };
4018
4481
  }
4019
4482
 
4483
+ // src/withdraw/use-withdraw-estimate.ts
4484
+ var import_react14 = require("react");
4485
+ function useWithdrawEstimate({
4486
+ amount,
4487
+ selectedToken,
4488
+ selectedNetwork
4489
+ }) {
4490
+ return (0, import_react14.useMemo)(() => {
4491
+ const numAmount = Number(amount);
4492
+ if (!amount || isNaN(numAmount) || numAmount <= 0 || !selectedToken || !selectedNetwork) {
4493
+ return null;
4494
+ }
4495
+ const network = selectedNetwork.toLowerCase();
4496
+ let feeVal = 0.1;
4497
+ let reserveVal = 0.2;
4498
+ if (network === "1" || network === "mainnet" || network === "ethereum") {
4499
+ feeVal = 1.22;
4500
+ reserveVal = 0.3;
4501
+ } else if (network === "137" || network === "polygon") {
4502
+ feeVal = 0.05;
4503
+ reserveVal = 0.15;
4504
+ } else if (network === "42161" || network === "arbitrum") {
4505
+ feeVal = 0.05;
4506
+ reserveVal = 0.15;
4507
+ } else if (network === "8453" || network === "base") {
4508
+ feeVal = 0.05;
4509
+ reserveVal = 0.15;
4510
+ } else if (network === "56" || network === "bnb" || network === "bsc") {
4511
+ feeVal = 0.1;
4512
+ reserveVal = 0.2;
4513
+ } else if (network === "792703809" || network === "solana") {
4514
+ feeVal = 0.01;
4515
+ reserveVal = 0.04;
4516
+ } else if (network === "1337" || network === "hyperliquid") {
4517
+ feeVal = 0.02;
4518
+ reserveVal = 0.08;
4519
+ }
4520
+ const youReceiveVal = Math.max(0, numAmount - feeVal);
4521
+ return {
4522
+ estimatedFees: `~$${feeVal.toFixed(2)}`,
4523
+ networkReserve: `~$${reserveVal.toFixed(2)}`,
4524
+ youReceive: `~${youReceiveVal.toFixed(2)} ${selectedToken}`
4525
+ };
4526
+ }, [amount, selectedToken, selectedNetwork]);
4527
+ }
4528
+
4020
4529
  // src/withdraw/use-withdrawal-lifecycle.ts
4021
- var import_react12 = require("react");
4530
+ var import_react15 = require("react");
4022
4531
  var import_react_query15 = require("@tanstack/react-query");
4023
- var INITIAL_STATE = {
4532
+ var INITIAL_STATE2 = {
4024
4533
  pending: true,
4025
4534
  status: null,
4535
+ requestedAmountRaw: null,
4536
+ completedAmountRaw: null,
4026
4537
  terminal: false,
4027
4538
  lastLeg: null,
4028
4539
  legs: [],
@@ -4053,14 +4564,16 @@ var mergeLegs = (prev, snapshot, delta) => {
4053
4564
  return next;
4054
4565
  };
4055
4566
  var restToLifecycleState = (response) => {
4056
- var _a;
4567
+ var _a, _b;
4057
4568
  return {
4058
4569
  pending: false,
4059
4570
  status: response.status,
4571
+ requestedAmountRaw: response.requested.amountRaw,
4572
+ completedAmountRaw: (_a = response.completedAmountRaw) != null ? _a : null,
4060
4573
  terminal: response.status === "completed" || response.status === "partial" || response.status === "failed",
4061
4574
  lastLeg: null,
4062
4575
  legs: response.legs.map(restLegToWsLeg),
4063
- errorMessage: (_a = response.errorMessage) != null ? _a : null,
4576
+ errorMessage: (_b = response.errorMessage) != null ? _b : null,
4064
4577
  // No server timestamp on the REST response — we use 0 as "older than any
4065
4578
  // WS timestamp" so a subsequent WS event always wins. Callers that read
4066
4579
  // `timestamp` should treat 0/null interchangeably as "unset".
@@ -4071,14 +4584,14 @@ function useWithdrawalLifecycle(withdrawalId) {
4071
4584
  const client = useAggClient();
4072
4585
  const wsConnected = useAggWebSocketConnectionState();
4073
4586
  const queryClient = (0, import_react_query15.useQueryClient)();
4074
- const [state, setState] = (0, import_react12.useState)(INITIAL_STATE);
4075
- const stateRef = (0, import_react12.useRef)(state);
4587
+ const [state, setState] = (0, import_react15.useState)(INITIAL_STATE2);
4588
+ const stateRef = (0, import_react15.useRef)(state);
4076
4589
  stateRef.current = state;
4077
- const balanceRefetchedForRef = (0, import_react12.useRef)(null);
4078
- (0, import_react12.useEffect)(() => {
4079
- setState(INITIAL_STATE);
4590
+ const balanceRefetchedForRef = (0, import_react15.useRef)(null);
4591
+ (0, import_react15.useEffect)(() => {
4592
+ setState(INITIAL_STATE2);
4080
4593
  }, [withdrawalId]);
4081
- (0, import_react12.useEffect)(() => {
4594
+ (0, import_react15.useEffect)(() => {
4082
4595
  if (!withdrawalId) return;
4083
4596
  let cancelled = false;
4084
4597
  (() => __async(null, null, function* () {
@@ -4097,17 +4610,19 @@ function useWithdrawalLifecycle(withdrawalId) {
4097
4610
  cancelled = true;
4098
4611
  };
4099
4612
  }, [client, withdrawalId, wsConnected]);
4100
- const handler = (0, import_react12.useMemo)(() => {
4613
+ const handler = (0, import_react15.useMemo)(() => {
4101
4614
  if (!withdrawalId) return null;
4102
4615
  return (msg) => {
4103
4616
  if (msg.withdrawalId !== withdrawalId) return;
4104
4617
  setState((prev) => {
4105
- var _a, _b;
4618
+ var _a, _b, _c, _d;
4106
4619
  return {
4107
4620
  pending: false,
4108
4621
  status: msg.status,
4622
+ requestedAmountRaw: (_a = msg.requestedAmountRaw) != null ? _a : prev.requestedAmountRaw,
4623
+ completedAmountRaw: (_b = msg.completedAmountRaw) != null ? _b : prev.completedAmountRaw,
4109
4624
  terminal: msg.terminal,
4110
- lastLeg: (_a = msg.leg) != null ? _a : null,
4625
+ lastLeg: (_c = msg.leg) != null ? _c : null,
4111
4626
  // `legs[]` is the cumulative server-known truth. Snapshots
4112
4627
  // (`pending` / terminal rollup) carry a full `legs[]` and replace
4113
4628
  // it. Intermediate per-leg deltas carry only `leg` (no `legs[]`)
@@ -4115,23 +4630,23 @@ function useWithdrawalLifecycle(withdrawalId) {
4115
4630
  // (sourceChainId, destChainId, type) so the timeline UI doesn't
4116
4631
  // collapse to empty between snapshots.
4117
4632
  legs: mergeLegs(prev.legs, msg.legs, msg.leg),
4118
- errorMessage: (_b = msg.errorMessage) != null ? _b : null,
4633
+ errorMessage: (_d = msg.errorMessage) != null ? _d : null,
4119
4634
  timestamp: msg.timestamp
4120
4635
  };
4121
4636
  });
4122
4637
  };
4123
4638
  }, [withdrawalId]);
4124
4639
  useOnWithdrawalLifecycle(handler);
4125
- (0, import_react12.useEffect)(() => {
4640
+ (0, import_react15.useEffect)(() => {
4126
4641
  if (!withdrawalId) return;
4127
4642
  if (!state.terminal) return;
4128
4643
  if (balanceRefetchedForRef.current === withdrawalId) return;
4129
4644
  balanceRefetchedForRef.current = withdrawalId;
4130
- invalidateBalanceQueries(queryClient);
4645
+ invalidateUserMoneyState(queryClient);
4131
4646
  client.syncManagedBalances().catch(() => {
4132
4647
  });
4133
4648
  }, [client, queryClient, state.terminal, withdrawalId]);
4134
- const reset = (0, import_react12.useCallback)(() => setState(INITIAL_STATE), []);
4649
+ const reset = (0, import_react15.useCallback)(() => setState(INITIAL_STATE2), []);
4135
4650
  return { state, reset };
4136
4651
  }
4137
4652
 
@@ -4139,7 +4654,7 @@ function useWithdrawalLifecycle(withdrawalId) {
4139
4654
  var import_sdk4 = require("@agg-build/sdk");
4140
4655
 
4141
4656
  // src/use-geo-block.ts
4142
- var import_react13 = require("react");
4657
+ var import_react16 = require("react");
4143
4658
  var DEFAULT_STATE = {
4144
4659
  isLocationBlocked: false,
4145
4660
  isTradingBlocked: false,
@@ -4147,7 +4662,7 @@ var DEFAULT_STATE = {
4147
4662
  };
4148
4663
  function useGeoBlock() {
4149
4664
  var _a, _b;
4150
- const authContext = (0, import_react13.useContext)(AggAuthContext);
4665
+ const authContext = (0, import_react16.useContext)(AggAuthContext);
4151
4666
  if (process.env.NEXT_PUBLIC_GEO_BLOCK_DISABLE === "true") return DEFAULT_STATE;
4152
4667
  const isBlocked = (_b = (_a = authContext == null ? void 0 : authContext.user) == null ? void 0 : _a.isLocationBlocked) != null ? _b : false;
4153
4668
  if (!isBlocked) return DEFAULT_STATE;
@@ -4159,7 +4674,7 @@ function useGeoBlock() {
4159
4674
  }
4160
4675
 
4161
4676
  // src/use-agg-auth.ts
4162
- var import_react14 = require("react");
4677
+ var import_react17 = require("react");
4163
4678
  function useAggAuth(options = {}) {
4164
4679
  const {
4165
4680
  isAuthenticated,
@@ -4169,7 +4684,7 @@ function useAggAuth(options = {}) {
4169
4684
  signIn: signInWithProvider,
4170
4685
  signOut
4171
4686
  } = useAggAuthContext();
4172
- const signIn = (0, import_react14.useCallback)(
4687
+ const signIn = (0, import_react17.useCallback)(
4173
4688
  (statement) => __async(null, null, function* () {
4174
4689
  if (!options.signMessage) {
4175
4690
  throw new Error(
@@ -4193,11 +4708,11 @@ function useAggAuth(options = {}) {
4193
4708
  }
4194
4709
 
4195
4710
  // src/use-link-account.ts
4196
- var import_react15 = require("react");
4711
+ var import_react18 = require("react");
4197
4712
  function useLinkAccount() {
4198
4713
  const client = useAggClient();
4199
- const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
4200
- const [error, setError] = (0, import_react15.useState)(null);
4714
+ const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
4715
+ const [error, setError] = (0, import_react18.useState)(null);
4201
4716
  const run = (fn) => {
4202
4717
  setIsLoading(true);
4203
4718
  setError(null);
@@ -4207,11 +4722,11 @@ function useLinkAccount() {
4207
4722
  throw err;
4208
4723
  }).finally(() => setIsLoading(false));
4209
4724
  };
4210
- const startLink = (0, import_react15.useCallback)(
4725
+ const startLink = (0, import_react18.useCallback)(
4211
4726
  (body) => run(() => client.linkAccount(body)),
4212
4727
  [client]
4213
4728
  );
4214
- const confirmLink = (0, import_react15.useCallback)(
4729
+ const confirmLink = (0, import_react18.useCallback)(
4215
4730
  (token) => run(() => client.linkAccountConfirm(token)),
4216
4731
  [client]
4217
4732
  );
@@ -4257,10 +4772,10 @@ function useCategories(options) {
4257
4772
  }
4258
4773
 
4259
4774
  // src/use-debounced-value.ts
4260
- var import_react16 = require("react");
4775
+ var import_react19 = require("react");
4261
4776
  function useDebouncedValue(value, delay) {
4262
- const [debouncedValue, setDebouncedValue] = (0, import_react16.useState)(value);
4263
- (0, import_react16.useEffect)(() => {
4777
+ const [debouncedValue, setDebouncedValue] = (0, import_react19.useState)(value);
4778
+ (0, import_react19.useEffect)(() => {
4264
4779
  const timeoutId = window.setTimeout(() => {
4265
4780
  setDebouncedValue(value);
4266
4781
  }, delay);
@@ -4276,11 +4791,22 @@ var import_react_query17 = require("@tanstack/react-query");
4276
4791
  function useExecutionOrders(options = {}) {
4277
4792
  var _a, _b;
4278
4793
  const client = useAggClient();
4279
- const { status, limit = 50, enabled = true, refetchIntervalMs = false } = options;
4794
+ const {
4795
+ status,
4796
+ orderId,
4797
+ quoteId,
4798
+ limit = 50,
4799
+ enabled = true,
4800
+ refetchIntervalMs = false
4801
+ } = options;
4280
4802
  const query = (0, import_react_query17.useInfiniteQuery)({
4281
- queryKey: ["execution-orders", status != null ? status : "all", limit],
4803
+ // quoteId + orderId are part of the cache key — different filters
4804
+ // produce different result sets, so they have to vary the key.
4805
+ queryKey: ["execution-orders", status != null ? status : "all", quoteId != null ? quoteId : null, orderId != null ? orderId : null, limit],
4282
4806
  queryFn: ({ pageParam }) => client.getExecutionOrders({
4283
4807
  status,
4808
+ orderId,
4809
+ quoteId,
4284
4810
  limit,
4285
4811
  cursor: pageParam
4286
4812
  }),
@@ -4302,10 +4828,36 @@ function useExecutionOrders(options = {}) {
4302
4828
 
4303
4829
  // src/use-user-activity.ts
4304
4830
  var import_react_query18 = require("@tanstack/react-query");
4831
+ var DEFAULT_PENDING_REFETCH_INTERVAL_MS = 15e3;
4832
+ var PENDING_ACTIVITY_STATUSES = /* @__PURE__ */ new Set([
4833
+ "pending",
4834
+ // trade pre-fill lifecycle
4835
+ "signing",
4836
+ "pending_bridge",
4837
+ "submitting",
4838
+ "submitted",
4839
+ // withdrawal lifecycle
4840
+ "bridging",
4841
+ "transferring"
4842
+ ]);
4843
+ var hasPendingActivity = (pages) => {
4844
+ if (!pages) return false;
4845
+ for (const page of pages) {
4846
+ for (const item of page.data) {
4847
+ if (PENDING_ACTIVITY_STATUSES.has(item.status.toLowerCase())) return true;
4848
+ }
4849
+ }
4850
+ return false;
4851
+ };
4305
4852
  function useUserActivity(options = {}) {
4306
4853
  var _a, _b;
4307
4854
  const client = useAggClient();
4308
- const { type, limit = 50, enabled = true } = options;
4855
+ const {
4856
+ type,
4857
+ limit = 50,
4858
+ enabled = true,
4859
+ pendingRefetchIntervalMs = DEFAULT_PENDING_REFETCH_INTERVAL_MS
4860
+ } = options;
4309
4861
  const query = (0, import_react_query18.useInfiniteQuery)({
4310
4862
  queryKey: ["user-activity", type != null ? type : "all", limit],
4311
4863
  queryFn: ({ pageParam }) => client.getUserActivity({
@@ -4318,7 +4870,17 @@ function useUserActivity(options = {}) {
4318
4870
  var _a2;
4319
4871
  return lastPage.hasMore ? (_a2 = lastPage.nextCursor) != null ? _a2 : void 0 : void 0;
4320
4872
  },
4321
- enabled
4873
+ enabled,
4874
+ // Keep the previously-loaded pages visible while a refetch is in
4875
+ // flight (typically after a deposit / withdraw cache invalidation).
4876
+ // Without this the feed flashes to the skeleton mid-session, which
4877
+ // is worse UX than briefly showing slightly-stale rows.
4878
+ placeholderData: import_react_query18.keepPreviousData,
4879
+ refetchInterval: (q) => {
4880
+ if (pendingRefetchIntervalMs === false) return false;
4881
+ const data = q.state.data;
4882
+ return hasPendingActivity(data == null ? void 0 : data.pages) ? pendingRefetchIntervalMs : false;
4883
+ }
4322
4884
  });
4323
4885
  const activities = (_b = (_a = query.data) == null ? void 0 : _a.pages.flatMap((page) => page.data)) != null ? _b : [];
4324
4886
  const hasNextPage = !!query.hasNextPage;
@@ -4329,13 +4891,13 @@ function useUserActivity(options = {}) {
4329
4891
  }
4330
4892
 
4331
4893
  // src/use-external-id.ts
4332
- var import_react17 = require("react");
4894
+ var import_react20 = require("react");
4333
4895
  function useExternalId(options = {}) {
4334
4896
  const client = useAggClient();
4335
4897
  const { onSuccess, onError: onErrorCb } = options;
4336
- const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
4337
- const [error, setError] = (0, import_react17.useState)(null);
4338
- const linkExternalId = (0, import_react17.useCallback)(
4898
+ const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
4899
+ const [error, setError] = (0, import_react20.useState)(null);
4900
+ const linkExternalId = (0, import_react20.useCallback)(
4339
4901
  (assertion) => __async(null, null, function* () {
4340
4902
  setIsLoading(true);
4341
4903
  setError(null);
@@ -4386,17 +4948,17 @@ function useExecutionPositions(options = {}) {
4386
4948
  }
4387
4949
 
4388
4950
  // src/use-live-candle-overlay.ts
4389
- var import_react21 = require("react");
4951
+ var import_react24 = require("react");
4390
4952
 
4391
4953
  // src/use-live-candles.ts
4392
- var import_react20 = require("react");
4954
+ var import_react23 = require("react");
4393
4955
  var import_sdk3 = require("@agg-build/sdk");
4394
4956
 
4395
4957
  // src/use-market-chart.ts
4396
4958
  var import_react_query20 = require("@tanstack/react-query");
4397
4959
 
4398
4960
  // src/market-data/subscription.ts
4399
- var import_react18 = require("react");
4961
+ var import_react21 = require("react");
4400
4962
  function useMarketDataSubscription({
4401
4963
  marketId,
4402
4964
  additionalMarketIds,
@@ -4405,7 +4967,7 @@ function useMarketDataSubscription({
4405
4967
  trades = false
4406
4968
  }) {
4407
4969
  const ws = useAggWebSocket();
4408
- const allIds = (0, import_react18.useMemo)(() => {
4970
+ const allIds = (0, import_react21.useMemo)(() => {
4409
4971
  const ids = /* @__PURE__ */ new Set();
4410
4972
  if (marketId) ids.add(marketId);
4411
4973
  if (additionalMarketIds) {
@@ -4416,7 +4978,7 @@ function useMarketDataSubscription({
4416
4978
  return [...ids];
4417
4979
  }, [marketId, additionalMarketIds]);
4418
4980
  const stableKey = allIds.join("|");
4419
- (0, import_react18.useEffect)(() => {
4981
+ (0, import_react21.useEffect)(() => {
4420
4982
  if (!ws || !allIds.length || !enabled || !orderbook && !trades) return;
4421
4983
  const unsubscribers = [];
4422
4984
  for (const id of allIds) {
@@ -4453,24 +5015,23 @@ function useMarketChart(options) {
4453
5015
  endTs = null,
4454
5016
  countBack = null,
4455
5017
  enabled = true,
4456
- live
5018
+ live,
5019
+ refetchIntervalMs = null,
5020
+ rangeKey
4457
5021
  } = options;
5022
+ const resolvedRangeKey = rangeKey != null ? rangeKey : interval;
4458
5023
  const liveEnabled = live != null ? live : enableLiveUpdates;
4459
5024
  const outcomeIds = (() => {
4460
5025
  const ids = /* @__PURE__ */ new Set();
4461
- if (marketId) {
4462
- ids.add(marketId);
4463
- }
5026
+ if (marketId) ids.add(marketId);
4464
5027
  if (venueMarketIds) {
4465
5028
  for (const venueMarketId of venueMarketIds) {
4466
- if (venueMarketId) {
4467
- ids.add(venueMarketId);
4468
- }
5029
+ if (venueMarketId) ids.add(venueMarketId);
4469
5030
  }
4470
5031
  }
4471
- return [...ids];
5032
+ return [...ids].sort();
4472
5033
  })();
4473
- const primaryOutcomeId = (_a = outcomeIds[0]) != null ? _a : null;
5034
+ const primaryOutcomeId = (_a = marketId != null ? marketId : venueMarketIds == null ? void 0 : venueMarketIds.find(Boolean)) != null ? _a : null;
4474
5035
  const isQueryEnabled = enabled && outcomeIds.length > 0 && endTs != null && (startTs != null || countBack != null);
4475
5036
  useMarketDataSubscription({
4476
5037
  marketId: primaryOutcomeId,
@@ -4481,7 +5042,11 @@ function useMarketChart(options) {
4481
5042
  });
4482
5043
  const queries = (0, import_react_query20.useQueries)({
4483
5044
  queries: outcomeIds.map((outcomeId) => ({
4484
- queryKey: marketDataKeys.chart(outcomeId, interval, startTs, endTs, countBack),
5045
+ // Cache key is intentionally time-free. The rolling window's
5046
+ // startTs/endTs advance on every bucket but the user expects the same
5047
+ // chart on revisit — see comment on `marketDataKeys.chart`. queryFn
5048
+ // closes over the current window so refetches still fetch fresh data.
5049
+ queryKey: marketDataKeys.chart(outcomeId, interval, resolvedRangeKey, countBack),
4485
5050
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
4486
5051
  const response = yield client.getChartBars(
4487
5052
  {
@@ -4502,11 +5067,17 @@ function useMarketChart(options) {
4502
5067
  });
4503
5068
  }),
4504
5069
  enabled: isQueryEnabled,
4505
- staleTime: 3e4,
4506
- gcTime: 5 * 6e4,
5070
+ // Treat data as fresh for one bucket — within that window the
5071
+ // existing entry serves remounts without a refetch, and the
5072
+ // `refetchInterval` below schedules the next bucket's refresh.
5073
+ staleTime: refetchIntervalMs != null && refetchIntervalMs > 0 ? refetchIntervalMs : 3e4,
5074
+ // 60 min — survives typical tab/page revisits without re-fetching.
5075
+ gcTime: 60 * 6e4,
4507
5076
  refetchOnWindowFocus: false,
4508
5077
  retry: 1,
4509
- placeholderData: import_react_query20.keepPreviousData
5078
+ placeholderData: import_react_query20.keepPreviousData,
5079
+ refetchInterval: refetchIntervalMs != null && refetchIntervalMs > 0 ? refetchIntervalMs : false,
5080
+ refetchIntervalInBackground: false
4510
5081
  }))
4511
5082
  });
4512
5083
  const successfulDatasets = queries.flatMap((query) => {
@@ -4535,13 +5106,13 @@ function useMarketChart(options) {
4535
5106
  }
4536
5107
 
4537
5108
  // src/use-live-market-stores.ts
4538
- var import_react19 = require("react");
5109
+ var import_react22 = require("react");
4539
5110
  function useLiveMarketStores(venueMarketIds) {
4540
5111
  const ws = useAggWebSocket();
4541
- const [, forceRender] = (0, import_react19.useReducer)((c) => c + 1, 0);
4542
- const subsRef = (0, import_react19.useRef)(/* @__PURE__ */ new Map());
4543
- const stableKey = (0, import_react19.useMemo)(() => venueMarketIds.slice().sort().join("|"), [venueMarketIds]);
4544
- (0, import_react19.useEffect)(() => {
5112
+ const [, forceRender] = (0, import_react22.useReducer)((c) => c + 1, 0);
5113
+ const subsRef = (0, import_react22.useRef)(/* @__PURE__ */ new Map());
5114
+ const stableKey = (0, import_react22.useMemo)(() => venueMarketIds.slice().sort().join("|"), [venueMarketIds]);
5115
+ (0, import_react22.useEffect)(() => {
4545
5116
  if (!ws || venueMarketIds.length === 0) return;
4546
5117
  const current = subsRef.current;
4547
5118
  const desired = new Set(venueMarketIds);
@@ -4578,7 +5149,7 @@ function candleToLive(c, source) {
4578
5149
  function useLiveCandles(options) {
4579
5150
  var _a;
4580
5151
  const { market, interval = "5m", mode = "venue", startTs, endTs } = options;
4581
- const venueMarketIds = (0, import_react20.useMemo)(() => {
5152
+ const venueMarketIds = (0, import_react23.useMemo)(() => {
4582
5153
  if (!market) return [];
4583
5154
  if (mode === "venue") return [market.id];
4584
5155
  const ids = [market.id];
@@ -4598,7 +5169,7 @@ function useLiveCandles(options) {
4598
5169
  endTs: endTs != null ? endTs : null,
4599
5170
  enabled: !!restMarketId && startTs != null && endTs != null
4600
5171
  });
4601
- const liveData = (0, import_react20.useMemo)(() => {
5172
+ const liveData = (0, import_react23.useMemo)(() => {
4602
5173
  if (builders2.length === 0) return { closed: [], forming: null };
4603
5174
  if (mode === "venue" || builders2.length === 1) {
4604
5175
  return {
@@ -4611,7 +5182,7 @@ function useLiveCandles(options) {
4611
5182
  forming: (0, import_sdk3.mergeCandles)(builders2.map((b) => b.getForming(interval)))
4612
5183
  };
4613
5184
  }, [builders2, interval, mode]);
4614
- const candles = (0, import_react20.useMemo)(() => {
5185
+ const candles = (0, import_react23.useMemo)(() => {
4615
5186
  const byTime = /* @__PURE__ */ new Map();
4616
5187
  if (chartData) {
4617
5188
  const venueEntries = Object.values(chartData.venues);
@@ -4636,7 +5207,7 @@ function useLiveCandles(options) {
4636
5207
  merged.sort((a, b) => a.time - b.time);
4637
5208
  return merged;
4638
5209
  }, [chartData, liveData.closed]);
4639
- const liveCandle = (0, import_react20.useMemo)(() => {
5210
+ const liveCandle = (0, import_react23.useMemo)(() => {
4640
5211
  if (!liveData.forming) return null;
4641
5212
  return candleToLive(liveData.forming, "live");
4642
5213
  }, [liveData.forming]);
@@ -4684,7 +5255,7 @@ function useLiveCandleOverlay(options) {
4684
5255
  startTs,
4685
5256
  endTs
4686
5257
  });
4687
- const scaleCandle = (0, import_react21.useCallback)(
5258
+ const scaleCandle = (0, import_react24.useCallback)(
4688
5259
  (candle) => ({
4689
5260
  time: candle.time,
4690
5261
  open: candle.o * scale,
@@ -4695,8 +5266,8 @@ function useLiveCandleOverlay(options) {
4695
5266
  }),
4696
5267
  [scale]
4697
5268
  );
4698
- const scaledCandles = (0, import_react21.useMemo)(() => rawCandles.map(scaleCandle), [rawCandles, scaleCandle]);
4699
- const liveCandle = (0, import_react21.useMemo)(() => rawLive ? scaleCandle(rawLive) : null, [rawLive, scaleCandle]);
5269
+ const scaledCandles = (0, import_react24.useMemo)(() => rawCandles.map(scaleCandle), [rawCandles, scaleCandle]);
5270
+ const liveCandle = (0, import_react24.useMemo)(() => rawLive ? scaleCandle(rawLive) : null, [rawLive, scaleCandle]);
4700
5271
  return {
4701
5272
  liveCandle,
4702
5273
  scaledCandles,
@@ -4707,7 +5278,7 @@ function useLiveCandleOverlay(options) {
4707
5278
  }
4708
5279
 
4709
5280
  // src/use-event-orderbook-data.ts
4710
- var import_react22 = require("react");
5281
+ var import_react25 = require("react");
4711
5282
  function extractSelectedOutcomeIds(selectedMarket) {
4712
5283
  var _a, _b, _c;
4713
5284
  if (!selectedMarket) return [];
@@ -4727,17 +5298,17 @@ function useEventOrderbookData(venueMarkets, selectedMarketId) {
4727
5298
  const {
4728
5299
  features: { enableLiveUpdates }
4729
5300
  } = useAggUiConfig();
4730
- const selectedMarket = (0, import_react22.useMemo)(() => {
5301
+ const selectedMarket = (0, import_react25.useMemo)(() => {
4731
5302
  var _a;
4732
5303
  if (!selectedMarketId || !(venueMarkets == null ? void 0 : venueMarkets.length)) return null;
4733
5304
  return (_a = venueMarkets.find((m) => m.id === selectedMarketId)) != null ? _a : null;
4734
5305
  }, [venueMarkets, selectedMarketId]);
4735
- const selectedOutcomeIds = (0, import_react22.useMemo)(
5306
+ const selectedOutcomeIds = (0, import_react25.useMemo)(
4736
5307
  () => extractSelectedOutcomeIds(selectedMarket),
4737
5308
  [selectedMarket]
4738
5309
  );
4739
5310
  const selectedKey = selectedOutcomeIds.join("|");
4740
- (0, import_react22.useEffect)(() => {
5311
+ (0, import_react25.useEffect)(() => {
4741
5312
  if (!ws || !enableLiveUpdates || !selectedOutcomeIds.length) return;
4742
5313
  const unsubscribers = selectedOutcomeIds.map((id) => ws.subscribe(id, "orderbook"));
4743
5314
  return () => {
@@ -4829,7 +5400,7 @@ function useLiveMarket(canonicalMarketId) {
4829
5400
  }
4830
5401
 
4831
5402
  // src/use-live-outcome-prices.ts
4832
- var import_react23 = require("react");
5403
+ var import_react26 = require("react");
4833
5404
  var import_react_query22 = require("@tanstack/react-query");
4834
5405
  var EMPTY_PRICES = /* @__PURE__ */ new Map();
4835
5406
  var buildMidpointFingerprint = (outcomeIds, queries) => {
@@ -4845,7 +5416,7 @@ function useLiveOutcomePrices(venueMarkets) {
4845
5416
  const {
4846
5417
  features: { enableLiveUpdates }
4847
5418
  } = useAggUiConfig();
4848
- const outcomeIds = (0, import_react23.useMemo)(() => {
5419
+ const outcomeIds = (0, import_react26.useMemo)(() => {
4849
5420
  var _a;
4850
5421
  if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
4851
5422
  const ids = /* @__PURE__ */ new Set();
@@ -4867,11 +5438,11 @@ function useLiveOutcomePrices(venueMarkets) {
4867
5438
  }))
4868
5439
  });
4869
5440
  const fingerprint = buildMidpointFingerprint(outcomeIds, queries);
4870
- const prevRef = (0, import_react23.useRef)({
5441
+ const prevRef = (0, import_react26.useRef)({
4871
5442
  fingerprint: "",
4872
5443
  prices: EMPTY_PRICES
4873
5444
  });
4874
- const data = (0, import_react23.useMemo)(() => {
5445
+ const data = (0, import_react26.useMemo)(() => {
4875
5446
  var _a, _b, _c, _d;
4876
5447
  if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return EMPTY_PRICES;
4877
5448
  if (fingerprint === prevRef.current.fingerprint) {
@@ -4904,6 +5475,128 @@ function findLivePriceById(livePrices, id) {
4904
5475
  return livePrices.get(id);
4905
5476
  }
4906
5477
 
5478
+ // src/use-live-best-prices.ts
5479
+ var import_react27 = require("react");
5480
+ var import_react_query23 = require("@tanstack/react-query");
5481
+ var EMPTY = /* @__PURE__ */ new Map();
5482
+ var extractOutcomeBestPrices = (state) => {
5483
+ var _a, _b;
5484
+ const ob = state == null ? void 0 : state.orderbook;
5485
+ if (!ob) return {};
5486
+ const bestBid = (_a = ob.bids[0]) == null ? void 0 : _a.price;
5487
+ const bestAsk = (_b = ob.asks[0]) == null ? void 0 : _b.price;
5488
+ return {
5489
+ bestBid: bestBid != null ? bestBid : void 0,
5490
+ bestAsk: bestAsk != null ? bestAsk : void 0
5491
+ };
5492
+ };
5493
+ var buildFingerprint = (outcomeIds, queries) => {
5494
+ var _a, _b, _c, _d;
5495
+ const parts = [];
5496
+ for (let i = 0; i < outcomeIds.length; i++) {
5497
+ const ob = (_b = (_a = queries[i]) == null ? void 0 : _a.data) == null ? void 0 : _b.orderbook;
5498
+ const bid = (_c = ob == null ? void 0 : ob.bids[0]) == null ? void 0 : _c.price;
5499
+ const ask = (_d = ob == null ? void 0 : ob.asks[0]) == null ? void 0 : _d.price;
5500
+ parts.push(`${outcomeIds[i]}:${bid != null ? bid : "_"}:${ask != null ? ask : "_"}`);
5501
+ }
5502
+ return parts.join("|");
5503
+ };
5504
+ function useLiveBestPrices(venueMarkets) {
5505
+ const {
5506
+ features: { enableLiveUpdates }
5507
+ } = useAggUiConfig();
5508
+ const outcomeIds = (0, import_react27.useMemo)(() => {
5509
+ var _a, _b;
5510
+ if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
5511
+ const ids = /* @__PURE__ */ new Set();
5512
+ for (const vm of venueMarkets) {
5513
+ for (const outcome of (_a = vm.venueMarketOutcomes) != null ? _a : []) {
5514
+ if (outcome.id) ids.add(outcome.id);
5515
+ for (const ref of (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : []) {
5516
+ if (ref.venueMarketOutcomeId) ids.add(ref.venueMarketOutcomeId);
5517
+ }
5518
+ }
5519
+ }
5520
+ return [...ids].sort();
5521
+ }, [venueMarkets]);
5522
+ const queries = (0, import_react_query23.useQueries)({
5523
+ queries: outcomeIds.map((id) => ({
5524
+ queryKey: marketDataKeys.live(id),
5525
+ queryFn: () => createMarketLiveState(id),
5526
+ enabled: false,
5527
+ staleTime: Infinity,
5528
+ gcTime: 5 * 6e4,
5529
+ initialData: () => createMarketLiveState(id)
5530
+ }))
5531
+ });
5532
+ const fingerprint = buildFingerprint(outcomeIds, queries);
5533
+ const prevRef = (0, import_react27.useRef)({
5534
+ fingerprint: "",
5535
+ result: EMPTY
5536
+ });
5537
+ return (0, import_react27.useMemo)(() => {
5538
+ var _a, _b, _c, _d;
5539
+ if (!(venueMarkets == null ? void 0 : venueMarkets.length) || !enableLiveUpdates) return EMPTY;
5540
+ if (fingerprint === prevRef.current.fingerprint) return prevRef.current.result;
5541
+ const perOutcome = /* @__PURE__ */ new Map();
5542
+ for (let i = 0; i < outcomeIds.length; i++) {
5543
+ const state = (_a = queries[i]) == null ? void 0 : _a.data;
5544
+ const best = extractOutcomeBestPrices(state);
5545
+ if (best.bestBid != null || best.bestAsk != null) {
5546
+ perOutcome.set(outcomeIds[i], best);
5547
+ }
5548
+ }
5549
+ if (perOutcome.size === 0) {
5550
+ prevRef.current = { fingerprint, result: EMPTY };
5551
+ return EMPTY;
5552
+ }
5553
+ const result = new Map(perOutcome);
5554
+ for (const vm of venueMarkets) {
5555
+ for (const outcome of (_b = vm.venueMarketOutcomes) != null ? _b : []) {
5556
+ const refs = (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : [];
5557
+ if (!refs.length) continue;
5558
+ const group = [outcome.id, ...refs.map((ref) => ref.venueMarketOutcomeId)];
5559
+ let groupBestAsk;
5560
+ let groupBestBid;
5561
+ for (const id of group) {
5562
+ const entry = perOutcome.get(id);
5563
+ if (!entry) continue;
5564
+ if (entry.bestAsk != null && (groupBestAsk == null || entry.bestAsk < groupBestAsk)) {
5565
+ groupBestAsk = entry.bestAsk;
5566
+ }
5567
+ if (entry.bestBid != null && (groupBestBid == null || entry.bestBid > groupBestBid)) {
5568
+ groupBestBid = entry.bestBid;
5569
+ }
5570
+ }
5571
+ if (groupBestAsk == null && groupBestBid == null) continue;
5572
+ for (const id of group) {
5573
+ const prev = (_d = result.get(id)) != null ? _d : {};
5574
+ const nextBid = groupBestBid != null ? groupBestBid : prev.bestBid;
5575
+ const nextAsk = groupBestAsk != null ? groupBestAsk : prev.bestAsk;
5576
+ if (nextBid == null && nextAsk == null) continue;
5577
+ result.set(id, __spreadValues(__spreadValues({}, nextBid != null ? { bestBid: nextBid } : {}), nextAsk != null ? { bestAsk: nextAsk } : {}));
5578
+ }
5579
+ }
5580
+ }
5581
+ prevRef.current = { fingerprint, result };
5582
+ return result;
5583
+ }, [venueMarkets, enableLiveUpdates, fingerprint, outcomeIds, queries]);
5584
+ }
5585
+ function mergeBestPricesPreferringLive(rest, live) {
5586
+ var _a, _b, _c;
5587
+ if (!live.size) return rest != null ? rest : EMPTY;
5588
+ if (!rest || !rest.size) return live;
5589
+ const merged = new Map(rest);
5590
+ for (const [id, liveEntry] of live) {
5591
+ const prev = (_a = merged.get(id)) != null ? _a : {};
5592
+ merged.set(id, {
5593
+ bestBid: (_b = liveEntry.bestBid) != null ? _b : prev.bestBid,
5594
+ bestAsk: (_c = liveEntry.bestAsk) != null ? _c : prev.bestAsk
5595
+ });
5596
+ }
5597
+ return merged;
5598
+ }
5599
+
4907
5600
  // src/use-live-trades.ts
4908
5601
  function useLiveTrades(canonicalMarketId) {
4909
5602
  const {
@@ -4920,19 +5613,146 @@ function useLiveTrades(canonicalMarketId) {
4920
5613
  }
4921
5614
 
4922
5615
  // src/use-midpoints.ts
4923
- var import_react24 = require("react");
4924
- var import_react_query23 = require("@tanstack/react-query");
5616
+ var import_react_query24 = require("@tanstack/react-query");
5617
+ var import_react28 = require("react");
4925
5618
  var normalizeVenueMarketIds = (venueMarkets) => {
4926
- return [...new Set((venueMarkets != null ? venueMarkets : []).map((market) => market.id).filter(Boolean))].sort(
4927
- (left, right) => left.localeCompare(right)
5619
+ var _a;
5620
+ const ids = /* @__PURE__ */ new Set();
5621
+ for (const market of venueMarkets != null ? venueMarkets : []) {
5622
+ if (market.id) ids.add(market.id);
5623
+ for (const sibling of (_a = market.matchedVenueMarkets) != null ? _a : []) {
5624
+ if (sibling.id) ids.add(sibling.id);
5625
+ }
5626
+ }
5627
+ return [...ids].sort((left, right) => left.localeCompare(right));
5628
+ };
5629
+ var normalizeOutcomeLabel = (label) => {
5630
+ return typeof label === "string" ? label.trim().toLowerCase() : "";
5631
+ };
5632
+ var resolveBestMidpointCandidateOutcomeIds = (venueMarkets) => {
5633
+ var _a, _b;
5634
+ if (!(venueMarkets == null ? void 0 : venueMarkets.length)) return [];
5635
+ const candidateIds = [];
5636
+ for (const market of venueMarkets) {
5637
+ const outcomes = (_a = market.venueMarketOutcomes) != null ? _a : [];
5638
+ const yesOutcome = outcomes.find((outcome) => normalizeOutcomeLabel(outcome.label) === "yes");
5639
+ if (yesOutcome == null ? void 0 : yesOutcome.id) {
5640
+ candidateIds.push(yesOutcome.id);
5641
+ continue;
5642
+ }
5643
+ const firstOutcomeId = (_b = outcomes[0]) == null ? void 0 : _b.id;
5644
+ if (firstOutcomeId) {
5645
+ candidateIds.push(firstOutcomeId);
5646
+ }
5647
+ }
5648
+ return [...new Set(candidateIds)];
5649
+ };
5650
+ var resolveSiblingOutcomeMidpoint = (matched, ref) => {
5651
+ var _a, _b;
5652
+ if (!(matched == null ? void 0 : matched.length)) return null;
5653
+ const sibling = matched.find((m) => m.venueMarketId === ref.venueMarketId);
5654
+ if (!((_a = sibling == null ? void 0 : sibling.outcomes) == null ? void 0 : _a.length)) return null;
5655
+ const sibOutcome = sibling.outcomes.find(
5656
+ (o) => o.venueMarketOutcomeId === ref.venueMarketOutcomeId
4928
5657
  );
5658
+ if ((sibOutcome == null ? void 0 : sibOutcome.midpoint) == null) return null;
5659
+ return { midpoint: sibOutcome.midpoint, venue: (_b = sibling.venue) != null ? _b : null };
5660
+ };
5661
+ var extractBestPrices = (data, venueMarkets) => {
5662
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5663
+ const bestPrices = /* @__PURE__ */ new Map();
5664
+ const venuesByOutcome = /* @__PURE__ */ new Map();
5665
+ if (!(data == null ? void 0 : data.length)) return { bestPrices, bestPriceVenuesByOutcomeId: venuesByOutcome };
5666
+ const setEntry = (outcomeId, next) => {
5667
+ const prev = bestPrices.get(outcomeId);
5668
+ const merged = __spreadValues({}, prev != null ? prev : {});
5669
+ if (next.bestBid != null) merged.bestBid = next.bestBid;
5670
+ if (next.bestAsk != null) merged.bestAsk = next.bestAsk;
5671
+ if (merged.bestBid != null || merged.bestAsk != null) bestPrices.set(outcomeId, merged);
5672
+ const prevVenues = venuesByOutcome.get(outcomeId);
5673
+ const mergedVenues = __spreadValues({}, prevVenues != null ? prevVenues : {});
5674
+ if (next.bestBidVenue != null) mergedVenues.bestBidVenue = next.bestBidVenue;
5675
+ if (next.bestAskVenue != null) mergedVenues.bestAskVenue = next.bestAskVenue;
5676
+ if (mergedVenues.bestBidVenue || mergedVenues.bestAskVenue) {
5677
+ venuesByOutcome.set(outcomeId, mergedVenues);
5678
+ }
5679
+ };
5680
+ for (const item of data) {
5681
+ const venue = (_a = item.venue) != null ? _a : null;
5682
+ for (const o of (_b = item.outcomes) != null ? _b : []) {
5683
+ if (o.bestBid != null || o.bestAsk != null) {
5684
+ setEntry(o.venueMarketOutcomeId, {
5685
+ bestBid: o.bestBid,
5686
+ bestAsk: o.bestAsk,
5687
+ bestBidVenue: o.bestBid != null ? venue : null,
5688
+ bestAskVenue: o.bestAsk != null ? venue : null
5689
+ });
5690
+ }
5691
+ }
5692
+ }
5693
+ for (const item of data) {
5694
+ for (const m of (_c = item.matched) != null ? _c : []) {
5695
+ const venue = (_d = m.venue) != null ? _d : null;
5696
+ for (const o of (_e = m.outcomes) != null ? _e : []) {
5697
+ if (bestPrices.has(o.venueMarketOutcomeId)) continue;
5698
+ if (o.bestBid != null || o.bestAsk != null) {
5699
+ setEntry(o.venueMarketOutcomeId, {
5700
+ bestBid: o.bestBid,
5701
+ bestAsk: o.bestAsk,
5702
+ bestBidVenue: o.bestBid != null ? venue : null,
5703
+ bestAskVenue: o.bestAsk != null ? venue : null
5704
+ });
5705
+ }
5706
+ }
5707
+ }
5708
+ }
5709
+ if (venueMarkets == null ? void 0 : venueMarkets.length) {
5710
+ for (const market of venueMarkets) {
5711
+ for (const outcome of (_f = market.venueMarketOutcomes) != null ? _f : []) {
5712
+ const refs = (_g = outcome.matchedVenueMarketOutcomes) != null ? _g : [];
5713
+ if (!refs.length) continue;
5714
+ const group = [outcome.id, ...refs.map((ref) => ref.venueMarketOutcomeId)];
5715
+ let bestAsk;
5716
+ let bestBid;
5717
+ let bestAskVenue;
5718
+ let bestBidVenue;
5719
+ for (const id of group) {
5720
+ const entry = bestPrices.get(id);
5721
+ const venues = venuesByOutcome.get(id);
5722
+ if (!entry) continue;
5723
+ if (entry.bestAsk != null && (bestAsk == null || entry.bestAsk < bestAsk)) {
5724
+ bestAsk = entry.bestAsk;
5725
+ bestAskVenue = (_h = venues == null ? void 0 : venues.bestAskVenue) != null ? _h : bestAskVenue;
5726
+ }
5727
+ if (entry.bestBid != null && (bestBid == null || entry.bestBid > bestBid)) {
5728
+ bestBid = entry.bestBid;
5729
+ bestBidVenue = (_i = venues == null ? void 0 : venues.bestBidVenue) != null ? _i : bestBidVenue;
5730
+ }
5731
+ }
5732
+ if (bestAsk == null && bestBid == null) continue;
5733
+ for (const id of group) {
5734
+ setEntry(id, {
5735
+ bestBid,
5736
+ bestAsk,
5737
+ bestBidVenue,
5738
+ bestAskVenue
5739
+ });
5740
+ }
5741
+ }
5742
+ }
5743
+ }
5744
+ return { bestPrices, bestPriceVenuesByOutcomeId: venuesByOutcome };
4929
5745
  };
4930
5746
  function useMidpoints(venueMarkets) {
4931
5747
  const client = useAggClient();
4932
- const ids = (0, import_react24.useMemo)(() => normalizeVenueMarketIds(venueMarkets), [venueMarkets]);
4933
- const { data, isLoading } = (0, import_react_query23.useQuery)({
5748
+ const ids = (0, import_react28.useMemo)(() => normalizeVenueMarketIds(venueMarkets), [venueMarkets]);
5749
+ const bestMidpointCandidateOutcomeIds = (0, import_react28.useMemo)(
5750
+ () => resolveBestMidpointCandidateOutcomeIds(venueMarkets),
5751
+ [venueMarkets]
5752
+ );
5753
+ const { data, isLoading } = (0, import_react_query24.useQuery)({
4934
5754
  queryKey: ["midpoints", ids],
4935
- queryFn: () => client.getMidpoints(ids),
5755
+ queryFn: () => client.getMidpoints(ids, { bestPrice: true }),
4936
5756
  enabled: ids.length > 0,
4937
5757
  staleTime: Infinity,
4938
5758
  gcTime: 30 * 6e4,
@@ -4940,73 +5760,156 @@ function useMidpoints(venueMarkets) {
4940
5760
  refetchOnWindowFocus: false,
4941
5761
  refetchOnReconnect: false
4942
5762
  });
4943
- const result = (0, import_react24.useMemo)(() => {
4944
- var _a, _b, _c, _d, _e, _f;
5763
+ const result = (0, import_react28.useMemo)(() => {
5764
+ var _a, _b, _c, _d, _e;
4945
5765
  const map = /* @__PURE__ */ new Map();
4946
5766
  const venueMap = /* @__PURE__ */ new Map();
4947
5767
  if (!(data == null ? void 0 : data.data) || !venueMarkets) return { map, venueMap };
5768
+ const itemByMarketId = new Map(data.data.map((item) => [item.venueMarketId, item]));
4948
5769
  for (const item of data.data) {
4949
- if ((_a = item.outcomes) == null ? void 0 : _a.length) {
4950
- for (const o of item.outcomes) {
4951
- if (o.midpoint != null) {
4952
- map.set(o.venueMarketOutcomeId, o.midpoint);
4953
- if (item.venue) venueMap.set(o.venueMarketOutcomeId, item.venue);
4954
- }
4955
- }
4956
- if ((_b = item.matched) == null ? void 0 : _b.length) {
4957
- const market = venueMarkets.find((vm) => vm.id === item.venueMarketId);
4958
- if (market) {
4959
- const primaryYesOutcome = market.venueMarketOutcomes.find(
4960
- (o) => {
4961
- var _a2;
4962
- return ((_a2 = o.label) == null ? void 0 : _a2.toLowerCase()) === "yes";
4963
- }
4964
- );
4965
- const primaryYesMidpoint = primaryYesOutcome ? (_c = map.get(primaryYesOutcome.id)) != null ? _c : null : null;
4966
- let bestMatchedMidpoint = null;
4967
- let bestMatchedVenue = null;
4968
- for (const m of item.matched) {
4969
- if (m.midpoint == null) continue;
4970
- if (bestMatchedMidpoint == null || m.midpoint < bestMatchedMidpoint) {
4971
- bestMatchedMidpoint = m.midpoint;
4972
- bestMatchedVenue = (_d = m.venue) != null ? _d : null;
4973
- }
4974
- }
4975
- if (bestMatchedMidpoint != null && (primaryYesMidpoint == null || bestMatchedMidpoint < primaryYesMidpoint)) {
4976
- for (const outcome of market.venueMarketOutcomes) {
4977
- const isYes = ((_e = outcome.label) == null ? void 0 : _e.toLowerCase()) === "yes";
4978
- map.set(outcome.id, isYes ? bestMatchedMidpoint : 1 - bestMatchedMidpoint);
4979
- if (bestMatchedVenue) venueMap.set(outcome.id, bestMatchedVenue);
4980
- }
4981
- }
5770
+ if (!((_a = item.outcomes) == null ? void 0 : _a.length)) continue;
5771
+ for (const o of item.outcomes) {
5772
+ if (o.midpoint == null) continue;
5773
+ map.set(o.venueMarketOutcomeId, o.midpoint);
5774
+ if (item.venue) venueMap.set(o.venueMarketOutcomeId, item.venue);
5775
+ }
5776
+ }
5777
+ for (const market of venueMarkets) {
5778
+ const item = itemByMarketId.get(market.id);
5779
+ if (!item) continue;
5780
+ for (const outcome of market.venueMarketOutcomes) {
5781
+ const refs = (_b = outcome.matchedVenueMarketOutcomes) != null ? _b : [];
5782
+ if (!refs.length) continue;
5783
+ let best = (_c = map.get(outcome.id)) != null ? _c : null;
5784
+ let bestVenue = (_d = item.venue) != null ? _d : null;
5785
+ for (const ref of refs) {
5786
+ const sib = resolveSiblingOutcomeMidpoint(item.matched, ref);
5787
+ if (sib == null) continue;
5788
+ if (best == null || sib.midpoint < best) {
5789
+ best = sib.midpoint;
5790
+ bestVenue = (_e = sib.venue) != null ? _e : bestVenue;
4982
5791
  }
4983
5792
  }
4984
- continue;
4985
- }
4986
- if (item.midpoint != null) {
4987
- const market = venueMarkets.find((vm) => vm.id === item.venueMarketId);
4988
- if (!market) continue;
4989
- for (const outcome of market.venueMarketOutcomes) {
4990
- const isYes = ((_f = outcome.label) == null ? void 0 : _f.toLowerCase()) === "yes";
4991
- map.set(outcome.id, isYes ? item.midpoint : 1 - item.midpoint);
4992
- if (item.venue) venueMap.set(outcome.id, item.venue);
5793
+ if (best != null) {
5794
+ map.set(outcome.id, best);
5795
+ if (bestVenue) venueMap.set(outcome.id, bestVenue);
4993
5796
  }
4994
5797
  }
4995
5798
  }
4996
5799
  return { map, venueMap };
4997
5800
  }, [data, venueMarkets]);
5801
+ const { bestMidpoint, bestMidpointVenue } = (0, import_react28.useMemo)(() => {
5802
+ let value;
5803
+ let venue;
5804
+ for (const outcomeId of bestMidpointCandidateOutcomeIds) {
5805
+ const midpoint = result.map.get(outcomeId);
5806
+ if (midpoint == null) continue;
5807
+ if (value == null || midpoint < value) {
5808
+ value = midpoint;
5809
+ venue = result.venueMap.get(outcomeId);
5810
+ }
5811
+ }
5812
+ if (value == null) {
5813
+ for (const [outcomeId, midpoint] of result.map) {
5814
+ if (value == null || midpoint < value) {
5815
+ value = midpoint;
5816
+ venue = result.venueMap.get(outcomeId);
5817
+ }
5818
+ }
5819
+ }
5820
+ return { bestMidpoint: value, bestMidpointVenue: venue };
5821
+ }, [bestMidpointCandidateOutcomeIds, result.map, result.venueMap]);
5822
+ const { bestPrices, bestPriceVenuesByOutcomeId } = (0, import_react28.useMemo)(
5823
+ () => extractBestPrices(data == null ? void 0 : data.data, venueMarkets),
5824
+ [data == null ? void 0 : data.data, venueMarkets]
5825
+ );
4998
5826
  return {
4999
5827
  prices: result.map,
5828
+ bestMidpointsByOutcomeId: result.map,
5000
5829
  venueByOutcomeId: result.venueMap,
5001
- isLoading: isLoading && ids.length > 0
5830
+ bestPrices,
5831
+ bestPriceVenuesByOutcomeId,
5832
+ isLoading: isLoading && ids.length > 0,
5833
+ bestMidpoint,
5834
+ bestMidpointVenue
5002
5835
  };
5003
5836
  }
5004
5837
 
5838
+ // src/use-tradable-venues.ts
5839
+ var import_react29 = require("react");
5840
+ function useTradableVenues(venueMarkets) {
5841
+ const { prices, isLoading } = useMidpoints(venueMarkets);
5842
+ const tradableVenues = (0, import_react29.useMemo)(() => {
5843
+ var _a;
5844
+ if (isLoading) return null;
5845
+ if (!venueMarkets || venueMarkets.length === 0) return /* @__PURE__ */ new Set();
5846
+ const set = /* @__PURE__ */ new Set();
5847
+ for (const market of venueMarkets) {
5848
+ const outcomes = (_a = market.venueMarketOutcomes) != null ? _a : [];
5849
+ for (const outcome of outcomes) {
5850
+ if (prices.has(outcome.id)) {
5851
+ set.add(market.venue);
5852
+ break;
5853
+ }
5854
+ }
5855
+ }
5856
+ return set;
5857
+ }, [venueMarkets, prices, isLoading]);
5858
+ return { tradableVenues, isLoading };
5859
+ }
5860
+
5861
+ // src/use-rolling-chart-window.ts
5862
+ var import_react30 = require("react");
5863
+ var RANGE_SECONDS_BY_RANGE = {
5864
+ "1H": 60 * 60,
5865
+ "6H": 6 * 60 * 60,
5866
+ "1D": 24 * 60 * 60,
5867
+ "1W": 7 * 24 * 60 * 60,
5868
+ "1M": 30 * 24 * 60 * 60,
5869
+ ALL: 6 * 30 * 24 * 60 * 60
5870
+ };
5871
+ var rangeToSeconds = (range) => RANGE_SECONDS_BY_RANGE[range];
5872
+ var resolveRollingWindow = (params) => {
5873
+ var _a;
5874
+ const interval = (_a = params.interval) != null ? _a : timeRangeToInterval(params.range);
5875
+ const intervalSeconds = getIntervalSeconds(interval);
5876
+ const rangeSeconds = rangeToSeconds(params.range);
5877
+ const endTs = Math.ceil(params.nowSec / intervalSeconds) * intervalSeconds;
5878
+ return {
5879
+ range: params.range,
5880
+ interval,
5881
+ rangeSeconds,
5882
+ intervalSeconds,
5883
+ nowSec: params.nowSec,
5884
+ endTs,
5885
+ startTs: endTs - rangeSeconds,
5886
+ refetchIntervalMs: intervalSeconds * 1e3
5887
+ };
5888
+ };
5889
+ var useRollingChartWindow = (options) => {
5890
+ var _a;
5891
+ const tickMs = (_a = options.tickMs) != null ? _a : 1e3;
5892
+ const optionsNowMs = options.nowMs;
5893
+ const nowMs = (0, import_react30.useMemo)(() => optionsNowMs != null ? optionsNowMs : (() => Date.now()), [optionsNowMs]);
5894
+ const [nowSec, setNowSec] = (0, import_react30.useState)(() => Math.floor(nowMs() / 1e3));
5895
+ (0, import_react30.useEffect)(() => {
5896
+ setNowSec(Math.floor(nowMs() / 1e3));
5897
+ const handle = setInterval(() => {
5898
+ setNowSec(Math.floor(nowMs() / 1e3));
5899
+ }, tickMs);
5900
+ return () => clearInterval(handle);
5901
+ }, [tickMs, nowMs]);
5902
+ return (0, import_react30.useMemo)(
5903
+ () => resolveRollingWindow({ range: options.range, nowSec, interval: options.interval }),
5904
+ [options.range, options.interval, nowSec]
5905
+ );
5906
+ };
5907
+
5005
5908
  // src/use-market-orderbook.ts
5006
- var import_react_query24 = require("@tanstack/react-query");
5909
+ var import_react_query25 = require("@tanstack/react-query");
5007
5910
  function useMarketOrderbook(options) {
5008
5911
  var _a, _b, _c, _d, _e, _f, _g;
5009
- const queryClient = (0, import_react_query24.useQueryClient)();
5912
+ const queryClient = (0, import_react_query25.useQueryClient)();
5010
5913
  const ws = useAggWebSocket();
5011
5914
  const isConnected = useAggWebSocketConnectionState();
5012
5915
  const {
@@ -5023,7 +5926,7 @@ function useMarketOrderbook(options) {
5023
5926
  enabled: enabled && !!selectedOutcomeId,
5024
5927
  orderbook: true
5025
5928
  });
5026
- const liveQueries = (0, import_react_query24.useQueries)({
5929
+ const liveQueries = (0, import_react_query25.useQueries)({
5027
5930
  queries: subscriptionIds.map((subscriptionId) => ({
5028
5931
  queryKey: marketDataKeys.live(subscriptionId),
5029
5932
  queryFn: () => createMarketLiveState(subscriptionId),
@@ -5089,7 +5992,7 @@ function useMarketOrderbook(options) {
5089
5992
  }
5090
5993
 
5091
5994
  // src/use-order-book.ts
5092
- var import_react_query25 = require("@tanstack/react-query");
5995
+ var import_react_query26 = require("@tanstack/react-query");
5093
5996
  function useOrderBook(options) {
5094
5997
  const client = useAggClient();
5095
5998
  const { orderbooks, enabled = true, canonicalMarketId } = options;
@@ -5102,7 +6005,7 @@ function useOrderBook(options) {
5102
6005
  venueMarketOutcomeId: outcome.id
5103
6006
  })) : void 0
5104
6007
  });
5105
- const batchedResult = (0, import_react_query25.useQuery)({
6008
+ const batchedResult = (0, import_react_query26.useQuery)({
5106
6009
  queryKey: requestedVenueMarketIds.length ? ["orderbooks", requestedVenueMarketIds, null] : ["orderbooks", "__disabled__", null],
5107
6010
  queryFn: ({ signal }) => client.getOrderbooks(
5108
6011
  {
@@ -5115,7 +6018,7 @@ function useOrderBook(options) {
5115
6018
  gcTime: 5 * 6e4,
5116
6019
  refetchOnWindowFocus: false,
5117
6020
  retry: 1,
5118
- placeholderData: import_react_query25.keepPreviousData
6021
+ placeholderData: import_react_query26.keepPreviousData
5119
6022
  });
5120
6023
  const data = (() => {
5121
6024
  var _a, _b;
@@ -5170,7 +6073,7 @@ function useOrderBook(options) {
5170
6073
  }
5171
6074
 
5172
6075
  // src/use-orderbook-quote.ts
5173
- var import_react_query26 = require("@tanstack/react-query");
6076
+ var import_react_query27 = require("@tanstack/react-query");
5174
6077
  var QUOTE_DEBOUNCE_MS = 300;
5175
6078
  var createUnavailableOrderbookError = (message, code, retryable) => {
5176
6079
  const error = new Error(message);
@@ -5232,7 +6135,7 @@ function useOrderbookQuote(options) {
5232
6135
  const { marketId, side, size, enabled = true } = options;
5233
6136
  const debouncedSize = useDebouncedValue(size, QUOTE_DEBOUNCE_MS);
5234
6137
  const shouldFetch = enabled && !!marketId && debouncedSize > 0;
5235
- const query = (0, import_react_query26.useQuery)({
6138
+ const query = (0, import_react_query27.useQuery)({
5236
6139
  queryKey: marketId ? marketDataKeys.orderbookQuote(marketId, side, debouncedSize) : ["market-data", "orderbook-quote", "__disabled__"],
5237
6140
  queryFn: () => __async(null, null, function* () {
5238
6141
  var _a2, _b, _c, _d;
@@ -5263,7 +6166,7 @@ function useOrderbookQuote(options) {
5263
6166
  staleTime: 1e4,
5264
6167
  gcTime: 5 * 6e4,
5265
6168
  retry: 1,
5266
- placeholderData: import_react_query26.keepPreviousData
6169
+ placeholderData: import_react_query27.keepPreviousData
5267
6170
  });
5268
6171
  return {
5269
6172
  data: (_a = query.data) != null ? _a : null,
@@ -5274,12 +6177,12 @@ function useOrderbookQuote(options) {
5274
6177
  }
5275
6178
 
5276
6179
  // src/use-orders.ts
5277
- var import_react_query27 = require("@tanstack/react-query");
6180
+ var import_react_query28 = require("@tanstack/react-query");
5278
6181
  function useOrders(options = {}) {
5279
6182
  var _a, _b, _c, _d;
5280
6183
  const client = useAggClient();
5281
6184
  const { userId, status, limit = 50, offset = 0, enabled = true } = options;
5282
- const query = (0, import_react_query27.useQuery)({
6185
+ const query = (0, import_react_query28.useQuery)({
5283
6186
  queryKey: ["orders", userId != null ? userId : "me", status != null ? status : "all", limit, offset],
5284
6187
  queryFn: () => client.getOrders({
5285
6188
  userId,
@@ -5296,16 +6199,16 @@ function useOrders(options = {}) {
5296
6199
  }
5297
6200
 
5298
6201
  // src/use-search.ts
5299
- var import_react_query28 = require("@tanstack/react-query");
5300
- var import_react25 = require("react");
6202
+ var import_react_query29 = require("@tanstack/react-query");
6203
+ var import_react31 = require("react");
5301
6204
  function useSearch(options) {
5302
6205
  var _a, _b, _c;
5303
- const client = (0, import_react25.useContext)(AggClientContext);
5304
- const queryClient = (0, import_react25.useContext)(import_react_query28.QueryClientContext);
5305
- const [fallbackQueryClient] = (0, import_react25.useState)(() => new import_react_query28.QueryClient());
5306
- const { q, type, categoryIds, limit = 20, enabled = true } = options;
6206
+ const client = (0, import_react31.useContext)(AggClientContext);
6207
+ const queryClient = (0, import_react31.useContext)(import_react_query29.QueryClientContext);
6208
+ const [fallbackQueryClient] = (0, import_react31.useState)(() => new import_react_query29.QueryClient());
6209
+ const { q, type, categoryIds, limit = 20, enabled = true, deep = false } = options;
5307
6210
  const isEnabled = enabled && q.length > 0;
5308
- (0, import_react25.useEffect)(() => {
6211
+ (0, import_react31.useEffect)(() => {
5309
6212
  if (queryClient) return void 0;
5310
6213
  fallbackQueryClient.mount();
5311
6214
  return () => {
@@ -5315,9 +6218,11 @@ function useSearch(options) {
5315
6218
  if (isEnabled && !client) {
5316
6219
  throw new Error("useSearch must be used within an <AggProvider>");
5317
6220
  }
5318
- const query = (0, import_react_query28.useInfiniteQuery)(
6221
+ const query = (0, import_react_query29.useInfiniteQuery)(
5319
6222
  {
5320
- queryKey: ["search", q, type, (_a = categoryIds == null ? void 0 : categoryIds.join(",")) != null ? _a : "", limit],
6223
+ // deep is part of the key TanStack treats deep vs light as
6224
+ // independent queries so users can have both modes cached side-by-side.
6225
+ queryKey: ["search", q, type, (_a = categoryIds == null ? void 0 : categoryIds.join(",")) != null ? _a : "", limit, deep],
5321
6226
  queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
5322
6227
  if (!client) {
5323
6228
  throw new Error("useSearch must be used within an <AggProvider>");
@@ -5327,7 +6232,8 @@ function useSearch(options) {
5327
6232
  type,
5328
6233
  categoryIds,
5329
6234
  limit,
5330
- cursor: pageParam
6235
+ cursor: pageParam,
6236
+ deep
5331
6237
  });
5332
6238
  return res;
5333
6239
  }),
@@ -5337,7 +6243,7 @@ function useSearch(options) {
5337
6243
  if (!lastPage.hasMore) return void 0;
5338
6244
  return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
5339
6245
  },
5340
- placeholderData: import_react_query28.keepPreviousData,
6246
+ placeholderData: import_react_query29.keepPreviousData,
5341
6247
  enabled: isEnabled && !!client
5342
6248
  },
5343
6249
  queryClient != null ? queryClient : fallbackQueryClient
@@ -5355,8 +6261,95 @@ function useSearch(options) {
5355
6261
  };
5356
6262
  }
5357
6263
 
6264
+ // src/use-market-search.ts
6265
+ var import_react32 = require("react");
6266
+ function useMarketSearch(options) {
6267
+ var _a;
6268
+ const {
6269
+ type,
6270
+ categoryIds,
6271
+ limit = 20,
6272
+ debounceMs = 200,
6273
+ enableSuggestions = true,
6274
+ minLength = 1
6275
+ } = options;
6276
+ const [query, setQueryState] = (0, import_react32.useState)("");
6277
+ const [submittedQuery, setSubmittedQuery] = (0, import_react32.useState)(null);
6278
+ const debouncedQuery = useDebouncedValue(query, debounceMs);
6279
+ const trimmedDebounced = debouncedQuery.trim();
6280
+ const suggestionsEnabled = enableSuggestions && trimmedDebounced.length >= minLength;
6281
+ const suggestionsQuery = useSearch({
6282
+ q: trimmedDebounced,
6283
+ type,
6284
+ categoryIds,
6285
+ limit,
6286
+ enabled: suggestionsEnabled,
6287
+ deep: false
6288
+ });
6289
+ const submittedQ = (_a = submittedQuery == null ? void 0 : submittedQuery.trim()) != null ? _a : "";
6290
+ const resultsQuery = useSearch({
6291
+ q: submittedQ,
6292
+ type,
6293
+ categoryIds,
6294
+ limit,
6295
+ enabled: submittedQ.length > 0,
6296
+ deep: true
6297
+ });
6298
+ const setQuery = (0, import_react32.useCallback)((value) => {
6299
+ setQueryState(value);
6300
+ }, []);
6301
+ const submit = (0, import_react32.useCallback)(
6302
+ (q) => {
6303
+ const target = (q != null ? q : query).trim();
6304
+ if (target.length === 0) return;
6305
+ setSubmittedQuery(target);
6306
+ },
6307
+ [query]
6308
+ );
6309
+ const clear = (0, import_react32.useCallback)(() => {
6310
+ setQueryState("");
6311
+ setSubmittedQuery(null);
6312
+ }, []);
6313
+ return {
6314
+ /** Current input value (controlled). */
6315
+ query,
6316
+ /** Update the input value. Triggers the debounced typeahead. */
6317
+ setQuery,
6318
+ /** The query value that produced the current `results`, or null if none. */
6319
+ submittedQuery,
6320
+ /** Fire a deep search. Use this on Enter / Search button. */
6321
+ submit,
6322
+ /** Reset both input and results state. */
6323
+ clear,
6324
+ /**
6325
+ * Typeahead state. Backed by a light /search call (no reranker).
6326
+ * `data` is paginated like `useSearch.data` (flattened across pages).
6327
+ */
6328
+ suggestions: {
6329
+ data: suggestionsQuery.data,
6330
+ isLoading: suggestionsQuery.isLoading,
6331
+ isError: suggestionsQuery.isError,
6332
+ error: suggestionsQuery.error
6333
+ },
6334
+ /**
6335
+ * Full-page results state. Backed by a deep /search call (reranker on).
6336
+ * Cursor pagination is exposed via `fetchNextPage` / `hasNextPage`.
6337
+ */
6338
+ results: {
6339
+ data: resultsQuery.data,
6340
+ isLoading: resultsQuery.isLoading,
6341
+ isError: resultsQuery.isError,
6342
+ error: resultsQuery.error,
6343
+ hasNextPage: resultsQuery.hasNextPage,
6344
+ fetchNextPage: resultsQuery.fetchNextPage,
6345
+ isFetchingNextPage: resultsQuery.isFetchingNextPage
6346
+ }
6347
+ };
6348
+ }
6349
+
5358
6350
  // src/use-smart-route.ts
5359
- var import_react_query29 = require("@tanstack/react-query");
6351
+ var import_react_query30 = require("@tanstack/react-query");
6352
+ var SMART_ROUTE_STALE_TIME_MS = 2e4;
5360
6353
  function useSmartRoute(options) {
5361
6354
  var _a, _b;
5362
6355
  const client = useAggClient();
@@ -5371,10 +6364,12 @@ function useSmartRoute(options) {
5371
6364
  chainBalances,
5372
6365
  slipCapBps,
5373
6366
  compareVenues,
5374
- enabled = true
6367
+ deepEstimate,
6368
+ enabled = true,
6369
+ staleTimeMs = SMART_ROUTE_STALE_TIME_MS
5375
6370
  } = options;
5376
6371
  const resolvedVenueMarketOutcomeId = (_a = venueMarketOutcomeId != null ? venueMarketOutcomeId : venueMarketId) != null ? _a : outcomeId;
5377
- const query = (0, import_react_query29.useQuery)({
6372
+ const query = (0, import_react_query30.useQuery)({
5378
6373
  queryKey: [
5379
6374
  "smart-route",
5380
6375
  resolvedVenueMarketOutcomeId,
@@ -5384,7 +6379,8 @@ function useSmartRoute(options) {
5384
6379
  sellShares != null ? sellShares : null,
5385
6380
  chainBalances ? JSON.stringify(chainBalances) : null,
5386
6381
  slipCapBps != null ? slipCapBps : null,
5387
- compareVenues != null ? compareVenues : false
6382
+ compareVenues != null ? compareVenues : false,
6383
+ deepEstimate != null ? deepEstimate : false
5388
6384
  ],
5389
6385
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
5390
6386
  return client.getSmartRoute(
@@ -5396,17 +6392,19 @@ function useSmartRoute(options) {
5396
6392
  sellShares,
5397
6393
  chainBalances,
5398
6394
  slipCapBps,
5399
- compareVenues
6395
+ compareVenues,
6396
+ deepEstimate
5400
6397
  },
5401
6398
  { signal }
5402
6399
  );
5403
6400
  }),
5404
6401
  enabled: enabled && !!resolvedVenueMarketOutcomeId && ((maxSpend != null ? maxSpend : 0) > 0 || (sellShares != null ? sellShares : 0) > 0),
5405
- staleTime: 1e4,
6402
+ staleTime: staleTimeMs,
6403
+ refetchInterval: staleTimeMs > 0 ? staleTimeMs : false,
5406
6404
  gcTime: 6e4,
5407
6405
  refetchOnWindowFocus: false,
5408
6406
  retry: 1,
5409
- placeholderData: import_react_query29.keepPreviousData
6407
+ placeholderData: import_react_query30.keepPreviousData
5410
6408
  });
5411
6409
  const error = query.error;
5412
6410
  return {
@@ -5419,12 +6417,12 @@ function useSmartRoute(options) {
5419
6417
  }
5420
6418
 
5421
6419
  // src/use-user-holdings.ts
5422
- var import_react_query30 = require("@tanstack/react-query");
6420
+ var import_react_query31 = require("@tanstack/react-query");
5423
6421
  function useUserHoldings(options) {
5424
6422
  var _a, _b;
5425
6423
  const client = useAggClient();
5426
6424
  const { venue, venueMarketId, venueEventId, enabled = true } = options;
5427
- const query = (0, import_react_query30.useInfiniteQuery)({
6425
+ const query = (0, import_react_query31.useInfiniteQuery)({
5428
6426
  queryKey: ["user-holdings", venue, venueMarketId, venueEventId],
5429
6427
  queryFn: (_0) => __async(null, [_0], function* ({ pageParam }) {
5430
6428
  return client.getUserHoldings({
@@ -5450,15 +6448,15 @@ function useUserHoldings(options) {
5450
6448
  }
5451
6449
 
5452
6450
  // src/use-enriched-venue-event.ts
5453
- var import_react27 = require("react");
6451
+ var import_react34 = require("react");
5454
6452
 
5455
6453
  // src/use-venue-event.ts
5456
- var import_react_query31 = require("@tanstack/react-query");
6454
+ var import_react_query32 = require("@tanstack/react-query");
5457
6455
  function useVenueEvent(options) {
5458
6456
  var _a;
5459
6457
  const client = useAggClient();
5460
6458
  const { eventId, enabled = true } = options;
5461
- const query = (0, import_react_query31.useQuery)({
6459
+ const query = (0, import_react_query32.useQuery)({
5462
6460
  queryKey: ["venue-event", eventId],
5463
6461
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
5464
6462
  return client.getVenueEventById(eventId, { signal });
@@ -5477,13 +6475,13 @@ function useVenueEvent(options) {
5477
6475
  }
5478
6476
 
5479
6477
  // src/use-venue-markets.ts
5480
- var import_react_query32 = require("@tanstack/react-query");
5481
- var import_react26 = require("react");
6478
+ var import_react_query33 = require("@tanstack/react-query");
6479
+ var import_react33 = require("react");
5482
6480
  function useVenueMarkets(options) {
5483
6481
  var _a, _b, _c, _d, _e;
5484
- const client = (0, import_react26.useContext)(AggClientContext);
5485
- const queryClient = (0, import_react26.useContext)(import_react_query32.QueryClientContext);
5486
- const [fallbackQueryClient] = (0, import_react26.useState)(() => new import_react_query32.QueryClient());
6482
+ const client = (0, import_react33.useContext)(AggClientContext);
6483
+ const queryClient = (0, import_react33.useContext)(import_react_query33.QueryClientContext);
6484
+ const [fallbackQueryClient] = (0, import_react33.useState)(() => new import_react_query33.QueryClient());
5487
6485
  const venue = options == null ? void 0 : options.venue;
5488
6486
  const venueEventId = options == null ? void 0 : options.venueEventId;
5489
6487
  const search = options == null ? void 0 : options.search;
@@ -5494,7 +6492,7 @@ function useVenueMarkets(options) {
5494
6492
  const limit = (_b = options == null ? void 0 : options.limit) != null ? _b : 20;
5495
6493
  const sortBy = options == null ? void 0 : options.sortBy;
5496
6494
  const sortDir = options == null ? void 0 : options.sortDir;
5497
- (0, import_react26.useEffect)(() => {
6495
+ (0, import_react33.useEffect)(() => {
5498
6496
  if (queryClient) return void 0;
5499
6497
  fallbackQueryClient.mount();
5500
6498
  return () => {
@@ -5504,7 +6502,7 @@ function useVenueMarkets(options) {
5504
6502
  if (enabled && !client) {
5505
6503
  throw new Error("useVenueMarkets must be used within an <AggProvider>");
5506
6504
  }
5507
- const query = (0, import_react_query32.useInfiniteQuery)(
6505
+ const query = (0, import_react_query33.useInfiniteQuery)(
5508
6506
  {
5509
6507
  queryKey: [
5510
6508
  "venue-markets",
@@ -5574,7 +6572,7 @@ function useEnrichedVenueEvent(options) {
5574
6572
  sortBy: "yesPrice",
5575
6573
  sortDir: "desc"
5576
6574
  });
5577
- const enrichedEvent = (0, import_react27.useMemo)(() => {
6575
+ const enrichedEvent = (0, import_react34.useMemo)(() => {
5578
6576
  if (!event) return void 0;
5579
6577
  if (markets.length === 0) return event;
5580
6578
  return mergeEventWithFullMarkets(event, markets);
@@ -5588,13 +6586,13 @@ function useEnrichedVenueEvent(options) {
5588
6586
  }
5589
6587
 
5590
6588
  // src/use-venue-events.ts
5591
- var import_react_query33 = require("@tanstack/react-query");
5592
- var import_react28 = require("react");
6589
+ var import_react_query34 = require("@tanstack/react-query");
6590
+ var import_react35 = require("react");
5593
6591
  function useVenueEvents(options) {
5594
6592
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
5595
- const client = (0, import_react28.useContext)(AggClientContext);
5596
- const queryClient = (0, import_react28.useContext)(import_react_query33.QueryClientContext);
5597
- const [fallbackQueryClient] = (0, import_react28.useState)(() => new import_react_query33.QueryClient());
6593
+ const client = (0, import_react35.useContext)(AggClientContext);
6594
+ const queryClient = (0, import_react35.useContext)(import_react_query34.QueryClientContext);
6595
+ const [fallbackQueryClient] = (0, import_react35.useState)(() => new import_react_query34.QueryClient());
5598
6596
  const venues = options == null ? void 0 : options.venues;
5599
6597
  const search = options == null ? void 0 : options.search;
5600
6598
  const categoryIds = options == null ? void 0 : options.categoryIds;
@@ -5609,7 +6607,7 @@ function useVenueEvents(options) {
5609
6607
  const maxYesPrice = options == null ? void 0 : options.maxYesPrice;
5610
6608
  const endDateFrom = options == null ? void 0 : options.endDateFrom;
5611
6609
  const initialPages = options == null ? void 0 : options.initialPages;
5612
- (0, import_react28.useEffect)(() => {
6610
+ (0, import_react35.useEffect)(() => {
5613
6611
  if (queryClient) return void 0;
5614
6612
  fallbackQueryClient.mount();
5615
6613
  return () => {
@@ -5619,7 +6617,7 @@ function useVenueEvents(options) {
5619
6617
  if (enabled && !client) {
5620
6618
  throw new Error("useVenueEvents must be used within an <AggProvider>");
5621
6619
  }
5622
- const query = (0, import_react_query33.useInfiniteQuery)(
6620
+ const query = (0, import_react_query34.useInfiniteQuery)(
5623
6621
  {
5624
6622
  queryKey: [
5625
6623
  queryKeyScope,
@@ -5662,13 +6660,13 @@ function useVenueEvents(options) {
5662
6660
  return (_a2 = lastPage.nextCursor) != null ? _a2 : void 0;
5663
6661
  },
5664
6662
  // TODO: RMIK - Comment out to show skeletons on category switch
5665
- placeholderData: import_react_query33.keepPreviousData,
6663
+ placeholderData: import_react_query34.keepPreviousData,
5666
6664
  enabled: enabled && !!client
5667
6665
  },
5668
6666
  queryClient != null ? queryClient : fallbackQueryClient
5669
6667
  );
5670
- const prefetchedRef = (0, import_react28.useRef)(false);
5671
- (0, import_react28.useEffect)(() => {
6668
+ const prefetchedRef = (0, import_react35.useRef)(false);
6669
+ (0, import_react35.useEffect)(() => {
5672
6670
  var _a2, _b2;
5673
6671
  if (prefetchedRef.current) return;
5674
6672
  if (!initialPages || initialPages <= 1) return;
@@ -5686,7 +6684,7 @@ function useVenueEvents(options) {
5686
6684
  query.hasNextPage,
5687
6685
  query.fetchNextPage
5688
6686
  ]);
5689
- const events = (0, import_react28.useMemo)(
6687
+ const events = (0, import_react35.useMemo)(
5690
6688
  () => {
5691
6689
  var _a2, _b2;
5692
6690
  return (_b2 = (_a2 = query.data) == null ? void 0 : _a2.pages.flatMap((page) => page.data)) != null ? _b2 : [];
@@ -5704,7 +6702,7 @@ function useVenueEvents(options) {
5704
6702
  }
5705
6703
 
5706
6704
  // src/use-venue-market-midpoints.ts
5707
- var import_react_query34 = require("@tanstack/react-query");
6705
+ var import_react_query35 = require("@tanstack/react-query");
5708
6706
  var MAX_VENUE_MARKET_IDS_PER_REQUEST = 200;
5709
6707
  var normalizeVenueMarketIds2 = (venueMarketIds) => {
5710
6708
  return [
@@ -5740,7 +6738,7 @@ function useVenueMarketMidpoints(options) {
5740
6738
  const client = useAggClient();
5741
6739
  const enabled = (_a = options.enabled) != null ? _a : true;
5742
6740
  const requestedVenueMarketIds = normalizeVenueMarketIds2(options.venueMarketIds);
5743
- const query = (0, import_react_query34.useQuery)({
6741
+ const query = (0, import_react_query35.useQuery)({
5744
6742
  queryKey: requestedVenueMarketIds.length ? ["venue-market-midpoints", requestedVenueMarketIds] : ["venue-market-midpoints", "__disabled__"],
5745
6743
  queryFn: (_0) => __async(null, [_0], function* ({ signal }) {
5746
6744
  const venueMarketIdChunks = chunkVenueMarketIds(requestedVenueMarketIds);
@@ -5749,7 +6747,7 @@ function useVenueMarketMidpoints(options) {
5749
6747
  }
5750
6748
  const chunkResponses = yield Promise.all(
5751
6749
  venueMarketIdChunks.map((venueMarketIds) => {
5752
- return client.getMidpoints({ venueMarketIds }, { signal });
6750
+ return client.getMidpoints({ venueMarketIds, bestPrice: true }, { signal });
5753
6751
  })
5754
6752
  );
5755
6753
  return mergeMidpointResponses(chunkResponses);
@@ -5759,7 +6757,7 @@ function useVenueMarketMidpoints(options) {
5759
6757
  gcTime: 5 * 6e4,
5760
6758
  refetchOnWindowFocus: false,
5761
6759
  retry: 1,
5762
- placeholderData: import_react_query34.keepPreviousData
6760
+ placeholderData: import_react_query35.keepPreviousData
5763
6761
  });
5764
6762
  const midpointRows = (_c = (_b = query.data) == null ? void 0 : _b.data) != null ? _c : [];
5765
6763
  const midpointsByVenueMarketId = mapMidpointsByVenueMarketId(midpointRows);
@@ -5794,60 +6792,68 @@ function computePriceGaps(input) {
5794
6792
  }
5795
6793
 
5796
6794
  // src/use-viewport-midpoints.ts
5797
- var import_react29 = require("react");
5798
- var normalizeOutcomeLabel = (value) => value.trim().toLowerCase();
5799
- var resolveYesMidpoint = (outcomes) => {
5800
- if (!(outcomes == null ? void 0 : outcomes.length)) return void 0;
5801
- const yesOutcome = outcomes.find((outcome) => normalizeOutcomeLabel(outcome.label) === "yes");
5802
- return yesOutcome == null ? void 0 : yesOutcome.midpoint;
6795
+ var import_react36 = require("react");
6796
+ var buildOutcomeMidpointMap = (outcomes) => {
6797
+ const m = /* @__PURE__ */ new Map();
6798
+ if (!outcomes) return m;
6799
+ for (const o of outcomes) {
6800
+ if (o.midpoint != null) m.set(o.venueMarketOutcomeId, o.midpoint);
6801
+ }
6802
+ return m;
5803
6803
  };
5804
6804
  var resolveUncachedVisibleMarketIds = (visibleMarkets, cache, inFlightIds) => {
6805
+ var _a;
6806
+ const seen = /* @__PURE__ */ new Set();
5805
6807
  const idsToFetch = [];
6808
+ const consider = (id) => {
6809
+ if (!id) return;
6810
+ if (seen.has(id)) return;
6811
+ if (inFlightIds.has(id)) return;
6812
+ if (cache.has(id)) return;
6813
+ seen.add(id);
6814
+ idsToFetch.push(id);
6815
+ };
5806
6816
  for (const market of visibleMarkets) {
5807
- if (inFlightIds.has(market.id)) continue;
5808
- if (cache.has(market.id)) continue;
5809
- idsToFetch.push(market.id);
6817
+ consider(market.id);
6818
+ for (const sibling of (_a = market.matchedVenueMarkets) != null ? _a : []) {
6819
+ consider(sibling.id);
6820
+ }
5810
6821
  }
5811
6822
  return idsToFetch;
5812
6823
  };
5813
6824
  var buildCachedMidpointEntries = (requestedVenueMarketIds, rows) => {
5814
- var _a, _b, _c;
6825
+ var _a;
5815
6826
  const rowsByVenueMarketId = new Map(rows.map((item) => [item.venueMarketId, item]));
5816
6827
  const nextCacheEntries = /* @__PURE__ */ new Map();
5817
6828
  for (const venueMarketId of requestedVenueMarketIds) {
5818
6829
  const item = rowsByVenueMarketId.get(venueMarketId);
5819
- const yesMidpoint = resolveYesMidpoint(item == null ? void 0 : item.outcomes);
5820
6830
  nextCacheEntries.set(venueMarketId, __spreadProps(__spreadValues({}, (item == null ? void 0 : item.venue) ? { venue: item.venue } : {}), {
5821
- midpoint: (_a = yesMidpoint != null ? yesMidpoint : item == null ? void 0 : item.midpoint) != null ? _a : null,
5822
- spread: (_b = item == null ? void 0 : item.spread) != null ? _b : null,
5823
- matched: ((_c = item == null ? void 0 : item.matched) != null ? _c : []).map((matched) => {
5824
- var _a2, _b2;
5825
- return __spreadValues({
5826
- venueMarketId: matched.venueMarketId,
5827
- midpoint: (_a2 = matched.midpoint) != null ? _a2 : null,
5828
- spread: (_b2 = matched.spread) != null ? _b2 : null
5829
- }, matched.venue ? { venue: matched.venue } : {});
5830
- })
6831
+ ownOutcomes: buildOutcomeMidpointMap(item == null ? void 0 : item.outcomes),
6832
+ matched: ((_a = item == null ? void 0 : item.matched) != null ? _a : []).map((sib) => __spreadProps(__spreadValues({
6833
+ venueMarketId: sib.venueMarketId
6834
+ }, sib.venue ? { venue: sib.venue } : {}), {
6835
+ outcomes: buildOutcomeMidpointMap(sib.outcomes)
6836
+ }))
5831
6837
  }));
5832
6838
  }
5833
6839
  return nextCacheEntries;
5834
6840
  };
5835
6841
  function useViewportMidpoints(visibleMarkets) {
5836
6842
  const client = useAggClient();
5837
- const [cache, setCache] = (0, import_react29.useState)(() => /* @__PURE__ */ new Map());
5838
- const inFlightRef = (0, import_react29.useRef)(/* @__PURE__ */ new Set());
5839
- const visibleRef = (0, import_react29.useRef)(visibleMarkets);
6843
+ const [cache, setCache] = (0, import_react36.useState)(() => /* @__PURE__ */ new Map());
6844
+ const inFlightRef = (0, import_react36.useRef)(/* @__PURE__ */ new Set());
6845
+ const visibleRef = (0, import_react36.useRef)(visibleMarkets);
5840
6846
  visibleRef.current = visibleMarkets;
5841
- const visibleFp = (0, import_react29.useMemo)(
6847
+ const visibleFp = (0, import_react36.useMemo)(
5842
6848
  () => [...new Set(visibleMarkets.map((m) => m.id))].sort().join("|"),
5843
6849
  [visibleMarkets]
5844
6850
  );
5845
- (0, import_react29.useEffect)(() => {
6851
+ (0, import_react36.useEffect)(() => {
5846
6852
  const toFetch = resolveUncachedVisibleMarketIds(visibleRef.current, cache, inFlightRef.current);
5847
6853
  if (!toFetch.length) return;
5848
6854
  let cancelled = false;
5849
6855
  for (const id of toFetch) inFlightRef.current.add(id);
5850
- client.getMidpoints(toFetch).then((resp) => {
6856
+ client.getMidpoints(toFetch, { bestPrice: true }).then((resp) => {
5851
6857
  var _a;
5852
6858
  if (cancelled) return;
5853
6859
  const nextCacheEntries = buildCachedMidpointEntries(toFetch, (_a = resp.data) != null ? _a : []);
@@ -5866,29 +6872,31 @@ function useViewportMidpoints(visibleMarkets) {
5866
6872
  cancelled = true;
5867
6873
  };
5868
6874
  }, [visibleFp, cache]);
5869
- const { prices, venueByOutcomeId } = (0, import_react29.useMemo)(() => {
5870
- var _a, _b, _c, _d, _e, _f;
6875
+ const { prices, venueByOutcomeId } = (0, import_react36.useMemo)(() => {
6876
+ var _a, _b, _c, _d;
5871
6877
  const map = /* @__PURE__ */ new Map();
5872
6878
  const venueMap = /* @__PURE__ */ new Map();
5873
6879
  for (const market of visibleMarkets) {
5874
6880
  const entry = cache.get(market.id);
5875
6881
  if (!entry) continue;
5876
- let mid = entry.midpoint;
5877
- let midVenue = (_a = entry.venue) != null ? _a : market.venue;
5878
- for (const m of entry.matched) {
5879
- const matchedFromCache = (_b = cache.get(m.venueMarketId)) == null ? void 0 : _b.midpoint;
5880
- const candidateMidpoint = matchedFromCache != null ? matchedFromCache : m.midpoint;
5881
- if (candidateMidpoint == null) continue;
5882
- if (mid == null || candidateMidpoint < mid) {
5883
- mid = candidateMidpoint;
5884
- midVenue = (_e = (_d = (_c = cache.get(m.venueMarketId)) == null ? void 0 : _c.venue) != null ? _d : m.venue) != null ? _e : market.venue;
5885
- }
5886
- }
5887
- if (mid == null) continue;
6882
+ const ownVenue = (_a = entry.venue) != null ? _a : market.venue;
5888
6883
  for (const outcome of market.venueMarketOutcomes) {
5889
- const isYes = ((_f = outcome.label) == null ? void 0 : _f.toLowerCase()) === "yes";
5890
- map.set(outcome.id, isYes ? mid : 1 - mid);
5891
- venueMap.set(outcome.id, midVenue);
6884
+ let best = (_b = entry.ownOutcomes.get(outcome.id)) != null ? _b : null;
6885
+ let bestVenue = best != null ? ownVenue : null;
6886
+ for (const ref of (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : []) {
6887
+ const sib = entry.matched.find((m) => m.venueMarketId === ref.venueMarketId);
6888
+ if (!sib) continue;
6889
+ const sibMidpoint = sib.outcomes.get(ref.venueMarketOutcomeId);
6890
+ if (sibMidpoint == null) continue;
6891
+ if (best == null || sibMidpoint < best) {
6892
+ best = sibMidpoint;
6893
+ bestVenue = (_d = sib.venue) != null ? _d : bestVenue;
6894
+ }
6895
+ }
6896
+ if (best != null) {
6897
+ map.set(outcome.id, best);
6898
+ if (bestVenue) venueMap.set(outcome.id, bestVenue);
6899
+ }
5892
6900
  }
5893
6901
  }
5894
6902
  return { prices: map, venueByOutcomeId: venueMap };
@@ -5897,15 +6905,15 @@ function useViewportMidpoints(visibleMarkets) {
5897
6905
  }
5898
6906
 
5899
6907
  // src/use-visible-ids.ts
5900
- var import_react30 = require("react");
6908
+ var import_react37 = require("react");
5901
6909
  function useVisibleIds(options = {}) {
5902
6910
  const { rootMargin = "0px", threshold = 0 } = options;
5903
- const [visibleIds, setVisibleIds] = (0, import_react30.useState)(() => /* @__PURE__ */ new Set());
5904
- const observerRef = (0, import_react30.useRef)(null);
5905
- const elementsRef = (0, import_react30.useRef)(/* @__PURE__ */ new Map());
5906
- const elementIdRef = (0, import_react30.useRef)(/* @__PURE__ */ new WeakMap());
5907
- const callbackRefsRef = (0, import_react30.useRef)(/* @__PURE__ */ new Map());
5908
- (0, import_react30.useEffect)(() => {
6911
+ const [visibleIds, setVisibleIds] = (0, import_react37.useState)(() => /* @__PURE__ */ new Set());
6912
+ const observerRef = (0, import_react37.useRef)(null);
6913
+ const elementsRef = (0, import_react37.useRef)(/* @__PURE__ */ new Map());
6914
+ const elementIdRef = (0, import_react37.useRef)(/* @__PURE__ */ new WeakMap());
6915
+ const callbackRefsRef = (0, import_react37.useRef)(/* @__PURE__ */ new Map());
6916
+ (0, import_react37.useEffect)(() => {
5909
6917
  if (typeof IntersectionObserver === "undefined") return;
5910
6918
  const observer = new IntersectionObserver(
5911
6919
  (entries) => {
@@ -5937,7 +6945,7 @@ function useVisibleIds(options = {}) {
5937
6945
  observerRef.current = null;
5938
6946
  };
5939
6947
  }, [rootMargin, threshold]);
5940
- const register = (0, import_react30.useCallback)((id) => {
6948
+ const register = (0, import_react37.useCallback)((id) => {
5941
6949
  const existing = callbackRefsRef.current.get(id);
5942
6950
  if (existing) return existing;
5943
6951
  const callback = (el) => {
@@ -5970,12 +6978,12 @@ function useVisibleIds(options = {}) {
5970
6978
  }
5971
6979
 
5972
6980
  // src/use-app-config.ts
5973
- var import_react_query35 = require("@tanstack/react-query");
6981
+ var import_react_query36 = require("@tanstack/react-query");
5974
6982
  var FIVE_MINUTES = 5 * 60 * 1e3;
5975
6983
  function useAppConfig() {
5976
- var _a, _b, _c, _d, _e, _f;
6984
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5977
6985
  const client = useAggClient();
5978
- const query = (0, import_react_query35.useQuery)({
6986
+ const query = (0, import_react_query36.useQuery)({
5979
6987
  queryKey: ["agg", "app-config"],
5980
6988
  queryFn: () => client.getAppConfig(),
5981
6989
  staleTime: FIVE_MINUTES
@@ -5984,6 +6992,7 @@ function useAppConfig() {
5984
6992
  disabledVenues: (_b = (_a = query.data) == null ? void 0 : _a.disabledVenues) != null ? _b : [],
5985
6993
  disabledCategoryPresets: (_d = (_c = query.data) == null ? void 0 : _c.disabledCategoryPresets) != null ? _d : [],
5986
6994
  earlyAccessEnabled: (_f = (_e = query.data) == null ? void 0 : _e.earlyAccessEnabled) != null ? _f : false,
6995
+ authOptions: (_h = (_g = query.data) == null ? void 0 : _g.authOptions) != null ? _h : [],
5987
6996
  isLoading: query.isLoading,
5988
6997
  error: query.error
5989
6998
  };
@@ -6004,6 +7013,8 @@ function useAppConfig() {
6004
7013
  MatchType,
6005
7014
  QueryClient,
6006
7015
  QueryClientProvider,
7016
+ RedeemRejectedError,
7017
+ TradeSide,
6007
7018
  TurnstileChallengeError,
6008
7019
  Venue,
6009
7020
  computeClosedPositionTotals,
@@ -6018,9 +7029,13 @@ function useAppConfig() {
6018
7029
  getWalletAddressFromUserProfile,
6019
7030
  invalidateBalanceQueries,
6020
7031
  invalidatePositionQueries,
7032
+ invalidateUserActivityQueries,
7033
+ invalidateUserMoneyState,
7034
+ mergeBestPricesPreferringLive,
6021
7035
  optimizedImageUrl,
6022
7036
  parseEmail,
6023
7037
  parseEmailStrict,
7038
+ rangeToSeconds,
6024
7039
  requestAggAuthChooserOpen,
6025
7040
  resolveAggUiLabels,
6026
7041
  resolveDefaultTradingMarket,
@@ -6028,6 +7043,7 @@ function useAppConfig() {
6028
7043
  resolveMarketTradingState,
6029
7044
  resolveMarketWinningOutcome,
6030
7045
  resolveOrderEligibility,
7046
+ resolveRollingWindow,
6031
7047
  resolveTradingStateKind,
6032
7048
  sortVenues,
6033
7049
  timeRangeToInterval,
@@ -6058,6 +7074,7 @@ function useAppConfig() {
6058
7074
  useGeoBlock,
6059
7075
  useLabels,
6060
7076
  useLinkAccount,
7077
+ useLiveBestPrices,
6061
7078
  useLiveCandleOverlay,
6062
7079
  useLiveCandles,
6063
7080
  useLiveMarket,
@@ -6067,6 +7084,7 @@ function useAppConfig() {
6067
7084
  useManagedBalances,
6068
7085
  useMarketChart,
6069
7086
  useMarketOrderbook,
7087
+ useMarketSearch,
6070
7088
  useMidpoints,
6071
7089
  useOnBalanceUpdate,
6072
7090
  useOnOrderSubmitted,
@@ -6082,11 +7100,15 @@ function useAppConfig() {
6082
7100
  useRampSession,
6083
7101
  useRedeem,
6084
7102
  useRedeemEligibleCount,
7103
+ useRedeemLifecycle,
7104
+ useRedeemLifecycles,
7105
+ useRollingChartWindow,
6085
7106
  useSdkLabels,
6086
7107
  useSdkUiConfig,
6087
7108
  useSearch,
6088
7109
  useSmartRoute,
6089
7110
  useSyncBalances,
7111
+ useTradableVenues,
6090
7112
  useUserActivity,
6091
7113
  useUserHoldings,
6092
7114
  useVenueEvent,
@@ -6095,7 +7117,9 @@ function useAppConfig() {
6095
7117
  useVenueMarkets,
6096
7118
  useViewportMidpoints,
6097
7119
  useVisibleIds,
7120
+ useWithdrawEstimate,
6098
7121
  useWithdrawFlow,
6099
7122
  useWithdrawManaged,
6100
- useWithdrawalLifecycle
7123
+ useWithdrawalLifecycle,
7124
+ userActivityQueryKeys
6101
7125
  });