@agg-build/ui 1.3.0 → 2.1.0

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 (44) hide show
  1. package/dist/{chunk-ONVP7YWS.mjs → chunk-3OI2ZLLT.mjs} +94 -39
  2. package/dist/{chunk-UFC7L74C.mjs → chunk-C5M2OOM3.mjs} +1 -1
  3. package/dist/{chunk-QUZWA34R.mjs → chunk-DXF2LMNN.mjs} +512 -503
  4. package/dist/{chunk-5ALBEKAT.mjs → chunk-R6FBYAY5.mjs} +246 -194
  5. package/dist/{chunk-6PQ6O6M5.mjs → chunk-Y6PVXAUQ.mjs} +34 -90
  6. package/dist/{chunk-YWJIYEJV.mjs → chunk-YAEA6EDG.mjs} +31 -18
  7. package/dist/{chunk-55ODXLOS.mjs → chunk-YMVD6Q2A.mjs} +1 -1
  8. package/dist/events.js +894 -903
  9. package/dist/events.mjs +3 -3
  10. package/dist/index.js +2609 -2530
  11. package/dist/index.mjs +9 -7
  12. package/dist/modals.js +278 -171
  13. package/dist/modals.mjs +5 -3
  14. package/dist/pages.js +2014 -1991
  15. package/dist/pages.mjs +6 -6
  16. package/dist/primitives.js +526 -475
  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 +28 -15
  21. package/dist/trading.mjs +4 -4
  22. package/dist/types/events/list/category-sidebar.d.mts +33 -0
  23. package/dist/types/events/list/category-sidebar.d.ts +33 -0
  24. package/dist/types/events/list/event-list-tabs.d.mts +2 -0
  25. package/dist/types/events/list/event-list-tabs.d.ts +2 -0
  26. package/dist/types/events/list/event-list.utils.d.mts +0 -4
  27. package/dist/types/events/list/event-list.utils.d.ts +0 -4
  28. package/dist/types/events/list/index.d.mts +1 -0
  29. package/dist/types/events/list/index.d.ts +1 -0
  30. package/dist/types/pages/event-market/event-market.types.d.mts +1 -0
  31. package/dist/types/pages/event-market/event-market.types.d.ts +1 -0
  32. package/dist/types/pages/user-profile/index.d.mts +1 -1
  33. package/dist/types/pages/user-profile/index.d.ts +1 -1
  34. package/dist/types/pages/user-profile/user-profile.types.d.mts +1 -0
  35. package/dist/types/pages/user-profile/user-profile.types.d.ts +1 -0
  36. package/dist/types/shared/use-horizontal-scroll-state.d.mts +15 -0
  37. package/dist/types/shared/use-horizontal-scroll-state.d.ts +15 -0
  38. package/dist/types/withdraw/index.d.mts +9 -1
  39. package/dist/types/withdraw/index.d.ts +9 -1
  40. package/dist/types/withdraw/steps/withdraw-amount.d.mts +10 -1
  41. package/dist/types/withdraw/steps/withdraw-amount.d.ts +10 -1
  42. package/dist/types/withdraw/withdraw-modal.types.d.mts +8 -0
  43. package/dist/types/withdraw/withdraw-modal.types.d.ts +8 -0
  44. package/package.json +3 -3
@@ -38,7 +38,7 @@ import {
38
38
  shortenAddress,
39
39
  useOptionalToast,
40
40
  venueLogoLabels
41
- } from "./chunk-QUZWA34R.mjs";
41
+ } from "./chunk-DXF2LMNN.mjs";
42
42
 
43
43
  // src/deposit/index.tsx
44
44
  import { useAggAuthState, useAggUiConfig, useDepositAddresses, useLabels as useLabels11 } from "@agg-build/hooks";
