@agg-build/ui 2.1.1 → 2.1.2

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 (40) hide show
  1. package/dist/{chunk-TERG43WW.mjs → chunk-5RBHMMY3.mjs} +1 -1
  2. package/dist/{chunk-RPXRTXCY.mjs → chunk-75AMJAWR.mjs} +1 -1
  3. package/dist/{chunk-IQT4I5B4.mjs → chunk-7ZR5JYB3.mjs} +39 -241
  4. package/dist/{chunk-NK57KMYN.mjs → chunk-JJDYOBVG.mjs} +117 -48
  5. package/dist/{chunk-WU2C3C6K.mjs → chunk-NRNBJPYK.mjs} +1 -1
  6. package/dist/{chunk-YJO6LMRT.mjs → chunk-TBD3N4T4.mjs} +69 -7
  7. package/dist/{chunk-XHDGSRG7.mjs → chunk-ZOECARZW.mjs} +359 -14
  8. package/dist/events.js +175 -59
  9. package/dist/events.mjs +3 -3
  10. package/dist/index.js +1080 -820
  11. package/dist/index.mjs +12 -8
  12. package/dist/modals.js +1 -1
  13. package/dist/modals.mjs +3 -3
  14. package/dist/pages.js +845 -589
  15. package/dist/pages.mjs +6 -6
  16. package/dist/primitives.js +68 -7
  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 +679 -339
  21. package/dist/trading.mjs +10 -6
  22. package/dist/types/events/shared/format-event-title.d.mts +25 -0
  23. package/dist/types/events/shared/format-event-title.d.ts +25 -0
  24. package/dist/types/events/shared/select-best-outcome.d.mts +88 -0
  25. package/dist/types/events/shared/select-best-outcome.d.ts +88 -0
  26. package/dist/types/pages/event-market/event-market.types.d.mts +7 -0
  27. package/dist/types/pages/event-market/event-market.types.d.ts +7 -0
  28. package/dist/types/primitives/search/search.utils.d.mts +3 -1
  29. package/dist/types/primitives/search/search.utils.d.ts +3 -1
  30. package/dist/types/trading/index.d.mts +2 -0
  31. package/dist/types/trading/index.d.ts +2 -0
  32. package/dist/types/trading/place-order/index.d.mts +1 -1
  33. package/dist/types/trading/place-order/index.d.ts +1 -1
  34. package/dist/types/trading/place-order/index.place-order.types.d.mts +23 -1
  35. package/dist/types/trading/place-order/index.place-order.types.d.ts +23 -1
  36. package/dist/types/trading/use-claim-winnings.d.mts +84 -0
  37. package/dist/types/trading/use-claim-winnings.d.ts +84 -0
  38. package/dist/types/trading/use-resolved-market-claim.d.mts +26 -0
  39. package/dist/types/trading/use-resolved-market-claim.d.ts +26 -0
  40. package/package.json +3 -3
@@ -8,10 +8,10 @@ import {
8
8
  getTradingValueLabel,
9
9
  getTradingVenueLabel,
10
10
  resolveOrderEligibilityMessage
11
- } from "./chunk-TERG43WW.mjs";
11
+ } from "./chunk-5RBHMMY3.mjs";
12
12
  import {
13
13
  GeoBlockBanner
14
- } from "./chunk-RPXRTXCY.mjs";
14
+ } from "./chunk-75AMJAWR.mjs";
15
15
  import {
16
16
  AGG_TERMS_OF_SERVICE_URL,
17
17
  Button,
@@ -31,14 +31,17 @@ import {
31
31
  UserTrustIcon,
32
32
  VenueLogo,
33
33
  __async,
34
+ __objRest,
34
35
  __pow,
36
+ __restKey,
35
37
  __spreadProps,
36
38
  __spreadValues,
37
39
  cn,
38
40
  formatUsd,
39
41
  getMotionClassName,
40
- skeletonViews
41
- } from "./chunk-YJO6LMRT.mjs";
42
+ skeletonViews,
43
+ useOptionalToast
44
+ } from "./chunk-TBD3N4T4.mjs";
42
45
 
43
46
  // src/trading/types.ts
