@agg-build/ui 1.2.6 → 1.2.8

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 (32) hide show
  1. package/dist/{chunk-2HI6K7JF.mjs → chunk-2YVW6J5N.mjs} +12 -6
  2. package/dist/{chunk-5FXMHTVR.mjs → chunk-BW4DQYWM.mjs} +1 -1
  3. package/dist/{chunk-34L7ZKJW.mjs → chunk-HQRT3B3L.mjs} +3 -2
  4. package/dist/{chunk-WPF47BQQ.mjs → chunk-IIEE4FVO.mjs} +9 -2
  5. package/dist/{chunk-TBKDLNOE.mjs → chunk-RPIYL7EA.mjs} +29 -8
  6. package/dist/{chunk-E45WOOMN.mjs → chunk-SMGKYWEP.mjs} +22 -8
  7. package/dist/{chunk-FS3FGVAG.mjs → chunk-U6YU5OE7.mjs} +671 -152
  8. package/dist/events.js +51 -15
  9. package/dist/events.mjs +3 -3
  10. package/dist/index.js +771 -196
  11. package/dist/index.mjs +27 -20
  12. package/dist/modals.js +8 -1
  13. package/dist/modals.mjs +3 -3
  14. package/dist/pages.js +735 -174
  15. package/dist/pages.mjs +6 -6
  16. package/dist/primitives.js +3 -2
  17. package/dist/primitives.mjs +1 -1
  18. package/dist/styles.css +1 -1
  19. package/dist/tailwind.css +1 -1
  20. package/dist/trading.js +670 -150
  21. package/dist/trading.mjs +4 -4
  22. package/dist/types/primitives/switch-button/switch-button.constants.d.mts +1 -1
  23. package/dist/types/primitives/switch-button/switch-button.constants.d.ts +1 -1
  24. package/dist/types/primitives/tooltip/index.d.mts +1 -1
  25. package/dist/types/primitives/tooltip/index.d.ts +1 -1
  26. package/dist/types/primitives/tooltip/tooltip.types.d.mts +2 -0
  27. package/dist/types/primitives/tooltip/tooltip.types.d.ts +2 -0
  28. package/dist/types/trading/place-order/index.place-order.execution-debug.d.mts +183 -0
  29. package/dist/types/trading/place-order/index.place-order.execution-debug.d.ts +183 -0
  30. package/dist/types/trading/place-order/index.place-order.execution-steps.d.mts +72 -0
  31. package/dist/types/trading/place-order/index.place-order.execution-steps.d.ts +72 -0
  32. package/package.json +1 -1