@@ -1873,8 +1873,30 @@ var WithdrawMethodStep = ({
1873
1873
  };
1874
1874
 
1875
1875
  // src/withdraw/steps/withdraw-amount.tsx
1876
- import { useLabels as useLabels13, useWithdrawEstimate as useWithdrawEstimate2 } from "@agg-build/hooks";
1876
+ import { useLabels as useLabels13, useWithdrawPreview } from "@agg-build/hooks";
1877
1877
  import { Fragment as Fragment8, jsx as jsx14, jsxs as jsxs14 } from "react/jsx-runtime";
1878
+ var formatRawTokenAmount = (rawAmount, decimals) => {
1879
+ if (!rawAmount) return "0";
1880
+ const raw = BigInt(rawAmount);
1881
+ const divisor = BigInt(`1${"0".repeat(decimals)}`);
1882
+ const whole = raw / divisor;
1883
+ const remainder = raw % divisor;
1884
+ if (remainder === BigInt(0)) return whole.toString();
1885
+ return `${whole.toString()}.${remainder.toString().padStart(decimals, "0").replace(/0+$/, "")}`;
1886
+ };
1887
+ var parseTokenAmountToRaw = (amount, decimals) => {
1888
+ const normalizedAmount = amount.trim();
1889
+ if (!normalizedAmount || !/^\d*(?:\.\d*)?$/.test(normalizedAmount)) return null;
1890
+ const [wholePart = "0", fractionalPart = ""] = normalizedAmount.split(".");
1891
+ if (fractionalPart.length > decimals) return null;
1892
+ const normalizedWhole = wholePart === "" ? "0" : wholePart;
1893
+ const normalizedFraction = fractionalPart.padEnd(decimals, "0");
1894
+ try {
1895
+ return `${BigInt(normalizedWhole)}${normalizedFraction}`.replace(/^0+(?=\d)/, "");
1896
+ } catch (e) {
1897
+ return null;
1898
+ }
1899
+ };
1878
1900
  var WithdrawAmountStep = ({
1879
1901
  amount,
1880
1902
  destinationWallet,
@@ -1883,8 +1905,10 @@ var WithdrawAmountStep = ({
1883
1905
  networkOptions,
1884
1906
  selectedToken,
1885
1907
  selectedNetwork,
1908
+ destDecimals,
1886
1909
  isConfirming = false,
1887
1910
  error,
1911
+ max = false,
1888
1912
  onBack,
1889
1913
  onAmountChange,
1890
1914
  onDestinationChange,
@@ -1893,18 +1917,31 @@ var WithdrawAmountStep = ({
1893
1917
  onMaxClick,
1894
1918
  onContinue
1895
1919
  }) => {
1920
+ var _a, _b, _c, _d;
1896
1921
  const labels = useLabels13();
1897
1922
  const SOLANA_CHAIN_ID = "792703809";
1898
1923
  const isSolanaDest = selectedNetwork === SOLANA_CHAIN_ID;
1899
1924
  const trimmedDestination = destinationWallet.trim();
1900
1925
  const isValidAddress = isSolanaDest ? /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(trimmedDestination) : /^0x[a-fA-F0-9]{40}$/.test(trimmedDestination);
1901
1926
  const isValid = Number(amount) > 0 && isValidAddress;
1902
- const isDisabled = !isValid || isConfirming;
1903
- const withdrawEstimate = useWithdrawEstimate2({
1904
- amount,
1905
- selectedToken,
1906
- selectedNetwork
1927
+ const amountRaw = amount && Number(amount) > 0 ? parseTokenAmountToRaw(amount, destDecimals) : null;
1928
+ const destinationChainId = Number(selectedNetwork) || null;
1929
+ const preview = useWithdrawPreview({
1930
+ amountRaw,
1931
+ tokenSymbol: selectedToken || null,
1932
+ destinationChainId,
1933
+ destinationAddress: trimmedDestination || null,
1934
+ max
1907
1935
  });
1936
+ const previewUnviable = ((_a = preview.data) == null ? void 0 : _a.pricingStatus) === "unviable";
1937
+ const previewUnviableMessage = previewUnviable ? ((_b = preview.data) == null ? void 0 : _b.maxDeliverableRaw) != null && BigInt(preview.data.maxDeliverableRaw) > BigInt(0) ? `Amount exceeds your withdrawable balance. Max: ~${formatRawTokenAmount(preview.data.maxDeliverableRaw, destDecimals)} ${selectedToken}` : (_d = (_c = preview.data) == null ? void 0 : _c.unviableReason) != null ? _d : "This amount can't be withdrawn right now." : null;
1938
+ const previewLoading = preview.isFetching;
1939
+ const isDisabled = !isValid || isConfirming || previewUnviable || previewLoading;
1940
+ const withdrawEstimate = preview.data && preview.data.pricingStatus === "quoted" ? {
1941
+ estimatedFees: preview.data.feeRaw != null ? `~${formatRawTokenAmount(preview.data.feeRaw, destDecimals)} ${selectedToken}` : "\u2014",
1942
+ networkReserve: preview.data.networkFeeRaw != null ? `~${formatRawTokenAmount(preview.data.networkFeeRaw, destDecimals)} ${selectedToken}` : "\u2014",
1943
+ youReceive: preview.data.receiveAmountRaw != null ? `~${formatRawTokenAmount(preview.data.receiveAmountRaw, destDecimals)} ${selectedToken}` : "\u2014"
1944
+ } : null;
1908
1945
  const shouldShowWithdrawEstimate = Boolean(withdrawEstimate);
1909
1946
  return /* @__PURE__ */ jsxs14(Fragment8, { children: [
1910
1947
  /* @__PURE__ */ jsx14(
@@ -2007,17 +2044,19 @@ var WithdrawAmountStep = ({
2007
2044
  )
2008
2045
  ] })
2009
2046
  ] }),
2010
- shouldShowWithdrawEstimate && withdrawEstimate ? /* @__PURE__ */ jsx14(TransferFeeSummary, { estimate: withdrawEstimate, view: "withdraw" }) : null
2047
+ shouldShowWithdrawEstimate && withdrawEstimate ? /* @__PURE__ */ jsx14(TransferFeeSummary, { estimate: withdrawEstimate, view: "withdraw" }) : null,
2048
+ previewUnviableMessage ? /* @__PURE__ */ jsx14("p", { className: "agg-type-label text-agg-error", role: "alert", children: previewUnviableMessage }) : null
2011
2049
  ] }),
2012
2050
  /* @__PURE__ */ jsx14(
2013
2051
  Button,
2014
2052
  {
2015
- variant: isValid && !isConfirming ? "primary" : "secondary",
2053
+ variant: isValid && !isConfirming && !previewUnviable && !previewLoading ? "primary" : "secondary",
2016
2054
  size: "large",
2017
2055
  className: "w-full",
2018
2056
  disabled: isDisabled,
2057
+ prefix: previewLoading && !isConfirming ? /* @__PURE__ */ jsx14(LoadingIcon, { size: "small", className: "mr-2 text-current" }) : void 0,
2019
2058
  onClick: onContinue,
2020
- children: isConfirming ? labels.common.loading : labels.withdraw.walletFlow.confirm
2059
+ children: isConfirming ? labels.common.loading : previewLoading ? labels.withdraw.walletFlow.calculatingFees : labels.withdraw.walletFlow.confirm
2021
2060
  }
2022
2061
  ),
2023
2062
  error ? /* @__PURE__ */ jsx14("p", { className: "agg-type-label text-agg-error text-center", role: "alert", children: error }) : null
@@ -2247,7 +2286,7 @@ var getTokenDecimals = (tokenSymbol, chainId) => {
2247
2286
  }
2248
2287
  return (_a = TOKEN_DECIMALS_BY_SYMBOL[normalizedSymbol]) != null ? _a : DEFAULT_TOKEN_DECIMALS;
2249
2288
  };
2250
- var formatRawTokenAmount = (rawAmount, decimals) => {
2289
+ var formatRawTokenAmount2 = (rawAmount, decimals) => {
2251
2290
  const raw = BigInt(rawAmount);
2252
2291
  const divisor = BigInt(`1${"0".repeat(decimals)}`);
2253
2292
  const whole = raw / divisor;
@@ -2259,11 +2298,12 @@ var formatLifecycleTokenAmount = ({
2259
2298
  rawAmount,
2260
2299
  tokenSymbol,
2261
2300
  chainId
2262
- }) => `${formatRawTokenAmount(rawAmount, getTokenDecimals(tokenSymbol, chainId))} ${tokenSymbol}`;
2301
+ }) => `${formatRawTokenAmount2(rawAmount, getTokenDecimals(tokenSymbol, chainId))} ${tokenSymbol}`;
2263
2302
  var buildTerminalSummary = ({
2264
2303
  fallbackSummary,
2265
2304
  lifecycleCompletedAmountRaw,
2266
2305
  lifecycleRequestedAmountRaw,
2306
+ lifecycleFeeRaw,
2267
2307
  tokenSymbol,
2268
2308
  chainId
2269
2309
  }) => {
@@ -2273,24 +2313,25 @@ var buildTerminalSummary = ({
2273
2313
  tokenSymbol,
2274
2314
  chainId
2275
2315
  });
2276
- if (!lifecycleRequestedAmountRaw) {
2277
- return __spreadProps(__spreadValues({}, fallbackSummary), { amountReceived });
2278
- }
2279
- try {
2280
- const requestedRaw = BigInt(lifecycleRequestedAmountRaw);
2281
- const completedRaw = BigInt(lifecycleCompletedAmountRaw);
2282
- const feeRaw = requestedRaw > completedRaw ? requestedRaw - completedRaw : BigInt(0);
2283
- return __spreadProps(__spreadValues({}, fallbackSummary), {
2284
- amountReceived,
2285
- fees: formatLifecycleTokenAmount({
2286
- rawAmount: feeRaw.toString(),
2287
- tokenSymbol,
2288
- chainId
2289
- })
2290
- });
2291
- } catch (e) {
2292
- return __spreadProps(__spreadValues({}, fallbackSummary), { amountReceived });
2316
+ let feeRaw = lifecycleFeeRaw;
2317
+ if (feeRaw == null && lifecycleRequestedAmountRaw) {
2318
+ try {
2319
+ const r = BigInt(lifecycleRequestedAmountRaw);
2320
+ const c = BigInt(lifecycleCompletedAmountRaw);
2321
+ feeRaw = (r > c ? r - c : BigInt(0)).toString();
2322
+ } catch (e) {
2323
+ feeRaw = null;
2324
+ }
2293
2325
  }
2326
+ return __spreadValues(__spreadProps(__spreadValues({}, fallbackSummary), {
2327
+ amountReceived
2328
+ }), feeRaw != null ? {
2329
+ fees: formatLifecycleTokenAmount({
2330
+ rawAmount: feeRaw,
2331
+ tokenSymbol,
2332
+ chainId
2333
+ })
2334
+ } : {});
2294
2335
  };
2295
2336
  function isControlledWithdrawModalProps(props) {
2296
2337
  return "withdrawFlow" in props;
@@ -2394,6 +2435,7 @@ function WithdrawModalControlled({
2394
2435
  fallbackSummary: withdrawFlow.purchaseSummary,
2395
2436
  lifecycleCompletedAmountRaw: withdrawalLifecycleState.completedAmountRaw,
2396
2437
  lifecycleRequestedAmountRaw: withdrawalLifecycleState.requestedAmountRaw,
2438
+ lifecycleFeeRaw: withdrawalLifecycleState.feeRaw,
2397
2439
  tokenSymbol: withdrawFlow.selectedToken,
2398
2440
  chainId: withdrawFlow.selectedNetwork
2399
2441
  });
@@ -2415,8 +2457,13 @@ function WithdrawModalControlled({
2415
2457
  networkOptions: withdrawNetworkOptions,
2416
2458
  selectedToken: withdrawFlow.selectedToken,
2417
2459
  selectedNetwork: withdrawFlow.selectedNetwork,
2460
+ destDecimals: getTokenDecimals(
2461
+ withdrawFlow.selectedToken,
2462
+ withdrawFlow.selectedNetwork
2463
+ ),
2418
2464
  isConfirming,
2419
2465
  error: confirmError,
2466
+ max: withdrawFlow.isMax,
2420
2467
  onBack: handleBack,
2421
2468
  onAmountChange: onWithdrawAmountChange,
2422
2469
  onDestinationChange: onWithdrawDestinationChange,
@@ -3577,9 +3624,9 @@ var AccountsWalletsTab = ({
3577
3624
  )
3578
3625
  ] })
3579
3626
  ] }),
3580
- /* @__PURE__ */ jsxs24("div", { className: "agg-wallets-section flex flex-col gap-3", children: [
3627
+ wallets.length > 0 ? /* @__PURE__ */ jsxs24("div", { className: "agg-wallets-section flex flex-col gap-3", children: [
3581
3628
  /* @__PURE__ */ jsx24(SectionTitle, { children: "Wallets" }),
3582
- /* @__PURE__ */ jsx24("div", { className: "flex flex-col gap-2", children: wallets.length > 0 ? wallets.map((wallet) => {
3629
+ /* @__PURE__ */ jsx24("div", { className: "flex flex-col gap-2", children: wallets.map((wallet) => {
3583
3630
  var _a;
3584
3631
  return /* @__PURE__ */ jsx24(AccountRow, { className: "gap-4", children: /* @__PURE__ */ jsxs24("div", { className: "flex min-w-0 items-center gap-3", children: [
3585
3632
  /* @__PURE__ */ jsx24(
@@ -3592,8 +3639,8 @@ var AccountsWalletsTab = ({
3592
3639
  ),
3593
3640
  /* @__PURE__ */ jsx24(VerifiedBadge, {})
3594
3641
  ] }) }, `${wallet.chain}:${wallet.address}`);
3595
- }) : null })
3596
- ] })
3642
+ }) })
3643
+ ] }) : null
3597
3644
  ] });
3598
3645
  };
