@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
@@ -17,7 +17,7 @@ import {
17
17
  selectPrimaryVenueMarket,
18
18
  skeletonViews,
19
19
  sortOutcomes
20
- } from "./chunk-YJO6LMRT.mjs";
20
+ } from "./chunk-TBD3N4T4.mjs";
21
21
 
22
22
  // src/trading/trading-context/index.tsx
23
23
  import { useEventTradingContext } from "@agg-build/hooks";
@@ -3,7 +3,7 @@ import {
3
3
  AGG_TERMS_OF_SERVICE_URL,
4
4
  Icon,
5
5
  cn
6
- } from "./chunk-YJO6LMRT.mjs";
6
+ } from "./chunk-TBD3N4T4.mjs";
7
7
 
8
8
  // src/geo-block-banner/index.tsx
9
9
  import { useLabels } from "@agg-build/hooks";
@@ -10,13 +10,15 @@ import {
10
10
  isErrorWithStatus,
11
11
  useEventListTabs,
12
12
  useEventListTabsHeaderOverflow
13
- } from "./chunk-NK57KMYN.mjs";
13
+ } from "./chunk-JJDYOBVG.mjs";
14
14
  import {
15
15
  DEPOSIT_MODAL_OPEN_EVENT,
16
16
  PlaceOrder,
17
17
  SettlementDetails,
18
- WITHDRAW_MODAL_OPEN_EVENT
19
- } from "./chunk-XHDGSRG7.mjs";
18
+ WITHDRAW_MODAL_OPEN_EVENT,
19
+ useClaimWinnings,
20
+ useResolvedMarketClaim
21
+ } from "./chunk-ZOECARZW.mjs";
20
22
  import {
21
23
  AggErrorBoundary,
22
24
  Button,
@@ -45,9 +47,8 @@ import {
45
47
  filterOpenEvents,
46
48
  resolveTabVenus,
47
49
  shortenAddress,
48
- sortCategoriesForNavigation,
49
- useOptionalToast
50
- } from "./chunk-YJO6LMRT.mjs";
50
+ sortCategoriesForNavigation
51
+ } from "./chunk-TBD3N4T4.mjs";
51
52
 
52
53
  // src/pages/home/index.tsx
