@agg-build/ui 1.2.10 → 1.2.12

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.
Files changed (140) hide show
  1. package/dist/{chunk-K23CJ5UP.mjs → chunk-3JXBOU24.mjs} +580 -307
  2. package/dist/{chunk-5MTIBPDY.mjs → chunk-4WBQTUPW.mjs} +1091 -441
  3. package/dist/{chunk-5PSAIGOT.mjs → chunk-IBOE7DRY.mjs} +137 -61
  4. package/dist/{chunk-XKADJNAJ.mjs → chunk-J6WELNCX.mjs} +601 -326
  5. package/dist/{chunk-7JKGAWU5.mjs → chunk-U55T5BPE.mjs} +1802 -1564
  6. package/dist/{chunk-QFW5NDJ6.mjs → chunk-X3KCFWXN.mjs} +1312 -1040
  7. package/dist/{chunk-5MDFM2MX.mjs → chunk-YSW4ULL5.mjs} +1 -1
  8. package/dist/events.js +2892 -1746
  9. package/dist/events.mjs +3 -3
  10. package/dist/index.js +7085 -4956
  11. package/dist/index.mjs +520 -139
  12. package/dist/modals.js +3434 -2315
  13. package/dist/modals.mjs +3 -3
  14. package/dist/pages.js +4175 -2764
  15. package/dist/pages.mjs +6 -6
  16. package/dist/primitives.js +1295 -942
  17. package/dist/primitives.mjs +5 -1
  18. package/dist/styles.css +1 -1
  19. package/dist/tailwind.css +1 -1
  20. package/dist/trading.js +1677 -1249
  21. package/dist/trading.mjs +4 -4
  22. package/dist/types/agg-provider.d.mts +27 -0
  23. package/dist/types/agg-provider.d.ts +27 -0
  24. package/dist/types/deposit/deposit-modal.types.d.mts +10 -1
  25. package/dist/types/deposit/deposit-modal.types.d.ts +10 -1
  26. package/dist/types/deposit/index.d.mts +1 -1
  27. package/dist/types/deposit/index.d.ts +1 -1
  28. package/dist/types/deposit/steps/crypto-transfer.d.mts +1 -2
  29. package/dist/types/deposit/steps/crypto-transfer.d.ts +1 -2
  30. package/dist/types/deposit/steps/deposit-method.d.mts +2 -1
  31. package/dist/types/deposit/steps/deposit-method.d.ts +2 -1
  32. package/dist/types/events/item/event-list-item.types.d.mts +3 -1
  33. package/dist/types/events/item/event-list-item.types.d.ts +3 -1
  34. package/dist/types/events/item/event-list-item.utils.d.mts +26 -2
  35. package/dist/types/events/item/event-list-item.utils.d.ts +26 -2
  36. package/dist/types/events/item-details/event-list-item-details.types.d.mts +30 -1
  37. package/dist/types/events/item-details/event-list-item-details.types.d.ts +30 -1
  38. package/dist/types/events/list/event-list-tabs.d.mts +6 -1
  39. package/dist/types/events/list/event-list-tabs.d.ts +6 -1
  40. package/dist/types/events/market-details/index.d.mts +1 -1
  41. package/dist/types/events/market-details/index.d.ts +1 -1
  42. package/dist/types/events/market-details/market-details.types.d.mts +27 -2
  43. package/dist/types/events/market-details/market-details.types.d.ts +27 -2
  44. package/dist/types/events/market-details/market-details.utils.d.mts +18 -4
  45. package/dist/types/events/market-details/market-details.utils.d.ts +18 -4
  46. package/dist/types/events/market-details/orderbook-aggregation.d.mts +30 -10
  47. package/dist/types/events/market-details/orderbook-aggregation.d.ts +30 -10
  48. package/dist/types/events/shared/chart-auto-fallback.d.mts +43 -0
  49. package/dist/types/events/shared/chart-auto-fallback.d.ts +43 -0
  50. package/dist/types/events/shared/display-outcome-price.d.mts +14 -0
  51. package/dist/types/events/shared/display-outcome-price.d.ts +14 -0
  52. package/dist/types/events/shared/display-outcome-venue.d.mts +30 -0
  53. package/dist/types/events/shared/display-outcome-venue.d.ts +30 -0
  54. package/dist/types/events/shared/display-reference-price.d.mts +4 -0
  55. package/dist/types/events/shared/display-reference-price.d.ts +4 -0
  56. package/dist/types/events/shared/select-outcome-price.d.mts +21 -0
  57. package/dist/types/events/shared/select-outcome-price.d.ts +21 -0
  58. package/dist/types/index.d.mts +2 -0
  59. package/dist/types/index.d.ts +2 -0
  60. package/dist/types/notifications/agg-notification-events-provider.d.mts +35 -0
  61. package/dist/types/notifications/agg-notification-events-provider.d.ts +35 -0
  62. package/dist/types/notifications/agg-toast-provider.d.mts +27 -0
  63. package/dist/types/notifications/agg-toast-provider.d.ts +27 -0
  64. package/dist/types/notifications/deposit-notification-events.d.mts +10 -0
  65. package/dist/types/notifications/deposit-notification-events.d.ts +10 -0
  66. package/dist/types/notifications/index.d.mts +2 -0
  67. package/dist/types/notifications/index.d.ts +2 -0
  68. package/dist/types/pages/user-profile/components/available-balance-card.d.mts +2 -1
  69. package/dist/types/pages/user-profile/components/available-balance-card.d.ts +2 -1
  70. package/dist/types/pages/user-profile/components/positions-value-card.d.mts +2 -1
  71. package/dist/types/pages/user-profile/components/positions-value-card.d.ts +2 -1
  72. package/dist/types/pages/user-profile/index.d.mts +2 -2
  73. package/dist/types/pages/user-profile/index.d.ts +2 -2
  74. package/dist/types/pages/user-profile/user-profile.types.d.mts +54 -1
  75. package/dist/types/pages/user-profile/user-profile.types.d.ts +54 -1
  76. package/dist/types/primitives/button/button.types.d.mts +4 -0
  77. package/dist/types/primitives/button/button.types.d.ts +4 -0
  78. package/dist/types/primitives/button/index.d.mts +1 -1
  79. package/dist/types/primitives/button/index.d.ts +1 -1
  80. package/dist/types/primitives/chart/chart.utils.d.mts +9 -10
  81. package/dist/types/primitives/chart/chart.utils.d.ts +9 -10
  82. package/dist/types/primitives/icon/index.d.mts +2 -1
  83. package/dist/types/primitives/icon/index.d.ts +2 -1
  84. package/dist/types/primitives/icon/registry.d.mts +24 -0
  85. package/dist/types/primitives/icon/registry.d.ts +24 -0
  86. package/dist/types/primitives/icon/svg/circle-xmark.d.mts +5 -0
  87. package/dist/types/primitives/icon/svg/circle-xmark.d.ts +5 -0
  88. package/dist/types/primitives/icon/svg/sort-end-date.d.mts +5 -0
  89. package/dist/types/primitives/icon/svg/sort-end-date.d.ts +5 -0
  90. package/dist/types/primitives/icon/svg/sort-top-arbitrage.d.mts +5 -0
  91. package/dist/types/primitives/icon/svg/sort-top-arbitrage.d.ts +5 -0
  92. package/dist/types/primitives/icon/svg/sort-volume-24hr.d.mts +5 -0
  93. package/dist/types/primitives/icon/svg/sort-volume-24hr.d.ts +5 -0
  94. package/dist/types/primitives/icon/svg/sort-volume.d.mts +5 -0
  95. package/dist/types/primitives/icon/svg/sort-volume.d.ts +5 -0
  96. package/dist/types/primitives/icon/svg/spinner.d.mts +5 -0
  97. package/dist/types/primitives/icon/svg/spinner.d.ts +5 -0
  98. package/dist/types/primitives/select/index.d.mts +1 -1
  99. package/dist/types/primitives/select/index.d.ts +1 -1
  100. package/dist/types/primitives/select/select.types.d.mts +9 -0
  101. package/dist/types/primitives/select/select.types.d.ts +9 -0
  102. package/dist/types/primitives/toast/index.d.mts +2 -0
  103. package/dist/types/primitives/toast/index.d.ts +2 -0
  104. package/dist/types/primitives/toast/toast.types.d.mts +3 -0
  105. package/dist/types/primitives/toast/toast.types.d.ts +3 -0
  106. package/dist/types/primitives/tooltip/tooltip.types.d.mts +1 -0
  107. package/dist/types/primitives/tooltip/tooltip.types.d.ts +1 -0
  108. package/dist/types/primitives/typography/index.d.mts +1 -1
  109. package/dist/types/primitives/typography/index.d.ts +1 -1
  110. package/dist/types/primitives/typography/typography.types.d.mts +2 -0
  111. package/dist/types/primitives/typography/typography.types.d.ts +2 -0
  112. package/dist/types/profile/index.d.mts +1 -1
  113. package/dist/types/profile/index.d.ts +1 -1
  114. package/dist/types/profile/profile-modal.constants.d.mts +2 -2
  115. package/dist/types/profile/profile-modal.constants.d.ts +2 -2
  116. package/dist/types/profile/tabs/accounts-wallets-tab.d.mts +2 -17
  117. package/dist/types/profile/tabs/accounts-wallets-tab.d.ts +2 -17
  118. package/dist/types/profile/tabs/trading-access-tab.d.mts +15 -0
  119. package/dist/types/profile/tabs/trading-access-tab.d.ts +15 -0
  120. package/dist/types/shared/transfer-fee-summary.d.mts +10 -0
  121. package/dist/types/shared/transfer-fee-summary.d.ts +10 -0
  122. package/dist/types/shared/utils.d.mts +3 -0
  123. package/dist/types/shared/utils.d.ts +3 -0
  124. package/dist/types/trading/place-order/index.d.mts +1 -1
  125. package/dist/types/trading/place-order/index.d.ts +1 -1
  126. package/dist/types/trading/place-order/index.place-order.execution-steps.d.mts +9 -0
  127. package/dist/types/trading/place-order/index.place-order.execution-steps.d.ts +9 -0
  128. package/dist/types/trading/place-order/index.place-order.types.d.mts +15 -2
  129. package/dist/types/trading/place-order/index.place-order.types.d.ts +15 -2
  130. package/dist/types/trading/place-order/index.place-order.utils.d.mts +49 -6
  131. package/dist/types/trading/place-order/index.place-order.utils.d.ts +49 -6
  132. package/dist/types/withdraw/index.d.mts +1 -1
  133. package/dist/types/withdraw/index.d.ts +1 -1
  134. package/dist/types/withdraw/steps/withdraw-success.d.mts +13 -7
  135. package/dist/types/withdraw/steps/withdraw-success.d.ts +13 -7
  136. package/dist/types/withdraw/steps/withdraw-success.utils.d.mts +2 -0
  137. package/dist/types/withdraw/steps/withdraw-success.utils.d.ts +2 -0
  138. package/dist/types/withdraw/withdraw-modal.types.d.mts +5 -0
  139. package/dist/types/withdraw/withdraw-modal.types.d.ts +5 -0
  140. package/package.json +3 -3
@@ -2,15 +2,16 @@
2
2
  import {
3
3
  Settlement,
4
4
  formatProbabilityCents,
5
+ getDisplayOutcomePrice,
5
6
  getTradingDateLabel,
6
7
  getTradingPriceLabel,
7
8
  getTradingValueLabel,
8
9
  getTradingVenueLabel,
9
10
  resolveOrderEligibilityMessage
10
- } from "./chunk-5PSAIGOT.mjs";
11
+ } from "./chunk-IBOE7DRY.mjs";
11
12
  import {
12
13
  GeoBlockBanner
13
- } from "./chunk-5MDFM2MX.mjs";
14
+ } from "./chunk-YSW4ULL5.mjs";
14
15
  import {
15
16
  AGG_TERMS_OF_SERVICE_URL,
16
17
  Button,
@@ -35,9 +36,8 @@ import {
35
36
  cn,
36
37
  formatUsd,
37
38
  getMotionClassName,
38
- normalizeVenueMarketCluster,
39
39
  skeletonViews
40
- } from "./chunk-QFW5NDJ6.mjs";
40
+ } from "./chunk-X3KCFWXN.mjs";
41
41
 
42
42
  // src/trading/types.ts
43
43
  import { Venue, enumGuard, isFiniteNonNeg, safeParse } from "@agg-build/sdk";
