@agg-build/hooks 1.0.2 → 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,24 +472,66 @@ 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: {
509
+ activeFilter: "Active",
510
+ closedFilter: "Closed",
511
+ marketHeader: "Market",
466
512
  totalTradedHeader: "Total traded",
513
+ currentValueHeader: "Current value",
514
+ statusHeader: "Status",
515
+ resolutionHeader: "Resolution",
516
+ payoutHeader: "Payout",
517
+ resultHeader: "Result",
467
518
  amountWonHeader: "Amount won",
468
519
  claimHeader: "Claim",
469
520
  claim: "Claim",
470
521
  claimed: "Claimed",
471
522
  pending: "Pending",
523
+ open: "Open",
472
524
  won: "Won",
473
525
  lost: "Lost",
526
+ sold: "Sold",
474
527
  resolved: "Resolved",
475
528
  marketClosed: "Market closed",
476
- closed: "Closed"
529
+ closed: "Closed",
530
+ searchPlaceholder: "Search...",
531
+ noResults: "No results",
532
+ avgPrefix: "avg",
533
+ nowPrefix: "now",
534
+ finalPrefix: "final"
477
535
  }
478
536
  },
479
537
  eventList: {
@@ -611,7 +669,7 @@ var enUsLabels = {
611
669
  settlementEmpty: "No settlement details available.",
612
670
  disclaimer: "By trading, you agree to the Terms of Use of each exchange.",
613
671
  geoBlockTermsLink: "Terms of Use",
614
- geoBlockGenericMessage: "Trading is not available in your region. See ",
672
+ geoBlockGenericMessage: "None of the venues for this market are available in your region. See ",
615
673
  geoBlockVenueMessage: (venueLabel) => `Trading on ${venueLabel} is not available in your region. See `,
616
674
  geoBlockMessageSuffix: " for more information.",
617
675
  geoBlockModalAriaLabel: "Geo-restricted location",
@@ -665,6 +723,7 @@ var enUsLabels = {
665
723
  noMarketSelected: "Select a market to place an order.",
666
724
  noOrderbooks: "No live orderbooks are available for this market right now.",
667
725
  quoteUnavailable: "Quote temporarily unavailable. Please try again.",
726
+ quoteBalanceMismatch: "Quote balance mismatch. Try a different amount.",
668
727
  selectedVenueUnavailable: "The venue you selected is no longer available on this route. Review the updated options and try again.",
669
728
  engineUnavailable: "The routing engine is temporarily unavailable. Please try again in a moment.",
670
729
  insufficientInputAmount: "Trade amount is too small to cover bridging and execution costs. Increase your spend or deposit funds on the destination chain.",
@@ -691,10 +750,18 @@ var enUsLabels = {
691
750
  splitOrderDescription: "We split your order for the best price:",
692
751
  viewAllRoutes: (count) => `View all (${count})`,
693
752
  venueUnavailableInRegion: "Unavailable in your region",
753
+ platformFee: "0% platform fees",
754
+ estimatedFees: "Estimated fees",
755
+ estimatedFeesTooltipAria: "Estimated fees breakdown",
756
+ feeBreakdownVenueFees: "Venue fees",
757
+ feeBreakdownBridgeFees: "Bridge fees",
758
+ feeBreakdownExecutionGas: "Execution gas",
759
+ feeBreakdownTotalFees: "Total fees",
694
760
  toWin: (tab) => tab === "buy" ? "To win" : "Payout",
695
761
  buyingOutcome: (label) => `Buying ${label}`,
696
762
  sellingOutcome: (label) => `Selling ${label}`,
697
763
  findingBestRoute: "Finding the best route...",
764
+ checkingBalance: "Checking balance",
698
765
  submittingOrderProgress: "Submitting order...",
699
766
  orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
700
767
  executingOnVenue: (venueLabel) => `Executing on ${venueLabel}...`,
@@ -953,6 +1020,7 @@ var defaultAggUiSearchConfig = {
953
1020
  var defaultAggUiConfig = {
954
1021
  enableLogs: false,
955
1022
  enableWebsocketsLogs: false,
1023
+ enableDebug: false,
956
1024
  general: {
957
1025
  locale: DEFAULT_LOCALE,
958
1026
  theme: "light",
@@ -962,6 +1030,7 @@ var defaultAggUiConfig = {
962
1030
  features: {
963
1031
  enableAnimations: true,
964
1032
  enableLiveUpdates: true,
1033
+ showFeesBreakdown: false,
965
1034
  enableGradients: false
966
1035
  },
967
1036
  market: {
@@ -989,7 +1058,7 @@ var mergeAggUiSearchConfig = (config) => {
989
1058
  };
990
1059
  };
991
1060
  var mergeAggUiConfig = (persisted, config) => {
992
- 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;
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;
993
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;
994
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;
995
1064
  const formatters = createFormatters(locale);
@@ -997,31 +1066,33 @@ var mergeAggUiConfig = (persisted, config) => {
997
1066
  return {
998
1067
  enableLogs: (_i = config == null ? void 0 : config.enableLogs) != null ? _i : defaultAggUiConfig.enableLogs,
999
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,
1000
1070
  general: {
1001
1071
  locale,
1002
1072
  theme,
1003
- rootClassName: (_l = (_k = config == null ? void 0 : config.general) == null ? void 0 : _k.rootClassName) != null ? _l : defaultAggUiConfig.general.rootClassName,
1004
- 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)
1005
1075
  },
1006
1076
  features: {
1007
- enableAnimations: (_o = (_n = config == null ? void 0 : config.features) == null ? void 0 : _n.enableAnimations) != null ? _o : defaultAggUiConfig.features.enableAnimations,
1008
- enableLiveUpdates: (_q = (_p = config == null ? void 0 : config.features) == null ? void 0 : _p.enableLiveUpdates) != null ? _q : defaultAggUiConfig.features.enableLiveUpdates,
1009
- enableGradients: (_s = (_r = config == null ? void 0 : config.features) == null ? void 0 : _r.enableGradients) != null ? _s : 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
1010
1081
  },
1011
1082
  market: {
1012
- arbitrageThreshold: (_u = (_t = config == null ? void 0 : config.market) == null ? void 0 : _t.arbitrageThreshold) != null ? _u : defaultAggUiConfig.market.arbitrageThreshold
1083
+ arbitrageThreshold: (_x = (_w = config == null ? void 0 : config.market) == null ? void 0 : _w.arbitrageThreshold) != null ? _x : defaultAggUiConfig.market.arbitrageThreshold
1013
1084
  },
1014
1085
  chart: {
1015
- defaultChartTimeRange: (_w = (_v = config == null ? void 0 : config.chart) == null ? void 0 : _v.defaultChartTimeRange) != null ? _w : defaultAggUiConfig.chart.defaultChartTimeRange,
1016
- selectedChartTimeRange: (_A = (_z = (_x = persisted.chart) == null ? void 0 : _x.selectedChartTimeRange) != null ? _z : (_y = config == null ? void 0 : config.chart) == null ? void 0 : _y.defaultChartTimeRange) != null ? _A : 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,
1017
1088
  setSelectedChartTimeRange: defaultAggUiConfig.chart.setSelectedChartTimeRange
1018
1089
  },
1019
1090
  formatting: {
1020
- formatNumber: (_C = (_B = config == null ? void 0 : config.formatting) == null ? void 0 : _B.formatNumber) != null ? _C : formatters.formatNumber,
1021
- formatPercent: (_E = (_D = config == null ? void 0 : config.formatting) == null ? void 0 : _D.formatPercent) != null ? _E : formatters.formatPercent,
1022
- formatCurrency: (_G = (_F = config == null ? void 0 : config.formatting) == null ? void 0 : _F.formatCurrency) != null ? _G : formatters.formatCurrency,
1023
- formatCompactCurrency: (_I = (_H = config == null ? void 0 : config.formatting) == null ? void 0 : _H.formatCompactCurrency) != null ? _I : formatters.formatCompactCurrency,
1024
- formatDate: (_K = (_J = config == null ? void 0 : config.formatting) == null ? void 0 : _J.formatDate) != null ? _K : 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
1025
1096
  },
1026
1097
  search: mergeAggUiSearchConfig(config == null ? void 0 : config.search),
1027
1098
  walletActions: config == null ? void 0 : config.walletActions,
@@ -1084,6 +1155,26 @@ var shouldInvalidateBalancesForOrderEvent = (event, currentUserId) => {
1084
1155
  if (!currentUserId) return true;
1085
1156
  return event.userId === currentUserId;
1086
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
+ };
1087
1178
 
1088
1179
  // src/core/providers/balance-provider.tsx
1089
1180
  import { useQuery } from "@tanstack/react-query";
@@ -1104,6 +1195,7 @@ var CHAIN_LABELS = {
1104
1195
  10: "Optimism",
1105
1196
  56: "BNB",
1106
1197
  137: "Polygon",
1198
+ 1337: "Hyperliquid",
1107
1199
  8453: "Base",
1108
1200
  42161: "Arbitrum",
1109
1201
  43114: "Avalanche",
@@ -1143,7 +1235,9 @@ function AggBalanceProvider({ children }) {
1143
1235
  return client.getManagedBalances();
1144
1236
  }),
1145
1237
  enabled: Boolean(client && isAuthenticated),
1146
- staleTime: 1e4
1238
+ staleTime: 60 * 1e3,
1239
+ refetchOnWindowFocus: "always",
1240
+ refetchOnReconnect: "always"
1147
1241
  });
1148
1242
  const managedBalancesData = balancesQuery.data;
1149
1243
  const managedBalances = useMemo(
@@ -1341,6 +1435,7 @@ import {
1341
1435
  import { useQueryClient } from "@tanstack/react-query";
1342
1436
 
1343
1437
  // src/market-data/chart-cache.ts
1438
+ var MAX_CACHE_RETENTION_SECONDS = 7 * 30 * 24 * 60 * 60 + 14 * 24 * 60 * 60;
1344
1439
  var getIntervalSeconds = (interval) => {
1345
1440
  switch (interval) {
1346
1441
  case "1m":
@@ -1359,12 +1454,41 @@ var createVenueData = (venue, outcomeIds = []) => ({
1359
1454
  candles: [],
1360
1455
  liveCandle: null,
1361
1456
  lineValue: void 0,
1362
- lastTrade: null
1457
+ lastTrade: null,
1458
+ lastUpdateTs: null
1363
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
+ };
1364
1487
  var sortCandles = (candles) => {
1365
1488
  return [...candles].sort((left, right) => left.time - right.time);
1366
1489
  };
1367
1490
  var createMarketChartData = (params) => {
1491
+ var _a;
1368
1492
  const candles = sortCandles(
1369
1493
  params.response.data.map((candle) => ({
1370
1494
  time: Math.floor(candle.t / 1e3),
@@ -1377,6 +1501,7 @@ var createMarketChartData = (params) => {
1377
1501
  }))
1378
1502
  );
1379
1503
  const lastCandle = candles[candles.length - 1];
1504
+ const lastUpdateTs = (_a = lastCandle == null ? void 0 : lastCandle.time) != null ? _a : null;
1380
1505
  const venues = {
1381
1506
  [params.response.venue]: {
1382
1507
  venue: params.response.venue,
@@ -1384,7 +1509,8 @@ var createMarketChartData = (params) => {
1384
1509
  candles,
1385
1510
  liveCandle: null,
1386
1511
  lineValue: lastCandle == null ? void 0 : lastCandle.close,
1387
- lastTrade: null
1512
+ lastTrade: null,
1513
+ lastUpdateTs
1388
1514
  }
1389
1515
  };
1390
1516
  return {
@@ -1394,7 +1520,8 @@ var createMarketChartData = (params) => {
1394
1520
  interval: params.interval,
1395
1521
  startTs: params.startTs,
1396
1522
  endTs: params.endTs,
1397
- venues
1523
+ venues,
1524
+ lastUpdateTs
1398
1525
  };
1399
1526
  };
1400
1527
  var mergeMarketChartData = (params) => {
@@ -1428,9 +1555,75 @@ var mergeMarketChartData = (params) => {
1428
1555
  interval: params.interval,
1429
1556
  startTs: params.startTs,
1430
1557
  endTs: params.endTs,
1431
- venues
1558
+ venues,
1559
+ lastUpdateTs: resolveMaxLastUpdateTs(venues)
1432
1560
  };
1433
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
+ };
1434
1627
  var applyTradeToMarketChart = (data, trade) => {
1435
1628
  var _a, _b, _c;
1436
1629
  if (!data || data.marketId !== trade.outcomeId) {
@@ -1440,6 +1633,15 @@ var applyTradeToMarketChart = (data, trade) => {
1440
1633
  const intervalSeconds = getIntervalSeconds(data.interval);
1441
1634
  const expectedCandleTime = trade.timestamp - trade.timestamp % intervalSeconds;
1442
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
+ );
1443
1645
  if (liveCandle && liveCandle.time === expectedCandleTime) {
1444
1646
  liveCandle = __spreadProps(__spreadValues({}, liveCandle), {
1445
1647
  close: trade.price,
@@ -1459,16 +1661,20 @@ var applyTradeToMarketChart = (data, trade) => {
1459
1661
  source: "trade"
1460
1662
  };
1461
1663
  }
1462
- return __spreadProps(__spreadValues({}, data), {
1463
- venues: __spreadProps(__spreadValues({}, data.venues), {
1464
- [trade.venue]: __spreadProps(__spreadValues({}, currentVenue), {
1465
- outcomeIds: currentVenue.outcomeIds.includes(trade.outcomeId) ? currentVenue.outcomeIds : [...currentVenue.outcomeIds, trade.outcomeId],
1466
- liveCandle,
1467
- lineValue: (_c = liveCandle == null ? void 0 : liveCandle.close) != null ? _c : trade.price,
1468
- lastTrade: trade
1469
- })
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
1470
1672
  })
1471
1673
  });
1674
+ return __spreadProps(__spreadValues({}, data), {
1675
+ venues: nextVenues,
1676
+ lastUpdateTs: resolveMaxLastUpdateTs(nextVenues)
1677
+ });
1472
1678
  };
1473
1679
 
1474
1680
  // src/market-data/live-cache.ts
@@ -1659,7 +1865,15 @@ var marketDataKeys = {
1659
1865
  orderbook: (marketId, selectionKey, depth) => ["market-data", "orderbook", marketId, selectionKey != null ? selectionKey : null, depth != null ? depth : null],
1660
1866
  orderbookPrefix: (marketId) => marketId == null ? ["market-data", "orderbook"] : ["market-data", "orderbook", marketId],
1661
1867
  orderbookQuote: (marketId, side, size) => ["market-data", "orderbook-quote", marketId, side, size],
1662
- 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],
1663
1877
  chartPrefix: (marketId, interval) => {
1664
1878
  if (!marketId) return ["market-data", "chart"];
1665
1879
  if (!interval) return ["market-data", "chart", marketId];
@@ -1868,6 +2082,9 @@ function AggWebSocketProvider({ children }) {
1868
2082
  const invalidatePositionCaches = useCallback3(() => {
1869
2083
  invalidatePositionQueries(queryClient);
1870
2084
  }, [queryClient]);
2085
+ const invalidateActivityCaches = useCallback3(() => {
2086
+ invalidateUserActivityQueries(queryClient);
2087
+ }, [queryClient]);
1871
2088
  const callbacks = useMemo2(
1872
2089
  () => ({
1873
2090
  onSnapshot: (marketId, book) => {
@@ -1886,6 +2103,14 @@ function AggWebSocketProvider({ children }) {
1886
2103
  syncLiveQuery(marketId, (previous) => withLiveOrderbook(previous, book, "snapshot"));
1887
2104
  if (book.midpoint != null) {
1888
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
+ );
1889
2114
  }
1890
2115
  },
1891
2116
  onDelta: (marketId, book) => {
@@ -1931,6 +2156,14 @@ function AggWebSocketProvider({ children }) {
1931
2156
  });
1932
2157
  if (book.midpoint != null) {
1933
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
+ );
1934
2167
  }
1935
2168
  },
1936
2169
  onTrade: (trade) => {
@@ -1968,6 +2201,7 @@ function AggWebSocketProvider({ children }) {
1968
2201
  onBalanceUpdate: (msg) => {
1969
2202
  if (isClientAuthenticated) {
1970
2203
  invalidateBalanceCaches();
2204
+ invalidateActivityCaches();
1971
2205
  }
1972
2206
  for (const listener of balanceUpdateListenersRef.current) {
1973
2207
  listener(msg);
@@ -2033,6 +2267,7 @@ function AggWebSocketProvider({ children }) {
2033
2267
  [
2034
2268
  client,
2035
2269
  enableWebsocketsLogs,
2270
+ invalidateActivityCaches,
2036
2271
  invalidateBalanceCaches,
2037
2272
  invalidatePositionCaches,
2038
2273
  isClientAuthenticated,
@@ -2096,9 +2331,26 @@ var resolveTradingStateKind = (status) => {
2096
2331
  return "closed";
2097
2332
  };
2098
2333
  var resolveMarketWinningOutcome = (market) => {
2099
- var _a;
2334
+ var _a, _b, _c, _d;
2100
2335
  if (!market) return null;
2101
- 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;
2102
2354
  };
2103
2355
  var AFFIRMATIVE_WINNER_LABELS = /* @__PURE__ */ new Set(["yes", "up", "buy", "long", "true"]);
2104
2356
  var isAffirmativeWinnerLabel = (label) => {
@@ -2286,51 +2538,50 @@ function findOutcomeAcrossMarkets(event, outcomeId) {
2286
2538
  }
2287
2539
  return null;
2288
2540
  }
2541
+ var TradeSide = {
2542
+ Buy: "buy",
2543
+ Sell: "sell"
2544
+ };
2289
2545
  function tradingReducer(state, action) {
2290
- var _a, _b;
2546
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2291
2547
  switch (action.type) {
2292
2548
  case "INITIALIZE_EVENT": {
2293
2549
  if (!action.event) {
2294
- return { event: null, market: null, outcome: null };
2550
+ return { event: null, market: null, outcome: null, tradeSide: TradeSide.Buy };
2295
2551
  }
2296
- const market = resolveDefaultMarket(action.event);
2297
2552
  return {
2298
2553
  event: action.event,
2299
- market,
2300
- outcome: resolveDefaultOutcome(market)
2554
+ market: null,
2555
+ outcome: null,
2556
+ tradeSide: TradeSide.Buy
2301
2557
  };
2302
2558
  }
2303
2559
  case "SYNC_EVENT": {
2304
- const nextEvent = action.event;
2305
- const preservedMarket = state.market ? findMarketById(nextEvent, state.market.id) : null;
2306
- if (preservedMarket) {
2307
- const preservedMarketState = resolveMarketTradingState(preservedMarket);
2308
- if (preservedMarketState.isTradingDisabled) {
2309
- const tradableAlternative = resolveDefaultMarket(nextEvent);
2310
- if (tradableAlternative && resolveMarketTradingState(tradableAlternative).isOpen) {
2311
- return {
2312
- event: nextEvent,
2313
- market: tradableAlternative,
2314
- outcome: resolveDefaultOutcome(tradableAlternative)
2315
- };
2316
- }
2317
- }
2318
- 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) {
2319
2564
  return {
2320
- event: nextEvent,
2321
- market: preservedMarket,
2322
- 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
2323
2569
  };
2324
2570
  }
2325
- const defaultMarket = resolveDefaultMarket(nextEvent);
2571
+ const syncedOutcome = previousOutcomeId ? findOutcomeById(syncedMarket, previousOutcomeId) : null;
2326
2572
  return {
2327
- event: nextEvent,
2328
- market: defaultMarket,
2329
- outcome: resolveDefaultOutcome(defaultMarket)
2573
+ event: action.event,
2574
+ market: syncedMarket,
2575
+ outcome: syncedOutcome,
2576
+ tradeSide: (_f = state.tradeSide) != null ? _f : TradeSide.Buy
2330
2577
  };
2331
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
+ }
2332
2583
  case "SELECT_MARKET": {
2333
- 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;
2334
2585
  if (!market) return state;
2335
2586
  if (resolveMarketTradingState(market).kind === "resolved") return state;
2336
2587
  return __spreadProps(__spreadValues({}, state), {
@@ -2339,6 +2590,9 @@ function tradingReducer(state, action) {
2339
2590
  });
2340
2591
  }
2341
2592
  case "SELECT_OUTCOME": {
2593
+ if (((_j = state.outcome) == null ? void 0 : _j.id) === action.outcomeId) {
2594
+ return state;
2595
+ }
2342
2596
  if (state.market) {
2343
2597
  const outcomeInCurrentMarket = findOutcomeById(state.market, action.outcomeId);
2344
2598
  if (outcomeInCurrentMarket) {
@@ -2390,7 +2644,8 @@ function logAction(actionType, payload, prev, next, enableLogs) {
2390
2644
  var initialState = {
2391
2645
  event: null,
2392
2646
  market: null,
2393
- outcome: null
2647
+ outcome: null,
2648
+ tradeSide: TradeSide.Buy
2394
2649
  };
2395
2650
  var EventTradingContext = createContext4(void 0);
2396
2651
  var useEventTradingContext = () => {
@@ -2400,9 +2655,15 @@ var EventTradingProvider = ({
2400
2655
  children,
2401
2656
  enableLogs = false
2402
2657
  }) => {
2658
+ var _a, _b;
2403
2659
  const [state, rawDispatch] = useReducer(tradingReducer, initialState);
2404
2660
  const stateRef = useRef3(state);
2661
+ const pendingAtomicSelectionRef = useRef3(null);
2405
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
+ }
2406
2667
  const dispatch = useCallback4(
2407
2668
  (action) => {
2408
2669
  const prev = stateRef.current;
@@ -2425,24 +2686,45 @@ var EventTradingProvider = ({
2425
2686
  [dispatch]
2426
2687
  );
2427
2688
  const selectOutcome = useCallback4(
2428
- (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
+ },
2429
2695
  [dispatch]
2430
2696
  );
2431
2697
  const selectMarketAndOutcome = useCallback4(
2432
- (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 }),
2433
2713
  [dispatch]
2434
2714
  );
2435
2715
  const value = useMemo3(
2436
2716
  () => {
2437
- var _a, _b, _c, _d, _e, _f, _g, _h;
2717
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
2438
2718
  return {
2439
2719
  selectedEvent: state.event,
2440
2720
  selectedMarket: state.market,
2441
2721
  selectedOutcome: state.outcome,
2442
- 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,
2443
2723
  selectedMarketId: (_d = (_c = state.market) == null ? void 0 : _c.id) != null ? _d : null,
2444
2724
  selectedOutcomeId: (_f = (_e = state.outcome) == null ? void 0 : _e.id) != null ? _f : null,
2445
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,
2446
2728
  initializeFromEvent,
2447
2729
  syncEvent,
2448
2730
  selectMarket,
@@ -2450,7 +2732,15 @@ var EventTradingProvider = ({
2450
2732
  selectMarketAndOutcome
2451
2733
  };
2452
2734
  },
2453
- [state, initializeFromEvent, syncEvent, selectMarket, selectOutcome, selectMarketAndOutcome]
2735
+ [
2736
+ state,
2737
+ initializeFromEvent,
2738
+ syncEvent,
2739
+ selectMarket,
2740
+ selectOutcome,
2741
+ selectMarketAndOutcome,
2742
+ setTradeSide
2743
+ ]
2454
2744
  );
2455
2745
  return /* @__PURE__ */ jsx4(EventTradingContext.Provider, { value, children });
2456
2746
  };
@@ -2776,7 +3066,7 @@ var createAuthCallbackSession = (tokens) => {
2776
3066
  };
2777
3067
  };
2778
3068
  var executeWalletAuthFlow = (input) => __async(null, null, function* () {
2779
- var _a, _b;
3069
+ var _a, _b, _c, _d;
2780
3070
  const address = input.options.address.trim();
2781
3071
  const chain = (_a = input.options.chain) != null ? _a : "ethereum";
2782
3072
  const provider = chain === "solana" ? "siws" : "siwe";
@@ -2799,14 +3089,14 @@ var executeWalletAuthFlow = (input) => __async(null, null, function* () {
2799
3089
  uri: location.uri,
2800
3090
  nonce: startResult.nonce,
2801
3091
  chainId: typeof input.options.chainId === "string" ? input.options.chainId : "mainnet",
2802
- statement: input.options.statement
3092
+ statement: (_c = startResult.statement) != null ? _c : input.options.statement
2803
3093
  }) : input.client.buildSiweMessage({
2804
3094
  domain: location.domain,
2805
3095
  address,
2806
3096
  uri: location.uri,
2807
3097
  nonce: startResult.nonce,
2808
3098
  chainId: typeof input.options.chainId === "number" ? input.options.chainId : void 0,
2809
- statement: input.options.statement
3099
+ statement: (_d = startResult.statement) != null ? _d : input.options.statement
2810
3100
  });
2811
3101
  const signature = yield input.options.signMessage(message);
2812
3102
  const result = yield input.client.verify({ message, signature });
@@ -3117,7 +3407,7 @@ function useWithdrawManaged(options) {
3117
3407
  mutationFn: (params) => client.withdrawManaged(params),
3118
3408
  onSuccess: (data) => {
3119
3409
  var _a;
3120
- invalidateBalanceQueries(queryClient);
3410
+ invalidateUserMoneyState(queryClient);
3121
3411
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
3122
3412
  },
3123
3413
  onError: options == null ? void 0 : options.onError
@@ -3229,7 +3519,7 @@ function useSyncBalances(options) {
3229
3519
  mutationFn: () => client.syncManagedBalances(),
3230
3520
  onSuccess: () => {
3231
3521
  var _a;
3232
- invalidateBalanceQueries(queryClient);
3522
+ invalidateUserMoneyState(queryClient);
3233
3523
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
3234
3524
  },
3235
3525
  onError: options == null ? void 0 : options.onError
@@ -3311,6 +3601,12 @@ function useExecutionProgress({
3311
3601
  event: mappedEvent,
3312
3602
  filledAmountRaw: msg.filledAmountRaw,
3313
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,
3314
3610
  errorReason: event === "bridge_ws_subscribe_failed" ? (_a = msg.errorReason) != null ? _a : "Bridge event subscription failed." : msg.errorReason,
3315
3611
  timestamp: msg.timestamp
3316
3612
  };
@@ -3389,15 +3685,29 @@ function useExecutionProgress({
3389
3685
  });
3390
3686
  return;
3391
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
+ }
3392
3709
  if (event === "dag_failed") {
3393
- setDagProgress((prev) => {
3394
- var _a2;
3395
- if (!prev) return prev;
3396
- return __spreadProps(__spreadValues({}, prev), {
3397
- status: "failed",
3398
- errorReason: (_a2 = msg.errorReason) != null ? _a2 : null
3399
- });
3400
- });
3710
+ setDagProgress((prev) => buildFailedProgress(prev));
3401
3711
  return;
3402
3712
  }
3403
3713
  }, []);
@@ -3422,7 +3732,7 @@ function useExecutionProgress({
3422
3732
  }
3423
3733
  };
3424
3734
  const reconcile = () => __async(null, null, function* () {
3425
- var _a, _b, _c;
3735
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
3426
3736
  if (cancelled || pollInFlightRef.current) return;
3427
3737
  const pending = orderIds.filter((id) => !terminalOrderIdsRef.current.has(id));
3428
3738
  if (pending.length === 0) {
@@ -3454,7 +3764,13 @@ function useExecutionProgress({
3454
3764
  venue: (_a = order.venue) != null ? _a : "",
3455
3765
  event: mapped,
3456
3766
  filledAmountRaw: (_b = order.filledAmountRaw) != null ? _b : void 0,
3457
- 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,
3458
3774
  timestamp: new Date(order.updatedAt).getTime() || Date.now()
3459
3775
  });
3460
3776
  }
@@ -3534,11 +3850,27 @@ var computeClosedPositionTotals = (group) => {
3534
3850
 
3535
3851
  // src/execution/use-redeem.ts
3536
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";
3537
3861
  var useRedeem = () => {
3538
3862
  const client = useAggClient();
3539
3863
  const queryClient = useQueryClient6();
3540
3864
  return useMutation5({
3541
- 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
+ }),
3542
3874
  onSuccess: () => {
3543
3875
  queryClient.invalidateQueries({ queryKey: executionKeys.positionsPrefix() });
3544
3876
  queryClient.invalidateQueries({ queryKey: executionKeys.balances() });
@@ -3589,6 +3921,142 @@ var useRedeemEligibleCount = () => {
3589
3921
  return (_a = query.data) != null ? _a : 0;
3590
3922
  };
3591
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
+
3592
4060
  export {
3593
4061
  __spreadValues,
3594
4062
  __spreadProps,
@@ -3613,9 +4081,13 @@ export {
3613
4081
  executionKeys,
3614
4082
  invalidateBalanceQueries,
3615
4083
  invalidatePositionQueries,
4084
+ userActivityQueryKeys,
4085
+ invalidateUserActivityQueries,
4086
+ invalidateUserMoneyState,
3616
4087
  AggBalanceProvider,
3617
4088
  EventListStateProvider,
3618
4089
  useEventListState,
4090
+ getIntervalSeconds,
3619
4091
  createMarketChartData,
3620
4092
  mergeMarketChartData,
3621
4093
  createMarketLiveState,
@@ -3648,6 +4120,7 @@ export {
3648
4120
  resolveEventTradingState,
3649
4121
  resolveOrderEligibility,
3650
4122
  resolveDefaultMarket,
4123
+ TradeSide,
3651
4124
  tradingReducer,
3652
4125
  useEventTradingContext,
3653
4126
  AggUiProvider,
@@ -3662,7 +4135,10 @@ export {
3662
4135
  useSyncBalances,
3663
4136
  useExecutionProgress,
3664
4137
  computeClosedPositionTotals,
4138
+ RedeemRejectedError,
3665
4139
  useRedeem,
3666
4140
  useOnRedeemEvent2 as useOnRedeemEvent,
3667
- useRedeemEligibleCount
4141
+ useRedeemEligibleCount,
4142
+ useRedeemLifecycles,
4143
+ useRedeemLifecycle
3668
4144
  };