53
54
  import {
@@ -190,7 +191,8 @@ var EventMarketPageMobileTrade = ({
190
191
  showPlaceOrder = true,
191
192
  isOpen,
192
193
  onOpenChange,
193
- midpointsResult
194
+ midpointsResult,
195
+ onBeforePrimaryAction
194
196
  }) => {
195
197
  const labels = useLabels();
196
198
  if (!showPlaceOrder) return null;
@@ -230,6 +232,7 @@ var EventMarketPageMobileTrade = ({
230
232
  eventTradingState,
231
233
  executionMode,
232
234
  midpointsResult,
235
+ onBeforePrimaryAction,
233
236
  className: cn(
234
237
  "agg-mobile-trade-panel w-full overflow-hidden rounded-t-agg-2xl sm:rounded-agg-xl",
235
238
  classNames == null ? void 0 : classNames.mobileTrade
@@ -358,7 +361,8 @@ var EventMarketPageContent = ({
358
361
  showPlaceOrder,
359
362
  executionMode,
360
363
  stickyOrderPanel,
361
- resolvedClaim
364
+ resolvedClaim,
365
+ onBeforePrimaryAction
362
366
  }) => {
363
367
  const eventTradingState = useMemo(() => resolveEventTradingState(event), [event]);
364
368
  const stickyOrderPanelState = resolveEventMarketPageStickyState({
@@ -372,6 +376,12 @@ var EventMarketPageContent = ({
372
376
  const isMobileViewport = useIsMobileEventMarketViewport();
373
377
  const tradingContext = useEventTradingContext();
374
378
  const midpointsResult = useMidpoints(event.venueMarkets);
379
+ const internalResolvedClaim = useResolvedMarketClaim({
380
+ market: eventTradingState.primaryMarket,
381
+ enabled: eventTradingState.kind === "resolved",
382
+ executionMode: resolvedExecutionMode
383
+ });
384
+ const effectiveResolvedClaim = resolvedClaim != null ? resolvedClaim : internalResolvedClaim;
375
385
  const setTradeSideRef = useRef(tradingContext == null ? void 0 : tradingContext.setTradeSide);
376
386
  setTradeSideRef.current = tradingContext == null ? void 0 : tradingContext.setTradeSide;
377
387
  useEffect(() => {
@@ -449,8 +459,9 @@ var EventMarketPageContent = ({
449
459
  {
450
460
  eventTradingState,
451
461
  executionMode: resolvedExecutionMode,
452
- resolvedClaim,
462
+ resolvedClaim: effectiveResolvedClaim,
453
463
  midpointsResult,
464
+ onBeforePrimaryAction,
454
465
  className: cn(
455
466
  "agg-mobile-trade-panel w-full overflow-hidden",
456
467
  classNames == null ? void 0 : classNames.mobileTrade
@@ -475,8 +486,9 @@ var EventMarketPageContent = ({
475
486
  {
476
487
  eventTradingState,
477
488
  executionMode: resolvedExecutionMode,
478
- resolvedClaim,
489
+ resolvedClaim: effectiveResolvedClaim,
479
490
  midpointsResult,
491
+ onBeforePrimaryAction,
480
492
  className: cn(stickyOrderPanelState == null ? void 0 : stickyOrderPanelState.placeOrder, classNames == null ? void 0 : classNames.trade),
481
493
  classNames: resolveDesktopTradePlaceOrderClassNames(classNames)
482
494
  }
@@ -495,7 +507,8 @@ var EventMarketPageContent = ({
495
507
  showPlaceOrder,
496
508
  isOpen: isMobileTradeOpen,
497
509
  onOpenChange: setIsMobileTradeOpen,
498
- midpointsResult
510
+ midpointsResult,
511
+ onBeforePrimaryAction
499
512
  }
500
513
  ) : null
501
514
  ]
@@ -1154,11 +1167,7 @@ HomePage.displayName = "HomePage";
1154
1167
  // src/pages/user-profile/index.tsx
1155
1168
  import {
1156
1169
  computeClosedPositionTotals,
1157
- executionKeys,
1158
1170
  getWalletAddressFromUserProfile,
1159
- invalidateBalanceQueries,
1160
- invalidatePositionQueries,
1161
- invalidateUserActivityQueries,
1162
1171
  useAggAuthState,
1163
1172
  useAggBalance,
1164
1173
  useAggClient,
@@ -1167,13 +1176,11 @@ import {
1167
1176
  useGeoBlock,
1168
1177
  useLabels as useLabels7,
1169
1178
  useQueryClient,
1170
- useRedeem,
1171
- useRedeemLifecycles,
1172
1179
  useSdkUiConfig as useSdkUiConfig3,
1173
1180
  useUserActivity
1174
1181
  } from "@agg-build/hooks";
1175
1182
  import { Venue } from "@agg-build/sdk";
1176
- import { useCallback as useCallback3, useEffect as useEffect5, useMemo as useMemo4, useRef as useRef5, useState as useState6 } from "react";
1183
+ import { useCallback as useCallback3, useEffect as useEffect5, useMemo as useMemo4, useState as useState6 } from "react";
1177
1184
 
1178
1185
  // src/pages/user-profile/chain-display.ts
1179
1186
  var CHAIN_ID_TO_LABEL = {
@@ -3652,10 +3659,6 @@ function buildVenueShareBreakdown(outcome) {
3652
3659
  sharesLabel: `${twoDecimalNumberFormatter.format(row.size)} shares`
3653
3660
  }));
3654
3661
  }
3655
- var toClaimError = (err) => {
3656
- if (err instanceof Error) return err;
3657
- return new Error(String(err));
3658
- };
3659
3662
  var UserProfilePage = ({
3660
3663
  user,
3661
3664
  balanceChainsOverride,
@@ -3717,29 +3720,14 @@ var UserProfilePage = ({
3717
3720
  const {
3718
3721
  trading: { executionMode: configuredExecutionMode }
3719
3722
  } = useSdkUiConfig3();
3720
- const claimNotificationLabels = labels.notifications.claim;
3721
- const toastCtx = useOptionalToast();
3722
3723
  const queryClient = useQueryClient();
3723
- const redeemMutation = useRedeem();
3724
3724
  const [internalCancellingIds, setInternalCancellingIds] = useState6({});
3725
- const [activeRedeems, setActiveRedeems] = useState6({});
3726
- const activeClaimKeysRef = useRef5(/* @__PURE__ */ new Set());
3727
- const pendingClaimToastIdsRef = useRef5({});
3728
- const submittedClaimToastKeysRef = useRef5(/* @__PURE__ */ new Set());
3729
- const [submittingClaimKeys, setSubmittingClaimKeys] = useState6({});
3730
- const lifecycleInputs = useMemo4(
3731
- () => Object.values(activeRedeems),
3732
- [activeRedeems]
3733
- );
3734
- const lifecycleStates = useRedeemLifecycles(lifecycleInputs);
3735
- const internalClaimingIds = useMemo4(() => {
3736
- const out = __spreadValues({}, submittingClaimKeys);
3737
- for (const [claimKey, active] of Object.entries(activeRedeems)) {
3738
- const state = lifecycleStates[active.redeemId];
3739
- if (!state || !state.terminal) out[claimKey] = true;
3740
- }
3741
- return out;
3742
- }, [activeRedeems, lifecycleStates, submittingClaimKeys]);
3725
+ const { claim: startClaim, claimingKeys } = useClaimWinnings({
3726
+ onClaim,
3727
+ onClaimResult,
3728
+ onClaimSubmitError,
3729
+ externalClaimingKeys: claimingPositionKeys
3730
+ });
3743
3731
  const [profileUser, setProfileUser] = useState6(void 0);
3744
3732
  const shouldUseHookData = !user;
3745
3733
  const connectedVenues = useMemo4(() => {
@@ -3802,207 +3790,17 @@ var UserProfilePage = ({
3802
3790
  }),
3803
3791
  [client, onCancelOrder, queryClient]
3804
3792
  );
3805
- const invalidateClaimUiState = useCallback3(() => {
3806
- invalidateBalanceQueries(queryClient);
3807
- invalidatePositionQueries(queryClient);
3808
- queryClient.invalidateQueries({
3809
- queryKey: executionKeys.claimablePositionsCount(),
3810
- refetchType: "active"
3811
- });
3812
- invalidateUserActivityQueries(queryClient);
3813
- }, [queryClient]);
3814
3793
  const handleClaimPosition = useCallback3(
3815
- (position) => __async(null, null, function* () {
3794
+ (position) => {
3816
3795
  var _a, _b;
3817
- const claimKey = (_a = position.marketId) != null ? _a : position.id;
3818
- if (activeClaimKeysRef.current.has(claimKey) || (claimingPositionKeys == null ? void 0 : claimingPositionKeys[claimKey]) || internalClaimingIds[claimKey]) {
3819
- return;
3820
- }
3821
- activeClaimKeysRef.current.add(claimKey);
3822
- setSubmittingClaimKeys((prev) => __spreadProps(__spreadValues({}, prev), { [claimKey]: true }));
3823
- const pendingToastId = toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.pendingMessage, {
3824
- title: claimNotificationLabels.pendingTitle,
3825
- tone: "info"
3796
+ return startClaim({
3797
+ claimKey: (_a = position.marketId) != null ? _a : position.id,
3798
+ winningOutcomeIds: (_b = position.winningOutcomeIds) != null ? _b : [],
3799
+ payload: position
3826
3800
  });
3827
- if (pendingToastId != null) {
3828
- pendingClaimToastIdsRef.current[claimKey] = pendingToastId;
3829
- }
3830
- if (onClaim) {
3831
- try {
3832
- yield onClaim(position);
3833
- const pendingId = pendingClaimToastIdsRef.current[claimKey];
3834
- if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
3835
- delete pendingClaimToastIdsRef.current[claimKey];
3836
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.successMessage, {
3837
- title: claimNotificationLabels.successTitle,
3838
- tone: "success"
3839
- });
3840
- } catch (err) {
3841
- const error = toClaimError(err);
3842
- console.error("[UserProfilePage] redeem failed", error);
3843
- const pendingId = pendingClaimToastIdsRef.current[claimKey];
3844
- if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
3845
- delete pendingClaimToastIdsRef.current[claimKey];
3846
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage(error.message), {
3847
- title: claimNotificationLabels.failedTitle,
3848
- tone: "error"
3849
- });
3850
- onClaimSubmitError == null ? void 0 : onClaimSubmitError(claimKey, error);
3851
- throw error;
3852
- } finally {
3853
- invalidateClaimUiState();
3854
- activeClaimKeysRef.current.delete(claimKey);
3855
- setSubmittingClaimKeys((prev) => {
3856
- const _a2 = prev, { [claimKey]: _removed } = _a2, rest = __objRest(_a2, [__restKey(claimKey)]);
3857
- return rest;
3858
- });
3859
- }
3860
- return;
3861
- }
3862
- const venueMarketOutcomeIds = (_b = position.winningOutcomeIds) != null ? _b : [];
3863
- if (venueMarketOutcomeIds.length === 0) {
3864
- const error = new Error(claimNotificationLabels.missingOutcomeMessage);
3865
- console.error("[UserProfilePage] redeem failed", error);
3866
- const pendingId = pendingClaimToastIdsRef.current[claimKey];
3867
- if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
3868
- delete pendingClaimToastIdsRef.current[claimKey];
3869
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage(error.message), {
3870
- title: claimNotificationLabels.failedTitle,
3871
- tone: "error"
3872
- });
3873
- onClaimSubmitError == null ? void 0 : onClaimSubmitError(claimKey, error);
3874
- invalidateClaimUiState();
3875
- activeClaimKeysRef.current.delete(claimKey);
3876
- setSubmittingClaimKeys((prev) => {
3877
- const _a2 = prev, { [claimKey]: _removed } = _a2, rest = __objRest(_a2, [__restKey(claimKey)]);
3878
- return rest;
3879
- });
3880
- throw error;
3881
- }
3882
- try {
3883
- const response = yield redeemMutation.mutateAsync({ venueMarketOutcomeIds });
3884
- const expectedOutcomeIds = [];
3885
- const preFailedOutcomeIds = [];
3886
- const preFailedReasons = {};
3887
- const preConfirmedOutcomeIds = [];
3888
- const preConfirmedTxHashes = {};
3889
- for (const result of response.results) {
3890
- if (result.status === "submitted") {
3891
- expectedOutcomeIds.push(result.venueMarketOutcomeId);
3892
- } else if (result.status === "confirmed") {
3893
- preConfirmedOutcomeIds.push(result.venueMarketOutcomeId);
3894
- preConfirmedTxHashes[result.venueMarketOutcomeId] = result.txHash;
3895
- } else if (result.status === "ineligible" || result.status === "rejected") {
3896
- preFailedOutcomeIds.push(result.venueMarketOutcomeId);
3897
- preFailedReasons[result.venueMarketOutcomeId] = result.reason;
3898
- }
3899
- }
3900
- if (expectedOutcomeIds.length > 0) {
3901
- const pendingId = pendingClaimToastIdsRef.current[claimKey];
3902
- if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
3903
- delete pendingClaimToastIdsRef.current[claimKey];
3904
- submittedClaimToastKeysRef.current.add(claimKey);
3905
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.submittedMessage, {
3906
- title: claimNotificationLabels.submittedTitle,
3907
- tone: "success"
3908
- });
3909
- }
3910
- setActiveRedeems((prev) => __spreadProps(__spreadValues({}, prev), {
3911
- [claimKey]: {
3912
- redeemId: response.redeemId,
3913
- expectedOutcomeIds,
3914
- preFailedOutcomeIds,
3915
- preFailedReasons,
3916
- preConfirmedOutcomeIds,
3917
- preConfirmedTxHashes
3918
- }
3919
- }));
3920
- yield queryClient.invalidateQueries({ queryKey: ["current-user"] });
3921
- } catch (err) {
3922
- const error = toClaimError(err);
3923
- console.error("[UserProfilePage] redeem failed", error);
3924
- const pendingId = pendingClaimToastIdsRef.current[claimKey];
3925
- if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
3926
- delete pendingClaimToastIdsRef.current[claimKey];
3927
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage(error.message), {
3928
- title: claimNotificationLabels.failedTitle,
3929
- tone: "error"
3930
- });
3931
- onClaimSubmitError == null ? void 0 : onClaimSubmitError(claimKey, error);
3932
- throw error;
3933
- } finally {
3934
- activeClaimKeysRef.current.delete(claimKey);
3935
- setSubmittingClaimKeys((prev) => {
3936
- const _a2 = prev, { [claimKey]: _removed } = _a2, rest = __objRest(_a2, [__restKey(claimKey)]);
3937
- return rest;
3938
- });
3939
- }
3940
- }),
3941
- [
3942
- claimingPositionKeys,
3943
- claimNotificationLabels,
3944
- invalidateClaimUiState,
3945
- internalClaimingIds,
3946
- onClaim,
3947
- onClaimSubmitError,
3948
- queryClient,
3949
- redeemMutation,
3950
- toastCtx
3951
- ]
3801
+ },
3802
+ [startClaim]
3952
3803
  );
3953
- const firedTerminalRef = useRef5({});
3954
- useEffect5(() => {
3955
- var _a, _b;
3956
- for (const [claimKey, active] of Object.entries(activeRedeems)) {
3957
- const state = lifecycleStates[active.redeemId];
3958
- if (!state || !state.terminal) continue;
3959
- if (firedTerminalRef.current[active.redeemId]) continue;
3960
- firedTerminalRef.current[active.redeemId] = true;
3961
- onClaimResult == null ? void 0 : onClaimResult(claimKey, {
3962
- allConfirmed: state.allConfirmed,
3963
- anyFailed: state.anyFailed,
3964
- errorMessage: state.errorMessage
3965
- });
3966
- const pendingId = pendingClaimToastIdsRef.current[claimKey];
3967
- if (pendingId != null) toastCtx == null ? void 0 : toastCtx.dismiss(pendingId);
3968
- delete pendingClaimToastIdsRef.current[claimKey];
3969
- if (state.allConfirmed) {
3970
- if (!submittedClaimToastKeysRef.current.has(claimKey)) {
3971
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.successMessage, {
3972
- title: claimNotificationLabels.successTitle,
3973
- tone: "success"
3974
- });
3975
- }
3976
- } else if (state.anyFailed) {
3977
- const hasConfirmedLeg = Object.values(state.legs).some((leg) => leg.status === "confirmed");
3978
- if (hasConfirmedLeg) {
3979
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.partialMessage((_a = state.errorMessage) != null ? _a : void 0), {
3980
- title: claimNotificationLabels.partialTitle,
3981
- tone: "warning"
3982
- });
3983
- } else {
3984
- toastCtx == null ? void 0 : toastCtx.toast(claimNotificationLabels.failedMessage((_b = state.errorMessage) != null ? _b : void 0), {
3985
- title: claimNotificationLabels.failedTitle,
3986
- tone: "error"
3987
- });
3988
- }
3989
- }
3990
- submittedClaimToastKeysRef.current.delete(claimKey);
3991
- invalidateClaimUiState();
3992
- delete firedTerminalRef.current[active.redeemId];
3993
- setActiveRedeems((prev) => {
3994
- const _a2 = prev, { [claimKey]: _removed } = _a2, rest = __objRest(_a2, [__restKey(claimKey)]);
3995
- return rest;
3996
- });
3997
- }
3998
- }, [
3999
- activeRedeems,
4000
- claimNotificationLabels,
4001
- invalidateClaimUiState,
4002
- lifecycleStates,
4003
- onClaimResult,
4004
- toastCtx
4005
- ]);
4006
3804
  useEffect5(() => {
4007
3805
  if (!shouldUseHookData || !isAuthenticated) {
4008
3806
  setProfileUser(void 0);
@@ -4407,7 +4205,7 @@ var UserProfilePage = ({
4407
4205
  onPositionClick,
4408
4206
  getPositionHref,
4409
4207
  onClaim: handleClaimPosition,
4410
- claimingPositionKeys: claimingPositionKeys != null ? claimingPositionKeys : internalClaimingIds,
4208
+ claimingPositionKeys: claimingKeys,
4411
4209
  onActivityClick,
4412
4210
  getActivityHref,
4413
4211
  onOpenOrderClick,