@@ -82,6 +82,7 @@ import {
82
82
  getWalletAddressFromUserProfile,
83
83
  invalidateBalanceQueries,
84
84
  invalidatePositionQueries,
85
+ mergeBestPricesPreferringLive,
85
86
  requestAggAuthChooserOpen,
86
87
  resolveEventTradingState,
87
88
  resolveMarketTradingState,
@@ -96,8 +97,8 @@ import {
96
97
  useExecutionProgress,
97
98
  useGeoBlock,
98
99
  useLabels,
100
+ useLiveBestPrices,
99
101
  useLiveOutcomePrices,
100
- useMidpoints,
101
102
  useQueryClient,
102
103
  useSdkUiConfig,
103
104
  useSmartRoute
@@ -244,176 +245,6 @@ var PLACE_ORDER_OUTCOME_BUTTON_CLASS_NAMES = {
244
245
  inactive: "border-transparent bg-agg-secondary-hover font-agg-normal text-agg-foreground hover:bg-agg-tertiary"
245
246
  };
246
247
 
247
- // src/trading/place-order/index.place-order.execution-steps.ts
248
- import { Venue as Venue2 } from "@agg-build/sdk";
249
- var WAIT_STEP_TYPES = /* @__PURE__ */ new Set(["_wait", "wait"]);
250
- var CHECKING_BALANCE_STEP_TYPES = /* @__PURE__ */ new Set([
251
- "check-balance",
252
- "check-position",
253
- "position-reserve",
254
- "position-release"
255
- ]);
256
- var VENUE_BUY_SELL_REGEX = /^(?:buy|sell)-([a-z]+)$/;
257
- var VENUE_FINALIZE_REGEX = /^([a-z]+)-finalize$/;
258
- var VENUE_NAME_MAP = {
259
- kalshi: Venue2.kalshi,
260
- polymarket: Venue2.polymarket,
261
- limitless: Venue2.limitless,
262
- opinion: Venue2.opinion,
263
- predict: Venue2.predict,
264
- probable: Venue2.probable,
265
- myriad: Venue2.myriad,
266
- hyperliquid: Venue2.hyperliquid
267
- };
268
- var parseVenueName = (raw) => VENUE_NAME_MAP[raw];
269
- var NON_VENUE_FINALIZE_PREFIXES = /* @__PURE__ */ new Set(["bridge"]);
270
- var classifyExecutionStepType = (stepType) => {
271
- if (!stepType) return null;
272
- if (WAIT_STEP_TYPES.has(stepType)) return null;
273
- if (CHECKING_BALANCE_STEP_TYPES.has(stepType)) {
274
- return { kind: "checking-balance" };
275
- }
276
- const buySellMatch = stepType.match(VENUE_BUY_SELL_REGEX);
277
- if (buySellMatch) {
278
- const venue = parseVenueName(buySellMatch[1]);
279
- if (venue) return { kind: "executing-venue", venue };
280
- }
281
- const finalizeMatch = stepType.match(VENUE_FINALIZE_REGEX);
282
- if (finalizeMatch && !NON_VENUE_FINALIZE_PREFIXES.has(finalizeMatch[1])) {
283
- const venue = parseVenueName(finalizeMatch[1]);
284
- if (venue) return { kind: "executing-venue", venue };
285
- }
286
- if (stepType === "submit-verify-order-status") {
287
- return null;
288
- }
289
- return { kind: "submitting" };
290
- };
291
- var buildPhaseTimeline = (dag) => {
292
- const timeline = [];
293
- const completed = new Set(dag.completedSequences);
294
- for (let seq = 1; seq <= dag.totalSteps; seq++) {
295
- const stepType = dag.stepTypes[seq];
296
- if (!stepType) continue;
297
- const classified = classifyExecutionStepType(stepType);
298
- if (!classified) continue;
299
- const isCompleted = completed.has(seq);
300
- const last = timeline[timeline.length - 1];
301
- if (last && last.kind === classified.kind && last.venue === classified.venue) {
302
- last.lastSeq = seq;
303
- last.allCompleted = last.allCompleted && isCompleted;
304
- continue;
305
- }
306
- timeline.push({
307
- kind: classified.kind,
308
- venue: classified.venue,
309
- firstSeq: seq,
310
- lastSeq: seq,
311
- allCompleted: isCompleted
312
- });
313
- }
314
- return timeline;
315
- };
316
- var phaseRowId = (phase) => phase.venue ? `${phase.kind}:${phase.venue}` : phase.kind;
317
- var phaseRowLabel = (phase, labels) => {
318
- switch (phase.kind) {
319
- case "finding-route":
320
- return labels.findingBestRoute;
321
- case "checking-balance":
322
- return labels.checkingBalance;
323
- case "submitting":
324
- return labels.submittingOrderProgress;
325
- case "wallet-confirm":
326
- return labels.confirmTransactionInWallet;
327
- case "executing-venue":
328
- return labels.executingOnVenue(getTradingVenueLabel(phase.venue));
329
- case "filled":
330
- return labels.executionConfirmed;
331
- case "failed":
332
- return labels.orderFailureTitle;
333
- }
334
- };
335
- var buildSubmissionDisplayRows = ({
336
- phase,
337
- dagProgress,
338
- executionVenue,
339
- isAwaitingWalletConfirmation,
340
- labels
341
- }) => {
342
- if (phase === "finding-route") {
343
- return [
344
- {
345
- id: "finding-route",
346
- label: labels.findingBestRoute,
347
- status: "pending"
348
- }
349
- ];
350
- }
351
- const rows = [
352
- {
353
- id: "finding-route",
354
- label: labels.findingBestRoute,
355
- status: "complete"
356
- }
357
- ];
358
- const pushPhase = (phaseEntry, status) => {
359
- const id = phaseRowId(phaseEntry);
360
- if (rows.some((row) => row.id === id)) return;
361
- rows.push({
362
- id,
363
- label: phaseRowLabel(phaseEntry, labels),
364
- status,
365
- venue: phaseEntry.venue
366
- });
367
- };
368
- if (dagProgress && dagProgress.totalSteps > 0) {
369
- const timeline = buildPhaseTimeline(dagProgress);
370
- let activeEmitted = false;
371
- for (const entry of timeline) {
372
- const id = phaseRowId(entry);
373
- const alreadyShown = rows.some((row) => row.id === id);
374
- if (entry.allCompleted) {
375
- if (alreadyShown) continue;
376
- pushPhase(entry, "complete");
377
- continue;
378
- }
379
- if (activeEmitted) break;
380
- if (alreadyShown) continue;
381
- if (isAwaitingWalletConfirmation && entry.kind === "submitting") {
382
- pushPhase({ kind: "wallet-confirm" }, "pending");
383
- } else {
384
- pushPhase(entry, "pending");
385
- }
386
- activeEmitted = true;
387
- }
388
- if (!activeEmitted) {
389
- const last = rows[rows.length - 1];
390
- if (last && last.id.startsWith("executing-venue")) {
391
- last.status = "pending";
392
- } else {
393
- const fallbackVenue = executionVenue;
394
- rows.push({
395
- id: fallbackVenue ? `executing-venue:${fallbackVenue}` : "executing-venue",
396
- label: phaseRowLabel({ kind: "executing-venue", venue: fallbackVenue }, labels),
397
- status: "pending",
398
- venue: fallbackVenue
399
- });
400
- }
401
- }
402
- return rows;
403
- }
404
- if (isAwaitingWalletConfirmation) {
405
- pushPhase({ kind: "wallet-confirm" }, "pending");
406
- return rows;
407
- }
408
- if (phase === "submitting") {
409
- pushPhase({ kind: "submitting" }, "pending");
410
- return rows;
411
- }
412
- pushPhase({ kind: "submitting" }, "complete");
413
- pushPhase({ kind: "executing-venue", venue: executionVenue }, "pending");
414
- return rows;
415
- };
416
-
417
248
  // src/trading/place-order/index.place-order.execution-debug.ts
418
249
  var REDACTED = "[redacted]";
419
250
  var SENSITIVE_FIELD_PATTERNS = [
@@ -685,7 +516,194 @@ var enableExecutionDebugInBrowser = (initial) => {
685
516
  return store;
686
517
  };
687
518
 
519
+ // src/trading/place-order/index.place-order.execution-steps.ts
520
+ import { Venue as Venue2 } from "@agg-build/sdk";
521
+ var WAIT_STEP_TYPES = /* @__PURE__ */ new Set(["_wait", "wait"]);
522
+ var CHECKING_BALANCE_STEP_TYPES = /* @__PURE__ */ new Set([
523
+ "check-balance",
524
+ "check-position",
525
+ "position-reserve",
526
+ "position-release"
527
+ ]);
528
+ var VENUE_BUY_SELL_REGEX = /^(?:buy|sell)-([a-z]+)$/;
529
+ var VENUE_FINALIZE_REGEX = /^([a-z]+)-finalize$/;
530
+ var VENUE_NAME_MAP = {
531
+ kalshi: Venue2.kalshi,
532
+ polymarket: Venue2.polymarket,
533
+ limitless: Venue2.limitless,
534
+ opinion: Venue2.opinion,
535
+ predict: Venue2.predict,
536
+ probable: Venue2.probable,
537
+ myriad: Venue2.myriad,
538
+ hyperliquid: Venue2.hyperliquid
539
+ };
540
+ var parseVenueName = (raw) => VENUE_NAME_MAP[raw];
541
+ var NON_VENUE_FINALIZE_PREFIXES = /* @__PURE__ */ new Set(["bridge"]);
542
+ var classifyExecutionStepType = (stepType) => {
543
+ if (!stepType) return null;
544
+ if (WAIT_STEP_TYPES.has(stepType)) return null;
545
+ if (CHECKING_BALANCE_STEP_TYPES.has(stepType)) {
546
+ return { kind: "checking-balance" };
547
+ }
548
+ const buySellMatch = stepType.match(VENUE_BUY_SELL_REGEX);
549
+ if (buySellMatch) {
550
+ const venue = parseVenueName(buySellMatch[1]);
551
+ if (venue) return { kind: "executing-venue", venue };
552
+ }
553
+ const finalizeMatch = stepType.match(VENUE_FINALIZE_REGEX);
554
+ if (finalizeMatch && !NON_VENUE_FINALIZE_PREFIXES.has(finalizeMatch[1])) {
555
+ const venue = parseVenueName(finalizeMatch[1]);
556
+ if (venue) return { kind: "executing-venue", venue };
557
+ }
558
+ if (stepType === "submit-verify-order-status") {
559
+ return null;
560
+ }
561
+ return { kind: "submitting" };
562
+ };
563
+ var buildPhaseTimeline = (dag) => {
564
+ const timeline = [];
565
+ const completed = new Set(dag.completedSequences);
566
+ for (let seq = 1; seq <= dag.totalSteps; seq++) {
567
+ const stepType = dag.stepTypes[seq];
568
+ if (!stepType) continue;
569
+ const classified = classifyExecutionStepType(stepType);
570
+ if (!classified) continue;
571
+ const isCompleted = completed.has(seq);
572
+ const last = timeline[timeline.length - 1];
573
+ if (last && last.kind === classified.kind && last.venue === classified.venue) {
574
+ last.lastSeq = seq;
575
+ last.allCompleted = last.allCompleted && isCompleted;
576
+ continue;
577
+ }
578
+ timeline.push({
579
+ kind: classified.kind,
580
+ venue: classified.venue,
581
+ firstSeq: seq,
582
+ lastSeq: seq,
583
+ allCompleted: isCompleted
584
+ });
585
+ }
586
+ const blockHasProgress = (entry) => {
587
+ if (entry.allCompleted) return true;
588
+ for (let s = entry.firstSeq; s <= entry.lastSeq; s++) {
589
+ if (completed.has(s)) return true;
590
+ }
591
+ return false;
592
+ };
593
+ for (let i = timeline.length - 2; i >= 0; i--) {
594
+ if (timeline[i].allCompleted) continue;
595
+ for (let j = i + 1; j < timeline.length; j++) {
596
+ if (blockHasProgress(timeline[j])) {
597
+ timeline[i].allCompleted = true;
598
+ break;
599
+ }
600
+ }
601
+ }
602
+ return timeline;
603
+ };
604
+ var phaseRowId = (phase) => phase.venue ? `${phase.kind}:${phase.venue}` : phase.kind;
605
+ var phaseRowLabel = (phase, labels) => {
606
+ switch (phase.kind) {
607
+ case "finding-route":
608
+ return labels.findingBestRoute;
609
+ case "checking-balance":
610
+ return labels.checkingBalance;
611
+ case "submitting":
612
+ return labels.submittingOrderProgress;
613
+ case "wallet-confirm":
614
+ return labels.confirmTransactionInWallet;
615
+ case "executing-venue":
616
+ return labels.executingOnVenue(getTradingVenueLabel(phase.venue));
617
+ case "filled":
618
+ return labels.executionConfirmed;
619
+ case "failed":
620
+ return labels.orderFailureTitle;
621
+ }
622
+ };
623
+ var buildSubmissionDisplayRows = ({
624
+ phase,
625
+ dagProgress,
626
+ executionVenue,
627
+ isAwaitingWalletConfirmation,
628
+ labels
629
+ }) => {
630
+ if (phase === "finding-route") {
631
+ return [
632
+ {
633
+ id: "finding-route",
634
+ label: labels.findingBestRoute,
635
+ status: "pending"
636
+ }
637
+ ];
638
+ }
639
+ const rows = [
640
+ {
641
+ id: "finding-route",
642
+ label: labels.findingBestRoute,
643
+ status: "complete"
644
+ }
645
+ ];
646
+ const pushPhase = (phaseEntry, status) => {
647
+ const id = phaseRowId(phaseEntry);
648
+ if (rows.some((row) => row.id === id)) return;
649
+ rows.push({
650
+ id,
651
+ label: phaseRowLabel(phaseEntry, labels),
652
+ status,
653
+ venue: phaseEntry.venue
654
+ });
655
+ };
656
+ if (dagProgress && dagProgress.totalSteps > 0) {
657
+ const timeline = buildPhaseTimeline(dagProgress);
658
+ let activeEmitted = false;
659
+ for (const entry of timeline) {
660
+ const id = phaseRowId(entry);
661
+ const alreadyShown = rows.some((row) => row.id === id);
662
+ if (entry.allCompleted) {
663
+ if (alreadyShown) continue;
664
+ pushPhase(entry, "complete");
665
+ continue;
666
+ }
667
+ if (activeEmitted) break;
668
+ if (alreadyShown) continue;
669
+ if (isAwaitingWalletConfirmation && entry.kind === "submitting") {
670
+ pushPhase({ kind: "wallet-confirm" }, "pending");
671
+ } else {
672
+ pushPhase(entry, "pending");
673
+ }
674
+ activeEmitted = true;
675
+ }
676
+ if (!activeEmitted) {
677
+ const last = rows[rows.length - 1];
678
+ if (last && last.id.startsWith("executing-venue")) {
679
+ last.status = "pending";
680
+ } else {
681
+ const fallbackVenue = executionVenue;
682
+ rows.push({
683
+ id: fallbackVenue ? `executing-venue:${fallbackVenue}` : "executing-venue",
684
+ label: phaseRowLabel({ kind: "executing-venue", venue: fallbackVenue }, labels),
685
+ status: "pending",
686
+ venue: fallbackVenue
687
+ });
688
+ }
689
+ }
690
+ return rows;
691
+ }
692
+ if (isAwaitingWalletConfirmation) {
693
+ pushPhase({ kind: "wallet-confirm" }, "pending");
694
+ return rows;
695
+ }
696
+ if (phase === "submitting") {
697
+ pushPhase({ kind: "submitting" }, "pending");
698
+ return rows;
699
+ }
700
+ pushPhase({ kind: "submitting" }, "complete");
701
+ pushPhase({ kind: "executing-venue", venue: executionVenue }, "pending");
702
+ return rows;
703
+ };
704
+
688
705
  // src/trading/place-order/index.place-order.utils.ts
706
+ var ATOMIC_UNITS = 1e6;
689
707
  var routePriceLabelFormatter = new Intl.NumberFormat("en-US", {
690
708
  minimumFractionDigits: 0,
691
709
  maximumFractionDigits: 1
@@ -770,7 +788,13 @@ var parseFilledAmountRawDollars = (filledAmountRaw) => {
770
788
  if (!filledAmountRaw) return null;
771
789
  const raw = Number(filledAmountRaw);
772
790
  if (!Number.isFinite(raw) || raw <= 0) return null;
773
- return raw / 1e6;
791
+ return raw / ATOMIC_UNITS;
792
+ };
793
+ var parseDecimalString = (value) => {
794
+ if (value == null) return null;
795
+ const parsed = Number(value);
796
+ if (!Number.isFinite(parsed) || parsed <= 0) return null;
797
+ return parsed;
774
798
  };
775
799
  var resolvePlaceOrderQuoteResult = ({
776
800
  labels,
@@ -896,18 +920,17 @@ var buildLiveRouteCards = ({
896
920
  const isSplit = quoteData.fills.length > 1;
897
921
  const primaryWinnerVenue = quoteData.fills.length === 1 ? primaryVenue : void 0;
898
922
  const isPrimaryRouteGeoBlocked = quoteData.fills.length > 0 && quoteData.fills.some((f) => geoBlockedVenues.has(f.venue));
899
- const primaryCard = primaryResult ? isPrimaryRouteGeoBlocked ? {
923
+ const primaryCard = primaryResult ? isPrimaryRouteGeoBlocked ? isSplit ? null : {
900
924
  id: "live-route",
901
925
  hint: labels.venueUnavailableInRegion,
902
- kind: isSplit ? "split" : "venue",
903
- label: isSplit ? labels.orderSplitting : getTradingVenueLabel(
926
+ kind: "venue",
927
+ label: getTradingVenueLabel(
904
928
  parsedPrimaryVenue.success ? parsedPrimaryVenue.data : void 0
905
929
  ),
906
930
  numericValue: tradeSide === "sell" ? quoteData.rawExecCost : quoteData.totalFilled,
907
931
  quoteData,
908
- rows: isSplit ? mapQuoteDataToRoutingRows(quoteData) : void 0,
909
932
  value: primaryResult.value,
910
- venue: isSplit ? void 0 : parsedPrimaryVenue.success ? parsedPrimaryVenue.data : void 0,
933
+ venue: parsedPrimaryVenue.success ? parsedPrimaryVenue.data : void 0,
911
934
  isUnavailable: true
912
935
  } : {
913
936
  id: "live-route",
@@ -1197,6 +1220,61 @@ var MARKET_RESOLVED_ERROR_PATTERN = /\b(resolved|no longer accepting orders|acce
1197
1220
  var VENUE_UNAVAILABLE_ERROR_PATTERN = /\b(unavailable|unreachable|timeout|timed out|expired|canceled|cancelled|failed with no fills)\b/i;
1198
1221
  var ALCHEMY_SPONSORSHIP_ERROR_PATTERN = /\bsponsorship failed: sender has no balance of the token for erc20 sponsorship\b/i;
1199
1222
  var ALCHEMY_PREPARE_CALLS_ERROR_PATTERN = /\bwallet_prepareCalls\b/i;
1223
+ var DAG_CHECK_BALANCE_SHORTFALL_PATTERN = /\bInsufficient balance on chain\s+\d+\s+token\s+\S+:/i;
1224
+ var VENUE_CONNECTOR_UNREACHABLE_PATTERN = /\bvenue-connector\s+unreachable\b/i;
1225
+ var POLYMARKET_DEADLINE_TOO_SOON_PATTERN = /\bdeadline too soon\b/i;
1226
+ var SELL_NO_ONCHAIN_POSITION_PATTERN = /don'?t currently hold any on-chain shares/i;
1227
+ var VENUE_QUOTE_UNFILLABLE_PATTERN = /couldn'?t fill this order at the quoted price|no in-tolerance depth|couldn'?t fill this order at the quoted/i;
1228
+ var QUOTED_PRICE_UNAVAILABLE_PATTERN = /Quoted price is no longer available|missing a valid quoted price/i;
1229
+ var VENUE_MIN_ORDER_SIZE_PATTERN = /below (?:the )?(?:venue |Limitless'?s |Polymarket'?s |Hyperliquid'?s |predict\.fun'?s )?(?:0\.01-share )?minimum|Order amount too small/i;
1230
+ var SOURCE_BALANCE_CHANGED_PATTERN = /balance changed since the quote|wallet holds 0 (?:USDC|pUSD|of tokenId)|Polygon balance changed/i;
1231
+ var VENUE_MARKET_RESOLVED_PATTERN = /(?:Limitless|Myriad|Polymarket|Kalshi)?\s*market\s+(?:just\s+)?resolved|market just resolved/i;
1232
+ var DFLOW_WALLET_UNVERIFIED_PATTERN = /(?:wallet\s+needs\s+to\s+be\s+verified\s+with\s+dFlow|dflow\.net\/proof)/i;
1233
+ var VENUE_NO_QUOTE_PATH_PATTERN = /No active quote path/i;
1234
+ var SOLANA_BLOCKHASH_EXPIRED_PATTERN = /\b(blockhash(?:\s+(?:expired|not\s+found))?|TransactionExpiredBlockheightExceeded|transaction\s+expired)\b/i;
1235
+ var VENUE_RATE_LIMITED_PATTERN = /\b(429|rate[\s-]?limit(?:ed)?|too\s+many\s+requests|backoff)\b/i;
1236
+ var SERVICE_BLOCKED_ORDER_PATTERN = /Something on our side blocked this order/i;
1237
+ var ALCHEMY_BALANCE_REVERT_PATTERN = /\b(transfer amount exceeds balance|transferFrom failed|insufficient balance|insufficient funds)\b/i;
1238
+ var ALCHEMY_REVERT_DATA_SELECTOR_PATTERN = /\brevertData["']?:?\s*['"]?(0x[0-9a-fA-F]{8})/i;
1239
+ var REVERT_SELECTOR_MESSAGES = {
1240
+ // Solady TransferFromFailed() — ERC-20 transferFrom revert. Same recovery
1241
+ // as the plaintext "transfer amount exceeds balance": refresh balance and
1242
+ // re-quote (the P0-A tombstone + FE refetch in #1445 + #1446 handle the
1243
+ // server-side dedup).
1244
+ "0x7939f424": "Your balance changed since the quote. Please refresh and try again.",
1245
+ // Solady InsufficientBalance() — Solady's own balance-shortfall variant.
1246
+ "0xf4d678b8": "Your balance changed since the quote. Please refresh and try again."
1247
+ };
1248
+ function lookupRevertSelectorMessage(message) {
1249
+ var _a, _b;
1250
+ const match = message.match(ALCHEMY_REVERT_DATA_SELECTOR_PATTERN);
1251
+ if (!match) return null;
1252
+ const selector = (_a = match[1]) == null ? void 0 : _a.toLowerCase();
1253
+ if (!selector) return null;
1254
+ return (_b = REVERT_SELECTOR_MESSAGES[selector]) != null ? _b : null;
1255
+ }
1256
+ var ALCHEMY_SPONSORSHIP_POLICY_PATTERN = /\b(SPONSORSHIP_FAILED|sponsorship.*(quota|cap|exhausted|disabled)|policy.*(disabled|not found|exhausted))\b/i;
1257
+ var ALCHEMY_POLICY_MAX_COUNT_PATTERN = /\bSponsorship failed: Policy (max count|count) exceeded\b/i;
1258
+ var VENUE_TERMINATED_STATUS_PATTERN = /\bterminated with status=(\w+)/i;
1259
+ var friendlyTerminatedStatusMessage = (status) => {
1260
+ const normalized = status.toLowerCase();
1261
+ if (normalized === "cancelled" || normalized === "canceled") {
1262
+ return "Your order was canceled before it could fill \u2014 the price level moved between quote and submission. Please try again.";
1263
+ }
1264
+ if (normalized === "expired") {
1265
+ return "Your order expired before it could fill. Please try again.";
1266
+ }
1267
+ if (normalized === "rejected") {
1268
+ return "The venue rejected your order. Please try again.";
1269
+ }
1270
+ if (normalized === "failed") {
1271
+ return "Order didn't settle on-chain. Please try again.";
1272
+ }
1273
+ if (normalized === "unmatched") {
1274
+ return "No liquidity matched your order at the quoted price. Try a smaller size or re-quote.";
1275
+ }
1276
+ return "Your order did not fill. Please try again.";
1277
+ };
1200
1278
  var tryParseJsonErrorValue = (value) => {
1201
1279
  try {
1202
1280
  return JSON.parse(value);
@@ -1226,13 +1304,74 @@ var extractPlaceOrderErrorMessage = (value) => {
1226
1304
  };
1227
1305
  var normalizePlaceOrderErrorMessage = ({
1228
1306
  errorMessage,
1229
- fallbackMessage
1307
+ fallbackMessage,
1308
+ labels
1230
1309
  }) => {
1310
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
1231
1311
  const extractedMessage = extractPlaceOrderErrorMessage(errorMessage);
1232
1312
  if (!extractedMessage) return fallbackMessage;
1233
- if (ALCHEMY_SPONSORSHIP_ERROR_PATTERN.test(extractedMessage) || ALCHEMY_PREPARE_CALLS_ERROR_PATTERN.test(extractedMessage)) {
1313
+ if (DAG_CHECK_BALANCE_SHORTFALL_PATTERN.test(extractedMessage)) {
1314
+ return (_a = labels == null ? void 0 : labels.quoteBalanceMismatch) != null ? _a : "Quote balance mismatch. Try a different amount.";
1315
+ }
1316
+ if (VENUE_CONNECTOR_UNREACHABLE_PATTERN.test(extractedMessage)) {
1317
+ return (_b = labels == null ? void 0 : labels.serviceTemporarilyUnavailable) != null ? _b : "Service temporarily unavailable. Please try again in a moment.";
1318
+ }
1319
+ if (POLYMARKET_DEADLINE_TOO_SOON_PATTERN.test(extractedMessage)) {
1320
+ return (_c = labels == null ? void 0 : labels.orderDeadlineExpiredBeforeSubmission) != null ? _c : "Order deadline expired before submission. Please try again.";
1321
+ }
1322
+ if (DFLOW_WALLET_UNVERIFIED_PATTERN.test(extractedMessage)) {
1323
+ return (_d = labels == null ? void 0 : labels.dflowWalletUnverified) != null ? _d : "Your Solana wallet needs to be verified with dFlow before you can trade Kalshi markets. Verify at https://dflow.net/proof, then try again.";
1324
+ }
1325
+ if (SELL_NO_ONCHAIN_POSITION_PATTERN.test(extractedMessage)) {
1326
+ return (_e = labels == null ? void 0 : labels.sellNoOnchainPosition) != null ? _e : "You don't currently hold any on-chain shares of this outcome. If you just sold or redeemed elsewhere, your position display will refresh shortly \u2014 try again after that.";
1327
+ }
1328
+ if (VENUE_MARKET_RESOLVED_PATTERN.test(extractedMessage)) {
1329
+ return (_f = labels == null ? void 0 : labels.venueMarketResolved) != null ? _f : "This market just resolved. Pick a different market or wait for the next round.";
1330
+ }
1331
+ if (VENUE_NO_QUOTE_PATH_PATTERN.test(extractedMessage)) {
1332
+ return (_g = labels == null ? void 0 : labels.venueNoQuotePath) != null ? _g : "No active quote path for this market right now. Try a different size, or wait a moment and re-quote.";
1333
+ }
1334
+ if (QUOTED_PRICE_UNAVAILABLE_PATTERN.test(extractedMessage)) {
1335
+ return (_h = labels == null ? void 0 : labels.quoteUnavailable) != null ? _h : "Quote temporarily unavailable. Please try again.";
1336
+ }
1337
+ if (VENUE_QUOTE_UNFILLABLE_PATTERN.test(extractedMessage)) {
1338
+ return (_i = labels == null ? void 0 : labels.venueQuoteUnfillable) != null ? _i : "The venue couldn't fill this order at the quoted price right now. Try a smaller size, a higher slippage tolerance, or wait a moment and re-quote.";
1339
+ }
1340
+ if (VENUE_MIN_ORDER_SIZE_PATTERN.test(extractedMessage)) {
1341
+ return (_j = labels == null ? void 0 : labels.venueMinOrderSize) != null ? _j : "Order size is below the venue minimum. Try a larger amount.";
1342
+ }
1343
+ if (SOURCE_BALANCE_CHANGED_PATTERN.test(extractedMessage)) {
1344
+ return (_k = labels == null ? void 0 : labels.sourceBalanceChanged) != null ? _k : "Your balance changed since the quote. Refresh and try again, or pick a smaller amount.";
1345
+ }
1346
+ if (SOLANA_BLOCKHASH_EXPIRED_PATTERN.test(extractedMessage)) {
1347
+ return (_l = labels == null ? void 0 : labels.solanaBlockhashExpired) != null ? _l : "Solana transaction expired before submission. Please re-quote and try again.";
1348
+ }
1349
+ if (VENUE_RATE_LIMITED_PATTERN.test(extractedMessage)) {
1350
+ return (_m = labels == null ? void 0 : labels.venueRateLimited) != null ? _m : "The venue is rate-limiting requests right now. Please wait a moment and try again.";
1351
+ }
1352
+ if (SERVICE_BLOCKED_ORDER_PATTERN.test(extractedMessage)) {
1353
+ return (_n = labels == null ? void 0 : labels.serviceBlockedOrder) != null ? _n : "Something on our side blocked this order. Please contact support if it keeps happening \u2014 retrying with the same quote will hit the same issue.";
1354
+ }
1355
+ if (ALCHEMY_BALANCE_REVERT_PATTERN.test(extractedMessage)) {
1356
+ return "Your balance changed since the quote. Please refresh and try again.";
1357
+ }
1358
+ const selectorMessage = lookupRevertSelectorMessage(extractedMessage);
1359
+ if (selectorMessage) {
1360
+ return selectorMessage;
1361
+ }
1362
+ if (ALCHEMY_POLICY_MAX_COUNT_PATTERN.test(extractedMessage)) {
1363
+ return "Sponsored execution is temporarily unavailable (sponsor policy capacity reached). Please try again in a few minutes.";
1364
+ }
1365
+ if (ALCHEMY_SPONSORSHIP_POLICY_PATTERN.test(extractedMessage) || ALCHEMY_SPONSORSHIP_ERROR_PATTERN.test(extractedMessage)) {
1234
1366
  return "Sponsored execution is temporarily unavailable. Please try again.";
1235
1367
  }
1368
+ if (ALCHEMY_PREPARE_CALLS_ERROR_PATTERN.test(extractedMessage)) {
1369
+ return "Sponsored execution is temporarily unavailable. Please try again.";
1370
+ }
1371
+ const terminatedMatch = extractedMessage.match(VENUE_TERMINATED_STATUS_PATTERN);
1372
+ if (terminatedMatch) {
1373
+ return friendlyTerminatedStatusMessage((_o = terminatedMatch[1]) != null ? _o : "");
1374
+ }
1236
1375
  return extractedMessage;
1237
1376
  };
1238
1377
  var resolvePlaceOrderFailureKind = ({
@@ -1360,14 +1499,84 @@ var resolvePlaceOrderFailureActions = ({
1360
1499
  }
1361
1500
  ];
1362
1501
  };
1502
+ var resolveEventExecutionPrice = ({
1503
+ event,
1504
+ quoteData,
1505
+ submittedOrders
1506
+ }) => {
1507
+ var _a, _b, _c, _d, _e;
1508
+ const quoteVwap = quoteData && quoteData.totalFilled > 0 ? quoteData.rawExecCost / quoteData.totalFilled : 0;
1509
+ return (_e = (_d = (_b = parseDecimalString(event.executionPriceRaw)) != null ? _b : (_a = submittedOrders == null ? void 0 : submittedOrders.find((order) => order.orderId === event.orderId)) == null ? void 0 : _a.price) != null ? _d : (_c = quoteData == null ? void 0 : quoteData.fills.find((fill) => fill.venue === event.venue)) == null ? void 0 : _c.avgPrice) != null ? _e : quoteVwap > 0 ? quoteVwap : null;
1510
+ };
1511
+ var resolveActualExecutionEconomics = ({
1512
+ quoteData,
1513
+ tradeSide,
1514
+ terminalOrderEvents,
1515
+ submittedOrders
1516
+ }) => {
1517
+ var _a, _b;
1518
+ const fillEvents = (terminalOrderEvents != null ? terminalOrderEvents : []).filter(
1519
+ (event) => event.event === "filled" || event.event === "partial_fill"
1520
+ );
1521
+ const quoteVwap = quoteData && quoteData.totalFilled > 0 ? quoteData.rawExecCost / quoteData.totalFilled : 0;
1522
+ const hasActualFillData = fillEvents.some(
1523
+ (event) => event.filledAmountRaw != null || event.actualSharesRaw != null
1524
+ );
1525
+ if (!hasActualFillData) {
1526
+ return {
1527
+ hasActualFillData: false,
1528
+ actualRawExecCost: (_a = quoteData == null ? void 0 : quoteData.rawExecCost) != null ? _a : 0,
1529
+ actualTotalFilled: (_b = quoteData == null ? void 0 : quoteData.totalFilled) != null ? _b : 0,
1530
+ avgExecutionPrice: quoteVwap
1531
+ };
1532
+ }
1533
+ let usdSideTotal = 0;
1534
+ let sharesSideTotal = 0;
1535
+ let priceWeight = 0;
1536
+ let priceWeightedSum = 0;
1537
+ for (const event of fillEvents) {
1538
+ const eventPrice = resolveEventExecutionPrice({ event, quoteData, submittedOrders });
1539
+ if (tradeSide === "buy") {
1540
+ const filledUsd = parseFilledAmountRawDollars(event.filledAmountRaw);
1541
+ if (filledUsd == null) continue;
1542
+ const actualShares = parseFilledAmountRawDollars(event.actualSharesRaw);
1543
+ const shares = actualShares != null ? actualShares : eventPrice != null && eventPrice > 0 ? filledUsd / eventPrice : 0;
1544
+ usdSideTotal += filledUsd;
1545
+ sharesSideTotal += shares;
1546
+ if (filledUsd > 0 && eventPrice != null && eventPrice > 0) {
1547
+ priceWeight += filledUsd;
1548
+ priceWeightedSum += eventPrice * filledUsd;
1549
+ }
1550
+ } else {
1551
+ const shares = parseFilledAmountRawDollars(event.actualSharesRaw);
1552
+ if (shares == null) continue;
1553
+ const payout = eventPrice != null && eventPrice > 0 ? shares * eventPrice : 0;
1554
+ sharesSideTotal += shares;
1555
+ usdSideTotal += payout;
1556
+ if (shares > 0 && eventPrice != null && eventPrice > 0) {
1557
+ priceWeight += shares;
1558
+ priceWeightedSum += eventPrice * shares;
1559
+ }
1560
+ }
1561
+ }
1562
+ const avgExecutionPrice = priceWeight > 0 ? priceWeightedSum / priceWeight : sharesSideTotal > 0 && usdSideTotal > 0 ? usdSideTotal / sharesSideTotal : quoteVwap;
1563
+ return {
1564
+ hasActualFillData: true,
1565
+ actualRawExecCost: usdSideTotal,
1566
+ actualTotalFilled: sharesSideTotal,
1567
+ avgExecutionPrice
1568
+ };
1569
+ };
1363
1570
  var getPlaceOrderUnfilledRemaining = ({
1364
1571
  originalAmount,
1572
+ tradeSide,
1365
1573
  terminalOrderEvents
1366
1574
  }) => {
1367
1575
  const filled = (terminalOrderEvents != null ? terminalOrderEvents : []).reduce((acc, event) => {
1368
1576
  var _a;
1369
1577
  if (event.event !== "filled" && event.event !== "partial_fill") return acc;
1370
- return acc + ((_a = parseFilledAmountRawDollars(event.filledAmountRaw)) != null ? _a : 0);
1578
+ const raw = tradeSide === "buy" ? event.filledAmountRaw : event.actualSharesRaw;
1579
+ return acc + ((_a = parseFilledAmountRawDollars(raw)) != null ? _a : 0);
1371
1580
  }, 0);
1372
1581
  return Math.max(0, originalAmount - filled);
1373
1582
  };
@@ -1387,7 +1596,8 @@ var buildPlaceOrderFailureSummary = ({
1387
1596
  var _a;
1388
1597
  const normalizedErrorMessage = normalizePlaceOrderErrorMessage({
1389
1598
  errorMessage,
1390
- fallbackMessage: labels.orderFailed
1599
+ fallbackMessage: labels.orderFailed,
1600
+ labels
1391
1601
  });
1392
1602
  const submittedOrderId = resolvePrimarySubmittedOrderId({
1393
1603
  orderId,
@@ -1471,7 +1681,8 @@ var buildPlaceOrderFailureSummary = ({
1471
1681
  const perEventKind = resolvePlaceOrderFailureKind({
1472
1682
  errorMessage: normalizePlaceOrderErrorMessage({
1473
1683
  errorMessage: terminalEvent.errorReason,
1474
- fallbackMessage: labels.orderFailed
1684
+ fallbackMessage: labels.orderFailed,
1685
+ labels
1475
1686
  }),
1476
1687
  terminalEvent
1477
1688
  });
@@ -1708,17 +1919,17 @@ var PlaceOrderSuccessView = ({
1708
1919
  onDone,
1709
1920
  onShare: _onShare
1710
1921
  }) => {
1711
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1922
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1712
1923
  const [isExecutionDetailsExpanded, setIsExecutionDetailsExpanded] = useState2(true);
1713
- const newTradeLabel = (_a = tradingLabels.orderNewTrade) != null ? _a : "New Trade";
1714
- const _shareLabel = (_b = tradingLabels.orderShare) != null ? _b : "Share";
1924
+ const doneLabel = tradingLabels.orderDone;
1925
+ const _shareLabel = (_a = tradingLabels.orderShare) != null ? _a : "Share";
1715
1926
  const potentialReturnLabel = summary.potentialReturnLabel && tradingLabels.potentialReturnBonus ? tradingLabels.potentialReturnBonus(summary.potentialReturnLabel) : summary.potentialReturnLabel ? `+${summary.potentialReturnLabel} Better Payout` : null;
1716
- const resolvedActionLabel = (_c = summary.actionLabel) != null ? _c : tradingLabels.orderSuccessTitle;
1717
- const resolvedTradeSide = (_d = summary.tradeSide) != null ? _d : "buy";
1718
- const resolvedAmountLabel = (_e = summary.amountLabel) != null ? _e : resolvedTradeSide === "sell" ? summary.shares : summary.estimatedCost;
1719
- const resolvedToWinLabel = (_f = summary.toWinLabel) != null ? _f : resolvedTradeSide === "sell" ? summary.estimatedCost : resolveBuyToWinLabel(summary.shares);
1720
- const executionStepGroups = (_g = summary.executionStepGroups) != null ? _g : [];
1721
- const finalStep = (_h = executionStepGroups.at(-1)) == null ? void 0 : _h[0];
1927
+ const resolvedActionLabel = (_b = summary.actionLabel) != null ? _b : tradingLabels.orderSuccessTitle;
1928
+ const resolvedTradeSide = (_c = summary.tradeSide) != null ? _c : "buy";
1929
+ const resolvedAmountLabel = (_d = summary.amountLabel) != null ? _d : resolvedTradeSide === "sell" ? summary.shares : summary.estimatedCost;
1930
+ const resolvedToWinLabel = (_e = summary.toWinLabel) != null ? _e : resolvedTradeSide === "sell" ? summary.estimatedCost : resolveBuyToWinLabel(summary.shares);
1931
+ const executionStepGroups = (_f = summary.executionStepGroups) != null ? _f : [];
1932
+ const finalStep = (_g = executionStepGroups.at(-1)) == null ? void 0 : _g[0];
1722
1933
  const detailedStepGroups = executionStepGroups.slice(0, -1);
1723
1934
  const hasExecutionDetails = detailedStepGroups.length > 0;
1724
1935
  const resolveStepIconName = (tone) => {
@@ -1733,7 +1944,7 @@ var PlaceOrderSuccessView = ({
1733
1944
  /* @__PURE__ */ jsx3(
1734
1945
  RemoteImage,
1735
1946
  {
1736
- src: (_i = summary.eventImage) != null ? _i : null,
1947
+ src: (_h = summary.eventImage) != null ? _h : null,
1737
1948
  alt: "",
1738
1949
  className: "h-12 w-12 shrink-0 overflow-hidden rounded-agg-lg object-cover"
1739
1950
  }
@@ -1853,7 +2064,7 @@ var PlaceOrderSuccessView = ({
1853
2064
  ] }),
1854
2065
  summary.potentialReturnLabel ? /* @__PURE__ */ jsxs2("div", { className: "flex w-full flex-col items-center justify-center gap-1 overflow-hidden rounded-agg-lg border border-agg-primary/50 bg-gradient-to-b from-agg-primary/8 to-agg-primary/15 p-3 text-center", children: [
1855
2066
  /* @__PURE__ */ jsx3("p", { className: "bg-gradient-to-r from-agg-primary to-agg-primary-hover bg-clip-text text-agg-lg font-agg-bold leading-[28px] text-transparent", children: potentialReturnLabel }),
1856
- /* @__PURE__ */ jsx3("p", { className: "text-agg-xs leading-agg-4 text-agg-foreground", children: (_j = tradingLabels.withSmartRouting) != null ? _j : "with Smart Routing" })
2067
+ /* @__PURE__ */ jsx3("p", { className: "text-agg-xs leading-agg-4 text-agg-foreground", children: (_i = tradingLabels.withSmartRouting) != null ? _i : "with Smart Routing" })
1857
2068
  ] }) : null,
1858
2069
  /* @__PURE__ */ jsx3("div", { className: "agg-order-success-actions flex gap-3", children: /* @__PURE__ */ jsx3(
1859
2070
  Button,
@@ -1861,9 +2072,9 @@ var PlaceOrderSuccessView = ({
1861
2072
  variant: "secondary",
1862
2073
  size: "large",
1863
2074
  className: "flex-1",
1864
- "aria-label": newTradeLabel,
2075
+ "aria-label": doneLabel,
1865
2076
  onClick: onDone,
1866
- children: newTradeLabel
2077
+ children: doneLabel
1867
2078
  }
1868
2079
  ) })
1869
2080
  ] }) });
@@ -1878,6 +2089,14 @@ var resolveRefetchedQuoteData = (result) => {
1878
2089
  if (!data || typeof data !== "object" || !("quoteId" in data)) return null;
1879
2090
  return data;
1880
2091
  };
2092
+ var isFillRejection400 = (err) => {
2093
+ var _a;
2094
+ if (!err || typeof err !== "object") return false;
2095
+ const direct = err.status;
2096
+ if (direct === 400) return true;
2097
+ const nested = (_a = err.response) == null ? void 0 : _a.status;
2098
+ return nested === 400;
2099
+ };
1881
2100
  var LoadingGlyph = ({
1882
2101
  className,
1883
2102
  enableAnimations
@@ -2117,7 +2336,7 @@ var PlaceOrderSlippageControl = ({
2117
2336
  {
2118
2337
  name: "warning-filled",
2119
2338
  size: "small",
2120
- className: "mt-0.5 !h-4 !w-4 shrink-0 text-agg-warning",
2339
+ className: "mt-0.5 h-4! w-4! shrink-0 text-agg-warning",
2121
2340
  color: "currentColor"
2122
2341
  }
2123
2342
  ),
@@ -2172,17 +2391,10 @@ var PlaceOrderResolvedView = ({
2172
2391
  resolvedClaim,
2173
2392
  className
2174
2393
  }) => {
2175
- var _a, _b, _c, _d, _e, _f, _g, _h;
2394
+ var _a, _b, _c, _d, _e;
2176
2395
  const labels = useLabels();
2177
2396
  const tradingLabels = labels.trading;
2178
2397
  const extendedTradingLabels = tradingLabels;
2179
- const winningOutcomeLabel = (_c = (_b = (_a = tradingState.winningOutcome) == null ? void 0 : _a.label) == null ? void 0 : _b.trim().toLowerCase()) != null ? _c : "";
2180
- const isPositiveWinningOutcome = ["yes", "up", "buy", "long", "true"].includes(
2181
- winningOutcomeLabel
2182
- );
2183
- const resolvedIconName = isPositiveWinningOutcome ? "success-check" : "close";
2184
- const resolvedIconToneClassName = isPositiveWinningOutcome ? "text-agg-success" : "text-agg-error";
2185
- const resolvedIconContainerClassName = isPositiveWinningOutcome ? "bg-agg-success/15" : "bg-agg-error/15";
2186
2398
  return /* @__PURE__ */ jsx4(
2187
2399
  Card,
2188
2400
  {
@@ -2199,9 +2411,9 @@ var PlaceOrderResolvedView = ({
2199
2411
  {
2200
2412
  className: cn(
2201
2413
  "flex h-15 w-15 items-center justify-center rounded-full",
2202
- resolvedIconContainerClassName
2414
+ "bg-agg-primary/15"
2203
2415
  ),
2204
- children: /* @__PURE__ */ jsx4(Icon, { name: resolvedIconName, className: cn("h-6 w-6", resolvedIconToneClassName) })
2416
+ children: /* @__PURE__ */ jsx4(Icon, { name: "success-check", className: cn("h-6 w-6", "text-agg-primary") })
2205
2417
  }
2206
2418
  ),
2207
2419
  /* @__PURE__ */ jsxs3(
@@ -2221,18 +2433,18 @@ var PlaceOrderResolvedView = ({
2221
2433
  resolvedClaim ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
2222
2434
  /* @__PURE__ */ jsx4("div", { className: "h-px w-full bg-agg-separator" }),
2223
2435
  /* @__PURE__ */ jsxs3("div", { className: "flex w-full flex-col gap-5 p-6", children: [
2224
- /* @__PURE__ */ jsx4(Typography, { variant: "body-strong", className: "text-center", children: (_d = extendedTradingLabels.resolvedEarningsTitle) != null ? _d : "Your Earnings" }),
2436
+ /* @__PURE__ */ jsx4(Typography, { variant: "body-strong", className: "text-center", children: (_a = extendedTradingLabels.resolvedEarningsTitle) != null ? _a : "Your Earnings" }),
2225
2437
  /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-3 text-agg-sm leading-agg-5 text-agg-foreground", children: [
2226
2438
  resolvedClaim.resolutionDateLabel ? /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between gap-4", children: [
2227
- /* @__PURE__ */ jsx4("span", { children: (_e = extendedTradingLabels.resolvedResolutionDateLabel) != null ? _e : "Resolution date" }),
2439
+ /* @__PURE__ */ jsx4("span", { children: (_b = extendedTradingLabels.resolvedResolutionDateLabel) != null ? _b : "Resolution date" }),
2228
2440
  /* @__PURE__ */ jsx4("span", { className: "font-agg-bold", children: resolvedClaim.resolutionDateLabel })
2229
2441
  ] }) : null,
2230
2442
  /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between gap-4", children: [
2231
- /* @__PURE__ */ jsx4("span", { children: (_f = extendedTradingLabels.resolvedSharesLabel) != null ? _f : "Shares" }),
2443
+ /* @__PURE__ */ jsx4("span", { children: (_c = extendedTradingLabels.resolvedSharesLabel) != null ? _c : "Shares" }),
2232
2444
  /* @__PURE__ */ jsx4("span", { className: "font-agg-bold", children: resolvedClaim.sharesLabel })
2233
2445
  ] }),
2234
2446
  /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between gap-4", children: [
2235
- /* @__PURE__ */ jsx4("span", { children: (_g = extendedTradingLabels.resolvedTotalPayoutLabel) != null ? _g : "Total payout" }),
2447
+ /* @__PURE__ */ jsx4("span", { children: (_d = extendedTradingLabels.resolvedTotalPayoutLabel) != null ? _d : "Total payout" }),
2236
2448
  /* @__PURE__ */ jsx4("span", { className: "font-agg-bold", children: resolvedClaim.totalPayoutLabel })
2237
2449
  ] })
2238
2450
  ] }),
@@ -2244,7 +2456,7 @@ var PlaceOrderResolvedView = ({
2244
2456
  onClick: resolvedClaim.onClaim,
2245
2457
  isLoading: resolvedClaim.isClaiming,
2246
2458
  disabled: resolvedClaim.isClaiming,
2247
- children: (_h = extendedTradingLabels.claimWinnings) != null ? _h : "Claim Winnings"
2459
+ children: (_e = extendedTradingLabels.claimWinnings) != null ? _e : "Claim Winnings"
2248
2460
  }
2249
2461
  ) : null
2250
2462
  ] })
@@ -2263,7 +2475,7 @@ var renderRouteBreakdownRow = (row) => {
2263
2475
  className: "agg-route-breakdown-row flex items-center justify-between gap-4 text-left",
2264
2476
  children: [
2265
2477
  /* @__PURE__ */ jsxs3("div", { className: "agg-route-breakdown-market flex min-w-0 items-center gap-2", children: [
2266
- /* @__PURE__ */ jsx4(VenueLogo, { venue: row.venue, className: "!size-3", ariaLabel: venueLabel }),
2478
+ /* @__PURE__ */ jsx4(VenueLogo, { venue: row.venue, className: "size-3!", ariaLabel: venueLabel }),
2267
2479
  /* @__PURE__ */ jsx4("p", { className: "agg-route-breakdown-label truncate text-agg-sm leading-agg-5 text-agg-foreground", children: row.label })
2268
2480
  ] }),
2269
2481
  /* @__PURE__ */ jsxs3("div", { className: "agg-route-breakdown-value flex shrink-0 items-center gap-2 text-agg-sm leading-agg-5", children: [
@@ -2302,7 +2514,7 @@ var renderRouteCard = ({
2302
2514
  "transition-[background-color,border-color,color] duration-200 ease-in-out"
2303
2515
  ),
2304
2516
  card.isUnavailable ? "cursor-not-allowed" : "cursor-pointer",
2305
- isSelected && !card.isUnavailable ? "border border-agg-trade-highlight-border bg-gradient-to-b from-agg-trade-highlight-surface-from to-agg-trade-highlight-surface-to" : "border-transparent bg-agg-secondary-hover"
2517
+ isSelected && !card.isUnavailable ? "border border-agg-trade-highlight-border bg-linear-to-b from-agg-trade-highlight-surface-from to-agg-trade-highlight-surface-to" : "border-transparent bg-agg-secondary-hover"
2306
2518
  ),
2307
2519
  onClick: () => onSelect(card.id),
2308
2520
  children: /* @__PURE__ */ jsxs3("div", { className: "agg-route-card-content relative z-10 flex flex-col gap-3", children: [
@@ -2584,9 +2796,10 @@ var PlaceOrder = ({
2584
2796
  onSuccess,
2585
2797
  onError,
2586
2798
  onExecutionStateChange,
2587
- resolvedClaim
2799
+ resolvedClaim,
2800
+ midpointsResult
2588
2801
  }) => {
2589
- 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;
2802
+ 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;
2590
2803
  const {
2591
2804
  enableDebug: isExecutionDebugEnabled,
2592
2805
  features: { enableAnimations, showFeesBreakdown },
@@ -2662,14 +2875,24 @@ var PlaceOrder = ({
2662
2875
  const livePrices = useLiveOutcomePrices(
2663
2876
  scopedSelectedMarket ? [scopedSelectedMarket] : void 0
2664
2877
  );
2665
- const midpointsClusterMarkets = useMemo2(() => {
2666
- if (!scopedSelectedMarket) return [];
2667
- return normalizeVenueMarketCluster(
2668
- resolvedEventTradingState.displayMarkets,
2669
- scopedSelectedMarket.id
2670
- );
2671
- }, [resolvedEventTradingState.displayMarkets, scopedSelectedMarket]);
2672
- const { prices: clusterMidpoints } = useMidpoints(midpointsClusterMarkets);
2878
+ const wsBestPrices = useLiveBestPrices(scopedSelectedMarket ? [scopedSelectedMarket] : void 0);
2879
+ const clusterMidpointResult = midpointsResult != null ? midpointsResult : {
2880
+ prices: /* @__PURE__ */ new Map(),
2881
+ bestMidpointsByOutcomeId: /* @__PURE__ */ new Map(),
2882
+ venueByOutcomeId: /* @__PURE__ */ new Map(),
2883
+ bestPrices: /* @__PURE__ */ new Map(),
2884
+ bestPriceVenuesByOutcomeId: /* @__PURE__ */ new Map(),
2885
+ isLoading: false,
2886
+ bestMidpoint: void 0,
2887
+ bestMidpointVenue: void 0
2888
+ };
2889
+ const clusterBestMidpointsByOutcomeId = (_i = clusterMidpointResult.bestMidpointsByOutcomeId) != null ? _i : clusterMidpointResult.prices;
2890
+ const clusterBestMidpoint = clusterMidpointResult.bestMidpoint;
2891
+ const clusterBestPricesRest = clusterMidpointResult.bestPrices;
2892
+ const clusterBestPrices = useMemo2(
2893
+ () => mergeBestPricesPreferringLive(clusterBestPricesRest, wsBestPrices),
2894
+ [clusterBestPricesRest, wsBestPrices]
2895
+ );
2673
2896
  const outcomes = useMemo2(
2674
2897
  () => mapVenueMarketOutcomesToPlaceOrderOutcomes(scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.venueMarketOutcomes),
2675
2898
  [scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.venueMarketOutcomes]
@@ -2687,6 +2910,7 @@ var PlaceOrder = ({
2687
2910
  const [submissionProgressState, setSubmissionProgressState] = useState3(null);
2688
2911
  const executionDebugStoreRef = useRef2(null);
2689
2912
  const executionDebugAttemptIdRef = useRef2(null);
2913
+ const submittedSelectionRef = useRef2(null);
2690
2914
  useEffect2(() => {
2691
2915
  if (!isExecutionDebugEnabled) {
2692
2916
  executionDebugStoreRef.current = null;
@@ -2762,15 +2986,16 @@ var PlaceOrder = ({
2762
2986
  isSell,
2763
2987
  scopedSelectedMarket,
2764
2988
  scopedSelectedOutcome,
2765
- (_j = (_i = smartRoute.data) == null ? void 0 : _i.positionAvailability) == null ? void 0 : _j.totalSellableShares
2989
+ (_k = (_j = smartRoute.data) == null ? void 0 : _j.positionAvailability) == null ? void 0 : _k.totalSellableShares
2766
2990
  ]);
2767
- const isCurrentSellableSharesLoading = isSell && isAuthenticated && !(typeof ((_l = (_k = smartRoute.data) == null ? void 0 : _k.positionAvailability) == null ? void 0 : _l.totalSellableShares) === "number") && (isExecutionPositionsLoading || isExecutionPositionsFetching);
2991
+ const isCurrentSellableSharesLoading = isSell && isAuthenticated && !(typeof ((_m = (_l = smartRoute.data) == null ? void 0 : _l.positionAvailability) == null ? void 0 : _m.totalSellableShares) === "number") && (isExecutionPositionsLoading || isExecutionPositionsFetching);
2768
2992
  const displayedCurrentSellableShares = useMemo2(() => {
2769
2993
  if (!Number.isFinite(currentSellableShares) || currentSellableShares <= 0) return 0;
2770
2994
  return Math.floor(currentSellableShares * 100) / 100;
2771
2995
  }, [currentSellableShares]);
2772
2996
  const isAtMaxSellableShares = isSell && displayedCurrentSellableShares > 0 && Math.abs(internalAmount - displayedCurrentSellableShares) < 1e-9;
2773
2997
  useEffect2(() => {
2998
+ if (submissionProgressState != null) return;
2774
2999
  if (!isSell || isCurrentSellableSharesLoading) return;
2775
3000
  if (scopedSelectedOutcomeId === sellFilledForOutcomeId) return;
2776
3001
  setInternalAmount(displayedCurrentSellableShares);
@@ -2782,7 +3007,8 @@ var PlaceOrder = ({
2782
3007
  scopedSelectedOutcomeId,
2783
3008
  sellFilledForOutcomeId,
2784
3009
  displayedCurrentSellableShares,
2785
- onAmountChange
3010
+ onAmountChange,
3011
+ submissionProgressState
2786
3012
  ]);
2787
3013
  const routeCards = useMemo2(
2788
3014
  () => smartRoute.data ? buildLiveRouteCards({
@@ -2812,12 +3038,16 @@ var PlaceOrder = ({
2812
3038
  setSelectedRouteCardId(resolvedSelectedRouteCardId);
2813
3039
  }
2814
3040
  }, [resolvedSelectedRouteCardId, routeCards.length, selectedRouteCardId]);
3041
+ const isSubmissionLocked = submissionProgressState != null;
3042
+ const isSubmissionLockedRef = useRef2(isSubmissionLocked);
3043
+ isSubmissionLockedRef.current = isSubmissionLocked;
2815
3044
  useEffect2(() => {
3045
+ if (isSubmissionLockedRef.current) return;
2816
3046
  setSubmissionFeedback(null);
2817
3047
  setSubmissionProgressState(null);
2818
3048
  }, [internalAmount, internalSlippage, internalTab, scopedSelectedOutcomeId]);
2819
3049
  const orderedRouteCards = routeCards;
2820
- const selectedRouteCard = (_n = (_m = orderedRouteCards.find((card) => card.id === resolvedSelectedRouteCardId)) != null ? _m : orderedRouteCards[0]) != null ? _n : null;
3050
+ const selectedRouteCard = (_o = (_n = orderedRouteCards.find((card) => card.id === resolvedSelectedRouteCardId)) != null ? _n : orderedRouteCards[0]) != null ? _o : null;
2821
3051
  const isKalshiRoute = useMemo2(() => {
2822
3052
  if (selectedRouteCard) {
2823
3053
  return selectedRouteCard.venue === "kalshi" || selectedRouteCard.quoteData.fills.some((f) => f.venue === "kalshi");
@@ -2841,7 +3071,7 @@ var PlaceOrder = ({
2841
3071
  } = useKalshiKycFlow({
2842
3072
  isKalshiVerified,
2843
3073
  userId: user == null ? void 0 : user.id,
2844
- walletAddress: (_o = getWalletAddressFromUserProfile(user)) != null ? _o : null,
3074
+ walletAddress: (_p = getWalletAddressFromUserProfile(user)) != null ? _p : null,
2845
3075
  onError
2846
3076
  });
2847
3077
  const handleRouteCardSelect = useCallback2(
@@ -2858,29 +3088,37 @@ var PlaceOrder = ({
2858
3088
  [resolvedSelectedRouteCardId, routeCards]
2859
3089
  );
2860
3090
  const executionProgress = useExecutionProgress({
2861
- orderIds: (_p = submissionProgressState == null ? void 0 : submissionProgressState.orderIds) != null ? _p : null,
2862
- enabled: ((submissionProgressState == null ? void 0 : submissionProgressState.phase) === "submitting" || (submissionProgressState == null ? void 0 : submissionProgressState.phase) === "executing") && !!((_q = submissionProgressState == null ? void 0 : submissionProgressState.orderIds) == null ? void 0 : _q.length)
3091
+ orderIds: (_q = submissionProgressState == null ? void 0 : submissionProgressState.orderIds) != null ? _q : null,
3092
+ enabled: ((submissionProgressState == null ? void 0 : submissionProgressState.phase) === "submitting" || (submissionProgressState == null ? void 0 : submissionProgressState.phase) === "executing") && !!((_r = submissionProgressState == null ? void 0 : submissionProgressState.orderIds) == null ? void 0 : _r.length)
2863
3093
  });
2864
- const selectedOutcomeLabel = (_t = (_s = (_r = outcomes.find((outcome) => outcome.id === scopedSelectedOutcomeId)) == null ? void 0 : _r.label) != null ? _s : scopedSelectedOutcome == null ? void 0 : scopedSelectedOutcome.label) != null ? _t : "";
2865
- const headerImage = (_v = (_u = scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.image) != null ? _u : scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.image) != null ? _v : null;
2866
- const headerTitle = (_x = (_w = scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.title) != null ? _w : scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.question) != null ? _x : "";
2867
- const headerSubtitle = (_y = scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.question) != null ? _y : "";
3094
+ const selectedOutcomeLabel = (_u = (_t = (_s = outcomes.find((outcome) => outcome.id === scopedSelectedOutcomeId)) == null ? void 0 : _s.label) != null ? _t : scopedSelectedOutcome == null ? void 0 : scopedSelectedOutcome.label) != null ? _u : "";
3095
+ const headerImage = (_w = (_v = scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.image) != null ? _v : scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.image) != null ? _w : null;
3096
+ const headerTitle = (_y = (_x = scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.title) != null ? _x : scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.question) != null ? _y : "";
3097
+ const headerSubtitle = (_z = scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.question) != null ? _z : "";
2868
3098
  const buildExecutionSummary = useCallback2(
2869
3099
  (quoteData, executionVenue, orderId, partialFillSummary) => {
2870
3100
  var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
2871
3101
  if (!quoteData) return void 0;
2872
- const avgPriceValue = quoteData.totalFilled > 0 ? quoteData.rawExecCost / quoteData.totalFilled : 0;
2873
- const avgPriceLabel = quoteData.totalFilled > 0 ? getTradingRoutePriceLabel(avgPriceValue) : "\u2014";
2874
- const actionPriceLabel = quoteData.totalFilled > 0 ? `~${avgPriceLabel}` : avgPriceLabel;
3102
+ const actualEconomics = resolveActualExecutionEconomics({
3103
+ quoteData,
3104
+ tradeSide: internalTab,
3105
+ terminalOrderEvents: executionProgress.terminalOrderEvents,
3106
+ submittedOrders: executionProgress.submittedOrders
3107
+ });
3108
+ const usdSide = actualEconomics.hasActualFillData ? actualEconomics.actualRawExecCost : quoteData.rawExecCost;
3109
+ const sharesSide = actualEconomics.hasActualFillData ? actualEconomics.actualTotalFilled : quoteData.totalFilled;
3110
+ const avgPriceValue = actualEconomics.hasActualFillData ? actualEconomics.avgExecutionPrice : quoteData.totalFilled > 0 ? quoteData.rawExecCost / quoteData.totalFilled : 0;
3111
+ const avgPriceLabel = avgPriceValue > 0 ? getTradingRoutePriceLabel(avgPriceValue) : "\u2014";
3112
+ const actionPriceLabel = avgPriceValue > 0 ? `~${avgPriceLabel}` : avgPriceLabel;
2875
3113
  const actionLabel2 = internalTab === "buy" ? (_b2 = (_a2 = tradingLabels.boughtOutcomeAtPrice) == null ? void 0 : _a2.call(tradingLabels, selectedOutcomeLabel, actionPriceLabel)) != null ? _b2 : `Bought ${selectedOutcomeLabel} at ${actionPriceLabel}` : (_d2 = (_c2 = tradingLabels.soldOutcomeAtPrice) == null ? void 0 : _c2.call(tradingLabels, selectedOutcomeLabel, actionPriceLabel)) != null ? _d2 : `Sold ${selectedOutcomeLabel} at ${actionPriceLabel}`;
2876
- const sharesLabel = quoteData.totalFilled.toLocaleString("en-US", {
3114
+ const sharesLabel = sharesSide.toLocaleString("en-US", {
2877
3115
  minimumFractionDigits: 2,
2878
3116
  maximumFractionDigits: 2
2879
3117
  });
2880
- const payoutLabel = formatUsd(quoteData.rawExecCost);
3118
+ const payoutLabel = formatUsd(usdSide);
2881
3119
  const amountLabel = internalTab === "sell" ? sharesLabel : payoutLabel;
2882
- const toWinLabel = internalTab === "sell" ? payoutLabel : formatUsd(quoteData.totalFilled);
2883
- const potentialReturnValue = getPlaceOrderPotentialReturn(quoteData);
3120
+ const toWinLabel = internalTab === "sell" ? payoutLabel : formatUsd(sharesSide);
3121
+ const potentialReturnValue = actualEconomics.hasActualFillData ? 0 : getPlaceOrderPotentialReturn(quoteData);
2884
3122
  const potentialReturnLabel = potentialReturnValue > 0 ? formatUsd(potentialReturnValue) : void 0;
2885
3123
  const eventTitle = (_f2 = (_e2 = scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.title) != null ? _e2 : scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.question) != null ? _f2 : "";
2886
3124
  const eventDateSource = (_g2 = scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.endDate) != null ? _g2 : scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.endDate;
@@ -2922,6 +3160,7 @@ var PlaceOrder = ({
2922
3160
  },
2923
3161
  [
2924
3162
  executionProgress.submittedOrders,
3163
+ executionProgress.terminalOrderEvents,
2925
3164
  headerImage,
2926
3165
  internalTab,
2927
3166
  scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.endDate,
@@ -2944,26 +3183,7 @@ var PlaceOrder = ({
2944
3183
  });
2945
3184
  });
2946
3185
  }
2947
- if (executionProgress.phase === "balance_updated") {
2948
- setSubmissionProgressState((prev) => {
2949
- var _a2, _b2;
2950
- if (!prev || prev.phase !== "submitting" && prev.phase !== "executing") return prev;
2951
- return __spreadProps(__spreadValues({}, prev), {
2952
- phase: "success",
2953
- summary: buildExecutionSummary(
2954
- selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData,
2955
- prev.executionVenue,
2956
- (_b2 = prev.orderId) != null ? _b2 : (_a2 = executionProgress.submittedOrders[0]) == null ? void 0 : _a2.orderId
2957
- )
2958
- });
2959
- });
2960
- }
2961
- }, [
2962
- buildExecutionSummary,
2963
- executionProgress.phase,
2964
- executionProgress.submittedOrders,
2965
- selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData
2966
- ]);
3186
+ }, [executionProgress.phase, executionProgress.submittedOrders]);
2967
3187
  useEffect2(() => {
2968
3188
  var _a2, _b2;
2969
3189
  const dp = executionProgress.dagProgress;
@@ -3003,7 +3223,8 @@ var PlaceOrder = ({
3003
3223
  if (dp.status === "failed") {
3004
3224
  const errorMessage = normalizePlaceOrderErrorMessage({
3005
3225
  errorMessage: dp.errorReason,
3006
- fallbackMessage: tradingLabels.orderFailed
3226
+ fallbackMessage: tradingLabels.orderFailed,
3227
+ labels: tradingLabels
3007
3228
  });
3008
3229
  return __spreadProps(__spreadValues({}, prev), {
3009
3230
  phase: "failed",
@@ -3056,7 +3277,8 @@ var PlaceOrder = ({
3056
3277
  );
3057
3278
  const errorMessage = normalizePlaceOrderErrorMessage({
3058
3279
  errorMessage: firstFailedEvent == null ? void 0 : firstFailedEvent.errorReason,
3059
- fallbackMessage: tradingLabels.orderFailed
3280
+ fallbackMessage: tradingLabels.orderFailed,
3281
+ labels: tradingLabels
3060
3282
  });
3061
3283
  return __spreadProps(__spreadValues({}, prev), {
3062
3284
  phase: "failed",
@@ -3071,8 +3293,24 @@ var PlaceOrder = ({
3071
3293
  executionProgress.terminalOrderEvents,
3072
3294
  selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData,
3073
3295
  submissionProgressState == null ? void 0 : submissionProgressState.orderIds,
3074
- tradingLabels.orderFailed
3296
+ tradingLabels
3075
3297
  ]);
3298
+ const estDurationMs = (selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData) && typeof selectedRouteCard.quoteData.estDurationMs === "number" ? selectedRouteCard.quoteData.estDurationMs : 6e4;
3299
+ useEffect2(() => {
3300
+ const phase = submissionProgressState == null ? void 0 : submissionProgressState.phase;
3301
+ if (phase !== "submitting" && phase !== "executing") return;
3302
+ const timeoutMs = Math.max(6e4, 2 * estDurationMs);
3303
+ const id = setTimeout(() => {
3304
+ setSubmissionProgressState((prev) => {
3305
+ if (!prev || prev.phase === "success" || prev.phase === "failed") return prev;
3306
+ return __spreadProps(__spreadValues({}, prev), {
3307
+ phase: "failed",
3308
+ errorMessage: "Couldn't confirm the order in time. Your trade may still complete in the background \u2014 check your activity feed."
3309
+ });
3310
+ });
3311
+ }, timeoutMs);
3312
+ return () => clearTimeout(id);
3313
+ }, [submissionProgressState == null ? void 0 : submissionProgressState.phase, estDurationMs]);
3076
3314
  useEffect2(() => {
3077
3315
  var _a2, _b2;
3078
3316
  if (!submissionProgressState) return;
@@ -3116,9 +3354,10 @@ var PlaceOrder = ({
3116
3354
  onError == null ? void 0 : onError(new Error(submissionProgressState.errorMessage));
3117
3355
  }
3118
3356
  }, [submissionProgressState, onExecutionStateChange, onSuccess, onError, queryClient]);
3119
- const activeQuoteData = (_A = (_z = selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData) != null ? _z : smartRoute.data) != null ? _A : null;
3357
+ const activeQuoteData = (_B = (_A = selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData) != null ? _A : smartRoute.data) != null ? _B : null;
3120
3358
  const visibleRouteCards = orderedRouteCards.length > PLACE_ORDER_ROUTE_COLLAPSED_CARD_COUNT && !isRoutesExpanded ? orderedRouteCards.slice(0, PLACE_ORDER_ROUTE_COLLAPSED_CARD_COUNT) : orderedRouteCards;
3121
3359
  const hasEnteredAmount = internalAmount > 0;
3360
+ const isQuoteLoading = hasEnteredAmount && (smartRoute.isFetching || smartRoute.isLoading);
3122
3361
  const isInsufficientBalance = !isSell && isAuthenticated && hasEnteredAmount && !isBalanceLoading && internalAmount > totalBalance;
3123
3362
  const isBelowMinimum = !isSell && hasEnteredAmount && internalAmount < MIN_BUY_ORDER_AMOUNT;
3124
3363
  const quoteStatus = useMemo2(() => {
@@ -3140,29 +3379,32 @@ var PlaceOrder = ({
3140
3379
  if (!smartRoute.error) return null;
3141
3380
  return normalizePlaceOrderErrorMessage({
3142
3381
  errorMessage: smartRoute.error.message,
3143
- fallbackMessage: tradingLabels.quoteUnavailable
3382
+ fallbackMessage: tradingLabels.quoteUnavailable,
3383
+ labels: tradingLabels
3144
3384
  });
3145
- }, [smartRoute.error, tradingLabels.quoteUnavailable]);
3385
+ }, [smartRoute.error, tradingLabels]);
3146
3386
  const progressActionLabel = (internalTab === "buy" ? tradingLabels.buyingOutcome(selectedOutcomeLabel) : tradingLabels.sellingOutcome(selectedOutcomeLabel)).trim();
3147
3387
  const canRetryRemaining = useMemo2(() => {
3148
3388
  const remaining = getPlaceOrderUnfilledRemaining({
3149
3389
  originalAmount: internalAmount,
3390
+ tradeSide: internalTab,
3150
3391
  terminalOrderEvents: executionProgress.terminalOrderEvents
3151
3392
  });
3152
3393
  const minRemainder = isSell ? MIN_SELL_ORDER_SHARES : MIN_BUY_ORDER_AMOUNT;
3153
3394
  return remaining >= minRemainder;
3154
- }, [executionProgress.terminalOrderEvents, internalAmount, isSell]);
3395
+ }, [executionProgress.terminalOrderEvents, internalAmount, internalTab, isSell]);
3155
3396
  const PARTIAL_FILL_AUTO_SUCCESS_THRESHOLD = 0.95;
3156
3397
  const shouldAutoSkipPartialFill = useMemo2(() => {
3157
3398
  if (internalAmount <= 0) return false;
3158
3399
  const remaining = getPlaceOrderUnfilledRemaining({
3159
3400
  originalAmount: internalAmount,
3401
+ tradeSide: internalTab,
3160
3402
  terminalOrderEvents: executionProgress.terminalOrderEvents
3161
3403
  });
3162
3404
  const filled = Math.max(0, internalAmount - remaining);
3163
3405
  const fillRatio = filled / internalAmount;
3164
3406
  return fillRatio >= PARTIAL_FILL_AUTO_SUCCESS_THRESHOLD || !canRetryRemaining;
3165
- }, [canRetryRemaining, executionProgress.terminalOrderEvents, internalAmount]);
3407
+ }, [canRetryRemaining, executionProgress.terminalOrderEvents, internalAmount, internalTab]);
3166
3408
  const failureSummary = useMemo2(() => {
3167
3409
  var _a2;
3168
3410
  if ((submissionProgressState == null ? void 0 : submissionProgressState.phase) !== "failed") return void 0;
@@ -3201,7 +3443,7 @@ var PlaceOrder = ({
3201
3443
  }
3202
3444
  return (_d2 = selectedRouteCard.hint) != null ? _d2 : "";
3203
3445
  }, [selectedRouteCard, tradingLabels]);
3204
- const displayedToWinValue = (_B = selectedRouteCard == null ? void 0 : selectedRouteCard.numericValue) != null ? _B : 0;
3446
+ const displayedToWinValue = (_C = selectedRouteCard == null ? void 0 : selectedRouteCard.numericValue) != null ? _C : 0;
3205
3447
  const activeFeeBreakdown = activeQuoteData == null ? void 0 : activeQuoteData.feeBreakdown;
3206
3448
  const estimatedFeesValue = useMemo2(() => {
3207
3449
  if (!activeFeeBreakdown) return null;
@@ -3242,13 +3484,13 @@ var PlaceOrder = ({
3242
3484
  ];
3243
3485
  }, [activeFeeBreakdown, tradingLabels]);
3244
3486
  const isActionLoading = isPrimaryActionLoading || executeManaged.isPending;
3245
- const selectedRouteGeoBlocked = (_C = selectedRouteCard == null ? void 0 : selectedRouteCard.isUnavailable) != null ? _C : false;
3487
+ const selectedRouteGeoBlocked = (_D = selectedRouteCard == null ? void 0 : selectedRouteCard.isUnavailable) != null ? _D : false;
3246
3488
  const geoBlockedVenuesFromWarnings = useMemo2(
3247
3489
  () => {
3248
3490
  var _a2;
3249
3491
  return extractGeoBlockedVenues((_a2 = smartRoute.data) == null ? void 0 : _a2.warnings);
3250
3492
  },
3251
- [(_D = smartRoute.data) == null ? void 0 : _D.warnings]
3493
+ [(_E = smartRoute.data) == null ? void 0 : _E.warnings]
3252
3494
  );
3253
3495
  const isPrimaryVenueGeoBlocked = useMemo2(() => {
3254
3496
  var _a2, _b2;
@@ -3258,25 +3500,23 @@ var PlaceOrder = ({
3258
3500
  }, [selectedRouteCard, geoBlockedVenuesFromWarnings]);
3259
3501
  const shouldShowGeoBlockBanner = isTradingBlocked || selectedRouteGeoBlocked || isPrimaryVenueGeoBlocked;
3260
3502
  const actionLabel = `${internalTab === "buy" ? tradingLabels.buy : tradingLabels.sell} ${selectedOutcomeLabel}`.trim();
3261
- const isActionDisabled = isPrimaryActionDisabled || !orderEligibility.canPlaceOrder || isActionLoading || !hasEnteredAmount || !scopedSelectedMarket || isInsufficientBalance || isBelowMinimum || !selectedRouteCard || !selectedRouteCard.quoteData.quoteId || selectedRouteGeoBlocked || !isAuthenticated || quoteStatus !== void 0;
3503
+ const isActionDisabled = isPrimaryActionDisabled || !orderEligibility.canPlaceOrder || isActionLoading || !hasEnteredAmount || !scopedSelectedMarket || isInsufficientBalance || isBelowMinimum || isQuoteLoading || !selectedRouteCard || !selectedRouteCard.quoteData.quoteId || selectedRouteGeoBlocked || !isAuthenticated || quoteStatus !== void 0;
3262
3504
  const shouldShowSmartRouting = orderEligibility.canPlaceOrder && hasEnteredAmount && (orderedRouteCards.length > 0 || smartRoute.isFetching);
3263
- const shouldShowRouteToggle = orderedRouteCards.length > PLACE_ORDER_ROUTE_COLLAPSED_CARD_COUNT;
3264
- const handleStartNewTrade = useCallback2(() => {
3505
+ const shouldShowRouteToggle = !isQuoteLoading && orderedRouteCards.length > PLACE_ORDER_ROUTE_COLLAPSED_CARD_COUNT;
3506
+ const handleReturnToOrderForm = useCallback2(() => {
3507
+ const submittedSelection = submittedSelectionRef.current;
3508
+ submittedSelectionRef.current = null;
3265
3509
  setSubmissionProgressState(null);
3266
3510
  setSubmissionFeedback(null);
3267
- setInternalAmount(0);
3268
- setSellFilledForOutcomeId(null);
3269
- setInternalSlippage(DEFAULT_SLIPPAGE_VALUE);
3270
- setInternalTab("buy");
3271
3511
  setIsRoutesExpanded(false);
3272
3512
  setSelectedRouteCardId(null);
3273
- onAmountChange == null ? void 0 : onAmountChange(0);
3274
- onSlippageChange == null ? void 0 : onSlippageChange(formatPercentageValue(DEFAULT_SLIPPAGE_VALUE));
3275
- onTabChange == null ? void 0 : onTabChange("buy");
3276
- if (scopedSelectedEvent) {
3277
- tradingContext == null ? void 0 : tradingContext.initializeFromEvent(scopedSelectedEvent);
3513
+ if (submittedSelection && tradingContext) {
3514
+ tradingContext.selectMarketAndOutcome(
3515
+ submittedSelection.marketId,
3516
+ submittedSelection.outcomeId
3517
+ );
3278
3518
  }
3279
- }, [onAmountChange, onSlippageChange, onTabChange, scopedSelectedEvent, tradingContext]);
3519
+ }, [tradingContext]);
3280
3520
  const handleShareTrade = () => {
3281
3521
  var _a2, _b2;
3282
3522
  const shareText = (_b2 = (_a2 = submissionProgressState == null ? void 0 : submissionProgressState.summary) == null ? void 0 : _a2.shareText) == null ? void 0 : _b2.trim();
@@ -3356,6 +3596,12 @@ var PlaceOrder = ({
3356
3596
  finalStatus: "failed"
3357
3597
  });
3358
3598
  }
3599
+ if (isFillRejection400(error)) {
3600
+ try {
3601
+ yield smartRoute.refetch();
3602
+ } catch (e) {
3603
+ }
3604
+ }
3359
3605
  throw error;
3360
3606
  }
3361
3607
  }),
@@ -3368,7 +3614,7 @@ var PlaceOrder = ({
3368
3614
  scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.id,
3369
3615
  scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.id,
3370
3616
  scopedSelectedOutcomeId,
3371
- smartRoute.data,
3617
+ smartRoute,
3372
3618
  tradingLabels.quoteUnavailable
3373
3619
  ]
3374
3620
  );
@@ -3410,8 +3656,8 @@ var PlaceOrder = ({
3410
3656
  ]);
3411
3657
  const handleRetrySubmission = useCallback2(() => __async(null, null, function* () {
3412
3658
  var _a2, _b2, _c2;
3413
- if (!orderEligibility.canPlaceOrder) {
3414
- handleStartNewTrade();
3659
+ if (!orderEligibility.canPlaceOrder || (failureSummary == null ? void 0 : failureSummary.kind) === "generic") {
3660
+ handleReturnToOrderForm();
3415
3661
  return;
3416
3662
  }
3417
3663
  setSubmissionFeedback(null);
@@ -3420,6 +3666,7 @@ var PlaceOrder = ({
3420
3666
  if ((failureSummary == null ? void 0 : failureSummary.kind) === "partial_fill" && internalAmount > 0) {
3421
3667
  const remaining = getPlaceOrderUnfilledRemaining({
3422
3668
  originalAmount: internalAmount,
3669
+ tradeSide: internalTab,
3423
3670
  terminalOrderEvents: executionProgress.terminalOrderEvents
3424
3671
  });
3425
3672
  if (remaining > 0) {
@@ -3468,7 +3715,8 @@ var PlaceOrder = ({
3468
3715
  } catch (error) {
3469
3716
  const errorMessage = normalizePlaceOrderErrorMessage({
3470
3717
  errorMessage: error instanceof Error ? error.message : String(error),
3471
- fallbackMessage: tradingLabels.orderFailed
3718
+ fallbackMessage: tradingLabels.orderFailed,
3719
+ labels: tradingLabels
3472
3720
  });
3473
3721
  setSubmissionProgressState({
3474
3722
  phase: "failed",
@@ -3481,7 +3729,7 @@ var PlaceOrder = ({
3481
3729
  executionProgress.terminalOrderEvents,
3482
3730
  failureSummary == null ? void 0 : failureSummary.kind,
3483
3731
  handleExecuteQuote,
3484
- handleStartNewTrade,
3732
+ handleReturnToOrderForm,
3485
3733
  internalAmount,
3486
3734
  internalTab,
3487
3735
  isSell,
@@ -3512,7 +3760,7 @@ var PlaceOrder = ({
3512
3760
  className: resolvedStatusClassName,
3513
3761
  summary: submissionProgressState.summary,
3514
3762
  tradingLabels,
3515
- onDone: handleStartNewTrade,
3763
+ onDone: handleReturnToOrderForm,
3516
3764
  onShare: handleShareTrade
3517
3765
  }
3518
3766
  );
@@ -3526,7 +3774,7 @@ var PlaceOrder = ({
3526
3774
  summary: failureSummary,
3527
3775
  tradingLabels,
3528
3776
  onRetry: handleRetrySubmission,
3529
- onDone: handleStartNewTrade,
3777
+ onDone: handleReturnToOrderForm,
3530
3778
  onSkip: handleSkipToSuccess
3531
3779
  }
3532
3780
  );
@@ -3546,6 +3794,7 @@ var PlaceOrder = ({
3546
3794
  const handleTabChange = (nextTab) => {
3547
3795
  if (!orderEligibility.canPlaceOrder) return;
3548
3796
  setInternalTab(nextTab);
3797
+ tradingContext == null ? void 0 : tradingContext.setTradeSide(nextTab);
3549
3798
  if (nextTab === "sell") {
3550
3799
  setInternalAmount(0);
3551
3800
  setSellFilledForOutcomeId(null);
@@ -3601,13 +3850,20 @@ var PlaceOrder = ({
3601
3850
  }
3602
3851
  if (!selectedRouteCard) return;
3603
3852
  setSubmissionFeedback(null);
3853
+ if (scopedSelectedMarket && scopedSelectedOutcomeId) {
3854
+ submittedSelectionRef.current = {
3855
+ marketId: scopedSelectedMarket.id,
3856
+ outcomeId: scopedSelectedOutcomeId
3857
+ };
3858
+ }
3604
3859
  try {
3605
3860
  setSubmissionProgressState({ phase: "finding-route" });
3606
3861
  yield handleExecuteQuote(selectedRouteCard.quoteData);
3607
3862
  } catch (error) {
3608
3863
  const errorMessage = normalizePlaceOrderErrorMessage({
3609
3864
  errorMessage: error instanceof Error ? error.message : String(error),
3610
- fallbackMessage: tradingLabels.orderFailed
3865
+ fallbackMessage: tradingLabels.orderFailed,
3866
+ labels: tradingLabels
3611
3867
  });
3612
3868
  setSubmissionProgressState({
3613
3869
  phase: "failed",
@@ -3704,10 +3960,18 @@ var PlaceOrder = ({
3704
3960
  ),
3705
3961
  outcomes.length >= 2 ? /* @__PURE__ */ jsx4("div", { className: "agg-outcomes flex w-full max-w-full gap-2", children: outcomes.map((outcome, index) => {
3706
3962
  var _a2, _b2, _c2;
3707
- const price = (_b2 = (_a2 = clusterMidpoints.get(outcome.id)) != null ? _a2 : livePrices.get(outcome.id)) != null ? _b2 : outcome.price;
3963
+ const price = getDisplayOutcomePrice({
3964
+ outcomeId: outcome.id,
3965
+ outcomeLabel: outcome.label,
3966
+ selection: (_a2 = tradingContext == null ? void 0 : tradingContext.tradeSide) != null ? _a2 : isSell ? "sell" : "buy",
3967
+ bestPrices: clusterBestPrices,
3968
+ bestMidpoint: clusterBestMidpoint,
3969
+ bestMidpointsByOutcomeId: clusterBestMidpointsByOutcomeId,
3970
+ livePrices,
3971
+ fallbackPrice: outcome.price
3972
+ });
3708
3973
  const isActive = outcome.id === scopedSelectedOutcomeId;
3709
3974
  const isPositive = resolveIsPositiveOutcome(outcome, index);
3710
- const displayLabel = ((_c2 = outcome.title) == null ? void 0 : _c2.trim()) || outcome.label;
3711
3975
  return /* @__PURE__ */ jsxs3(
3712
3976
  "button",
3713
3977
  {
@@ -3724,7 +3988,7 @@ var PlaceOrder = ({
3724
3988
  "leading-agg-5! flex-1 min-w-0 gap-1 md:gap-2"
3725
3989
  ),
3726
3990
  "aria-pressed": isActive,
3727
- "aria-label": `${displayLabel} ${formatProbabilityCents(price)}`,
3991
+ "aria-label": `${(_b2 = outcome.title) != null ? _b2 : outcome.label} ${formatProbabilityCents(price)}`,
3728
3992
  disabled: !orderEligibility.canPlaceOrder || isResolvedOutcomeCtaLocked,
3729
3993
  onClick: () => handleOutcomeChange(outcome.id),
3730
3994
  children: [
@@ -3734,7 +3998,7 @@ var PlaceOrder = ({
3734
3998
  as: "span",
3735
3999
  variant: isActive ? "body-strong" : "body",
3736
4000
  className: cn("whitespace-nowrap truncate"),
3737
- children: displayLabel
4001
+ children: (_c2 = outcome.title) != null ? _c2 : outcome.label
3738
4002
  }
3739
4003
  ),
3740
4004
  /* @__PURE__ */ jsx4(Typography, { as: "span", variant: isActive ? "body-strong" : "body", children: formatProbabilityCents(price) })
@@ -3841,7 +4105,19 @@ var PlaceOrder = ({
3841
4105
  }
3842
4106
  ) : null
3843
4107
  ] }),
3844
- /* @__PURE__ */ jsx4("div", { className: "agg-route-list flex flex-col gap-2", children: visibleRouteCards.length > 0 ? visibleRouteCards.map((card) => {
4108
+ /* @__PURE__ */ jsx4("div", { className: "agg-route-list flex flex-col gap-2", children: isQuoteLoading ? /* @__PURE__ */ jsxs3(
4109
+ "div",
4110
+ {
4111
+ className: "agg-route-loading flex flex-col gap-2",
4112
+ role: "status",
4113
+ "aria-label": labels.common.loading,
4114
+ "aria-live": "polite",
4115
+ children: [
4116
+ /* @__PURE__ */ jsx4(PlaceOrderRouteCardSkeleton, {}),
4117
+ /* @__PURE__ */ jsx4(PlaceOrderRouteCardSkeleton, {})
4118
+ ]
4119
+ }
4120
+ ) : visibleRouteCards.length > 0 ? visibleRouteCards.map((card) => {
3845
4121
  return /* @__PURE__ */ jsx4(Fragment, { children: renderRouteCard({
3846
4122
  card,
3847
4123
  enableAnimations,
@@ -3850,12 +4126,9 @@ var PlaceOrder = ({
3850
4126
  onSelect: handleRouteCardSelect,
3851
4127
  tradingLabels
3852
4128
  }) }, card.id);
3853
- }) : smartRoute.isFetching ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
3854
- /* @__PURE__ */ jsx4(PlaceOrderRouteCardSkeleton, {}),
3855
- /* @__PURE__ */ jsx4(PlaceOrderRouteCardSkeleton, {})
3856
- ] }) : null })
4129
+ }) : null })
3857
4130
  ] }) : null,
3858
- hasEnteredAmount && selectedRouteCard && orderEligibility.canPlaceOrder ? /* @__PURE__ */ jsxs3("div", { className: "agg-order-summary flex items-start justify-between gap-4", children: [
4131
+ hasEnteredAmount && selectedRouteCard && !isQuoteLoading && orderEligibility.canPlaceOrder ? /* @__PURE__ */ jsxs3("div", { className: "agg-order-summary flex items-start justify-between gap-4", children: [
3859
4132
  /* @__PURE__ */ jsxs3("div", { className: "agg-order-summary-meta flex flex-col", children: [
3860
4133
  /* @__PURE__ */ jsx4("p", { className: "agg-order-summary-label text-agg-base font-agg-bold leading-agg-6 text-agg-foreground", children: tradingLabels.toWin(internalTab) }),
3861
4134
  /* @__PURE__ */ jsx4("p", { className: "agg-order-summary-hint text-agg-sm leading-agg-5 text-agg-muted-foreground", children: displayedToWinHint })