package/dist/trading.js CHANGED
@@ -5623,6 +5623,7 @@ var Tooltip = ({
5623
5623
  side = "top",
5624
5624
  delayDuration = 150,
5625
5625
  collisionPadding = 12,
5626
+ sideOffset = 0,
5626
5627
  classNames,
5627
5628
  "aria-label": ariaLabel
5628
5629
  }) => {
@@ -5650,7 +5651,7 @@ var Tooltip = ({
5650
5651
  TooltipPrimitive.Content,
5651
5652
  {
5652
5653
  side,
5653
- sideOffset: 0,
5654
+ sideOffset,
5654
5655
  collisionPadding,
5655
5656
  className: cn(
5656
5657
  "group/agg-tooltip",
@@ -5832,6 +5833,447 @@ var PLACE_ORDER_OUTCOME_BUTTON_CLASS_NAMES = {
5832
5833
  inactive: "border-transparent bg-agg-secondary-hover font-agg-normal text-agg-foreground hover:bg-agg-tertiary"
5833
5834
  };
5834
5835
 
5836
+ // src/trading/place-order/index.place-order.execution-steps.ts
5837
+ var import_sdk14 = require("@agg-build/sdk");
5838
+ var WAIT_STEP_TYPES = /* @__PURE__ */ new Set(["_wait", "wait"]);
5839
+ var CHECKING_BALANCE_STEP_TYPES = /* @__PURE__ */ new Set([
5840
+ "check-balance",
5841
+ "check-position",
5842
+ "position-reserve",
5843
+ "position-release"
5844
+ ]);
5845
+ var VENUE_BUY_SELL_REGEX = /^(?:buy|sell)-([a-z]+)$/;
5846
+ var VENUE_FINALIZE_REGEX = /^([a-z]+)-finalize$/;
5847
+ var VENUE_NAME_MAP = {
5848
+ kalshi: import_sdk14.Venue.kalshi,
5849
+ polymarket: import_sdk14.Venue.polymarket,
5850
+ limitless: import_sdk14.Venue.limitless,
5851
+ opinion: import_sdk14.Venue.opinion,
5852
+ predict: import_sdk14.Venue.predict,
5853
+ probable: import_sdk14.Venue.probable,
5854
+ myriad: import_sdk14.Venue.myriad,
5855
+ hyperliquid: import_sdk14.Venue.hyperliquid
5856
+ };
5857
+ var parseVenueName = (raw) => VENUE_NAME_MAP[raw];
5858
+ var NON_VENUE_FINALIZE_PREFIXES = /* @__PURE__ */ new Set(["bridge"]);
5859
+ var classifyExecutionStepType = (stepType) => {
5860
+ if (!stepType) return null;
5861
+ if (WAIT_STEP_TYPES.has(stepType)) return null;
5862
+ if (CHECKING_BALANCE_STEP_TYPES.has(stepType)) {
5863
+ return { kind: "checking-balance" };
5864
+ }
5865
+ const buySellMatch = stepType.match(VENUE_BUY_SELL_REGEX);
5866
+ if (buySellMatch) {
5867
+ const venue = parseVenueName(buySellMatch[1]);
5868
+ if (venue) return { kind: "executing-venue", venue };
5869
+ }
5870
+ const finalizeMatch = stepType.match(VENUE_FINALIZE_REGEX);
5871
+ if (finalizeMatch && !NON_VENUE_FINALIZE_PREFIXES.has(finalizeMatch[1])) {
5872
+ const venue = parseVenueName(finalizeMatch[1]);
5873
+ if (venue) return { kind: "executing-venue", venue };
5874
+ }
5875
+ if (stepType === "submit-verify-order-status") {
5876
+ return null;
5877
+ }
5878
+ return { kind: "submitting" };
5879
+ };
5880
+ var buildPhaseTimeline = (dag) => {
5881
+ const timeline = [];
5882
+ const completed = new Set(dag.completedSequences);
5883
+ for (let seq = 1; seq <= dag.totalSteps; seq++) {
5884
+ const stepType = dag.stepTypes[seq];
5885
+ if (!stepType) continue;
5886
+ const classified = classifyExecutionStepType(stepType);
5887
+ if (!classified) continue;
5888
+ const isCompleted = completed.has(seq);
5889
+ const last = timeline[timeline.length - 1];
5890
+ if (last && last.kind === classified.kind && last.venue === classified.venue) {
5891
+ last.lastSeq = seq;
5892
+ last.allCompleted = last.allCompleted && isCompleted;
5893
+ continue;
5894
+ }
5895
+ timeline.push({
5896
+ kind: classified.kind,
5897
+ venue: classified.venue,
5898
+ firstSeq: seq,
5899
+ lastSeq: seq,
5900
+ allCompleted: isCompleted
5901
+ });
5902
+ }
5903
+ return timeline;
5904
+ };
5905
+ var phaseRowId = (phase) => phase.venue ? `${phase.kind}:${phase.venue}` : phase.kind;
5906
+ var phaseRowLabel = (phase, labels) => {
5907
+ switch (phase.kind) {
5908
+ case "finding-route":
5909
+ return labels.findingBestRoute;
5910
+ case "checking-balance":
5911
+ return labels.checkingBalance;
5912
+ case "submitting":
5913
+ return labels.submittingOrderProgress;
5914
+ case "wallet-confirm":
5915
+ return labels.confirmTransactionInWallet;
5916
+ case "executing-venue":
5917
+ return labels.executingOnVenue(getTradingVenueLabel(phase.venue));
5918
+ case "filled":
5919
+ return labels.executionConfirmed;
5920
+ case "failed":
5921
+ return labels.orderFailureTitle;
5922
+ }
5923
+ };
5924
+ var buildSubmissionDisplayRows = ({
5925
+ phase,
5926
+ dagProgress,
5927
+ executionVenue,
5928
+ isAwaitingWalletConfirmation,
5929
+ labels
5930
+ }) => {
5931
+ if (phase === "finding-route") {
5932
+ return [
5933
+ {
5934
+ id: "finding-route",
5935
+ label: labels.findingBestRoute,
5936
+ status: "pending"
5937
+ }
5938
+ ];
5939
+ }
5940
+ const rows = [
5941
+ {
5942
+ id: "finding-route",
5943
+ label: labels.findingBestRoute,
5944
+ status: "complete"
5945
+ }
5946
+ ];
5947
+ const pushPhase = (phaseEntry, status) => {
5948
+ const id = phaseRowId(phaseEntry);
5949
+ if (rows.some((row) => row.id === id)) return;
5950
+ rows.push({
5951
+ id,
5952
+ label: phaseRowLabel(phaseEntry, labels),
5953
+ status,
5954
+ venue: phaseEntry.venue
5955
+ });
5956
+ };
5957
+ if (dagProgress && dagProgress.totalSteps > 0) {
5958
+ const timeline = buildPhaseTimeline(dagProgress);
5959
+ let activeEmitted = false;
5960
+ for (const entry of timeline) {
5961
+ const id = phaseRowId(entry);
5962
+ const alreadyShown = rows.some((row) => row.id === id);
5963
+ if (entry.allCompleted) {
5964
+ if (alreadyShown) continue;
5965
+ pushPhase(entry, "complete");
5966
+ continue;
5967
+ }
5968
+ if (activeEmitted) break;
5969
+ if (alreadyShown) continue;
5970
+ if (isAwaitingWalletConfirmation && entry.kind === "submitting") {
5971
+ pushPhase({ kind: "wallet-confirm" }, "pending");
5972
+ } else {
5973
+ pushPhase(entry, "pending");
5974
+ }
5975
+ activeEmitted = true;
5976
+ }
5977
+ if (!activeEmitted) {
5978
+ const last = rows[rows.length - 1];
5979
+ if (last && last.id.startsWith("executing-venue")) {
5980
+ last.status = "pending";
5981
+ } else {
5982
+ const fallbackVenue = executionVenue;
5983
+ rows.push({
5984
+ id: fallbackVenue ? `executing-venue:${fallbackVenue}` : "executing-venue",
5985
+ label: phaseRowLabel({ kind: "executing-venue", venue: fallbackVenue }, labels),
5986
+ status: "pending",
5987
+ venue: fallbackVenue
5988
+ });
5989
+ }
5990
+ }
5991
+ return rows;
5992
+ }
5993
+ if (isAwaitingWalletConfirmation) {
5994
+ pushPhase({ kind: "wallet-confirm" }, "pending");
5995
+ return rows;
5996
+ }
5997
+ if (phase === "submitting") {
5998
+ pushPhase({ kind: "submitting" }, "pending");
5999
+ return rows;
6000
+ }
6001
+ pushPhase({ kind: "submitting" }, "complete");
6002
+ pushPhase({ kind: "executing-venue", venue: executionVenue }, "pending");
6003
+ return rows;
6004
+ };
6005
+
6006
+ // src/trading/place-order/index.place-order.execution-debug.ts
6007
+ var REDACTED = "[redacted]";
6008
+ var SENSITIVE_FIELD_PATTERNS = [
6009
+ "token",
6010
+ "authorization",
6011
+ "cookie",
6012
+ "secret",
6013
+ "signature",
6014
+ "privatekey",
6015
+ "private_key",
6016
+ "accesstoken",
6017
+ "access_token",
6018
+ "refreshtoken",
6019
+ "refresh_token",
6020
+ "jwt",
6021
+ "password",
6022
+ "apikey",
6023
+ "api_key",
6024
+ "email",
6025
+ "headers"
6026
+ ];
6027
+ var isSensitiveFieldName = (name) => {
6028
+ const normalized = name.toLowerCase();
6029
+ return SENSITIVE_FIELD_PATTERNS.some((pattern) => normalized.includes(pattern));
6030
+ };
6031
+ var sanitizeExecutionDebugValue = (input) => {
6032
+ const ancestors = /* @__PURE__ */ new Set();
6033
+ const walk = (value) => {
6034
+ if (value === null || value === void 0) return value;
6035
+ if (typeof value !== "object") return value;
6036
+ if (ancestors.has(value)) return "[circular]";
6037
+ ancestors.add(value);
6038
+ try {
6039
+ if (Array.isArray(value)) {
6040
+ return value.map((entry) => walk(entry));
6041
+ }
6042
+ if (value instanceof Error) {
6043
+ return {
6044
+ name: value.name,
6045
+ message: value.message,
6046
+ stack: value.stack
6047
+ };
6048
+ }
6049
+ const out = {};
6050
+ for (const [key, raw] of Object.entries(value)) {
6051
+ if (isSensitiveFieldName(key)) {
6052
+ out[key] = REDACTED;
6053
+ continue;
6054
+ }
6055
+ out[key] = walk(raw);
6056
+ }
6057
+ return out;
6058
+ } finally {
6059
+ ancestors.delete(value);
6060
+ }
6061
+ };
6062
+ return walk(input);
6063
+ };
6064
+ var cloneEnvironment = (env) => __spreadProps(__spreadValues({}, env), {
6065
+ packageVersions: env.packageVersions ? __spreadValues({}, env.packageVersions) : void 0
6066
+ });
6067
+ var buildEnvironment = (overrides) => {
6068
+ var _a;
6069
+ const url = typeof window !== "undefined" ? (_a = window.location) == null ? void 0 : _a.href : void 0;
6070
+ const userAgent = typeof navigator !== "undefined" && typeof navigator.userAgent === "string" ? navigator.userAgent : void 0;
6071
+ return __spreadValues({
6072
+ url,
6073
+ userAgent,
6074
+ capturedAt: Date.now()
6075
+ }, overrides);
6076
+ };
6077
+ var generateAttemptId = () => {
6078
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
6079
+ return crypto.randomUUID();
6080
+ }
6081
+ return `attempt-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
6082
+ };
6083
+ var createExecutionDebugStore = (initial) => {
6084
+ let attempts = [];
6085
+ let environment = buildEnvironment(initial);
6086
+ const findAttempt = (attemptId) => attempts.find((attempt) => attempt.attemptId === attemptId);
6087
+ const touch = (attempt) => {
6088
+ attempt.updatedAt = Date.now();
6089
+ };
6090
+ return {
6091
+ appendAttempt(input = {}) {
6092
+ var _a, _b;
6093
+ const now = Date.now();
6094
+ const attempt = {
6095
+ attemptId: (_a = input.attemptId) != null ? _a : generateAttemptId(),
6096
+ startedAt: now,
6097
+ updatedAt: now,
6098
+ status: (_b = input.status) != null ? _b : "quoting",
6099
+ quoteId: input.quoteId,
6100
+ orderId: input.orderId,
6101
+ orderIds: input.orderIds,
6102
+ quote: input.quote,
6103
+ selectedRoute: input.selectedRoute,
6104
+ bridge: input.bridge,
6105
+ venueExecution: input.venueExecution,
6106
+ rawEvents: [],
6107
+ normalizedSteps: [],
6108
+ errors: []
6109
+ };
6110
+ attempts = [...attempts, attempt];
6111
+ return attempt;
6112
+ },
6113
+ updateAttempt(attemptId, patch) {
6114
+ const attempt = findAttempt(attemptId);
6115
+ if (!attempt) return;
6116
+ if (patch.status !== void 0) attempt.status = patch.status;
6117
+ if (patch.quoteId !== void 0) attempt.quoteId = patch.quoteId;
6118
+ if (patch.orderId !== void 0) attempt.orderId = patch.orderId;
6119
+ if (patch.orderIds !== void 0) attempt.orderIds = patch.orderIds;
6120
+ if (patch.quote !== void 0) attempt.quote = patch.quote;
6121
+ if (patch.selectedRoute !== void 0) attempt.selectedRoute = patch.selectedRoute;
6122
+ if (patch.bridge !== void 0) attempt.bridge = patch.bridge;
6123
+ if (patch.venueExecution !== void 0) attempt.venueExecution = patch.venueExecution;
6124
+ if (patch.finalStatus !== void 0) attempt.finalStatus = patch.finalStatus;
6125
+ touch(attempt);
6126
+ },
6127
+ appendEvent(attemptId, event) {
6128
+ var _a;
6129
+ const attempt = findAttempt(attemptId);
6130
+ if (!attempt) return;
6131
+ attempt.rawEvents.push({
6132
+ kind: event.kind,
6133
+ label: event.label,
6134
+ data: event.data,
6135
+ timestamp: (_a = event.timestamp) != null ? _a : Date.now()
6136
+ });
6137
+ touch(attempt);
6138
+ },
6139
+ appendError(attemptId, error) {
6140
+ var _a;
6141
+ const attempt = findAttempt(attemptId);
6142
+ if (!attempt) return;
6143
+ attempt.errors.push({
6144
+ message: error.message,
6145
+ name: error.name,
6146
+ code: error.code,
6147
+ stack: error.stack,
6148
+ failedStep: error.failedStep,
6149
+ data: error.data,
6150
+ timestamp: (_a = error.timestamp) != null ? _a : Date.now()
6151
+ });
6152
+ touch(attempt);
6153
+ },
6154
+ setNormalizedSteps(attemptId, steps) {
6155
+ const attempt = findAttempt(attemptId);
6156
+ if (!attempt) return;
6157
+ attempt.normalizedSteps = steps;
6158
+ touch(attempt);
6159
+ },
6160
+ getSnapshot() {
6161
+ return {
6162
+ attempts: attempts.map((attempt) => __spreadProps(__spreadValues({}, attempt), {
6163
+ rawEvents: [...attempt.rawEvents],
6164
+ normalizedSteps: [...attempt.normalizedSteps],
6165
+ errors: [...attempt.errors]
6166
+ })),
6167
+ environment: cloneEnvironment(environment)
6168
+ };
6169
+ },
6170
+ getFailedAttempts() {
6171
+ return attempts.filter(
6172
+ (attempt) => attempt.status === "failed" || attempt.finalStatus === "failed" || attempt.errors.length > 0
6173
+ ).map((attempt) => __spreadProps(__spreadValues({}, attempt), {
6174
+ rawEvents: [...attempt.rawEvents],
6175
+ normalizedSteps: [...attempt.normalizedSteps],
6176
+ errors: [...attempt.errors]
6177
+ }));
6178
+ },
6179
+ clear() {
6180
+ attempts = [];
6181
+ environment = buildEnvironment(initial);
6182
+ }
6183
+ };
6184
+ };
6185
+ var writeClipboardLegacy = (text) => {
6186
+ if (typeof document === "undefined") return false;
6187
+ const textarea = document.createElement("textarea");
6188
+ textarea.value = text;
6189
+ textarea.setAttribute("readonly", "");
6190
+ textarea.style.position = "fixed";
6191
+ textarea.style.top = "-1000px";
6192
+ textarea.style.opacity = "0";
6193
+ document.body.appendChild(textarea);
6194
+ try {
6195
+ textarea.select();
6196
+ return document.execCommand("copy");
6197
+ } catch (e) {
6198
+ return false;
6199
+ } finally {
6200
+ document.body.removeChild(textarea);
6201
+ }
6202
+ };
6203
+ var tryWriteClipboard = (text, consoleImpl) => __async(null, null, function* () {
6204
+ var _a;
6205
+ if (typeof navigator !== "undefined" && ((_a = navigator.clipboard) == null ? void 0 : _a.writeText)) {
6206
+ try {
6207
+ yield navigator.clipboard.writeText(text);
6208
+ consoleImpl.info("[agg-execution-debug] Copied execution data to clipboard.");
6209
+ return;
6210
+ } catch (e) {
6211
+ }
6212
+ }
6213
+ if (writeClipboardLegacy(text)) {
6214
+ consoleImpl.info("[agg-execution-debug] Copied execution data to clipboard.");
6215
+ return;
6216
+ }
6217
+ consoleImpl.warn(
6218
+ "[agg-execution-debug] Clipboard copy was blocked by the browser. The JSON is logged below \u2014 right-click the entry and copy."
6219
+ );
6220
+ consoleImpl.log(text);
6221
+ });
6222
+ var installExecutionDebugWindow = ({
6223
+ store,
6224
+ consoleImpl
6225
+ }) => {
6226
+ if (typeof window === "undefined") return () => {
6227
+ };
6228
+ const targetConsole = consoleImpl != null ? consoleImpl : console;
6229
+ const previous = {
6230
+ executionData: window.executionData,
6231
+ getExecutionData: window.getExecutionData,
6232
+ getFailedExecutionData: window.getFailedExecutionData,
6233
+ clearExecutionData: window.clearExecutionData,
6234
+ storeRef: window.__aggExecutionDebugStore
6235
+ };
6236
+ const refresh = () => {
6237
+ window.executionData = sanitizeExecutionDebugValue(store.getSnapshot());
6238
+ };
6239
+ refresh();
6240
+ window.__aggExecutionDebugStore = store;
6241
+ window.getExecutionData = () => {
6242
+ const data = sanitizeExecutionDebugValue(store.getSnapshot());
6243
+ window.executionData = data;
6244
+ void tryWriteClipboard(JSON.stringify(data, null, 2), targetConsole);
6245
+ return data;
6246
+ };
6247
+ window.getFailedExecutionData = () => {
6248
+ const failed = sanitizeExecutionDebugValue({ attempts: store.getFailedAttempts() });
6249
+ void tryWriteClipboard(JSON.stringify(failed, null, 2), targetConsole);
6250
+ return failed;
6251
+ };
6252
+ window.clearExecutionData = () => {
6253
+ store.clear();
6254
+ refresh();
6255
+ };
6256
+ targetConsole.info(
6257
+ "AGG execution debug enabled. Run window.getFailedExecutionData() after a failed order to copy logs."
6258
+ );
6259
+ return () => {
6260
+ if (typeof window === "undefined") return;
6261
+ window.executionData = previous.executionData;
6262
+ window.getExecutionData = previous.getExecutionData;
6263
+ window.getFailedExecutionData = previous.getFailedExecutionData;
6264
+ window.clearExecutionData = previous.clearExecutionData;
6265
+ window.__aggExecutionDebugStore = previous.storeRef;
6266
+ };
6267
+ };
6268
+ var enableExecutionDebugInBrowser = (initial) => {
6269
+ if (typeof window === "undefined") return null;
6270
+ const existing = window.__aggExecutionDebugStore;
6271
+ if (existing) return existing;
6272
+ const store = createExecutionDebugStore(initial);
6273
+ installExecutionDebugWindow({ store });
6274
+ return store;
6275
+ };
6276
+
5835
6277
  // src/trading/place-order/index.place-order.utils.ts
5836
6278
  var routePriceLabelFormatter = new Intl.NumberFormat("en-US", {
5837
6279
  minimumFractionDigits: 0,
@@ -6042,18 +6484,19 @@ var buildLiveRouteCards = ({
6042
6484
  const parsedPrimaryVenue = parseVenue(primaryVenue);
6043
6485
  const isSplit = quoteData.fills.length > 1;
6044
6486
  const primaryWinnerVenue = quoteData.fills.length === 1 ? primaryVenue : void 0;
6045
- const isPrimaryRouteGeoBlocked = quoteData.fills.length > 0 && quoteData.fills.every((f) => geoBlockedVenues.has(f.venue));
6487
+ const isPrimaryRouteGeoBlocked = quoteData.fills.length > 0 && quoteData.fills.some((f) => geoBlockedVenues.has(f.venue));
6046
6488
  const primaryCard = primaryResult ? isPrimaryRouteGeoBlocked ? {
6047
6489
  id: "live-route",
6048
6490
  hint: labels.venueUnavailableInRegion,
6049
- kind: "venue",
6050
- label: getTradingVenueLabel(
6491
+ kind: isSplit ? "split" : "venue",
6492
+ label: isSplit ? labels.orderSplitting : getTradingVenueLabel(
6051
6493
  parsedPrimaryVenue.success ? parsedPrimaryVenue.data : void 0
6052
6494
  ),
6053
6495
  numericValue: tradeSide === "sell" ? quoteData.rawExecCost : quoteData.totalFilled,
6054
6496
  quoteData,
6497
+ rows: isSplit ? mapQuoteDataToRoutingRows(quoteData) : void 0,
6055
6498
  value: primaryResult.value,
6056
- venue: parsedPrimaryVenue.success ? parsedPrimaryVenue.data : void 0,
6499
+ venue: isSplit ? void 0 : parsedPrimaryVenue.success ? parsedPrimaryVenue.data : void 0,
6057
6500
  isUnavailable: true
6058
6501
  } : {
6059
6502
  id: "live-route",
@@ -7018,21 +7461,6 @@ PlaceOrderSuccessView.displayName = "PlaceOrderSuccessView";
7018
7461
 
7019
7462
  // src/trading/place-order/index.tsx
7020
7463
  var import_jsx_runtime113 = require("react/jsx-runtime");
7021
- var DEFAULT_STEP_LABELS = {
7022
- "check-balance": "Checking balance",
7023
- "check-position": "Checking position",
7024
- "lane-bridge": "Bridging funds",
7025
- bridge: "Bridging funds",
7026
- "bridge-to-user": "Transferring to wallet",
7027
- "sweep-bridge": "Completing bridge",
7028
- "submit-order": "Submitting order",
7029
- "order-bridge-execute": "Executing order",
7030
- "transfer-to-user": "Transferring to wallet"
7031
- };
7032
- var getDefaultStepLabel = (stepType) => {
7033
- var _a;
7034
- return (_a = DEFAULT_STEP_LABELS[stepType]) != null ? _a : stepType.replace(/-/g, " ").replace(/^\w/, (c) => c.toUpperCase());
7035
- };
7036
7464
  var resolveRefetchedQuoteData = (result) => {
7037
7465
  if (!result || typeof result !== "object" || !("data" in result)) return null;
7038
7466
  const data = result.data;
@@ -7532,7 +7960,6 @@ var renderRouteCard = ({
7532
7960
  }
7533
7961
  );
7534
7962
  };
7535
- var normalizeOrderIdLabelInput2 = (orderId) => orderId.replace(/^#+/, "");
7536
7963
  var renderSubmissionSurface = ({
7537
7964
  actionLabel,
7538
7965
  className,
@@ -7544,81 +7971,12 @@ var renderSubmissionSurface = ({
7544
7971
  progressState,
7545
7972
  tradingLabels
7546
7973
  }) => {
7547
- const resolveStepGroups = () => {
7548
- var _a, _b, _c;
7549
- if (progressState.phase === "finding-route") {
7550
- return [
7551
- [
7552
- {
7553
- id: "finding-route",
7554
- label: tradingLabels.findingBestRoute,
7555
- status: "pending"
7556
- }
7557
- ]
7558
- ];
7559
- }
7560
- const dag = progressState.dagProgress;
7561
- if (dag && dag.totalSteps > 0) {
7562
- const steps = [
7563
- {
7564
- id: "finding-route",
7565
- label: tradingLabels.findingBestRoute,
7566
- status: "complete"
7567
- }
7568
- ];
7569
- for (let i = 1; i <= dag.totalSteps; i++) {
7570
- const isCompleted = dag.completedSequences.includes(i);
7571
- const isCurrent = i === dag.currentSequence && !isCompleted;
7572
- const stepType = (_a = dag.stepTypes[i]) != null ? _a : null;
7573
- const stepLabel = stepType ? getDefaultStepLabel(stepType) : `Step ${i} of ${dag.totalSteps}`;
7574
- const prev = steps[steps.length - 1];
7575
- if (prev && prev.label === stepLabel) {
7576
- if (prev.status === "complete" && !isCompleted) {
7577
- prev.status = "pending";
7578
- }
7579
- continue;
7580
- }
7581
- steps.push({
7582
- id: `dag-step-${i}`,
7583
- label: stepLabel,
7584
- status: isCompleted ? "complete" : isCurrent ? "pending" : "pending"
7585
- });
7586
- }
7587
- return [steps];
7588
- }
7589
- const baseSteps = [
7590
- {
7591
- id: "finding-route",
7592
- label: tradingLabels.findingBestRoute,
7593
- status: "complete"
7594
- },
7595
- {
7596
- id: "submitting-order",
7597
- label: tradingLabels.submittingOrderProgress,
7598
- status: "complete"
7599
- }
7600
- ];
7601
- const submittedOrderId = (_c = progressState.orderId) != null ? _c : (_b = progressState.orderIds) == null ? void 0 : _b[0];
7602
- if (submittedOrderId) {
7603
- baseSteps.push({
7604
- id: "order-submitted",
7605
- label: tradingLabels.orderSubmittedProgress(normalizeOrderIdLabelInput2(submittedOrderId)),
7606
- status: "complete"
7607
- });
7608
- }
7609
- return [
7610
- baseSteps,
7611
- [
7612
- {
7613
- id: "executing-order",
7614
- label: tradingLabels.executingOnVenue(getTradingVenueLabel(progressState.executionVenue)),
7615
- status: "pending",
7616
- venue: progressState.executionVenue
7617
- }
7618
- ]
7619
- ];
7620
- };
7621
- const stepGroups = resolveStepGroups();
7974
+ const displayRows = buildSubmissionDisplayRows({
7975
+ phase: progressState.phase,
7976
+ dagProgress: progressState.dagProgress,
7977
+ executionVenue: progressState.executionVenue,
7978
+ labels: tradingLabels
7979
+ });
7622
7980
  return /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
7623
7981
  Card,
7624
7982
  {
@@ -7640,51 +7998,50 @@ var renderSubmissionSurface = ({
7640
7998
  /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(LoadingGlyph, { enableAnimations, className: "h-4 w-4 text-current" }),
7641
7999
  /* @__PURE__ */ (0, import_jsx_runtime113.jsx)("span", { children: actionLabel })
7642
8000
  ] }),
7643
- /* @__PURE__ */ (0, import_jsx_runtime113.jsx)("div", { className: "agg-order-submission-steps flex flex-col gap-4", children: stepGroups.map((steps, groupIndex) => {
7644
- return /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
7645
- "div",
7646
- {
7647
- className: "agg-order-submission-group flex flex-col gap-2",
7648
- children: steps.map((step) => {
7649
- return /* @__PURE__ */ (0, import_jsx_runtime113.jsxs)(
7650
- "div",
7651
- {
7652
- className: "agg-order-submission-step flex items-center gap-2 text-agg-sm leading-agg-5 text-agg-foreground",
7653
- children: [
7654
- step.status === "complete" ? /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
7655
- Icon,
7656
- {
7657
- name: "check-circle",
7658
- size: "small",
7659
- className: "h-3 w-3 shrink-0 text-agg-primary",
7660
- "aria-hidden": "true"
7661
- }
7662
- ) : /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
7663
- LoadingGlyph,
7664
- {
7665
- enableAnimations,
7666
- className: "h-3 w-3 shrink-0 text-agg-primary"
7667
- }
7668
- ),
7669
- /* @__PURE__ */ (0, import_jsx_runtime113.jsx)("p", { className: "min-w-0 flex-1", children: step.label }),
7670
- step.venue ? /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
7671
- VenueLogo,
7672
- {
7673
- venue: step.venue,
7674
- size: "small",
7675
- ariaLabel: getTradingVenueLabel(step.venue),
7676
- className: "h-4 w-4"
7677
- }
7678
- ) : null
7679
- ]
7680
- },
7681
- step.id
7682
- );
7683
- })
7684
- },
7685
- `step-group-${groupIndex}`
7686
- );
7687
- }) })
8001
+ /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
8002
+ "div",
8003
+ {
8004
+ className: "agg-order-submission-steps agg-order-submission-group flex flex-col gap-2",
8005
+ "data-testid": "agg-order-submission-steps",
8006
+ children: displayRows.map((step) => {
8007
+ return /* @__PURE__ */ (0, import_jsx_runtime113.jsxs)(
8008
+ "div",
8009
+ {
8010
+ className: "agg-order-submission-step flex items-center gap-2 text-agg-sm leading-agg-5 text-agg-foreground",
8011
+ "data-status": step.status,
8012
+ children: [
8013
+ step.status === "complete" ? /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
8014
+ Icon,
8015
+ {
8016
+ name: "check-circle",
8017
+ size: "small",
8018
+ className: "h-3 w-3 shrink-0 text-agg-primary",
8019
+ "aria-hidden": "true"
8020
+ }
8021
+ ) : /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
8022
+ LoadingGlyph,
8023
+ {
8024
+ enableAnimations,
8025
+ className: "h-3 w-3 shrink-0 text-agg-primary"
8026
+ }
8027
+ ),
8028
+ /* @__PURE__ */ (0, import_jsx_runtime113.jsx)("p", { className: "min-w-0 flex-1", children: step.label }),
8029
+ step.venue ? /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
8030
+ VenueLogo,
8031
+ {
8032
+ venue: step.venue,
8033
+ size: "small",
8034
+ ariaLabel: getTradingVenueLabel(step.venue),
8035
+ className: "h-4 w-4"
8036
+ }
8037
+ ) : null
8038
+ ]
8039
+ },
8040
+ step.id
8041
+ );
8042
+ })
8043
+ }
8044
+ )
7688
8045
  ] })
7689
8046
  ] })
7690
8047
  }
@@ -7820,6 +8177,7 @@ var PlaceOrder = ({
7820
8177
  }) => {
7821
8178
  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;
7822
8179
  const {
8180
+ enableDebug: isExecutionDebugEnabled,
7823
8181
  features: { enableAnimations, showFeesBreakdown },
7824
8182
  general: { locale }
7825
8183
  } = (0, import_hooks29.useSdkUiConfig)();
@@ -7916,6 +8274,27 @@ var PlaceOrder = ({
7916
8274
  const [isSplitDetailOpen, setIsSplitDetailOpen] = (0, import_react9.useState)(false);
7917
8275
  const [submissionFeedback, setSubmissionFeedback] = (0, import_react9.useState)(null);
7918
8276
  const [submissionProgressState, setSubmissionProgressState] = (0, import_react9.useState)(null);
8277
+ const executionDebugStoreRef = (0, import_react9.useRef)(null);
8278
+ const executionDebugAttemptIdRef = (0, import_react9.useRef)(null);
8279
+ (0, import_react9.useEffect)(() => {
8280
+ if (!isExecutionDebugEnabled) {
8281
+ executionDebugStoreRef.current = null;
8282
+ return;
8283
+ }
8284
+ executionDebugStoreRef.current = enableExecutionDebugInBrowser();
8285
+ }, [isExecutionDebugEnabled]);
8286
+ (0, import_react9.useEffect)(() => {
8287
+ if (!isExecutionDebugEnabled) return;
8288
+ const store = executionDebugStoreRef.current;
8289
+ if (!store) return;
8290
+ store.clear();
8291
+ executionDebugAttemptIdRef.current = null;
8292
+ }, [
8293
+ isExecutionDebugEnabled,
8294
+ scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.id,
8295
+ scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.id,
8296
+ scopedSelectedOutcomeId
8297
+ ]);
7919
8298
  const debouncedAmount = (0, import_hooks29.useDebouncedValue)(internalAmount, 300);
7920
8299
  const isSell = (0, import_react9.useMemo)(() => internalTab === "sell", [internalTab]);
7921
8300
  const {
@@ -8175,8 +8554,39 @@ var PlaceOrder = ({
8175
8554
  selectedRouteCard == null ? void 0 : selectedRouteCard.quoteData
8176
8555
  ]);
8177
8556
  (0, import_react9.useEffect)(() => {
8557
+ var _a2, _b2;
8178
8558
  const dp = executionProgress.dagProgress;
8179
8559
  if (!dp) return;
8560
+ const debugStore = executionDebugStoreRef.current;
8561
+ const debugAttemptId = executionDebugAttemptIdRef.current;
8562
+ if (debugStore && debugAttemptId) {
8563
+ debugStore.appendEvent(debugAttemptId, {
8564
+ kind: "ws_update",
8565
+ label: "dag_progress",
8566
+ data: dp
8567
+ });
8568
+ const normalizedRows = buildSubmissionDisplayRows({
8569
+ phase: "executing",
8570
+ dagProgress: dp,
8571
+ labels: tradingLabels
8572
+ });
8573
+ debugStore.setNormalizedSteps(debugAttemptId, normalizedRows);
8574
+ debugStore.appendEvent(debugAttemptId, {
8575
+ kind: "normalized_steps",
8576
+ data: normalizedRows
8577
+ });
8578
+ if (dp.status === "failed") {
8579
+ debugStore.appendError(debugAttemptId, {
8580
+ message: (_a2 = dp.errorReason) != null ? _a2 : "DAG execution failed",
8581
+ failedStep: (_b2 = dp.currentStepType) != null ? _b2 : void 0,
8582
+ data: { currentSequence: dp.currentSequence, totalSteps: dp.totalSteps }
8583
+ });
8584
+ debugStore.updateAttempt(debugAttemptId, {
8585
+ status: "failed",
8586
+ finalStatus: "failed"
8587
+ });
8588
+ }
8589
+ }
8180
8590
  setSubmissionProgressState((prev) => {
8181
8591
  if (!prev) return prev;
8182
8592
  if (dp.status === "failed") {
@@ -8192,7 +8602,7 @@ var PlaceOrder = ({
8192
8602
  }
8193
8603
  return __spreadProps(__spreadValues({}, prev), { dagProgress: dp });
8194
8604
  });
8195
- }, [executionProgress.dagProgress, tradingLabels.orderFailed]);
8605
+ }, [executionProgress.dagProgress, tradingLabels]);
8196
8606
  (0, import_react9.useEffect)(() => {
8197
8607
  const orderIds = submissionProgressState == null ? void 0 : submissionProgressState.orderIds;
8198
8608
  if (!(orderIds == null ? void 0 : orderIds.length)) return;
@@ -8200,6 +8610,17 @@ var PlaceOrder = ({
8200
8610
  orderIds,
8201
8611
  executionProgress.terminalOrderEvents
8202
8612
  );
8613
+ const debugStore = executionDebugStoreRef.current;
8614
+ const debugAttemptId = executionDebugAttemptIdRef.current;
8615
+ if (debugStore && debugAttemptId && executionProgress.terminalOrderEvents.length > 0) {
8616
+ debugStore.appendEvent(debugAttemptId, {
8617
+ kind: "terminal_event",
8618
+ data: {
8619
+ aggregateStatus,
8620
+ events: executionProgress.terminalOrderEvents
8621
+ }
8622
+ });
8623
+ }
8203
8624
  if (aggregateStatus === "pending") return;
8204
8625
  setSubmissionProgressState((prev) => {
8205
8626
  var _a2, _b2, _c2;
@@ -8242,14 +8663,45 @@ var PlaceOrder = ({
8242
8663
  tradingLabels.orderFailed
8243
8664
  ]);
8244
8665
  (0, import_react9.useEffect)(() => {
8666
+ var _a2, _b2;
8245
8667
  if (!submissionProgressState) return;
8246
8668
  onExecutionStateChange == null ? void 0 : onExecutionStateChange(submissionProgressState);
8669
+ const debugStore = executionDebugStoreRef.current;
8670
+ const debugAttemptId = executionDebugAttemptIdRef.current;
8671
+ if (debugStore && debugAttemptId) {
8672
+ debugStore.appendEvent(debugAttemptId, {
8673
+ kind: "state_change",
8674
+ label: submissionProgressState.phase,
8675
+ data: {
8676
+ phase: submissionProgressState.phase,
8677
+ executionVenue: submissionProgressState.executionVenue,
8678
+ orderIds: submissionProgressState.orderIds,
8679
+ errorMessage: submissionProgressState.errorMessage
8680
+ }
8681
+ });
8682
+ }
8247
8683
  if (submissionProgressState.phase === "success" && submissionProgressState.summary) {
8248
8684
  (0, import_hooks29.invalidateBalanceQueries)(queryClient);
8249
8685
  (0, import_hooks29.invalidatePositionQueries)(queryClient);
8686
+ if (debugStore && debugAttemptId) {
8687
+ debugStore.updateAttempt(debugAttemptId, {
8688
+ status: "succeeded",
8689
+ finalStatus: "succeeded"
8690
+ });
8691
+ }
8250
8692
  onSuccess == null ? void 0 : onSuccess(submissionProgressState.summary);
8251
8693
  }
8252
8694
  if (submissionProgressState.phase === "failed" && submissionProgressState.errorMessage) {
8695
+ if (debugStore && debugAttemptId) {
8696
+ debugStore.appendError(debugAttemptId, {
8697
+ message: submissionProgressState.errorMessage,
8698
+ failedStep: (_b2 = (_a2 = submissionProgressState.dagProgress) == null ? void 0 : _a2.currentStepType) != null ? _b2 : void 0
8699
+ });
8700
+ debugStore.updateAttempt(debugAttemptId, {
8701
+ status: "failed",
8702
+ finalStatus: "failed"
8703
+ });
8704
+ }
8253
8705
  onError == null ? void 0 : onError(new Error(submissionProgressState.errorMessage));
8254
8706
  }
8255
8707
  }, [submissionProgressState, onExecutionStateChange, onSuccess, onError, queryClient]);
@@ -8423,23 +8875,91 @@ var PlaceOrder = ({
8423
8875
  };
8424
8876
  const handleExecuteQuote = (0, import_react9.useCallback)(
8425
8877
  (quoteData) => __async(null, null, function* () {
8878
+ var _a2, _b2, _c2;
8426
8879
  const quoteId = quoteData == null ? void 0 : quoteData.quoteId;
8427
8880
  if (!quoteId) {
8428
8881
  throw new Error(tradingLabels.quoteUnavailable);
8429
8882
  }
8883
+ const debugStore = executionDebugStoreRef.current;
8884
+ const venues = (_b2 = (_a2 = quoteData == null ? void 0 : quoteData.fills) == null ? void 0 : _a2.map((fill) => fill.venue).filter(Boolean)) != null ? _b2 : [];
8885
+ const debugAttempt = debugStore == null ? void 0 : debugStore.appendAttempt({
8886
+ status: "executing",
8887
+ quoteId,
8888
+ quote: {
8889
+ request: {
8890
+ venueMarketOutcomeId: scopedSelectedOutcomeId,
8891
+ amount: internalAmount,
8892
+ slippage: internalSlippage,
8893
+ tradeSide: isSell ? "sell" : "buy"
8894
+ },
8895
+ response: smartRoute.data,
8896
+ selectedRoute: quoteData,
8897
+ side: isSell ? "sell" : "buy",
8898
+ marketId: scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.id,
8899
+ eventId: scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.id,
8900
+ outcomeId: scopedSelectedOutcomeId != null ? scopedSelectedOutcomeId : void 0,
8901
+ venues,
8902
+ capturedAt: Date.now()
8903
+ },
8904
+ selectedRoute: quoteData
8905
+ });
8906
+ executionDebugAttemptIdRef.current = (_c2 = debugAttempt == null ? void 0 : debugAttempt.attemptId) != null ? _c2 : null;
8430
8907
  if (onPrimaryAction) {
8908
+ debugStore == null ? void 0 : debugStore.appendEvent(debugAttempt.attemptId, {
8909
+ kind: "execute_request",
8910
+ label: "delegated_to_partner",
8911
+ data: { quoteId }
8912
+ });
8431
8913
  onPrimaryAction({ quoteId });
8432
8914
  return;
8433
8915
  }
8434
- const response = yield executeManaged.mutateAsync({ quoteId });
8435
- setSubmissionProgressState({
8436
- executionVenue: resolveExecutionVenueFromQuote(quoteData),
8437
- orderId: response.orderIds[0],
8438
- orderIds: response.orderIds,
8439
- phase: "submitting"
8440
- });
8916
+ try {
8917
+ const response = yield executeManaged.mutateAsync({ quoteId });
8918
+ if (debugAttempt) {
8919
+ debugStore == null ? void 0 : debugStore.appendEvent(debugAttempt.attemptId, {
8920
+ kind: "execute_response",
8921
+ data: { orderIds: response.orderIds }
8922
+ });
8923
+ debugStore == null ? void 0 : debugStore.updateAttempt(debugAttempt.attemptId, {
8924
+ orderId: response.orderIds[0],
8925
+ orderIds: response.orderIds
8926
+ });
8927
+ }
8928
+ setSubmissionProgressState({
8929
+ executionVenue: resolveExecutionVenueFromQuote(quoteData),
8930
+ orderId: response.orderIds[0],
8931
+ orderIds: response.orderIds,
8932
+ phase: "submitting"
8933
+ });
8934
+ } catch (error) {
8935
+ if (debugAttempt) {
8936
+ const err = error instanceof Error ? error : new Error(String(error));
8937
+ debugStore == null ? void 0 : debugStore.appendError(debugAttempt.attemptId, {
8938
+ message: err.message,
8939
+ name: err.name,
8940
+ stack: err.stack,
8941
+ failedStep: "execute_request"
8942
+ });
8943
+ debugStore == null ? void 0 : debugStore.updateAttempt(debugAttempt.attemptId, {
8944
+ status: "failed",
8945
+ finalStatus: "failed"
8946
+ });
8947
+ }
8948
+ throw error;
8949
+ }
8441
8950
  }),
8442
- [executeManaged, onPrimaryAction, tradingLabels.quoteUnavailable]
8951
+ [
8952
+ executeManaged,
8953
+ internalAmount,
8954
+ internalSlippage,
8955
+ isSell,
8956
+ onPrimaryAction,
8957
+ scopedSelectedEvent == null ? void 0 : scopedSelectedEvent.id,
8958
+ scopedSelectedMarket == null ? void 0 : scopedSelectedMarket.id,
8959
+ scopedSelectedOutcomeId,
8960
+ smartRoute.data,
8961
+ tradingLabels.quoteUnavailable
8962
+ ]
8443
8963
  );
8444
8964
  const handleSkipToSuccess = (0, import_react9.useCallback)(() => {
8445
8965
  const primaryFilledEvent = executionProgress.terminalOrderEvents.find(