@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.
@@ -370,6 +370,12 @@ var enUsLabels = {
370
370
  max: "Max",
371
371
  tokenLabel: "Receive token",
372
372
  networkLabel: "Receive network",
373
+ estimatedFees: "Est. fees",
374
+ networkReserve: "Network reserve",
375
+ networkReserveTooltipAria: "Network reserve details",
376
+ networkReserveTooltipLineOne: "This reserve helps cover network and bridge costs.",
377
+ networkReserveTooltipLineTwo: "Any unused amount stays in your balance.",
378
+ youReceive: "You'll receive",
373
379
  confirm: "Confirm withdrawal",
374
380
  successTitle: "Withdrawal submitted",
375
381
  successDescription: (tokenSymbol) => `Your ${tokenSymbol} withdrawal is being processed and will arrive shortly.`,
@@ -378,12 +384,16 @@ var enUsLabels = {
378
384
  // terminal status — otherwise a finished withdrawal would keep showing
379
385
  // "submitted / processing" forever and force the user to hard-refresh.
380
386
  successTitleCompleted: "Withdrawal complete",
381
- successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol} withdrawal has been delivered.`,
387
+ successDescriptionCompleted: (tokenSymbol) => `Your ${tokenSymbol} has been successfully sent to your wallet.`,
382
388
  successTitlePartial: "Withdrawal partially completed",
383
- successDescriptionPartial: (tokenSymbol) => `Some legs of your ${tokenSymbol} withdrawal completed; see details below.`,
389
+ successDescriptionPartial: () => "Part of your withdrawal was completed successfully, but the remaining funds failed to transfer and were returned to your balance.",
384
390
  successTitleFailed: "Withdrawal failed",
385
- successDescriptionFailed: (tokenSymbol) => `Your ${tokenSymbol} withdrawal could not be completed.`,
391
+ successDescriptionFailed: () => "We couldn't complete your withdrawal. Your funds were returned to your balance.",
392
+ retry: "Try Again",
393
+ close: "Close",
394
+ loadingDescription: "This may take a few minutes. You can safely close this window and check the status later in your activity.",
386
395
  summary: {
396
+ requestedWithdrawal: "Requested withdrawal",
387
397
  // The response is `pricingStatus: "unquoted"` — we don't know net
388
398
  // output until on-chain settlement. Calling this "Amount received"
389
399
  // would imply receipt before the lifecycle has confirmed. Keep it
@@ -401,6 +411,12 @@ var enUsLabels = {
401
411
  completed: "Withdrawal complete.",
402
412
  partial: "Withdrawal partially completed \u2014 see details below.",
403
413
  failed: "Withdrawal failed.",
414
+ loadingSteps: {
415
+ preparing: "Preparing funds",
416
+ bridging: "Bridging between networks",
417
+ sending: "Sending to your wallet",
418
+ confirming: "Waiting for network confirmation"
419
+ },
404
420
  steps: {
405
421
  bridge: (sourceChainName, destChainName) => `Bridging from ${sourceChainName} to ${destChainName}`,
406
422
  transfer: (destChainName) => `Transferring on ${destChainName}`
@@ -456,10 +472,37 @@ var enUsLabels = {
456
472
  externalWallet: "Deposit from external wallet",
457
473
  card: "Deposit with card"
458
474
  },
475
+ depositStatusTitles: {
476
+ connectedWallet: {
477
+ pending: "Processing deposit from connected wallet",
478
+ completed: "Successful deposit from connected wallet",
479
+ failed: "Failed deposit from connected wallet",
480
+ canceled: "Canceled deposit from connected wallet"
481
+ },
482
+ externalWallet: {
483
+ pending: "Processing deposit from external wallet",
484
+ completed: "Successful deposit from external wallet",
485
+ failed: "Failed deposit from external wallet",
486
+ canceled: "Canceled deposit from external wallet"
487
+ },
488
+ card: {
489
+ pending: "Processing deposit with card",
490
+ completed: "Successful deposit with card",
491
+ failed: "Failed deposit with card",
492
+ canceled: "Canceled deposit with card"
493
+ }
494
+ },
495
+ withdrawalStatusTitles: {
496
+ pending: "Processing withdrawal",
497
+ completed: "Successful withdrawal",
498
+ failed: "Failed withdrawal",
499
+ canceled: "Canceled withdrawal"
500
+ },
459
501
  // Activity-row title for any withdrawal regardless of lifecycle
460
- // state (pending / completed / failed) — render the asset rather
461
- // than implying success. The ActivityRow renders a separate status
462
- // chip when the row is failed.
502
+ // state — render the asset rather than implying success. The
503
+ // ActivityRow renders a separate status chip when the row is
504
+ // failed. Retained for partner overrides that still want a
505
+ // status-agnostic title.
463
506
  withdrawalTitle: (tokenSymbol) => `Withdraw ${tokenSymbol}`
464
507
  },
465
508
  positions: {
@@ -680,6 +723,7 @@ var enUsLabels = {
680
723
  noMarketSelected: "Select a market to place an order.",
681
724
  noOrderbooks: "No live orderbooks are available for this market right now.",
682
725
  quoteUnavailable: "Quote temporarily unavailable. Please try again.",
726
+ quoteBalanceMismatch: "Quote balance mismatch. Try a different amount.",
683
727
  selectedVenueUnavailable: "The venue you selected is no longer available on this route. Review the updated options and try again.",
684
728
  engineUnavailable: "The routing engine is temporarily unavailable. Please try again in a moment.",
685
729
  insufficientInputAmount: "Trade amount is too small to cover bridging and execution costs. Increase your spend or deposit funds on the destination chain.",
@@ -717,6 +761,7 @@ var enUsLabels = {
717
761
  buyingOutcome: (label) => `Buying ${label}`,
718
762
  sellingOutcome: (label) => `Selling ${label}`,
719
763
  findingBestRoute: "Finding the best route...",
764
+ checkingBalance: "Checking balance",
720
765
  submittingOrderProgress: "Submitting order...",
721
766
  orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
722
767
  executingOnVenue: (venueLabel) => `Executing on ${venueLabel}...`,
@@ -975,6 +1020,7 @@ var defaultAggUiSearchConfig = {
975
1020
  var defaultAggUiConfig = {
976
1021
  enableLogs: false,
977
1022
  enableWebsocketsLogs: false,
1023
+ enableDebug: false,
978
1024
  general: {
979
1025
  locale: DEFAULT_LOCALE,
980
1026
  theme: "light",
@@ -1012,7 +1058,7 @@ var mergeAggUiSearchConfig = (config) => {
1012
1058
  };
1013
1059
  };
1014
1060
  var mergeAggUiConfig = (persisted, config) => {
1015
- 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;
1061
+ 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;
1016
1062
  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;
1017
1063
  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;
1018
1064
  const formatters = createFormatters(locale);
@@ -1020,32 +1066,33 @@ var mergeAggUiConfig = (persisted, config) => {
1020
1066
  return {
1021
1067
  enableLogs: (_i = config == null ? void 0 : config.enableLogs) != null ? _i : defaultAggUiConfig.enableLogs,
1022
1068
  enableWebsocketsLogs: (_j = config == null ? void 0 : config.enableWebsocketsLogs) != null ? _j : defaultAggUiConfig.enableWebsocketsLogs,
1069
+ enableDebug: (_k = config == null ? void 0 : config.enableDebug) != null ? _k : defaultAggUiConfig.enableDebug,
1023
1070
  general: {
1024
1071
  locale,
1025
1072
  theme,
1026
- rootClassName: (_l = (_k = config == null ? void 0 : config.general) == null ? void 0 : _k.rootClassName) != null ? _l : defaultAggUiConfig.general.rootClassName,
1027
- labels: mergeAggUiLabels(defaultLabels, (_m = config == null ? void 0 : config.general) == null ? void 0 : _m.labels)
1073
+ rootClassName: (_m = (_l = config == null ? void 0 : config.general) == null ? void 0 : _l.rootClassName) != null ? _m : defaultAggUiConfig.general.rootClassName,
1074
+ labels: mergeAggUiLabels(defaultLabels, (_n = config == null ? void 0 : config.general) == null ? void 0 : _n.labels)
1028
1075
  },
1029
1076
  features: {
1030
- enableAnimations: (_o = (_n = config == null ? void 0 : config.features) == null ? void 0 : _n.enableAnimations) != null ? _o : defaultAggUiConfig.features.enableAnimations,
1031
- enableLiveUpdates: (_q = (_p = config == null ? void 0 : config.features) == null ? void 0 : _p.enableLiveUpdates) != null ? _q : defaultAggUiConfig.features.enableLiveUpdates,
1032
- showFeesBreakdown: (_s = (_r = config == null ? void 0 : config.features) == null ? void 0 : _r.showFeesBreakdown) != null ? _s : defaultAggUiConfig.features.showFeesBreakdown,
1033
- enableGradients: (_u = (_t = config == null ? void 0 : config.features) == null ? void 0 : _t.enableGradients) != null ? _u : defaultAggUiConfig.features.enableGradients
1077
+ enableAnimations: (_p = (_o = config == null ? void 0 : config.features) == null ? void 0 : _o.enableAnimations) != null ? _p : defaultAggUiConfig.features.enableAnimations,
1078
+ enableLiveUpdates: (_r = (_q = config == null ? void 0 : config.features) == null ? void 0 : _q.enableLiveUpdates) != null ? _r : defaultAggUiConfig.features.enableLiveUpdates,
1079
+ showFeesBreakdown: (_t = (_s = config == null ? void 0 : config.features) == null ? void 0 : _s.showFeesBreakdown) != null ? _t : defaultAggUiConfig.features.showFeesBreakdown,
1080
+ enableGradients: (_v = (_u = config == null ? void 0 : config.features) == null ? void 0 : _u.enableGradients) != null ? _v : defaultAggUiConfig.features.enableGradients
1034
1081
  },
1035
1082
  market: {
1036
- arbitrageThreshold: (_w = (_v = config == null ? void 0 : config.market) == null ? void 0 : _v.arbitrageThreshold) != null ? _w : defaultAggUiConfig.market.arbitrageThreshold
1083
+ arbitrageThreshold: (_x = (_w = config == null ? void 0 : config.market) == null ? void 0 : _w.arbitrageThreshold) != null ? _x : defaultAggUiConfig.market.arbitrageThreshold
1037
1084
  },
1038
1085
  chart: {
1039
- defaultChartTimeRange: (_y = (_x = config == null ? void 0 : config.chart) == null ? void 0 : _x.defaultChartTimeRange) != null ? _y : defaultAggUiConfig.chart.defaultChartTimeRange,
1040
- 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,
1086
+ defaultChartTimeRange: (_z = (_y = config == null ? void 0 : config.chart) == null ? void 0 : _y.defaultChartTimeRange) != null ? _z : defaultAggUiConfig.chart.defaultChartTimeRange,
1087
+ 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,
1041
1088
  setSelectedChartTimeRange: defaultAggUiConfig.chart.setSelectedChartTimeRange
1042
1089
  },
1043
1090
  formatting: {
1044
- formatNumber: (_E = (_D = config == null ? void 0 : config.formatting) == null ? void 0 : _D.formatNumber) != null ? _E : formatters.formatNumber,
1045
- formatPercent: (_G = (_F = config == null ? void 0 : config.formatting) == null ? void 0 : _F.formatPercent) != null ? _G : formatters.formatPercent,
1046
- formatCurrency: (_I = (_H = config == null ? void 0 : config.formatting) == null ? void 0 : _H.formatCurrency) != null ? _I : formatters.formatCurrency,
1047
- formatCompactCurrency: (_K = (_J = config == null ? void 0 : config.formatting) == null ? void 0 : _J.formatCompactCurrency) != null ? _K : formatters.formatCompactCurrency,
1048
- formatDate: (_M = (_L = config == null ? void 0 : config.formatting) == null ? void 0 : _L.formatDate) != null ? _M : formatters.formatDate
1091
+ formatNumber: (_F = (_E = config == null ? void 0 : config.formatting) == null ? void 0 : _E.formatNumber) != null ? _F : formatters.formatNumber,
1092
+ formatPercent: (_H = (_G = config == null ? void 0 : config.formatting) == null ? void 0 : _G.formatPercent) != null ? _H : formatters.formatPercent,
1093
+ formatCurrency: (_J = (_I = config == null ? void 0 : config.formatting) == null ? void 0 : _I.formatCurrency) != null ? _J : formatters.formatCurrency,
1094
+ formatCompactCurrency: (_L = (_K = config == null ? void 0 : config.formatting) == null ? void 0 : _K.formatCompactCurrency) != null ? _L : formatters.formatCompactCurrency,
1095
+ formatDate: (_N = (_M = config == null ? void 0 : config.formatting) == null ? void 0 : _M.formatDate) != null ? _N : formatters.formatDate
1049
1096
  },
1050
1097
  search: mergeAggUiSearchConfig(config == null ? void 0 : config.search),
1051
1098
  walletActions: config == null ? void 0 : config.walletActions,
@@ -1108,6 +1155,26 @@ var shouldInvalidateBalancesForOrderEvent = (event, currentUserId) => {
1108
1155
  if (!currentUserId) return true;
1109
1156
  return event.userId === currentUserId;
1110
1157
  };
1158
+ var userActivityQueryKeys = {
1159
+ all: () => ["user-activity"]
1160
+ };
1161
+ var invalidateUserActivityQueries = (queryClient, options) => {
1162
+ var _a;
1163
+ const strategy = (_a = options == null ? void 0 : options.strategy) != null ? _a : "remove";
1164
+ if (strategy === "remove") {
1165
+ queryClient.removeQueries({ queryKey: userActivityQueryKeys.all() });
1166
+ return;
1167
+ }
1168
+ queryClient.invalidateQueries({
1169
+ queryKey: userActivityQueryKeys.all(),
1170
+ refetchType: "all"
1171
+ });
1172
+ };
1173
+ var invalidateUserMoneyState = (queryClient, options) => {
1174
+ invalidateBalanceQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
1175
+ invalidatePositionQueries(queryClient, { refetchType: options == null ? void 0 : options.refetchType });
1176
+ invalidateUserActivityQueries(queryClient, { strategy: options == null ? void 0 : options.activityStrategy });
1177
+ };
1111
1178
 
1112
1179
  // src/core/providers/balance-provider.tsx
1113
1180
  import { useQuery } from "@tanstack/react-query";
@@ -1128,6 +1195,7 @@ var CHAIN_LABELS = {
1128
1195
  10: "Optimism",
1129
1196
  56: "BNB",
1130
1197
  137: "Polygon",
1198
+ 1337: "Hyperliquid",
1131
1199
  8453: "Base",
1132
1200
  42161: "Arbitrum",
1133
1201
  43114: "Avalanche",
@@ -1167,7 +1235,9 @@ function AggBalanceProvider({ children }) {
1167
1235
  return client.getManagedBalances();
1168
1236
  }),
1169
1237
  enabled: Boolean(client && isAuthenticated),
1170
- staleTime: 1e4
1238
+ staleTime: 60 * 1e3,
1239
+ refetchOnWindowFocus: "always",
1240
+ refetchOnReconnect: "always"
1171
1241
  });
1172
1242
  const managedBalancesData = balancesQuery.data;
1173
1243
  const managedBalances = useMemo(
@@ -1365,6 +1435,7 @@ import {
1365
1435
  import { useQueryClient } from "@tanstack/react-query";
1366
1436
 
1367
1437
  // src/market-data/chart-cache.ts
1438
+ var MAX_CACHE_RETENTION_SECONDS = 7 * 30 * 24 * 60 * 60 + 14 * 24 * 60 * 60;
1368
1439
  var getIntervalSeconds = (interval) => {
1369
1440
  switch (interval) {
1370
1441
  case "1m":
@@ -1383,12 +1454,41 @@ var createVenueData = (venue, outcomeIds = []) => ({
1383
1454
  candles: [],
1384
1455
  liveCandle: null,
1385
1456
  lineValue: void 0,
1386
- lastTrade: null
1457
+ lastTrade: null,
1458
+ lastUpdateTs: null
1387
1459
  });
1460
+ var pruneCandlesBefore = (candles, cutoffTs) => {
1461
+ if (cutoffTs <= 0) return candles;
1462
+ let firstKeptIndex = 0;
1463
+ while (firstKeptIndex < candles.length && candles[firstKeptIndex].time < cutoffTs) {
1464
+ firstKeptIndex += 1;
1465
+ }
1466
+ if (firstKeptIndex === 0) return candles;
1467
+ return candles.slice(firstKeptIndex);
1468
+ };
1469
+ var promoteClosedLiveCandle = (candles, liveCandle, expectedCandleTime) => {
1470
+ if (!liveCandle || liveCandle.time >= expectedCandleTime) {
1471
+ return { candles, promoted: false };
1472
+ }
1473
+ if (candles.some((candle) => candle.time === liveCandle.time)) {
1474
+ return { candles, promoted: false };
1475
+ }
1476
+ return { candles: sortCandles([...candles, liveCandle]), promoted: true };
1477
+ };
1478
+ var resolveMaxLastUpdateTs = (venues) => {
1479
+ let max = null;
1480
+ for (const venueData of Object.values(venues)) {
1481
+ if (venueData.lastUpdateTs != null && (max == null || venueData.lastUpdateTs > max)) {
1482
+ max = venueData.lastUpdateTs;
1483
+ }
1484
+ }
1485
+ return max;
1486
+ };
1388
1487
  var sortCandles = (candles) => {
1389
1488
  return [...candles].sort((left, right) => left.time - right.time);
1390
1489
  };
1391
1490
  var createMarketChartData = (params) => {
1491
+ var _a;
1392
1492
  const candles = sortCandles(
1393
1493
  params.response.data.map((candle) => ({
1394
1494
  time: Math.floor(candle.t / 1e3),
@@ -1401,6 +1501,7 @@ var createMarketChartData = (params) => {
1401
1501
  }))
1402
1502
  );
1403
1503
  const lastCandle = candles[candles.length - 1];
1504
+ const lastUpdateTs = (_a = lastCandle == null ? void 0 : lastCandle.time) != null ? _a : null;
1404
1505
  const venues = {
1405
1506
  [params.response.venue]: {
1406
1507
  venue: params.response.venue,
@@ -1408,7 +1509,8 @@ var createMarketChartData = (params) => {
1408
1509
  candles,
1409
1510
  liveCandle: null,
1410
1511
  lineValue: lastCandle == null ? void 0 : lastCandle.close,
1411
- lastTrade: null
1512
+ lastTrade: null,
1513
+ lastUpdateTs
1412
1514
  }
1413
1515
  };
1414
1516
  return {
@@ -1418,7 +1520,8 @@ var createMarketChartData = (params) => {
1418
1520
  interval: params.interval,
1419
1521
  startTs: params.startTs,
1420
1522
  endTs: params.endTs,
1421
- venues
1523
+ venues,
1524
+ lastUpdateTs
1422
1525
  };
1423
1526
  };
1424
1527
  var mergeMarketChartData = (params) => {
@@ -1452,9 +1555,75 @@ var mergeMarketChartData = (params) => {
1452
1555
  interval: params.interval,
1453
1556
  startTs: params.startTs,
1454
1557
  endTs: params.endTs,
1455
- venues
1558
+ venues,
1559
+ lastUpdateTs: resolveMaxLastUpdateTs(venues)
1456
1560
  };
1457
1561
  };
1562
+ var applyMidpointToMarketChart = (data, update) => {
1563
+ var _a;
1564
+ if (!data || !Number.isFinite(update.midpoint)) {
1565
+ return data;
1566
+ }
1567
+ const targetVenueEntry = Object.entries(data.venues).find(
1568
+ ([, venueData]) => venueData.outcomeIds.includes(update.outcomeId)
1569
+ );
1570
+ if (!targetVenueEntry && data.marketId !== update.outcomeId) {
1571
+ return data;
1572
+ }
1573
+ const [targetVenueName, currentVenue] = targetVenueEntry != null ? targetVenueEntry : [
1574
+ data.primaryVenue,
1575
+ (_a = data.venues[data.primaryVenue]) != null ? _a : createVenueData(data.primaryVenue, [update.outcomeId])
1576
+ ];
1577
+ const intervalSeconds = getIntervalSeconds(data.interval);
1578
+ const expectedCandleTime = update.timestamp - update.timestamp % intervalSeconds;
1579
+ let liveCandle = currentVenue.liveCandle;
1580
+ const { candles: promotedCandles } = promoteClosedLiveCandle(
1581
+ currentVenue.candles,
1582
+ liveCandle,
1583
+ expectedCandleTime
1584
+ );
1585
+ const nextCandles = pruneCandlesBefore(
1586
+ promotedCandles,
1587
+ update.timestamp - MAX_CACHE_RETENTION_SECONDS
1588
+ );
1589
+ if (liveCandle && liveCandle.time === expectedCandleTime) {
1590
+ if (liveCandle.source === "trade") {
1591
+ liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
1592
+ close: update.midpoint
1593
+ });
1594
+ } else {
1595
+ liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
1596
+ close: update.midpoint,
1597
+ high: Math.max(liveCandle.high, update.midpoint),
1598
+ low: Math.min(liveCandle.low, update.midpoint),
1599
+ source: "midpoint"
1600
+ });
1601
+ }
1602
+ } else {
1603
+ liveCandle = {
1604
+ time: expectedCandleTime,
1605
+ open: update.midpoint,
1606
+ high: update.midpoint,
1607
+ low: update.midpoint,
1608
+ close: update.midpoint,
1609
+ volume: 0,
1610
+ source: "midpoint"
1611
+ };
1612
+ }
1613
+ const nextVenues = __spreadProps(__spreadValues({}, data.venues), {
1614
+ [targetVenueName]: __spreadProps(__spreadValues({}, currentVenue), {
1615
+ outcomeIds: currentVenue.outcomeIds.includes(update.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, update.outcomeId],
1616
+ candles: nextCandles,
1617
+ liveCandle,
1618
+ lineValue: update.midpoint,
1619
+ lastUpdateTs: update.timestamp
1620
+ })
1621
+ });
1622
+ return __spreadProps(__spreadValues({}, data), {
1623
+ venues: nextVenues,
1624
+ lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
1625
+ });
1626
+ };
1458
1627
  var applyTradeToMarketChart = (data, trade) => {
1459
1628
  var _a, _b, _c;
1460
1629
  if (!data || data.marketId !== trade.outcomeId) {
@@ -1464,6 +1633,15 @@ var applyTradeToMarketChart = (data, trade) => {
1464
1633
  const intervalSeconds = getIntervalSeconds(data.interval);
1465
1634
  const expectedCandleTime = trade.timestamp - trade.timestamp % intervalSeconds;
1466
1635
  let liveCandle = currentVenue.liveCandle;
1636
+ const { candles: promotedCandles } = promoteClosedLiveCandle(
1637
+ currentVenue.candles,
1638
+ liveCandle,
1639
+ expectedCandleTime
1640
+ );
1641
+ const nextCandles = pruneCandlesBefore(
1642
+ promotedCandles,
1643
+ trade.timestamp - MAX_CACHE_RETENTION_SECONDS
1644
+ );
1467
1645
  if (liveCandle && liveCandle.time === expectedCandleTime) {
1468
1646
  liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
1469
1647
  close: trade.price,
@@ -1483,16 +1661,20 @@ var applyTradeToMarketChart = (data, trade) => {
1483
1661
  source: "trade"
1484
1662
  };
1485
1663
  }
1486
- return __spreadProps(__spreadValues({}, data), {
1487
- venues: __spreadProps(__spreadValues({}, data.venues), {
1488
- [trade.venue]: __spreadProps(__spreadValues({}, currentVenue), {
1489
- outcomeIds: currentVenue.outcomeIds.includes(trade.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, trade.outcomeId],
1490
- liveCandle,
1491
- lineValue: (_c = liveCandle == null ? void 0 : liveCandle.close) != null ? _c : trade.price,
1492
- lastTrade: trade
1493
- })
1664
+ const nextVenues = __spreadProps(__spreadValues({}, data.venues), {
1665
+ [trade.venue]: __spreadProps(__spreadValues({}, currentVenue), {
1666
+ outcomeIds: currentVenue.outcomeIds.includes(trade.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, trade.outcomeId],
1667
+ candles: nextCandles,
1668
+ liveCandle,
1669
+ lineValue: (_c = liveCandle == null ? void 0 : liveCandle.close) != null ? _c : trade.price,
1670
+ lastTrade: trade,
1671
+ lastUpdateTs: trade.timestamp
1494
1672
  })
1495
1673
  });
1674
+ return __spreadProps(__spreadValues({}, data), {
1675
+ venues: nextVenues,
1676
+ lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
1677
+ });
1496
1678
  };
1497
1679
 
1498
1680
  // src/market-data/live-cache.ts
@@ -1683,7 +1865,15 @@ var marketDataKeys = {
1683
1865
  orderbook: (marketId, selectionKey, depth) => ["market-data", "orderbook", marketId, selectionKey != null ? selectionKey : null, depth != null ? depth : null],
1684
1866
  orderbookPrefix: (marketId) => marketId == null ? ["market-data", "orderbook"] : ["market-data", "orderbook", marketId],
1685
1867
  orderbookQuote: (marketId, side, size) => ["market-data", "orderbook-quote", marketId, side, size],
1686
- chart: (marketId, interval, startTs, endTs, countBack) => ["market-data", "chart", marketId, interval, startTs, endTs, countBack != null ? countBack : null],
1868
+ /**
1869
+ * Stable per `{marketId, interval, rangeKey}`. Deliberately excludes the
1870
+ * concrete `startTs`/`endTs` of the rolling window — those advance every
1871
+ * candle bucket, and including them would mint a fresh key on every
1872
+ * rollover, defeating React Query's cache on tab/page revisits. The
1873
+ * current window is passed to `queryFn` via closure instead, and
1874
+ * `refetchInterval` advances the data under the stable key.
1875
+ */
1876
+ chart: (marketId, interval, rangeKey, countBack) => ["market-data", "chart", marketId, interval, rangeKey, countBack != null ? countBack : null],
1687
1877
  chartPrefix: (marketId, interval) => {
1688
1878
  if (!marketId) return ["market-data", "chart"];
1689
1879
  if (!interval) return ["market-data", "chart", marketId];
@@ -1892,6 +2082,9 @@ function AggWebSocketProvider({ children }) {
1892
2082
  const invalidatePositionCaches = useCallback3(() => {
1893
2083
  invalidatePositionQueries(queryClient);
1894
2084
  }, [queryClient]);
2085
+ const invalidateActivityCaches = useCallback3(() => {
2086
+ invalidateUserActivityQueries(queryClient);
2087
+ }, [queryClient]);
1895
2088
  const callbacks = useMemo2(
1896
2089
  () => ({
1897
2090
  onSnapshot: (marketId, book) => {
@@ -1910,6 +2103,14 @@ function AggWebSocketProvider({ children }) {
1910
2103
  syncLiveQuery(marketId, (previous) => withLiveOrderbook(previous, book, "snapshot"));
1911
2104
  if (book.midpoint != null) {
1912
2105
  getOrCreateBuilder(marketId).addMidpoint(book.midpoint, book.timestamp);
2106
+ syncChartQueries(
2107
+ marketId,
2108
+ (_queryKey, previous) => applyMidpointToMarketChart(previous, {
2109
+ outcomeId: marketId,
2110
+ midpoint: book.midpoint,
2111
+ timestamp: book.timestamp
2112
+ })
2113
+ );
1913
2114
  }
1914
2115
  },
1915
2116
  onDelta: (marketId, book) => {
@@ -1955,6 +2156,14 @@ function AggWebSocketProvider({ children }) {
1955
2156
  });
1956
2157
  if (book.midpoint != null) {
1957
2158
  getOrCreateBuilder(marketId).addMidpoint(book.midpoint, book.timestamp);
2159
+ syncChartQueries(
2160
+ marketId,
2161
+ (_queryKey, previous) => applyMidpointToMarketChart(previous, {
2162
+ outcomeId: marketId,
2163
+ midpoint: book.midpoint,
2164
+ timestamp: book.timestamp
2165
+ })
2166
+ );
1958
2167
  }
1959
2168
  },
1960
2169
  onTrade: (trade) => {
@@ -1992,6 +2201,7 @@ function AggWebSocketProvider({ children }) {
1992
2201
  onBalanceUpdate: (msg) => {
1993
2202
  if (isClientAuthenticated) {
1994
2203
  invalidateBalanceCaches();
2204
+ invalidateActivityCaches();
1995
2205
  }
1996
2206
  for (const listener of balanceUpdateListenersRef.current) {
1997
2207
  listener(msg);
@@ -2057,6 +2267,7 @@ function AggWebSocketProvider({ children }) {
2057
2267
  [
2058
2268
  client,
2059
2269
  enableWebsocketsLogs,
2270
+ invalidateActivityCaches,
2060
2271
  invalidateBalanceCaches,
2061
2272
  invalidatePositionCaches,
2062
2273
  isClientAuthenticated,
@@ -2120,9 +2331,26 @@ var resolveTradingStateKind = (status) => {
2120
2331
  return "closed";
2121
2332
  };
2122
2333
  var resolveMarketWinningOutcome = (market) => {
2123
- var _a;
2334
+ var _a, _b, _c, _d;
2124
2335
  if (!market) return null;
2125
- return (_a = market.venueMarketOutcomes.find((outcome) => outcome.winner === true)) != null ? _a : null;
2336
+ const localWinningOutcome = (_a = market.venueMarketOutcomes.find((outcome) => outcome.winner === true)) != null ? _a : null;
2337
+ if (localWinningOutcome) return localWinningOutcome;
2338
+ const matchedVenueMarkets = (_b = market.matchedVenueMarkets) != null ? _b : [];
2339
+ if (!matchedVenueMarkets.length) return null;
2340
+ for (const outcome of market.venueMarketOutcomes) {
2341
+ const matchedRefs = (_c = outcome.matchedVenueMarketOutcomes) != null ? _c : [];
2342
+ for (const ref of matchedRefs) {
2343
+ const matchedMarket = matchedVenueMarkets.find((item) => item.id === ref.venueMarketId);
2344
+ if (!matchedMarket) continue;
2345
+ const matchedOutcome = (_d = matchedMarket.venueMarketOutcomes) == null ? void 0 : _d.find(
2346
+ (item) => item.id === ref.venueMarketOutcomeId
2347
+ );
2348
+ if ((matchedOutcome == null ? void 0 : matchedOutcome.winner) === true) {
2349
+ return outcome;
2350
+ }
2351
+ }
2352
+ }
2353
+ return null;
2126
2354
  };
2127
2355
  var AFFIRMATIVE_WINNER_LABELS = /* @__PURE__ */ new Set(["yes", "up", "buy", "long", "true"]);
2128
2356
  var isAffirmativeWinnerLabel = (label) => {
@@ -2310,51 +2538,50 @@ function findOutcomeAcrossMarkets(event, outcomeId) {
2310
2538
  }
2311
2539
  return null;
2312
2540
  }
2541
+ var TradeSide = {
2542
+ Buy: "buy",
2543
+ Sell: "sell"
2544
+ };
2313
2545
  function tradingReducer(state, action) {
2314
- var _a, _b;
2546
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2315
2547
  switch (action.type) {
2316
2548
  case "INITIALIZE_EVENT": {
2317
2549
  if (!action.event) {
2318
- return { event: null, market: null, outcome: null };
2550
+ return { event: null, market: null, outcome: null, tradeSide: TradeSide.Buy };
2319
2551
  }
2320
- const market = resolveDefaultMarket(action.event);
2321
2552
  return {
2322
2553
  event: action.event,
2323
- market,
2324
- outcome: resolveDefaultOutcome(market)
2554
+ market: null,
2555
+ outcome: null,
2556
+ tradeSide: TradeSide.Buy
2325
2557
  };
2326
2558
  }
2327
2559
  case "SYNC_EVENT": {
2328
- const nextEvent = action.event;
2329
- const preservedMarket = state.market ? findMarketById(nextEvent, state.market.id) : null;
2330
- if (preservedMarket) {
2331
- const preservedMarketState = resolveMarketTradingState(preservedMarket);
2332
- if (preservedMarketState.isTradingDisabled) {
2333
- const tradableAlternative = resolveDefaultMarket(nextEvent);
2334
- if (tradableAlternative && resolveMarketTradingState(tradableAlternative).isOpen) {
2335
- return {
2336
- event: nextEvent,
2337
- market: tradableAlternative,
2338
- outcome: resolveDefaultOutcome(tradableAlternative)
2339
- };
2340
- }
2341
- }
2342
- const preservedOutcome = state.outcome ? findOutcomeById(preservedMarket, state.outcome.id) : null;
2560
+ const previousMarketId = (_b = (_a = state.market) == null ? void 0 : _a.id) != null ? _b : null;
2561
+ const previousOutcomeId = (_d = (_c = state.outcome) == null ? void 0 : _c.id) != null ? _d : null;
2562
+ const syncedMarket = previousMarketId ? findMarketById(action.event, previousMarketId) : null;
2563
+ if (!syncedMarket || resolveMarketTradingState(syncedMarket).isTradingDisabled) {
2343
2564
  return {
2344
- event: nextEvent,
2345
- market: preservedMarket,
2346
- outcome: preservedOutcome != null ? preservedOutcome : resolveDefaultOutcome(preservedMarket)
2565
+ event: action.event,
2566
+ market: null,
2567
+ outcome: null,
2568
+ tradeSide: (_e = state.tradeSide) != null ? _e : TradeSide.Buy
2347
2569
  };
2348
2570
  }
2349
- const defaultMarket = resolveDefaultMarket(nextEvent);
2571
+ const syncedOutcome = previousOutcomeId ? findOutcomeById(syncedMarket, previousOutcomeId) : null;
2350
2572
  return {
2351
- event: nextEvent,
2352
- market: defaultMarket,
2353
- outcome: resolveDefaultOutcome(defaultMarket)
2573
+ event: action.event,
2574
+ market: syncedMarket,
2575
+ outcome: syncedOutcome,
2576
+ tradeSide: (_f = state.tradeSide) != null ? _f : TradeSide.Buy
2354
2577
  };
2355
2578
  }
2579
+ case "SET_TRADE_SIDE": {
2580
+ if (((_g = state.tradeSide) != null ? _g : TradeSide.Buy) === action.tradeSide) return state;
2581
+ return __spreadProps(__spreadValues({}, state), { tradeSide: action.tradeSide });
2582
+ }
2356
2583
  case "SELECT_MARKET": {
2357
- const market = (_b = (_a = findMarketById(state.event, action.marketId)) != null ? _a : action.market) != null ? _b : null;
2584
+ const market = (_i = (_h = findMarketById(state.event, action.marketId)) != null ? _h : action.market) != null ? _i : null;
2358
2585
  if (!market) return state;
2359
2586
  if (resolveMarketTradingState(market).kind === "resolved") return state;
2360
2587
  return __spreadProps(__spreadValues({}, state), {
@@ -2363,6 +2590,9 @@ function tradingReducer(state, action) {
2363
2590
  });
2364
2591
  }
2365
2592
  case "SELECT_OUTCOME": {
2593
+ if (((_j = state.outcome) == null ? void 0 : _j.id) === action.outcomeId) {
2594
+ return state;
2595
+ }
2366
2596
  if (state.market) {
2367
2597
  const outcomeInCurrentMarket = findOutcomeById(state.market, action.outcomeId);
2368
2598
  if (outcomeInCurrentMarket) {
@@ -2414,7 +2644,8 @@ function logAction(actionType, payload, prev, next, enableLogs) {
2414
2644
  var initialState = {
2415
2645
  event: null,
2416
2646
  market: null,
2417
- outcome: null
2647
+ outcome: null,
2648
+ tradeSide: TradeSide.Buy
2418
2649
  };
2419
2650
  var EventTradingContext = createContext4(void 0);
2420
2651
  var useEventTradingContext = () => {
@@ -2424,9 +2655,15 @@ var EventTradingProvider = ({
2424
2655
  children,
2425
2656
  enableLogs = false
2426
2657
  }) => {
2658
+ var _a, _b;
2427
2659
  const [state, rawDispatch] = useReducer(tradingReducer, initialState);
2428
2660
  const stateRef = useRef3(state);
2661
+ const pendingAtomicSelectionRef = useRef3(null);
2429
2662
  stateRef.current = state;
2663
+ const pendingAtomicSelection = pendingAtomicSelectionRef.current;
2664
+ if (pendingAtomicSelection && ((_a = state.market) == null ? void 0 : _a.id) === pendingAtomicSelection.marketId && ((_b = state.outcome) == null ? void 0 : _b.id) === pendingAtomicSelection.outcomeId) {
2665
+ pendingAtomicSelectionRef.current = null;
2666
+ }
2430
2667
  const dispatch = useCallback4(
2431
2668
  (action) => {
2432
2669
  const prev = stateRef.current;
@@ -2449,24 +2686,45 @@ var EventTradingProvider = ({
2449
2686
  [dispatch]
2450
2687
  );
2451
2688
  const selectOutcome = useCallback4(
2452
- (outcomeId) => dispatch({ type: "SELECT_OUTCOME", outcomeId }),
2689
+ (outcomeId) => {
2690
+ var _a2, _b2;
2691
+ if (((_a2 = stateRef.current.outcome) == null ? void 0 : _a2.id) === outcomeId) return;
2692
+ if (((_b2 = pendingAtomicSelectionRef.current) == null ? void 0 : _b2.outcomeId) === outcomeId) return;
2693
+ dispatch({ type: "SELECT_OUTCOME", outcomeId });
2694
+ },
2453
2695
  [dispatch]
2454
2696
  );
2455
2697
  const selectMarketAndOutcome = useCallback4(
2456
- (marketId, outcomeId) => dispatch({ type: "SELECT_MARKET_AND_OUTCOME", marketId, outcomeId }),
2698
+ (marketId, outcomeId) => {
2699
+ var _a2, _b2, _c, _d;
2700
+ if (((_a2 = stateRef.current.market) == null ? void 0 : _a2.id) === marketId && ((_b2 = stateRef.current.outcome) == null ? void 0 : _b2.id) === outcomeId) {
2701
+ return;
2702
+ }
2703
+ if (((_c = pendingAtomicSelectionRef.current) == null ? void 0 : _c.marketId) === marketId && ((_d = pendingAtomicSelectionRef.current) == null ? void 0 : _d.outcomeId) === outcomeId) {
2704
+ return;
2705
+ }
2706
+ pendingAtomicSelectionRef.current = { marketId, outcomeId };
2707
+ dispatch({ type: "SELECT_MARKET_AND_OUTCOME", marketId, outcomeId });
2708
+ },
2709
+ [dispatch]
2710
+ );
2711
+ const setTradeSide = useCallback4(
2712
+ (tradeSide) => dispatch({ type: "SET_TRADE_SIDE", tradeSide }),
2457
2713
  [dispatch]
2458
2714
  );
2459
2715
  const value = useMemo3(
2460
2716
  () => {
2461
- var _a, _b, _c, _d, _e, _f, _g, _h;
2717
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
2462
2718
  return {
2463
2719
  selectedEvent: state.event,
2464
2720
  selectedMarket: state.market,
2465
2721
  selectedOutcome: state.outcome,
2466
- selectedEventId: (_b = (_a = state.event) == null ? void 0 : _a.id) != null ? _b : null,
2722
+ selectedEventId: (_b2 = (_a2 = state.event) == null ? void 0 : _a2.id) != null ? _b2 : null,
2467
2723
  selectedMarketId: (_d = (_c = state.market) == null ? void 0 : _c.id) != null ? _d : null,
2468
2724
  selectedOutcomeId: (_f = (_e = state.outcome) == null ? void 0 : _e.id) != null ? _f : null,
2469
2725
  selectedVenue: (_h = (_g = state.market) == null ? void 0 : _g.venue) != null ? _h : null,
2726
+ tradeSide: (_i = state.tradeSide) != null ? _i : TradeSide.Buy,
2727
+ setTradeSide,
2470
2728
  initializeFromEvent,
2471
2729
  syncEvent,
2472
2730
  selectMarket,
@@ -2474,7 +2732,15 @@ var EventTradingProvider = ({
2474
2732
  selectMarketAndOutcome
2475
2733
  };
2476
2734
  },
2477
- [state, initializeFromEvent, syncEvent, selectMarket, selectOutcome, selectMarketAndOutcome]
2735
+ [
2736
+ state,
2737
+ initializeFromEvent,
2738
+ syncEvent,
2739
+ selectMarket,
2740
+ selectOutcome,
2741
+ selectMarketAndOutcome,
2742
+ setTradeSide
2743
+ ]
2478
2744
  );
2479
2745
  return /* @__PURE__ */ jsx4(EventTradingContext.Provider, { value, children });
2480
2746
  };
@@ -2800,7 +3066,7 @@ var createAuthCallbackSession = (tokens) => {
2800
3066
  };
2801
3067
  };
2802
3068
  var executeWalletAuthFlow = (input) => __async(null, null, function* () {
2803
- var _a, _b;
3069
+ var _a, _b, _c, _d;
2804
3070
  const address = input.options.address.trim();
2805
3071
  const chain = (_a = input.options.chain) != null ? _a : "ethereum";
2806
3072
  const provider = chain === "solana" ? "siws" : "siwe";
@@ -2823,14 +3089,14 @@ var executeWalletAuthFlow = (input) => __async(null, null, function* () {
2823
3089
  uri: location.uri,
2824
3090
  nonce: startResult.nonce,
2825
3091
  chainId: typeof input.options.chainId === "string" ? input.options.chainId : "mainnet",
2826
- statement: input.options.statement
3092
+ statement: (_c = startResult.statement) != null ? _c : input.options.statement
2827
3093
  }) : input.client.buildSiweMessage({
2828
3094
  domain: location.domain,
2829
3095
  address,
2830
3096
  uri: location.uri,
2831
3097
  nonce: startResult.nonce,
2832
3098
  chainId: typeof input.options.chainId === "number" ? input.options.chainId : void 0,
2833
- statement: input.options.statement
3099
+ statement: (_d = startResult.statement) != null ? _d : input.options.statement
2834
3100
  });
2835
3101
  const signature = yield input.options.signMessage(message);
2836
3102
  const result = yield input.client.verify({ message, signature });
@@ -3141,7 +3407,7 @@ function useWithdrawManaged(options) {
3141
3407
  mutationFn: (params) => client.withdrawManaged(params),
3142
3408
  onSuccess: (data) => {
3143
3409
  var _a;
3144
- invalidateBalanceQueries(queryClient);
3410
+ invalidateUserMoneyState(queryClient);
3145
3411
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
3146
3412
  },
3147
3413
  onError: options == null ? void 0 : options.onError
@@ -3253,7 +3519,7 @@ function useSyncBalances(options) {
3253
3519
  mutationFn: () => client.syncManagedBalances(),
3254
3520
  onSuccess: () => {
3255
3521
  var _a;
3256
- invalidateBalanceQueries(queryClient);
3522
+ invalidateUserMoneyState(queryClient);
3257
3523
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
3258
3524
  },
3259
3525
  onError: options == null ? void 0 : options.onError
@@ -3335,6 +3601,12 @@ function useExecutionProgress({
3335
3601
  event: mappedEvent,
3336
3602
  filledAmountRaw: msg.filledAmountRaw,
3337
3603
  remainingAmountRaw: msg.remainingAmountRaw,
3604
+ actualSharesRaw: msg.actualSharesRaw,
3605
+ actualToWinRaw: msg.actualToWinRaw,
3606
+ quotedSharesRaw: msg.quotedSharesRaw,
3607
+ quotedToWinRaw: msg.quotedToWinRaw,
3608
+ executionPriceRaw: msg.executionPriceRaw,
3609
+ quotedPriceRaw: msg.quotedPriceRaw,
3338
3610
  errorReason: event === "bridge_ws_subscribe_failed" ? (_a = msg.errorReason) != null ? _a : "Bridge event subscription failed." : msg.errorReason,
3339
3611
  timestamp: msg.timestamp
3340
3612
  };
@@ -3413,15 +3685,29 @@ function useExecutionProgress({
3413
3685
  });
3414
3686
  return;
3415
3687
  }
3688
+ const buildFailedProgress = (prev) => {
3689
+ var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3690
+ const seq = (_b2 = (_a2 = msg.sequence) != null ? _a2 : prev == null ? void 0 : prev.currentSequence) != null ? _b2 : 0;
3691
+ const stepType = (_d = (_c2 = msg.stepType) != null ? _c2 : prev == null ? void 0 : prev.currentStepType) != null ? _d : null;
3692
+ const baseStepTypes = (_e = prev == null ? void 0 : prev.stepTypes) != null ? _e : {};
3693
+ const stepTypes = seq && stepType ? __spreadProps(__spreadValues({}, baseStepTypes), { [seq]: stepType }) : baseStepTypes;
3694
+ return {
3695
+ dagRunId: (_g = (_f = msg.dagRunId) != null ? _f : prev == null ? void 0 : prev.dagRunId) != null ? _g : "",
3696
+ totalSteps: (_i = (_h = msg.totalSteps) != null ? _h : prev == null ? void 0 : prev.totalSteps) != null ? _i : 0,
3697
+ currentSequence: seq,
3698
+ currentStepType: stepType,
3699
+ completedSequences: (_j = prev == null ? void 0 : prev.completedSequences) != null ? _j : [],
3700
+ stepTypes,
3701
+ status: "failed",
3702
+ errorReason: (_l = (_k = msg.errorReason) != null ? _k : prev == null ? void 0 : prev.errorReason) != null ? _l : null
3703
+ };
3704
+ };
3705
+ if (event === "step_failed") {
3706
+ setDagProgress((prev) => buildFailedProgress(prev));
3707
+ return;
3708
+ }
3416
3709
  if (event === "dag_failed") {
3417
- setDagProgress((prev) => {
3418
- var _a2;
3419
- if (!prev) return prev;
3420
- return __spreadProps(__spreadValues({}, prev), {
3421
- status: "failed",
3422
- errorReason: (_a2 = msg.errorReason) != null ? _a2 : null
3423
- });
3424
- });
3710
+ setDagProgress((prev) => buildFailedProgress(prev));
3425
3711
  return;
3426
3712
  }
3427
3713
  }, []);
@@ -3446,7 +3732,7 @@ function useExecutionProgress({
3446
3732
  }
3447
3733
  };
3448
3734
  const reconcile = () => __async(null, null, function* () {
3449
- var _a, _b, _c;
3735
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3450
3736
  if (cancelled || pollInFlightRef.current) return;
3451
3737
  const pending = orderIds.filter((id) => !terminalOrderIdsRef.current.has(id));
3452
3738
  if (pending.length === 0) {
@@ -3478,7 +3764,13 @@ function useExecutionProgress({
3478
3764
  venue: (_a = order.venue) != null ? _a : "",
3479
3765
  event: mapped,
3480
3766
  filledAmountRaw: (_b = order.filledAmountRaw) != null ? _b : void 0,
3481
- errorReason: (_c = order.errorMessage) != null ? _c : void 0,
3767
+ actualSharesRaw: (_c = order.actualSharesRaw) != null ? _c : void 0,
3768
+ actualToWinRaw: (_d = order.actualToWinRaw) != null ? _d : void 0,
3769
+ quotedSharesRaw: (_e = order.quotedSharesRaw) != null ? _e : void 0,
3770
+ quotedToWinRaw: (_f = order.quotedToWinRaw) != null ? _f : void 0,
3771
+ executionPriceRaw: (_g = order.executionPrice) != null ? _g : void 0,
3772
+ quotedPriceRaw: (_h = order.quotedPriceRaw) != null ? _h : void 0,
3773
+ errorReason: (_i = order.errorMessage) != null ? _i : void 0,
3482
3774
  timestamp: new Date(order.updatedAt).getTime() || Date.now()
3483
3775
  });
3484
3776
  }
@@ -3558,11 +3850,27 @@ var computeClosedPositionTotals = (group) => {
3558
3850
 
3559
3851
  // src/execution/use-redeem.ts
3560
3852
  import { useMutation as useMutation5, useQueryClient as useQueryClient6 } from "@tanstack/react-query";
3853
+ var RedeemRejectedError = class extends Error {
3854
+ constructor(message, response) {
3855
+ super(message);
3856
+ this.name = "RedeemRejectedError";
3857
+ this.response = response;
3858
+ }
3859
+ };
3860
+ var isLegRejected = (status) => status === "ineligible" || status === "rejected";
3561
3861
  var useRedeem = () => {
3562
3862
  const client = useAggClient();
3563
3863
  const queryClient = useQueryClient6();
3564
3864
  return useMutation5({
3565
- mutationFn: (body) => client.redeem(body),
3865
+ mutationFn: (body) => __async(null, null, function* () {
3866
+ const response = yield client.redeem(body);
3867
+ if (response.results.length > 0 && response.results.every((r) => isLegRejected(r.status))) {
3868
+ const reasons = response.results.map((r) => r.reason).filter((r) => Boolean(r));
3869
+ const message = reasons.length > 0 ? reasons.join("; ") : "Redeem rejected";
3870
+ throw new RedeemRejectedError(message, response);
3871
+ }
3872
+ return response;
3873
+ }),
3566
3874
  onSuccess: () => {
3567
3875
  queryClient.invalidateQueries({ queryKey: executionKeys.positionsPrefix() });
3568
3876
  queryClient.invalidateQueries({ queryKey: executionKeys.balances() });
@@ -3613,6 +3921,142 @@ var useRedeemEligibleCount = () => {
3613
3921
  return (_a = query.data) != null ? _a : 0;
3614
3922
  };
3615
3923
 
3924
+ // src/execution/use-redeem-lifecycles.ts
3925
+ import { useEffect as useEffect6, useMemo as useMemo7, useState as useState6 } from "react";
3926
+ var computeDerivedState = (legs, expectedCount) => {
3927
+ const legCount = Object.keys(legs).length;
3928
+ let allTerminal = legCount === expectedCount;
3929
+ let allConfirmed = allTerminal;
3930
+ let anyFailed = false;
3931
+ let errorMessage = null;
3932
+ for (const leg of Object.values(legs)) {
3933
+ if (leg.status === "submitted") allTerminal = false;
3934
+ if (leg.status !== "confirmed") allConfirmed = false;
3935
+ if (leg.status === "failed") {
3936
+ anyFailed = true;
3937
+ if (errorMessage === null && leg.errorMessage) errorMessage = leg.errorMessage;
3938
+ }
3939
+ }
3940
+ return {
3941
+ terminal: allTerminal,
3942
+ allConfirmed: allTerminal && allConfirmed,
3943
+ anyFailed,
3944
+ errorMessage
3945
+ };
3946
+ };
3947
+ var seedState = (input) => {
3948
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3949
+ const legs = {};
3950
+ for (const id of (_a = input.preFailedOutcomeIds) != null ? _a : []) {
3951
+ legs[id] = {
3952
+ status: "failed",
3953
+ txHash: null,
3954
+ errorMessage: (_c = (_b = input.preFailedReasons) == null ? void 0 : _b[id]) != null ? _c : null
3955
+ };
3956
+ }
3957
+ for (const id of (_d = input.preConfirmedOutcomeIds) != null ? _d : []) {
3958
+ legs[id] = {
3959
+ status: "confirmed",
3960
+ txHash: (_f = (_e = input.preConfirmedTxHashes) == null ? void 0 : _e[id]) != null ? _f : null,
3961
+ errorMessage: null
3962
+ };
3963
+ }
3964
+ 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);
3965
+ const derived = computeDerivedState(legs, expectedCount);
3966
+ return {
3967
+ pending: !derived.terminal,
3968
+ terminal: derived.terminal,
3969
+ allConfirmed: derived.allConfirmed,
3970
+ anyFailed: derived.anyFailed,
3971
+ errorMessage: derived.errorMessage,
3972
+ legs
3973
+ };
3974
+ };
3975
+ function useRedeemLifecycles(inputs) {
3976
+ const inputsByRedeemId = useMemo7(() => {
3977
+ const map = {};
3978
+ for (const input of inputs) {
3979
+ map[input.redeemId] = input;
3980
+ }
3981
+ return map;
3982
+ }, [inputs]);
3983
+ const [stateMap, setStateMap] = useState6(() => {
3984
+ const next = {};
3985
+ for (const [id, input] of Object.entries(inputsByRedeemId)) {
3986
+ next[id] = seedState(input);
3987
+ }
3988
+ return next;
3989
+ });
3990
+ useEffect6(() => {
3991
+ setStateMap((prev) => {
3992
+ let changed = false;
3993
+ const next = {};
3994
+ for (const [id, input] of Object.entries(inputsByRedeemId)) {
3995
+ const existing = prev[id];
3996
+ if (existing) {
3997
+ next[id] = existing;
3998
+ } else {
3999
+ next[id] = seedState(input);
4000
+ changed = true;
4001
+ }
4002
+ }
4003
+ if (Object.keys(next).length !== Object.keys(prev).length) changed = true;
4004
+ return changed ? next : prev;
4005
+ });
4006
+ }, [inputsByRedeemId]);
4007
+ useOnRedeemEvent(
4008
+ useMemo7(() => {
4009
+ if (Object.keys(inputsByRedeemId).length === 0) return null;
4010
+ return (event) => {
4011
+ const input = inputsByRedeemId[event.redeemId];
4012
+ if (!input) return;
4013
+ setStateMap((prev) => {
4014
+ var _a, _b, _c, _d;
4015
+ const existing = prev[event.redeemId];
4016
+ if (!existing) return prev;
4017
+ const nextLegs = __spreadProps(__spreadValues({}, existing.legs), {
4018
+ [event.venueMarketOutcomeId]: {
4019
+ status: event.status,
4020
+ txHash: event.txHash,
4021
+ errorMessage: event.errorMessage
4022
+ }
4023
+ });
4024
+ 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);
4025
+ const derived = computeDerivedState(nextLegs, expectedCount);
4026
+ const nextState = {
4027
+ pending: !derived.terminal,
4028
+ terminal: derived.terminal,
4029
+ allConfirmed: derived.allConfirmed,
4030
+ anyFailed: derived.anyFailed,
4031
+ errorMessage: derived.errorMessage,
4032
+ legs: nextLegs
4033
+ };
4034
+ return __spreadProps(__spreadValues({}, prev), { [event.redeemId]: nextState });
4035
+ });
4036
+ };
4037
+ }, [inputsByRedeemId])
4038
+ );
4039
+ return stateMap;
4040
+ }
4041
+
4042
+ // src/execution/use-redeem-lifecycle.ts
4043
+ import { useMemo as useMemo8 } from "react";
4044
+ var INITIAL_STATE = {
4045
+ pending: true,
4046
+ terminal: false,
4047
+ allConfirmed: false,
4048
+ anyFailed: false,
4049
+ errorMessage: null,
4050
+ legs: {}
4051
+ };
4052
+ function useRedeemLifecycle(input) {
4053
+ var _a;
4054
+ const inputs = useMemo8(() => input ? [input] : [], [input]);
4055
+ const map = useRedeemLifecycles(inputs);
4056
+ if (!input) return INITIAL_STATE;
4057
+ return (_a = map[input.redeemId]) != null ? _a : INITIAL_STATE;
4058
+ }
4059
+
3616
4060
  export {
3617
4061
  __spreadValues,
3618
4062
  __spreadProps,
@@ -3637,9 +4081,13 @@ export {
3637
4081
  executionKeys,
3638
4082
  invalidateBalanceQueries,
3639
4083
  invalidatePositionQueries,
4084
+ userActivityQueryKeys,
4085
+ invalidateUserActivityQueries,
4086
+ invalidateUserMoneyState,
3640
4087
  AggBalanceProvider,
3641
4088
  EventListStateProvider,
3642
4089
  useEventListState,
4090
+ getIntervalSeconds,
3643
4091
  createMarketChartData,
3644
4092
  mergeMarketChartData,
3645
4093
  createMarketLiveState,
@@ -3672,6 +4120,7 @@ export {
3672
4120
  resolveEventTradingState,
3673
4121
  resolveOrderEligibility,
3674
4122
  resolveDefaultMarket,
4123
+ TradeSide,
3675
4124
  tradingReducer,
3676
4125
  useEventTradingContext,
3677
4126
  AggUiProvider,
@@ -3686,7 +4135,10 @@ export {
3686
4135
  useSyncBalances,
3687
4136
  useExecutionProgress,
3688
4137
  computeClosedPositionTotals,
4138
+ RedeemRejectedError,
3689
4139
  useRedeem,
3690
4140
  useOnRedeemEvent2 as useOnRedeemEvent,
3691
- useRedeemEligibleCount
4141
+ useRedeemEligibleCount,
4142
+ useRedeemLifecycles,
4143
+ useRedeemLifecycle
3692
4144
  };