3599
3646
  AccountsWalletsTab.displayName = "AccountsWalletsTab";
@@ -4016,15 +4063,22 @@ var ProfileModal = ({
4016
4063
  const resolvedWallets = useMemo3(() => {
4017
4064
  var _a2, _b2;
4018
4065
  if (wallets) return wallets;
4019
- return (_b2 = (_a2 = user == null ? void 0 : user.wallets) == null ? void 0 : _a2.map((wallet) => {
4066
+ const walletAccounts = (_b2 = (_a2 = user == null ? void 0 : user.accounts) == null ? void 0 : _a2.filter((account) => {
4020
4067
  var _a3;
4068
+ const provider = (_a3 = account.provider) == null ? void 0 : _a3.toLowerCase();
4069
+ return provider === "wallet" || provider === "solana_wallet";
4070
+ })) != null ? _b2 : [];
4071
+ return walletAccounts.filter((account) => Boolean(account.providerAccountId)).map((account) => {
4072
+ var _a3, _b3;
4073
+ const chain = ((_a3 = account.provider) == null ? void 0 : _a3.toLowerCase()) === "solana_wallet" ? "solana" : "evm";
4074
+ const address = account.providerAccountId;
4021
4075
  return {
4022
- chain: wallet.chain,
4023
- address: wallet.address,
4024
- displayAddress: (_a3 = shortenAddress(wallet.address, { chain: wallet.chain })) != null ? _a3 : wallet.address
4076
+ chain,
4077
+ address,
4078
+ displayAddress: (_b3 = shortenAddress(address, { chain })) != null ? _b3 : address
4025
4079
  };
4026
- })) != null ? _b2 : [];
4027
- }, [user == null ? void 0 : user.wallets, wallets]);
4080
+ });
4081
+ }, [user == null ? void 0 : user.accounts, wallets]);
4028
4082
  return /* @__PURE__ */ jsx26(Modal, { open, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs26(
4029
4083
  Modal.Container,
4030
4084
  {
@@ -4227,6 +4281,7 @@ export {
4227
4281
  clearPendingCardSession,
4228
4282
  getPendingCardSession,
4229
4283
  DepositModal,
4284
+ buildTerminalSummary,
4230
4285
  WithdrawModal,
4231
4286
  HowItWorksStep,
4232
4287
  ProfileSetupStep,
@@ -17,7 +17,7 @@ import {
17
17
  selectPrimaryVenueMarket,
18
18
  skeletonViews,
19
19
  sortOutcomes
20
- } from "./chunk-QUZWA34R.mjs";
20
+ } from "./chunk-DXF2LMNN.mjs";
21
21
 
22
22
  // src/trading/trading-context/index.tsx
23
23
  import { useEventTradingContext } from "@agg-build/hooks";