44
47
  import { Venue, enumGuard, isFiniteNonNeg, safeParse } from "@agg-build/sdk";
@@ -2406,10 +2409,8 @@ var PlaceOrderResolvedView = ({
2406
2409
  resolvedClaim,
2407
2410
  className
2408
2411
  }) => {
2409
- var _a, _b, _c, _d, _e;
2410
2412
  const labels = useLabels();
2411
2413
  const tradingLabels = labels.trading;
2412
- const extendedTradingLabels = tradingLabels;
2413
2414
  return /* @__PURE__ */ jsx4(
2414
2415
  Card,
2415
2416
  {
@@ -2448,18 +2449,18 @@ var PlaceOrderResolvedView = ({
2448
2449
  resolvedClaim ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
2449
2450
  /* @__PURE__ */ jsx4("div", { className: "h-px w-full bg-agg-separator" }),
2450
2451
  /* @__PURE__ */ jsxs3("div", { className: "flex w-full flex-col gap-5 p-6", children: [
2451
- /* @__PURE__ */ jsx4(Typography, { variant: "body-strong", className: "text-center", children: (_a = extendedTradingLabels.resolvedEarningsTitle) != null ? _a : "Your Earnings" }),
2452
+ /* @__PURE__ */ jsx4(Typography, { variant: "body-strong", className: "text-center", children: tradingLabels.resolvedEarningsTitle }),
2452
2453
  /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-3 text-agg-sm leading-agg-5 text-agg-foreground", children: [
2453
2454
  resolvedClaim.resolutionDateLabel ? /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between gap-4", children: [
2454
- /* @__PURE__ */ jsx4("span", { children: (_b = extendedTradingLabels.resolvedResolutionDateLabel) != null ? _b : "Resolution date" }),
2455
+ /* @__PURE__ */ jsx4("span", { children: tradingLabels.resolvedResolutionDateLabel }),
2455
2456
  /* @__PURE__ */ jsx4("span", { className: "font-agg-bold", children: resolvedClaim.resolutionDateLabel })
2456
2457
  ] }) : null,
2457
2458
  /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between gap-4", children: [
2458
- /* @__PURE__ */ jsx4("span", { children: (_c = extendedTradingLabels.resolvedSharesLabel) != null ? _c : "Shares" }),
2459
+ /* @__PURE__ */ jsx4("span", { children: tradingLabels.resolvedSharesLabel }),
2459
2460
  /* @__PURE__ */ jsx4("span", { className: "font-agg-bold", children: resolvedClaim.sharesLabel })
2460
2461
  ] }),
2461
2462
  /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between gap-4", children: [
2462
- /* @__PURE__ */ jsx4("span", { children: (_d = extendedTradingLabels.resolvedTotalPayoutLabel) != null ? _d : "Total payout" }),
2463
+ /* @__PURE__ */ jsx4("span", { children: tradingLabels.resolvedTotalPayoutLabel }),
2463
2464
  /* @__PURE__ */ jsx4("span", { className: "font-agg-bold", children: resolvedClaim.totalPayoutLabel })
2464
2465
  ] })
2465
2466
  ] }),
@@ -2471,7 +2472,7 @@ var PlaceOrderResolvedView = ({
2471
2472
  onClick: resolvedClaim.onClaim,
2472
2473
  isLoading: resolvedClaim.isClaiming,
2473
2474
  disabled: resolvedClaim.isClaiming,
2474
- children: (_e = extendedTradingLabels.claimWinnings) != null ? _e : "Claim Winnings"
2475
+ children: tradingLabels.claimWinnings
2475
2476
  }
2476
2477
  ) : null
2477
2478
  ] })
@@ -2807,6 +2808,7 @@ var PlaceOrder = ({
2807
2808
  onClose,
2808
2809
  onOutcomeChange,
2809
2810
  onPrimaryAction,
2811
+ onBeforePrimaryAction,
2810
2812
  onTabChange,
2811
2813
  onSuccess,
2812
2814
  onError,
@@ -2945,6 +2947,7 @@ var PlaceOrder = ({
2945
2947
  const [isSplitDetailOpen, setIsSplitDetailOpen] = useState3(false);
2946
2948
  const [submissionFeedback, setSubmissionFeedback] = useState3(null);
2947
2949
  const [submissionProgressState, setSubmissionProgressState] = useState3(null);
2950
+ const [isBeforeActionPending, setIsBeforeActionPending] = useState3(false);
2948
2951
  const executionDebugStoreRef = useRef2(null);
2949
2952
  const executionDebugAttemptIdRef = useRef2(null);
2950
2953
  const submittedSelectionRef = useRef2(null);
@@ -3530,7 +3533,7 @@ var PlaceOrder = ({
3530
3533
  }
3531
3534
  ];
3532
3535
  }, [activeFeeBreakdown, tradingLabels]);
3533
- const isActionLoading = isPrimaryActionLoading || executeManaged.isPending;
3536
+ const isActionLoading = isPrimaryActionLoading || executeManaged.isPending || isBeforeActionPending;
3534
3537
  const selectedRouteGeoBlocked = (_D = selectedRouteCard == null ? void 0 : selectedRouteCard.isUnavailable) != null ? _D : false;
3535
3538
  const geoBlockedVenuesFromWarnings = useMemo2(
3536
3539
  () => {
@@ -3896,7 +3899,7 @@ var PlaceOrder = ({
3896
3899
  });
3897
3900
  };
3898
3901
  const handlePrimaryAction = () => __async(null, null, function* () {
3899
- var _a2;
3902
+ var _a2, _b2, _c2;
3900
3903
  if (!orderEligibility.canPlaceOrder) {
3901
3904
  setSubmissionFeedback({
3902
3905
  message: (_a2 = resolveOrderEligibilityMessage(labels, orderEligibility.reason)) != null ? _a2 : tradingLabels.orderFailed,
@@ -3906,6 +3909,26 @@ var PlaceOrder = ({
3906
3909
  }
3907
3910
  if (!selectedRouteCard) return;
3908
3911
  setSubmissionFeedback(null);
3912
+ if (onBeforePrimaryAction) {
3913
+ const beforeContext = isPaperMode ? { quoteId: (_b2 = selectedRouteCard.quoteData) == null ? void 0 : _b2.quoteId, mode: "paper" } : { quoteId: (_c2 = selectedRouteCard.quoteData) == null ? void 0 : _c2.quoteId };
3914
+ setIsBeforeActionPending(true);
3915
+ try {
3916
+ const proceed = yield onBeforePrimaryAction(beforeContext);
3917
+ if (proceed === false) return;
3918
+ } catch (error) {
3919
+ setSubmissionFeedback({
3920
+ message: normalizePlaceOrderErrorMessage({
3921
+ errorMessage: error instanceof Error ? error.message : String(error),
3922
+ fallbackMessage: tradingLabels.orderFailed,
3923
+ labels: tradingLabels
3924
+ }),
3925
+ tone: "error"
3926
+ });
3927
+ return;
3928
+ } finally {
3929
+ setIsBeforeActionPending(false);
3930
+ }
3931
+ }
3909
3932
  if (scopedSelectedMarket && scopedSelectedOutcomeId) {
3910
3933
  submittedSelectionRef.current = {
3911
3934
  marketId: scopedSelectedMarket.id,
@@ -4376,6 +4399,326 @@ var PlaceOrder = ({
4376
4399
  };
4377
4400
  PlaceOrder.displayName = "PlaceOrder";
4378
4401
 
4402
+ // src/trading/use-claim-winnings.ts
4403
+ import {
4404
+ executionKeys,
4405
+ invalidateBalanceQueries as invalidateBalanceQueries2,
4406
+ invalidatePositionQueries as invalidatePositionQueries2,
4407
+ invalidateUserActivityQueries,
4408
+ useLabels as useLabels2,
4409
+ useQueryClient as useQueryClient2,
4410
+ useRedeem,
4411
+ useRedeemLifecycles
4412
+ } from "@agg-build/hooks";
4413
+ import { useCallback as useCallback3, useEffect as useEffect3, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4414
+ var toClaimError = (err) => {
4415
+ if (err instanceof Error) return err;
4416
+ return new Error(String(err));
4417
+ };
4418
+ function useClaimWinnings(options = {}) {
4419
+ const { onClaim, onClaimResult, onClaimSubmitError, externalClaimingKeys } = options;
4420
+ const labels = useLabels2();
4421
+ const claimNotificationLabels = labels.notifications.claim;
4422
+ const toastCtx = useOptionalToast();
4423
+ const queryClient = useQueryClient2();
4424
+ const redeemMutation = useRedeem();
4425
+ const [activeRedeems, setActiveRedeems] = useState4({});
4426
+ const activeClaimKeysRef = useRef3(/* @__PURE__ */ new Set());
4427
+ const pendingClaimToastIdsRef = useRef3({});
4428
+ const submittedClaimToastKeysRef = useRef3(/* @__PURE__ */ new Set());
4429
+ const [submittingClaimKeys, setSubmittingClaimKeys] = useState4({});
4430
+ const lifecycleInputs = useMemo3(
4431
+ () => Object.values(activeRedeems),
4432
+ [activeRedeems]
4433
+ );
4434
+ const lifecycleStates = useRedeemLifecycles(lifecycleInputs);
4435
+ const internalClaimingIds = useMemo3(() => {
4436
+ const out = __spreadValues({}, submittingClaimKeys);
4437
+ for (const [claimKey, active] of Object.entries(activeRedeems)) {
4438
+ const state = lifecycleStates[active.redeemId];
4439
+ if (!state || !state.terminal) out[claimKey] = true;
4440
+ }
4441
+ return out;
4442
+ }, [activeRedeems, lifecycleStates, submittingClaimKeys]);
4443
+ const claimingKeys = externalClaimingKeys != null ? externalClaimingKeys : internalClaimingIds;
4444
+ const isClaiming = useCallback3(
4445
+ (claimKey) => Boolean(externalClaimingKeys == null ? void 0 : externalClaimingKeys[claimKey]) || Boolean(internalClaimingIds[claimKey]),
4446
+ [externalClaimingKeys, internalClaimingIds]
4447
+ );
4448
+ const invalidateClaimUiState = useCallback3(() => {
4449
+ invalidateBalanceQueries2(queryClient);
4450
+ invalidatePositionQueries2(queryClient);
4451
+ queryClient.invalidateQueries({
4452
+ queryKey: executionKeys.claimablePositionsCount(),
4453
+ refetchType: "active"
4454
+ });
4455
+ invalidateUserActivityQueries(queryClient);
4456
+ }, [queryClient]);
4457
+ const claim = useCallback3(
4458
+ (_0) => __async(null, [_0], function* ({ claimKey, winningOutcomeIds, payload }) {
4459
+ if (activeClaimKeysRef.current.has(claimKey) || Boolean(externalClaimingKeys == null ? void 0 : externalClaimingKeys[claimKey]) || internalClaimingIds[claimKey]) {
4460
+ return;
4461
+ }
4462
+ activeClaimKeysRef.current.add(claimKey);
4463
+ setSubmittingClaimKeys((prev) => __spreadProps(__spreadValues({}, prev), { [claimKey]: true }));
4464
+ const pendingToastId = toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.pendingMessage, {
4465
+ title: claimNotificationLabels.pendingTitle,
4466
+ tone: "info"
4467
+ });
4468
+ if (pendingToastId != null) {
4469
+ pendingClaimToastIdsRef.current[claimKey] = pendingToastId;
4470
+ }
4471
+ if (onClaim) {
4472
+ try {
4473
+ yield onClaim(payload);
4474
+ const pendingId = pendingClaimToastIdsRef.current[claimKey];
4475
+ if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
4476
+ delete pendingClaimToastIdsRef.current[claimKey];
4477
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.successMessage, {
4478
+ title: claimNotificationLabels.successTitle,
4479
+ tone: "success"
4480
+ });
4481
+ } catch (err) {
4482
+ const error = toClaimError(err);
4483
+ console.error("[useClaimWinnings] redeem failed", error);
4484
+ const pendingId = pendingClaimToastIdsRef.current[claimKey];
4485
+ if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
4486
+ delete pendingClaimToastIdsRef.current[claimKey];
4487
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage(error.message), {
4488
+ title: claimNotificationLabels.failedTitle,
4489
+ tone: "error"
4490
+ });
4491
+ onClaimSubmitError == null ? void 0 : onClaimSubmitError(claimKey, error);
4492
+ throw error;
4493
+ } finally {
4494
+ invalidateClaimUiState();
4495
+ activeClaimKeysRef.current.delete(claimKey);
4496
+ setSubmittingClaimKeys((prev) => {
4497
+ const _a = prev, { [claimKey]: _removed } = _a, rest = __objRest(_a, [__restKey(claimKey)]);
4498
+ return rest;
4499
+ });
4500
+ }
4501
+ return;
4502
+ }
4503
+ if (winningOutcomeIds.length === 0) {
4504
+ const error = new Error(claimNotificationLabels.missingOutcomeMessage);
4505
+ console.error("[useClaimWinnings] redeem failed", error);
4506
+ const pendingId = pendingClaimToastIdsRef.current[claimKey];
4507
+ if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
4508
+ delete pendingClaimToastIdsRef.current[claimKey];
4509
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage(error.message), {
4510
+ title: claimNotificationLabels.failedTitle,
4511
+ tone: "error"
4512
+ });
4513
+ onClaimSubmitError == null ? void 0 : onClaimSubmitError(claimKey, error);
4514
+ invalidateClaimUiState();
4515
+ activeClaimKeysRef.current.delete(claimKey);
4516
+ setSubmittingClaimKeys((prev) => {
4517
+ const _a = prev, { [claimKey]: _removed } = _a, rest = __objRest(_a, [__restKey(claimKey)]);
4518
+ return rest;
4519
+ });
4520
+ throw error;
4521
+ }
4522
+ try {
4523
+ const response = yield redeemMutation.mutateAsync({
4524
+ venueMarketOutcomeIds: winningOutcomeIds
4525
+ });
4526
+ const expectedOutcomeIds = [];
4527
+ const preFailedOutcomeIds = [];
4528
+ const preFailedReasons = {};
4529
+ const preConfirmedOutcomeIds = [];
4530
+ const preConfirmedTxHashes = {};
4531
+ for (const result of response.results) {
4532
+ if (result.status === "submitted") {
4533
+ expectedOutcomeIds.push(result.venueMarketOutcomeId);
4534
+ } else if (result.status === "confirmed") {
4535
+ preConfirmedOutcomeIds.push(result.venueMarketOutcomeId);
4536
+ preConfirmedTxHashes[result.venueMarketOutcomeId] = result.txHash;
4537
+ } else if (result.status === "ineligible" || result.status === "rejected") {
4538
+ preFailedOutcomeIds.push(result.venueMarketOutcomeId);
4539
+ preFailedReasons[result.venueMarketOutcomeId] = result.reason;
4540
+ }
4541
+ }
4542
+ if (expectedOutcomeIds.length > 0) {
4543
+ const pendingId = pendingClaimToastIdsRef.current[claimKey];
4544
+ if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
4545
+ delete pendingClaimToastIdsRef.current[claimKey];
4546
+ submittedClaimToastKeysRef.current.add(claimKey);
4547
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.submittedMessage, {
4548
+ title: claimNotificationLabels.submittedTitle,
4549
+ tone: "success"
4550
+ });
4551
+ }
4552
+ setActiveRedeems((prev) => __spreadProps(__spreadValues({}, prev), {
4553
+ [claimKey]: {
4554
+ redeemId: response.redeemId,
4555
+ expectedOutcomeIds,
4556
+ preFailedOutcomeIds,
4557
+ preFailedReasons,
4558
+ preConfirmedOutcomeIds,
4559
+ preConfirmedTxHashes
4560
+ }
4561
+ }));
4562
+ yield queryClient.invalidateQueries({ queryKey: ["current-user"] });
4563
+ } catch (err) {
4564
+ const error = toClaimError(err);
4565
+ console.error("[useClaimWinnings] redeem failed", error);
4566
+ const pendingId = pendingClaimToastIdsRef.current[claimKey];
4567
+ if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
4568
+ delete pendingClaimToastIdsRef.current[claimKey];
4569
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage(error.message), {
4570
+ title: claimNotificationLabels.failedTitle,
4571
+ tone: "error"
4572
+ });
4573
+ onClaimSubmitError == null ? void 0 : onClaimSubmitError(claimKey, error);
4574
+ throw error;
4575
+ } finally {
4576
+ activeClaimKeysRef.current.delete(claimKey);
4577
+ setSubmittingClaimKeys((prev) => {
4578
+ const _a = prev, { [claimKey]: _removed } = _a, rest = __objRest(_a, [__restKey(claimKey)]);
4579
+ return rest;
4580
+ });
4581
+ }
4582
+ }),
4583
+ [
4584
+ claimNotificationLabels,
4585
+ externalClaimingKeys,
4586
+ internalClaimingIds,
4587
+ invalidateClaimUiState,
4588
+ onClaim,
4589
+ onClaimSubmitError,
4590
+ queryClient,
4591
+ redeemMutation,
4592
+ toastCtx
4593
+ ]
4594
+ );
4595
+ const firedTerminalRef = useRef3({});
4596
+ useEffect3(() => {
4597
+ var _a, _b;
4598
+ for (const [claimKey, active] of Object.entries(activeRedeems)) {
4599
+ const state = lifecycleStates[active.redeemId];
4600
+ if (!state || !state.terminal) continue;
4601
+ if (firedTerminalRef.current[active.redeemId]) continue;
4602
+ firedTerminalRef.current[active.redeemId] = true;
4603
+ onClaimResult == null ? void 0 : onClaimResult(claimKey, {
4604
+ allConfirmed: state.allConfirmed,
4605
+ anyFailed: state.anyFailed,
4606
+ errorMessage: state.errorMessage
4607
+ });
4608
+ const pendingId = pendingClaimToastIdsRef.current[claimKey];
4609
+ if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
4610
+ delete pendingClaimToastIdsRef.current[claimKey];
4611
+ if (state.allConfirmed) {
4612
+ if (!submittedClaimToastKeysRef.current.has(claimKey)) {
4613
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.successMessage, {
4614
+ title: claimNotificationLabels.successTitle,
4615
+ tone: "success"
4616
+ });
4617
+ }
4618
+ } else if (state.anyFailed) {
4619
+ const hasConfirmedLeg = Object.values(state.legs).some((leg) => leg.status === "confirmed");
4620
+ if (hasConfirmedLeg) {
4621
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.partialMessage((_a = state.errorMessage) != null ? _a : void 0), {
4622
+ title: claimNotificationLabels.partialTitle,
4623
+ tone: "warning"
4624
+ });
4625
+ } else {
4626
+ toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage((_b = state.errorMessage) != null ? _b : void 0), {
4627
+ title: claimNotificationLabels.failedTitle,
4628
+ tone: "error"
4629
+ });
4630
+ }
4631
+ }
4632
+ submittedClaimToastKeysRef.current.delete(claimKey);
4633
+ invalidateClaimUiState();
4634
+ delete firedTerminalRef.current[active.redeemId];
4635
+ setActiveRedeems((prev) => {
4636
+ const _a2 = prev, { [claimKey]: _removed } = _a2, rest = __objRest(_a2, [__restKey(claimKey)]);
4637
+ return rest;
4638
+ });
4639
+ }
4640
+ }, [
4641
+ activeRedeems,
4642
+ claimNotificationLabels,
4643
+ invalidateClaimUiState,
4644
+ lifecycleStates,
4645
+ onClaimResult,
4646
+ toastCtx
4647
+ ]);
4648
+ return { claim, claimingKeys, isClaiming };
4649
+ }
4650
+
4651
+ // src/trading/use-resolved-market-claim.ts
4652
+ import {
4653
+ computeClosedPositionTotals,
4654
+ resolveMarketTradingState as resolveMarketTradingState2,
4655
+ useAggAuthState,
4656
+ useExecutionPositions as useExecutionPositions2
4657
+ } from "@agg-build/hooks";
4658
+ import { useMemo as useMemo4 } from "react";
4659
+ var sharesFormatter = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 });
4660
+ var dateFormatter = new Intl.DateTimeFormat("en-US", {
4661
+ month: "short",
4662
+ day: "numeric",
4663
+ year: "numeric"
4664
+ });
4665
+ var formatResolutionDate = (value) => {
4666
+ if (!value) return "";
4667
+ const date = new Date(value);
4668
+ if (Number.isNaN(date.getTime())) return "";
4669
+ return dateFormatter.format(date);
4670
+ };
4671
+ function useResolvedMarketClaim(options = {}) {
4672
+ var _a;
4673
+ const { market, enabled = true, executionMode } = options;
4674
+ const { isAuthenticated } = useAggAuthState();
4675
+ const tradingState = useMemo4(() => resolveMarketTradingState2(market), [market]);
4676
+ const isResolved = tradingState.kind === "resolved";
4677
+ const marketId = (_a = market == null ? void 0 : market.id) != null ? _a : null;
4678
+ const shouldFetch = Boolean(enabled && isAuthenticated && isResolved && marketId);
4679
+ const { positions } = useExecutionPositions2(__spreadValues({
4680
+ enabled: shouldFetch,
4681
+ status: "active",
4682
+ limit: 50
4683
+ }, executionMode === "paper" ? { mode: "paper" } : {}));
4684
+ const claimWinnings = useClaimWinnings();
4685
+ return useMemo4(() => {
4686
+ var _a2, _b, _c;
4687
+ if (!shouldFetch || !marketId) return void 0;
4688
+ const group = positions.find(
4689
+ (candidate) => candidate.targetMarketId === marketId
4690
+ );
4691
+ if (!group || group.venueMarket.status !== "resolved") return void 0;
4692
+ const winningOutcomes = group.venueMarket.venueMarketOutcomes.filter(
4693
+ (outcome) => outcome.winner === true && outcome.totalSize > 0
4694
+ );
4695
+ if (winningOutcomes.length === 0) return void 0;
4696
+ const totals = computeClosedPositionTotals(group);
4697
+ const winningShares = winningOutcomes.reduce((sum, outcome) => sum + outcome.totalSize, 0);
4698
+ const winningOutcomeLabel = ((_b = (_a2 = winningOutcomes[0]) == null ? void 0 : _a2.title) == null ? void 0 : _b.trim()) || ((_c = winningOutcomes[0]) == null ? void 0 : _c.label) || "";
4699
+ const claimKey = group.targetMarketId;
4700
+ const canClaim = group.redeemStatus === "eligible" && totals.winningOutcomeIds.length > 0;
4701
+ return {
4702
+ resolutionDateLabel: formatResolutionDate(group.resolutionDate),
4703
+ winningOutcomeLabel,
4704
+ sharesLabel: `${sharesFormatter.format(winningShares)} ${winningOutcomeLabel}`.trim(),
4705
+ // Payout is always shown with 2 decimals (e.g. "$8.50"), matching the
4706
+ // resolved-earnings design and the profile positions list.
4707
+ totalPayoutLabel: formatUsd(totals.amountWon, {
4708
+ minimumFractionDigits: 2,
4709
+ maximumFractionDigits: 2
4710
+ }),
4711
+ isClaiming: claimWinnings.isClaiming(claimKey),
4712
+ onClaim: canClaim ? () => {
4713
+ void claimWinnings.claim({
4714
+ claimKey,
4715
+ winningOutcomeIds: totals.winningOutcomeIds
4716
+ });
4717
+ } : void 0
4718
+ };
4719
+ }, [claimWinnings, marketId, positions, shouldFetch]);
4720
+ }
4721
+
4379
4722
  export {
4380
4723
  parseVenue,
4381
4724
  parseAmount,
@@ -4386,5 +4729,7 @@ export {
4386
4729
  requestAggWithdrawModalOpen,
4387
4730
  PlaceOrderFailureView,
4388
4731
  PlaceOrderSuccessView,
4389
- PlaceOrder
4732
+ PlaceOrder,
4733
+ useClaimWinnings,
4734
+ useResolvedMarketClaim
4390
4735
  };