@agg-build/ui 4.19.0 → 4.21.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 (45) hide show
  1. package/dist/{chunk-GT3DCFIT.mjs → chunk-5PA5KLXN.mjs} +17 -9
  2. package/dist/chunk-CKHECAKV.mjs +2724 -0
  3. package/dist/{chunk-NSQQ62QK.mjs → chunk-DONMO42Q.mjs} +1 -1
  4. package/dist/{chunk-DXASFSVL.mjs → chunk-JLO2BGSF.mjs} +546 -225
  5. package/dist/{chunk-5YHKIJ23.mjs → chunk-NV6WT3TN.mjs} +481 -826
  6. package/dist/{chunk-47CCGQH6.mjs → chunk-UXLC3FFY.mjs} +451 -1349
  7. package/dist/{event-market-2BAMDM5I.mjs → event-market-UREM3ZE7.mjs} +3 -3
  8. package/dist/events.js +419 -99
  9. package/dist/events.mjs +4 -2
  10. package/dist/index.js +22571 -21972
  11. package/dist/index.mjs +12 -10
  12. package/dist/modals.js +898 -335
  13. package/dist/modals.mjs +5 -5
  14. package/dist/pages.js +4328 -2833
  15. package/dist/pages.mjs +5 -5
  16. package/dist/styles.css +1 -1
  17. package/dist/tailwind.css +1 -1
  18. package/dist/trading.js +1746 -643
  19. package/dist/trading.mjs +2 -2
  20. package/dist/types/events/list/event-list-venue-strip.d.mts +29 -0
  21. package/dist/types/events/list/event-list-venue-strip.d.ts +29 -0
  22. package/dist/types/events/list/index.d.mts +2 -0
  23. package/dist/types/events/list/index.d.ts +2 -0
  24. package/dist/types/pages/user-profile/components/available-balance-card.d.mts +2 -1
  25. package/dist/types/pages/user-profile/components/available-balance-card.d.ts +2 -1
  26. package/dist/types/pages/user-profile/components/betdex-account-card.d.mts +3 -1
  27. package/dist/types/pages/user-profile/components/betdex-account-card.d.ts +3 -1
  28. package/dist/types/pages/user-profile/components/betdex-account-transfers.d.mts +2 -1
  29. package/dist/types/pages/user-profile/components/betdex-account-transfers.d.ts +2 -1
  30. package/dist/types/pages/user-profile/components/betdex-wallet-deposit.d.mts +6 -0
  31. package/dist/types/pages/user-profile/components/betdex-wallet-deposit.d.ts +6 -0
  32. package/dist/types/profile/tabs/trading-access-tab.d.mts +2 -1
  33. package/dist/types/profile/tabs/trading-access-tab.d.ts +2 -1
  34. package/dist/types/trading/manage-betdex-account-modal.d.mts +2 -1
  35. package/dist/types/trading/manage-betdex-account-modal.d.ts +2 -1
  36. package/dist/types/trading/place-order/index.place-order.types.d.mts +1 -0
  37. package/dist/types/trading/place-order/index.place-order.types.d.ts +1 -0
  38. package/dist/types/trading/place-order/index.place-order.utils.d.mts +2 -2
  39. package/dist/types/trading/place-order/index.place-order.utils.d.ts +2 -2
  40. package/dist/types/withdraw/steps/withdraw-amount.d.mts +3 -1
  41. package/dist/types/withdraw/steps/withdraw-amount.d.ts +3 -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
  45. package/dist/chunk-ROA5K67W.mjs +0 -1237
@@ -0,0 +1,2724 @@
1
+ "use client";
2
+ import {
3
+ AGG_TERMS_OF_SERVICE_URL,
4
+ BestPricesIcon,
5
+ Button,
6
+ CheckCircleIcon,
7
+ ChevronLeftIcon,
8
+ ChevronRightIcon,
9
+ CloseIcon,
10
+ CreateAccountIcon,
11
+ Icon,
12
+ InlineAlert,
13
+ LinkAccountsIcon,
14
+ LoadingIcon,
15
+ Modal,
16
+ ProfileIcon,
17
+ RemoteImage,
18
+ Select,
19
+ SkeletonBlock,
20
+ StayInControlIcon,
21
+ SuccessCheckIcon,
22
+ Tooltip,
23
+ Typography,
24
+ VenueLogo,
25
+ WalletIcon,
26
+ WarningIcon,
27
+ __async,
28
+ __spreadProps,
29
+ __spreadValues,
30
+ cn,
31
+ formatCompactUsd,
32
+ formatUsd,
33
+ getMotionClassName
34
+ } from "./chunk-XZVGHKMW.mjs";
35
+
36
+ // src/geo-block-banner/index.tsx
37
+ import { useLabels } from "@agg-build/hooks";
38
+ import { jsx, jsxs } from "react/jsx-runtime";
39
+ var GeoBlockBanner = ({
40
+ venue,
41
+ termsUrl = AGG_TERMS_OF_SERVICE_URL,
42
+ className
43
+ }) => {
44
+ const labels = useLabels();
45
+ const message = venue ? labels.trading.geoBlockVenueMessage(venue) : labels.trading.geoBlockGenericMessage;
46
+ return /* @__PURE__ */ jsxs(
47
+ "div",
48
+ {
49
+ className: cn("flex items-center gap-5 rounded-agg-lg bg-agg-secondary-hover p-3", className),
50
+ role: "status",
51
+ children: [
52
+ /* @__PURE__ */ jsxs("p", { className: "min-w-0 flex-1 text-agg-xs leading-agg-4 text-agg-foreground", children: [
53
+ message,
54
+ /* @__PURE__ */ jsx("a", { href: termsUrl, className: "underline", target: "_blank", rel: "noreferrer noopener", children: labels.trading.geoBlockTermsLink }),
55
+ labels.trading.geoBlockMessageSuffix
56
+ ] }),
57
+ /* @__PURE__ */ jsx(Icon, { name: "internet-security", className: "h-6 w-6 shrink-0 text-agg-muted-foreground" })
58
+ ]
59
+ }
60
+ );
61
+ };
62
+ GeoBlockBanner.displayName = "GeoBlockBanner";
63
+
64
+ // src/kyc/shared-kyc-modal.tsx
65
+ import { useLabels as useLabels2 } from "@agg-build/hooks";
66
+ import * as Dialog from "@radix-ui/react-dialog";
67
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
68
+ var SharedKycModal = ({
69
+ open,
70
+ state = "initial",
71
+ errorMessage,
72
+ onOpenChange,
73
+ onStartVerification
74
+ }) => {
75
+ const labels = useLabels2();
76
+ const modalLabels = labels.trading.sharedKyc.modal;
77
+ const isInitiating = state === "initiating";
78
+ const handleOpenChange = (nextOpen) => {
79
+ if (isInitiating && !nextOpen) return;
80
+ onOpenChange(nextOpen);
81
+ };
82
+ return /* @__PURE__ */ jsx2(Modal, { open, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs2(
83
+ Modal.Container,
84
+ {
85
+ maxWidth: "420px",
86
+ "aria-label": modalLabels.ariaLabel,
87
+ classNames: { container: "!rounded-agg-2xl" },
88
+ children: [
89
+ /* @__PURE__ */ jsx2("div", { className: "flex h-14 shrink-0 items-center justify-end px-5", children: /* @__PURE__ */ jsx2(
90
+ Dialog.Close,
91
+ {
92
+ "aria-label": labels.common.close,
93
+ disabled: isInitiating,
94
+ className: "flex size-11 cursor-pointer items-center justify-center rounded-agg-full text-agg-foreground hover:bg-agg-secondary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary disabled:cursor-not-allowed disabled:opacity-50",
95
+ children: /* @__PURE__ */ jsx2(Icon, { name: "close", size: "small", "aria-hidden": "true" })
96
+ }
97
+ ) }),
98
+ /* @__PURE__ */ jsx2(Modal.Body, { classNames: { root: "!px-8 !pb-9 !pt-0" }, children: state === "success" ? /* @__PURE__ */ jsxs2(
99
+ "div",
100
+ {
101
+ className: "flex flex-col items-center gap-6 text-center",
102
+ role: "status",
103
+ "aria-live": "polite",
104
+ children: [
105
+ /* @__PURE__ */ jsx2("div", { className: "flex size-12 items-center justify-center rounded-agg-full border border-agg-success bg-agg-success/10 text-agg-success", children: /* @__PURE__ */ jsx2(Icon, { name: "success-check", className: "size-5", "aria-hidden": "true" }) }),
106
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center gap-2", children: [
107
+ /* @__PURE__ */ jsx2(Dialog.Title, { children: /* @__PURE__ */ jsx2(Typography, { as: "span", variant: "body-large-strong", children: modalLabels.successTitle }) }),
108
+ /* @__PURE__ */ jsx2(Dialog.Description, { children: /* @__PURE__ */ jsx2(Typography, { as: "span", variant: "label", className: "text-pretty text-agg-foreground", children: modalLabels.successDescription }) })
109
+ ] }),
110
+ /* @__PURE__ */ jsx2(Button, { variant: "secondary", size: "large", onClick: () => handleOpenChange(false), children: modalLabels.done })
111
+ ]
112
+ }
113
+ ) : /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center gap-6 text-center", children: [
114
+ /* @__PURE__ */ jsx2(
115
+ Icon,
116
+ {
117
+ name: "user-trust",
118
+ className: "h-12! w-12! text-agg-muted-foreground",
119
+ "aria-hidden": "true"
120
+ }
121
+ ),
122
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center gap-2", children: [
123
+ /* @__PURE__ */ jsx2(Dialog.Title, { children: /* @__PURE__ */ jsx2(Typography, { as: "span", variant: "body-large-strong", children: state === "pending" ? modalLabels.pendingTitle : modalLabels.title }) }),
124
+ /* @__PURE__ */ jsx2(Dialog.Description, { children: /* @__PURE__ */ jsx2(Typography, { as: "span", variant: "label", className: "text-pretty text-agg-foreground", children: state === "pending" ? modalLabels.pendingDescription : modalLabels.freeDescription }) })
125
+ ] }),
126
+ state === "error" || state === "pending" && errorMessage ? /* @__PURE__ */ jsx2(
127
+ InlineAlert,
128
+ {
129
+ tone: "error",
130
+ variant: "surface",
131
+ message: errorMessage || modalLabels.error
132
+ }
133
+ ) : null,
134
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center gap-4", children: [
135
+ /* @__PURE__ */ jsx2(
136
+ Button,
137
+ {
138
+ variant: "primary",
139
+ size: "large",
140
+ isLoading: isInitiating,
141
+ disabled: isInitiating,
142
+ "aria-label": state === "pending" ? modalLabels.checkStatus : modalLabels.startVerification,
143
+ onClick: onStartVerification,
144
+ children: state === "pending" ? modalLabels.checkStatus : modalLabels.startVerification
145
+ }
146
+ ),
147
+ /* @__PURE__ */ jsx2(
148
+ Button,
149
+ {
150
+ variant: "tertiary",
151
+ size: "large",
152
+ disabled: isInitiating,
153
+ onClick: () => handleOpenChange(false),
154
+ children: modalLabels.doItLater
155
+ }
156
+ )
157
+ ] })
158
+ ] }) })
159
+ ]
160
+ }
161
+ ) });
162
+ };
163
+ SharedKycModal.displayName = "SharedKycModal";
164
+
165
+ // src/onboarding/steps/how-it-works.tsx
166
+ import { useCallback, useRef, useState } from "react";
167
+ import { useLabels as useLabels3 } from "@agg-build/hooks";
168
+
169
+ // src/onboarding/onboarding-modal.constants.ts
170
+ import { isVenueActive, Venue } from "@agg-build/sdk";
171
+ var HOW_IT_WORKS_FEATURE_KEYS = [
172
+ "createAccount",
173
+ "linkAccounts",
174
+ "bestPrices",
175
+ "stayInControl"
176
+ ];
177
+ var ONBOARDING_STEPS = {
178
+ HOW_IT_WORKS: 0,
179
+ PROFILE_SETUP: 1,
180
+ CONNECT_ACCOUNTS: 2
181
+ };
182
+ var ONCHAIN_VENUES = [
183
+ Venue.polymarket,
184
+ Venue.opinion,
185
+ Venue.predict,
186
+ Venue.pred
187
+ ].filter(isVenueActive);
188
+
189
+ // src/onboarding/steps/how-it-works.tsx
190
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
191
+ var defaultIcons = {
192
+ createAccount: /* @__PURE__ */ jsx3(CreateAccountIcon, { className: "h-[28px] w-[28px] text-agg-muted-foreground" }),
193
+ linkAccounts: /* @__PURE__ */ jsx3(LinkAccountsIcon, { className: "h-[28px] w-[28px] text-agg-muted-foreground" }),
194
+ bestPrices: /* @__PURE__ */ jsx3(BestPricesIcon, { className: "h-[28px] w-[28px] text-agg-muted-foreground" }),
195
+ stayInControl: /* @__PURE__ */ jsx3(StayInControlIcon, { className: "h-[28px] w-[28px] text-agg-muted-foreground" })
196
+ };
197
+ var HowItWorksStep = ({ onContinue, icons }) => {
198
+ const labels = useLabels3();
199
+ const scrollRef = useRef(null);
200
+ const [showTopGradient, setShowTopGradient] = useState(false);
201
+ const [showBottomGradient, setShowBottomGradient] = useState(true);
202
+ const handleScroll = useCallback(() => {
203
+ const el = scrollRef.current;
204
+ if (!el) return;
205
+ setShowTopGradient(el.scrollTop > 0);
206
+ setShowBottomGradient(el.scrollTop + el.clientHeight < el.scrollHeight - 1);
207
+ }, []);
208
+ return /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-6 h-[600px] sm:h-auto", children: [
209
+ /* @__PURE__ */ jsx3("h2", { className: "text-center text-agg-2xl font-agg-bold text-agg-foreground", children: labels.onboarding.howItWorks.title }),
210
+ /* @__PURE__ */ jsxs3("div", { className: "relative flex-1 min-h-0 sm:flex-initial", children: [
211
+ /* @__PURE__ */ jsx3(
212
+ "div",
213
+ {
214
+ ref: scrollRef,
215
+ onScroll: handleScroll,
216
+ className: "flex flex-col gap-4 overflow-y-auto sm:overflow-visible h-full",
217
+ children: HOW_IT_WORKS_FEATURE_KEYS.map((featureKey) => {
218
+ var _a;
219
+ const icon = (_a = icons == null ? void 0 : icons[featureKey]) != null ? _a : defaultIcons[featureKey];
220
+ const feature = labels.onboarding.howItWorks.features[featureKey];
221
+ return /* @__PURE__ */ jsxs3(
222
+ "div",
223
+ {
224
+ className: cn(
225
+ "flex items-center gap-4 py-4 px-5 sm:px-4",
226
+ "rounded-agg-md",
227
+ "bg-agg-secondary-hover"
228
+ ),
229
+ children: [
230
+ /* @__PURE__ */ jsxs3("div", { className: "flex flex-col flex-1 min-w-0 gap-[6px]", children: [
231
+ /* @__PURE__ */ jsx3("p", { className: "text-agg-base font-agg-bold leading-agg-6 text-agg-foreground", children: feature.title }),
232
+ /* @__PURE__ */ jsx3("p", { className: "text-agg-sm leading-agg-5 text-agg-foreground", children: feature.description })
233
+ ] }),
234
+ icon ? /* @__PURE__ */ jsx3("div", { className: "hidden shrink-0 items-center justify-center text-agg-muted-foreground sm:flex", children: icon }) : null
235
+ ]
236
+ },
237
+ featureKey
238
+ );
239
+ })
240
+ }
241
+ ),
242
+ /* @__PURE__ */ jsx3(
243
+ "div",
244
+ {
245
+ className: cn(
246
+ "pointer-events-none absolute inset-x-0 top-0 h-20",
247
+ "bg-gradient-to-b from-agg-secondary to-transparent",
248
+ "sm:hidden transition-opacity",
249
+ showTopGradient ? "opacity-100" : "opacity-0"
250
+ )
251
+ }
252
+ ),
253
+ /* @__PURE__ */ jsx3(
254
+ "div",
255
+ {
256
+ className: cn(
257
+ "pointer-events-none absolute inset-x-0 bottom-0 h-20",
258
+ "bg-gradient-to-t from-agg-secondary to-transparent",
259
+ "sm:hidden transition-opacity",
260
+ showBottomGradient ? "opacity-100" : "opacity-0"
261
+ )
262
+ }
263
+ )
264
+ ] }),
265
+ /* @__PURE__ */ jsx3(Button, { variant: "primary", size: "large", className: "w-full", onClick: onContinue, children: labels.onboarding.howItWorks.continue })
266
+ ] });
267
+ };
268
+ HowItWorksStep.displayName = "HowItWorksStep";
269
+
270
+ // src/onboarding/steps/profile-setup.tsx
271
+ import { useCallback as useCallback2, useRef as useRef2, useState as useState2 } from "react";
272
+ import { useLabels as useLabels4 } from "@agg-build/hooks";
273
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
274
+ var ProfileSetupStep = ({ onContinue }) => {
275
+ const labels = useLabels4();
276
+ const [username, setUsername] = useState2("");
277
+ const [avatarFile, setAvatarFile] = useState2();
278
+ const [avatarPreview, setAvatarPreview] = useState2();
279
+ const fileInputRef = useRef2(null);
280
+ const handleAvatarClick = useCallback2(() => {
281
+ var _a;
282
+ (_a = fileInputRef.current) == null ? void 0 : _a.click();
283
+ }, []);
284
+ const handleFileChange = useCallback2((e) => {
285
+ var _a;
286
+ const file = (_a = e.target.files) == null ? void 0 : _a[0];
287
+ if (!file) return;
288
+ setAvatarFile(file);
289
+ const reader = new FileReader();
290
+ reader.onload = (event) => {
291
+ var _a2;
292
+ setAvatarPreview((_a2 = event.target) == null ? void 0 : _a2.result);
293
+ };
294
+ reader.readAsDataURL(file);
295
+ }, []);
296
+ const handleContinue = useCallback2(() => {
297
+ onContinue({
298
+ username,
299
+ avatarFile,
300
+ avatarPreview
301
+ });
302
+ }, [username, avatarFile, avatarPreview, onContinue]);
303
+ return /* @__PURE__ */ jsxs4("div", { className: "flex flex-col gap-7", children: [
304
+ /* @__PURE__ */ jsx4("h2", { className: "text-center text-agg-2xl font-agg-bold text-agg-foreground", children: labels.onboarding.profileSetup.title }),
305
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-col gap-5 items-center w-full", children: [
306
+ /* @__PURE__ */ jsxs4("div", { className: "flex justify-center", children: [
307
+ /* @__PURE__ */ jsxs4(
308
+ "button",
309
+ {
310
+ type: "button",
311
+ onClick: handleAvatarClick,
312
+ className: cn(
313
+ "group relative flex items-center justify-center",
314
+ "h-[80px] w-[80px]",
315
+ "rounded-agg-full",
316
+ "bg-agg-secondary-hover",
317
+ !avatarPreview && "hover:bg-agg-tertiary",
318
+ "transition-colors cursor-pointer",
319
+ "overflow-hidden"
320
+ ),
321
+ "aria-label": labels.onboarding.profileSetup.uploadProfilePictureAria,
322
+ children: [
323
+ !avatarPreview ? /* @__PURE__ */ jsx4(
324
+ "svg",
325
+ {
326
+ "aria-hidden": true,
327
+ viewBox: "0 0 80 80",
328
+ className: "pointer-events-none absolute inset-0 h-full w-full text-agg-separator group-hover:text-agg-muted-foreground",
329
+ children: /* @__PURE__ */ jsx4(
330
+ "circle",
331
+ {
332
+ cx: "40",
333
+ cy: "40",
334
+ r: "39.5",
335
+ fill: "none",
336
+ stroke: "currentColor",
337
+ strokeWidth: "1",
338
+ strokeDasharray: "8 8"
339
+ }
340
+ )
341
+ }
342
+ ) : null,
343
+ avatarPreview ? /* @__PURE__ */ jsx4(
344
+ RemoteImage,
345
+ {
346
+ src: avatarPreview,
347
+ alt: labels.onboarding.profileSetup.profilePreviewAlt,
348
+ className: "h-full w-full object-cover"
349
+ }
350
+ ) : /* @__PURE__ */ jsx4(ProfileIcon, { className: "h-7 w-7 text-agg-muted-foreground" })
351
+ ]
352
+ }
353
+ ),
354
+ /* @__PURE__ */ jsx4(
355
+ "input",
356
+ {
357
+ ref: fileInputRef,
358
+ type: "file",
359
+ accept: "image/*",
360
+ onChange: handleFileChange,
361
+ className: "hidden",
362
+ "aria-hidden": "true"
363
+ }
364
+ )
365
+ ] }),
366
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-col gap-2 w-full", children: [
367
+ /* @__PURE__ */ jsx4(
368
+ "label",
369
+ {
370
+ htmlFor: "onboarding-username",
371
+ className: "text-agg-sm font-agg-bold text-agg-foreground",
372
+ children: labels.onboarding.profileSetup.usernameLabel
373
+ }
374
+ ),
375
+ /* @__PURE__ */ jsx4(
376
+ "input",
377
+ {
378
+ id: "onboarding-username",
379
+ type: "text",
380
+ value: username,
381
+ onChange: (e) => setUsername(e.target.value),
382
+ placeholder: labels.onboarding.profileSetup.usernamePlaceholder,
383
+ className: cn(
384
+ "w-full px-3 py-2.5",
385
+ "rounded-[4px]",
386
+ "border border-agg-separator",
387
+ "bg-agg-secondary text-agg-foreground",
388
+ "placeholder:text-agg-muted-foreground",
389
+ "outline-none",
390
+ "hover:bg-agg-secondary-hover",
391
+ "focus:border-agg-primary focus:ring-1 focus:ring-agg-primary",
392
+ "transition-colors",
393
+ "text-agg-sm sm:text-agg-base"
394
+ )
395
+ }
396
+ )
397
+ ] })
398
+ ] }),
399
+ /* @__PURE__ */ jsx4(Button, { variant: "primary", size: "large", className: "w-full", onClick: handleContinue, children: labels.onboarding.profileSetup.continue })
400
+ ] });
401
+ };
402
+ ProfileSetupStep.displayName = "ProfileSetupStep";
403
+
404
+ // src/onboarding/steps/connect-accounts.tsx
405
+ import { useLabels as useLabels5 } from "@agg-build/hooks";
406
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
407
+ var OnchainVenueLogos = () => {
408
+ return /* @__PURE__ */ jsx5("div", { className: "flex gap-1 sm:gap-0 sm:-space-x-5", children: ONCHAIN_VENUES.map((venue, index) => /* @__PURE__ */ jsx5("div", { style: { zIndex: ONCHAIN_VENUES.length - index }, children: /* @__PURE__ */ jsx5(VenueLogo, { venue, variant: "logo", size: "medium", className: "sm:h-8 sm:w-8" }) }, venue)) });
409
+ };
410
+ var VenueCard = ({
411
+ logos,
412
+ title,
413
+ mobileTitle,
414
+ description,
415
+ mobileDescription,
416
+ onConnect,
417
+ connected = false
418
+ }) => {
419
+ const labels = useLabels5();
420
+ const action = connected ? /* @__PURE__ */ jsx5(CheckCircleIcon, { className: "h-6 w-6 text-agg-success" }) : /* @__PURE__ */ jsx5(
421
+ Button,
422
+ {
423
+ variant: "tertiary",
424
+ size: "large",
425
+ className: "!h-auto !px-0 !py-0 text-agg-primary hover:bg-transparent hover:text-agg-primary-hover",
426
+ onClick: onConnect,
427
+ children: labels.onboarding.connectAccounts.connect
428
+ }
429
+ );
430
+ const mobileAction = connected ? /* @__PURE__ */ jsx5(CheckCircleIcon, { className: "h-6 w-6 text-agg-success" }) : /* @__PURE__ */ jsx5(
431
+ Button,
432
+ {
433
+ variant: "tertiary",
434
+ size: "medium",
435
+ className: "!h-auto !px-0 !py-0 text-agg-primary hover:bg-transparent hover:text-agg-primary-hover",
436
+ onClick: onConnect,
437
+ suffix: /* @__PURE__ */ jsx5(ChevronRightIcon, { className: "h-4 w-4" }),
438
+ children: labels.onboarding.connectAccounts.connectAccount
439
+ }
440
+ );
441
+ return /* @__PURE__ */ jsxs5(
442
+ "div",
443
+ {
444
+ className: cn(
445
+ "rounded-agg-md p-5 transition-colors",
446
+ connected ? "bg-agg-success/5" : "bg-agg-secondary-hover hover:bg-agg-tertiary"
447
+ ),
448
+ children: [
449
+ /* @__PURE__ */ jsxs5("div", { className: "hidden sm:flex items-center justify-between", children: [
450
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-5", children: [
451
+ /* @__PURE__ */ jsx5("div", { className: "shrink-0", children: logos }),
452
+ /* @__PURE__ */ jsxs5("div", { className: "flex flex-col gap-[2px]", children: [
453
+ /* @__PURE__ */ jsx5("p", { className: "text-agg-base font-agg-bold text-agg-foreground", children: title }),
454
+ /* @__PURE__ */ jsx5("p", { className: "text-agg-sm text-agg-foreground", children: description })
455
+ ] })
456
+ ] }),
457
+ /* @__PURE__ */ jsx5("div", { className: "shrink-0", children: action })
458
+ ] }),
459
+ /* @__PURE__ */ jsxs5("div", { className: "flex flex-col gap-3 sm:hidden", children: [
460
+ /* @__PURE__ */ jsxs5("div", { className: "flex flex-col gap-3", children: [
461
+ /* @__PURE__ */ jsx5("div", { className: "shrink-0", children: logos }),
462
+ /* @__PURE__ */ jsx5("p", { className: "text-agg-lg font-agg-bold text-agg-foreground", children: mobileTitle != null ? mobileTitle : title })
463
+ ] }),
464
+ /* @__PURE__ */ jsxs5("div", { className: "flex flex-col items-start gap-2", children: [
465
+ /* @__PURE__ */ jsx5("p", { className: "text-agg-base text-agg-foreground", children: mobileDescription != null ? mobileDescription : description }),
466
+ mobileAction
467
+ ] })
468
+ ] })
469
+ ]
470
+ }
471
+ );
472
+ };
473
+ var ConnectAccountsStep = ({
474
+ onConnectOnchain,
475
+ onContinue,
476
+ connectedOnchain = false
477
+ }) => {
478
+ const labels = useLabels5();
479
+ const canContinue = connectedOnchain;
480
+ return /* @__PURE__ */ jsxs5("div", { className: "flex flex-col gap-6", children: [
481
+ /* @__PURE__ */ jsx5("h2", { className: "text-center text-agg-2xl font-agg-bold text-agg-foreground", children: labels.onboarding.connectAccounts.title }),
482
+ /* @__PURE__ */ jsx5("div", { className: "flex flex-col gap-4", children: /* @__PURE__ */ jsx5(
483
+ VenueCard,
484
+ {
485
+ logos: /* @__PURE__ */ jsx5(OnchainVenueLogos, {}),
486
+ title: labels.onboarding.connectAccounts.onchainTitle,
487
+ mobileTitle: labels.onboarding.connectAccounts.onchainMobileTitle(
488
+ ONCHAIN_VENUES.length - 1
489
+ ),
490
+ description: labels.onboarding.connectAccounts.onchainDescription,
491
+ mobileDescription: labels.onboarding.connectAccounts.onchainMobileDescription,
492
+ onConnect: onConnectOnchain,
493
+ connected: connectedOnchain
494
+ }
495
+ ) }),
496
+ /* @__PURE__ */ jsx5(
497
+ Button,
498
+ {
499
+ variant: "primary",
500
+ size: "large",
501
+ className: "w-full",
502
+ onClick: onContinue,
503
+ disabled: !canContinue,
504
+ children: labels.onboarding.connectAccounts.continue
505
+ }
506
+ )
507
+ ] });
508
+ };
509
+ ConnectAccountsStep.displayName = "ConnectAccountsStep";
510
+
511
+ // src/onboarding/steps/connect-onchain-modal.tsx
512
+ import { useCallback as useCallback3, useState as useState3 } from "react";
513
+ import { useLabels as useLabels6 } from "@agg-build/hooks";
514
+ import * as Dialog2 from "@radix-ui/react-dialog";
515
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
516
+ var ConnectOnchainModal = ({
517
+ open,
518
+ onOpenChange,
519
+ onConnect
520
+ }) => {
521
+ const labels = useLabels6();
522
+ const [connecting, setConnecting] = useState3(false);
523
+ const [error, setError] = useState3();
524
+ const handleCancel = useCallback3(() => {
525
+ onOpenChange(false);
526
+ }, [onOpenChange]);
527
+ const handleConnect = useCallback3(() => __async(null, null, function* () {
528
+ if (connecting) return;
529
+ setConnecting(true);
530
+ setError(void 0);
531
+ try {
532
+ yield onConnect();
533
+ onOpenChange(false);
534
+ } catch (err) {
535
+ setError(
536
+ err instanceof Error ? err.message : labels.onboarding.connectOnchainModal.fallbackError
537
+ );
538
+ } finally {
539
+ setConnecting(false);
540
+ }
541
+ }), [connecting, labels.onboarding.connectOnchainModal.fallbackError, onConnect, onOpenChange]);
542
+ const handleOpenChange = useCallback3(
543
+ (value) => {
544
+ if (value) {
545
+ setError(void 0);
546
+ setConnecting(false);
547
+ }
548
+ onOpenChange(value);
549
+ },
550
+ [onOpenChange]
551
+ );
552
+ return /* @__PURE__ */ jsx6(Modal, { open, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs6(
553
+ Modal.Container,
554
+ {
555
+ maxWidth: "600px",
556
+ "aria-label": labels.onboarding.connectOnchainModal.ariaLabel,
557
+ classNames: { container: "!rounded-agg-lg" },
558
+ children: [
559
+ /* @__PURE__ */ jsx6(Dialog2.Title, { className: "sr-only", children: labels.onboarding.connectOnchainModal.title }),
560
+ /* @__PURE__ */ jsx6(
561
+ Modal.Header,
562
+ {
563
+ hideClose: false,
564
+ hideBorder: true,
565
+ classNames: {
566
+ root: "!min-h-0",
567
+ container: "!py-[18px] !px-8"
568
+ }
569
+ }
570
+ ),
571
+ /* @__PURE__ */ jsx6(Modal.Body, { classNames: { root: "!px-5 !pt-0 !pb-[60px] sm:!px-8" }, children: /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-8 items-center", children: [
572
+ /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-4 items-center text-center", children: [
573
+ /* @__PURE__ */ jsx6("h2", { className: "text-agg-2xl font-agg-bold text-agg-foreground", children: labels.onboarding.connectOnchainModal.title }),
574
+ /* @__PURE__ */ jsx6("p", { className: "text-agg-base text-center leading-agg-6 text-agg-foreground whitespace-pre-line", children: labels.onboarding.connectOnchainModal.description })
575
+ ] }),
576
+ /* @__PURE__ */ jsxs6("div", { className: "flex w-full flex-col items-center gap-4 rounded-agg-xl bg-agg-secondary-hover p-6", children: [
577
+ /* @__PURE__ */ jsx6("p", { className: "text-agg-sm font-agg-bold uppercase leading-agg-5 text-agg-muted-foreground", children: labels.onboarding.connectOnchainModal.supportedVenuesLabel }),
578
+ /* @__PURE__ */ jsx6("div", { className: "flex flex-wrap items-center justify-center gap-x-4 gap-y-3", children: ONCHAIN_VENUES.map((venue, index) => /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-[6px]", children: [
579
+ index > 0 && /* @__PURE__ */ jsx6("span", { className: "mr-2.5 h-3 w-px bg-agg-separator" }),
580
+ /* @__PURE__ */ jsx6(VenueLogo, { venue, size: "medium" }),
581
+ /* @__PURE__ */ jsx6("span", { className: "text-agg-base text-agg-foreground", children: labels.venues[venue] })
582
+ ] }, venue)) })
583
+ ] }),
584
+ /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-6 items-center", children: [
585
+ /* @__PURE__ */ jsxs6("div", { className: "flex flex-col gap-3 items-center", children: [
586
+ error ? /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-2", children: [
587
+ /* @__PURE__ */ jsx6(WarningIcon, { className: "h-3.5 w-3.5 shrink-0 text-agg-error" }),
588
+ /* @__PURE__ */ jsx6("p", { className: "text-agg-sm leading-agg-5 text-agg-error", children: error })
589
+ ] }) : null,
590
+ /* @__PURE__ */ jsx6(
591
+ Button,
592
+ {
593
+ variant: "primary",
594
+ size: "large",
595
+ onClick: handleConnect,
596
+ isLoading: connecting,
597
+ children: labels.onboarding.connectOnchainModal.connect
598
+ }
599
+ )
600
+ ] }),
601
+ /* @__PURE__ */ jsx6(
602
+ Button,
603
+ {
604
+ variant: "tertiary",
605
+ size: "medium",
606
+ className: "!h-auto !px-0 !py-0 text-agg-primary hover:bg-transparent hover:text-agg-primary-hover",
607
+ onClick: handleCancel,
608
+ children: labels.onboarding.connectOnchainModal.cancel
609
+ }
610
+ )
611
+ ] })
612
+ ] }) })
613
+ ]
614
+ }
615
+ ) });
616
+ };
617
+ ConnectOnchainModal.displayName = "ConnectOnchainModal";
618
+
619
+ // src/onboarding/steps/connect-kalshi-modal.tsx
620
+ import { getVenueAvailabilityState, useAppConfig, useLabels as useLabels7 } from "@agg-build/hooks";
621
+ import { Venue as Venue2 } from "@agg-build/sdk";
622
+ import * as Dialog3 from "@radix-ui/react-dialog";
623
+ import { useCallback as useCallback4, useEffect, useId, useMemo, useRef as useRef3, useState as useState4 } from "react";
624
+ import { z } from "zod";
625
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
626
+ var kalshiCredentialsSchema = z.object({
627
+ apiKeyId: z.string().trim().min(1),
628
+ privateKey: z.string().trim().min(1)
629
+ });
630
+ var getSafeConnectionError = ({
631
+ apiKeyId,
632
+ error,
633
+ fallback,
634
+ privateKey
635
+ }) => {
636
+ if (!(error instanceof Error) || !error.message.trim()) return fallback;
637
+ return [apiKeyId, privateKey].filter(Boolean).reduce(
638
+ (message, sensitiveValue) => message.split(sensitiveValue).join("[redacted]"),
639
+ error.message
640
+ ).trim();
641
+ };
642
+ var CloseButton = ({
643
+ className,
644
+ disabled
645
+ }) => {
646
+ const labels = useLabels7();
647
+ return /* @__PURE__ */ jsx7(
648
+ Dialog3.Close,
649
+ {
650
+ "aria-label": labels.common.close,
651
+ disabled,
652
+ className: cn(
653
+ "z-30 flex size-6 cursor-pointer items-center justify-center rounded-agg-full",
654
+ "text-agg-foreground transition-colors hover:text-agg-foreground/80",
655
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-accent",
656
+ "disabled:cursor-not-allowed disabled:opacity-50",
657
+ className
658
+ ),
659
+ children: /* @__PURE__ */ jsx7(Icon, { name: "close", size: "medium", className: "!text-agg-foreground" })
660
+ }
661
+ );
662
+ };
663
+ var ConnectKalshiModal = ({
664
+ open,
665
+ onOpenChange,
666
+ onVerify
667
+ }) => {
668
+ const labels = useLabels7();
669
+ const { disabledVenues, isLoading: isAppConfigLoading } = useAppConfig();
670
+ const apiKeyInputRef = useRef3(null);
671
+ const errorId = useId();
672
+ const [apiKeyId, setApiKeyId] = useState4("");
673
+ const [privateKey, setPrivateKey] = useState4("");
674
+ const [isVerifying, setIsVerifying] = useState4(false);
675
+ const [isConnected, setIsConnected] = useState4(false);
676
+ const [error, setError] = useState4();
677
+ const availabilityState = getVenueAvailabilityState({
678
+ venueId: Venue2.kalshi,
679
+ disabledVenues,
680
+ isConfigLoading: isAppConfigLoading
681
+ });
682
+ const parsedCredentials = useMemo(
683
+ () => kalshiCredentialsSchema.safeParse({ apiKeyId, privateKey }),
684
+ [apiKeyId, privateKey]
685
+ );
686
+ useEffect(() => {
687
+ if (!open) return;
688
+ setApiKeyId("");
689
+ setPrivateKey("");
690
+ setError(void 0);
691
+ setIsVerifying(false);
692
+ setIsConnected(false);
693
+ }, [open]);
694
+ const handleOpenAutoFocus = useCallback4((event) => {
695
+ var _a;
696
+ event.preventDefault();
697
+ (_a = apiKeyInputRef.current) == null ? void 0 : _a.focus({ preventScroll: true });
698
+ }, []);
699
+ const handleOpenChange = useCallback4(
700
+ (nextOpen) => {
701
+ if (isVerifying && !nextOpen) return;
702
+ onOpenChange(nextOpen);
703
+ },
704
+ [isVerifying, onOpenChange]
705
+ );
706
+ const handleVerify = useCallback4(() => __async(null, null, function* () {
707
+ if (!parsedCredentials.success || isVerifying || isConnected) return;
708
+ const credentials = parsedCredentials.data;
709
+ setIsVerifying(true);
710
+ setError(void 0);
711
+ try {
712
+ yield onVerify(credentials);
713
+ setApiKeyId("");
714
+ setPrivateKey("");
715
+ setIsConnected(true);
716
+ } catch (verificationError) {
717
+ setError(
718
+ getSafeConnectionError(__spreadProps(__spreadValues({}, credentials), {
719
+ error: verificationError,
720
+ fallback: labels.onboarding.connectKalshiModal.fallbackError
721
+ }))
722
+ );
723
+ } finally {
724
+ setIsVerifying(false);
725
+ }
726
+ }), [
727
+ isConnected,
728
+ isVerifying,
729
+ labels.onboarding.connectKalshiModal.fallbackError,
730
+ onVerify,
731
+ parsedCredentials
732
+ ]);
733
+ const handleSubmit = useCallback4(
734
+ (event) => {
735
+ event.preventDefault();
736
+ void handleVerify();
737
+ },
738
+ [handleVerify]
739
+ );
740
+ if (availabilityState === "hidden") return null;
741
+ return /* @__PURE__ */ jsx7(Modal, { open, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsx7(
742
+ Modal.Container,
743
+ {
744
+ maxWidth: isConnected ? "480px" : "600px",
745
+ "aria-label": labels.onboarding.connectKalshiModal.ariaLabel,
746
+ classNames: {
747
+ container: "!rounded-t-agg-xl !rounded-b-none md:!rounded-agg-2xl"
748
+ },
749
+ onOpenAutoFocus: isConnected ? void 0 : handleOpenAutoFocus,
750
+ children: isConnected ? /* @__PURE__ */ jsxs7(Modal.Body, { classNames: { root: "relative !px-5 !py-8 md:!px-10 md:!py-12" }, children: [
751
+ /* @__PURE__ */ jsx7(CloseButton, { className: "absolute right-5 top-5 md:right-8 md:top-8" }),
752
+ /* @__PURE__ */ jsxs7(
753
+ "div",
754
+ {
755
+ className: "flex flex-col items-center gap-8 text-center",
756
+ role: "status",
757
+ "aria-live": "polite",
758
+ children: [
759
+ /* @__PURE__ */ jsx7("div", { className: "flex size-[60px] items-center justify-center rounded-agg-full bg-agg-success/15", children: /* @__PURE__ */ jsx7(Icon, { name: "success-check", className: "size-6 text-agg-success", "aria-hidden": "true" }) }),
760
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col items-center gap-3", children: [
761
+ /* @__PURE__ */ jsx7(Dialog3.Title, { className: "text-agg-2xl font-agg-bold leading-agg-8 text-agg-foreground", children: labels.onboarding.connectKalshiModal.success.title }),
762
+ /* @__PURE__ */ jsx7(Dialog3.Description, { className: "text-agg-base leading-agg-6 text-agg-foreground", children: labels.onboarding.connectKalshiModal.success.description })
763
+ ] }),
764
+ /* @__PURE__ */ jsx7(Button, { variant: "secondary", size: "large", onClick: () => handleOpenChange(false), children: labels.onboarding.connectKalshiModal.success.done })
765
+ ]
766
+ }
767
+ )
768
+ ] }) : /* @__PURE__ */ jsxs7("form", { className: "flex min-h-0 flex-1 flex-col", onSubmit: handleSubmit, children: [
769
+ /* @__PURE__ */ jsx7(
770
+ Modal.Body,
771
+ {
772
+ classNames: { root: "relative !px-5 !pb-6 !pt-5 md:!px-10 md:!pb-0 md:!pt-12" },
773
+ children: /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-6 md:items-center md:gap-0", children: [
774
+ /* @__PURE__ */ jsxs7("div", { className: "flex w-full flex-col md:contents", children: [
775
+ /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-3 md:contents", children: [
776
+ /* @__PURE__ */ jsx7(
777
+ VenueLogo,
778
+ {
779
+ venue: Venue2.kalshi,
780
+ variant: "logo",
781
+ size: "large",
782
+ className: "!size-10 md:!mb-8 md:!size-[60px]"
783
+ }
784
+ ),
785
+ /* @__PURE__ */ jsx7(Dialog3.Title, { className: "text-agg-lg font-agg-bold leading-agg-7 text-agg-foreground md:mb-4 md:text-center md:text-agg-2xl md:leading-agg-8", children: labels.onboarding.connectKalshiModal.title }),
786
+ /* @__PURE__ */ jsx7(
787
+ CloseButton,
788
+ {
789
+ disabled: isVerifying,
790
+ className: "ml-auto shrink-0 md:absolute md:right-8 md:top-8 md:ml-0"
791
+ }
792
+ )
793
+ ] }),
794
+ /* @__PURE__ */ jsx7(Dialog3.Description, { className: "mt-3 text-agg-sm leading-agg-5 text-agg-foreground md:mb-8 md:mt-0 md:text-center md:text-agg-base md:leading-agg-6", children: labels.onboarding.connectKalshiModal.description })
795
+ ] }),
796
+ /* @__PURE__ */ jsxs7("div", { className: "flex w-full flex-col gap-4", children: [
797
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-3 rounded-agg-xl bg-agg-secondary-hover p-4", children: [
798
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-1", children: [
799
+ /* @__PURE__ */ jsx7("p", { className: "text-agg-xs font-agg-bold uppercase leading-agg-4 text-agg-muted-foreground", children: labels.onboarding.connectKalshiModal.stepOne.label }),
800
+ /* @__PURE__ */ jsx7("p", { className: "text-agg-sm font-agg-bold leading-agg-5 text-agg-foreground", children: labels.onboarding.connectKalshiModal.stepOne.title })
801
+ ] }),
802
+ /* @__PURE__ */ jsxs7("div", { className: "text-agg-sm leading-agg-5 text-agg-foreground", children: [
803
+ /* @__PURE__ */ jsx7("p", { children: labels.onboarding.connectKalshiModal.stepOne.instructions.signIn }),
804
+ /* @__PURE__ */ jsxs7("p", { children: [
805
+ labels.onboarding.connectKalshiModal.stepOne.instructions.goToProfilePrefix,
806
+ " ",
807
+ /* @__PURE__ */ jsx7("span", { className: "font-agg-bold", children: labels.onboarding.connectKalshiModal.stepOne.instructions.profileText }),
808
+ labels.onboarding.connectKalshiModal.stepOne.instructions.goToProfileSeparator,
809
+ " ",
810
+ /* @__PURE__ */ jsx7(
811
+ "a",
812
+ {
813
+ href: labels.onboarding.connectKalshiModal.stepOne.instructions.profileUrl,
814
+ target: "_blank",
815
+ rel: "noreferrer",
816
+ className: "cursor-pointer underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary",
817
+ children: labels.onboarding.connectKalshiModal.stepOne.instructions.profileUrl
818
+ }
819
+ )
820
+ ] }),
821
+ /* @__PURE__ */ jsxs7("p", { children: [
822
+ labels.onboarding.connectKalshiModal.stepOne.instructions.clickCreateKeyPrefix,
823
+ " ",
824
+ /* @__PURE__ */ jsx7("span", { className: "font-agg-bold", children: labels.onboarding.connectKalshiModal.stepOne.instructions.createKeyText }),
825
+ labels.onboarding.connectKalshiModal.stepOne.instructions.clickCreateKeySuffix
826
+ ] }),
827
+ /* @__PURE__ */ jsxs7("p", { children: [
828
+ labels.onboarding.connectKalshiModal.stepOne.instructions.selectPermissionsPrefix,
829
+ " ",
830
+ /* @__PURE__ */ jsx7("span", { className: "font-agg-bold", children: labels.onboarding.connectKalshiModal.stepOne.instructions.readWriteText }),
831
+ labels.onboarding.connectKalshiModal.stepOne.instructions.selectPermissionsSuffix
832
+ ] }),
833
+ /* @__PURE__ */ jsx7("p", { children: labels.onboarding.connectKalshiModal.stepOne.instructions.createKey })
834
+ ] }),
835
+ /* @__PURE__ */ jsxs7("p", { className: "text-agg-sm leading-agg-5 text-agg-foreground", children: [
836
+ labels.onboarding.connectKalshiModal.stepOne.footerLineOne,
837
+ /* @__PURE__ */ jsx7("br", {}),
838
+ labels.onboarding.connectKalshiModal.stepOne.footerLineTwo
839
+ ] })
840
+ ] }),
841
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-3 rounded-agg-xl bg-agg-secondary-hover p-4", children: [
842
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-1", children: [
843
+ /* @__PURE__ */ jsx7("p", { className: "text-agg-xs font-agg-bold uppercase leading-agg-4 text-agg-muted-foreground", children: labels.onboarding.connectKalshiModal.stepTwo.label }),
844
+ /* @__PURE__ */ jsx7("p", { className: "text-agg-sm font-agg-bold leading-agg-5 text-agg-foreground", children: labels.onboarding.connectKalshiModal.stepTwo.title })
845
+ ] }),
846
+ /* @__PURE__ */ jsx7("p", { className: "text-agg-sm leading-agg-5 text-agg-foreground", children: labels.onboarding.connectKalshiModal.stepTwo.description }),
847
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-2", children: [
848
+ /* @__PURE__ */ jsx7(
849
+ "label",
850
+ {
851
+ htmlFor: "kalshi-api-key-id",
852
+ className: "text-agg-sm font-agg-bold text-agg-foreground",
853
+ children: labels.onboarding.connectKalshiModal.stepTwo.apiKeyIdLabel
854
+ }
855
+ ),
856
+ /* @__PURE__ */ jsx7(
857
+ "input",
858
+ {
859
+ ref: apiKeyInputRef,
860
+ id: "kalshi-api-key-id",
861
+ type: "text",
862
+ autoComplete: "off",
863
+ value: apiKeyId,
864
+ onChange: (event) => setApiKeyId(event.target.value),
865
+ placeholder: labels.onboarding.connectKalshiModal.stepTwo.apiKeyIdPlaceholder,
866
+ disabled: isVerifying,
867
+ "aria-invalid": !!error,
868
+ "aria-describedby": error ? errorId : void 0,
869
+ className: cn(
870
+ "h-10 w-full rounded-agg-sm border border-agg-separator bg-agg-secondary px-3 py-2.5",
871
+ "text-agg-base text-agg-foreground placeholder:text-agg-muted-foreground",
872
+ "outline-none transition-colors focus:border-agg-primary focus:ring-1 focus:ring-agg-primary",
873
+ "disabled:cursor-not-allowed disabled:opacity-60"
874
+ )
875
+ }
876
+ )
877
+ ] }),
878
+ /* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-2", children: [
879
+ /* @__PURE__ */ jsx7(
880
+ "label",
881
+ {
882
+ htmlFor: "kalshi-private-key",
883
+ className: "text-agg-sm font-agg-bold text-agg-foreground",
884
+ children: labels.onboarding.connectKalshiModal.stepTwo.privateKeyLabel
885
+ }
886
+ ),
887
+ /* @__PURE__ */ jsx7(
888
+ "textarea",
889
+ {
890
+ id: "kalshi-private-key",
891
+ autoComplete: "off",
892
+ value: privateKey,
893
+ onChange: (event) => setPrivateKey(event.target.value),
894
+ placeholder: labels.onboarding.connectKalshiModal.stepTwo.privateKeyPlaceholder,
895
+ rows: 3,
896
+ disabled: isVerifying,
897
+ "aria-invalid": !!error,
898
+ "aria-describedby": error ? errorId : void 0,
899
+ className: cn(
900
+ "w-full resize-none rounded-agg-sm border border-agg-separator bg-agg-secondary px-3 py-2.5",
901
+ "text-agg-base text-agg-foreground placeholder:text-agg-muted-foreground",
902
+ "outline-none transition-colors focus:border-agg-primary focus:ring-1 focus:ring-agg-primary",
903
+ "disabled:cursor-not-allowed disabled:opacity-60"
904
+ )
905
+ }
906
+ )
907
+ ] })
908
+ ] })
909
+ ] }),
910
+ error ? /* @__PURE__ */ jsxs7(
911
+ "div",
912
+ {
913
+ id: errorId,
914
+ className: "flex items-center gap-2 md:justify-center",
915
+ role: "alert",
916
+ "aria-live": "assertive",
917
+ children: [
918
+ /* @__PURE__ */ jsx7(Icon, { name: "warning", size: "small", className: "size-3.5 text-agg-error" }),
919
+ /* @__PURE__ */ jsx7("p", { className: "text-agg-sm leading-agg-5 text-agg-error", children: error })
920
+ ]
921
+ }
922
+ ) : null
923
+ ] })
924
+ }
925
+ ),
926
+ /* @__PURE__ */ jsxs7(
927
+ Modal.Footer,
928
+ {
929
+ classNames: {
930
+ root: "relative !h-auto !gap-3 !p-4 md:!justify-center md:!border-0 md:!px-10 md:!pb-12 md:!pt-8"
931
+ },
932
+ children: [
933
+ /* @__PURE__ */ jsx7(
934
+ "div",
935
+ {
936
+ "aria-hidden": "true",
937
+ className: "pointer-events-none absolute inset-x-0 -top-[60px] h-[60px] bg-gradient-to-b from-transparent to-agg-secondary md:hidden"
938
+ }
939
+ ),
940
+ /* @__PURE__ */ jsx7(
941
+ Button,
942
+ {
943
+ variant: "secondary",
944
+ size: "large",
945
+ className: "shrink-0",
946
+ onClick: () => handleOpenChange(false),
947
+ disabled: isVerifying,
948
+ children: labels.onboarding.connectKalshiModal.actions.cancel
949
+ }
950
+ ),
951
+ /* @__PURE__ */ jsx7(
952
+ Button,
953
+ {
954
+ type: "submit",
955
+ variant: "primary",
956
+ size: "large",
957
+ className: "flex-1 md:flex-none",
958
+ disabled: !parsedCredentials.success || isVerifying,
959
+ isLoading: isVerifying,
960
+ children: labels.onboarding.connectKalshiModal.actions.verifyConnection
961
+ }
962
+ )
963
+ ]
964
+ }
965
+ )
966
+ ] })
967
+ }
968
+ ) });
969
+ };
970
+ ConnectKalshiModal.displayName = "ConnectKalshiModal";
971
+
972
+ // src/onboarding/steps/connect-prophetx-modal.tsx
973
+ import { useAppConfig as useAppConfig2, useLabels as useLabels8 } from "@agg-build/hooks";
974
+ import { Venue as Venue3 } from "@agg-build/sdk";
975
+ import * as Dialog4 from "@radix-ui/react-dialog";
976
+ import { useEffect as useEffect2, useId as useId2, useState as useState5 } from "react";
977
+ import { Fragment, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
978
+ function ConnectProphetxModal({
979
+ open,
980
+ onOpenChange,
981
+ onVerify,
982
+ onDisconnect,
983
+ allowExistingConnection = false
984
+ }) {
985
+ const copy = useLabels8().onboarding.connectProphetxModal;
986
+ const common = useLabels8().common;
987
+ const { prophetxExecutionMode, disabledVenues, isLoading } = useAppConfig2();
988
+ const id = useId2();
989
+ const [accessKey, setAccessKey] = useState5("");
990
+ const [secretKey, setSecretKey] = useState5("");
991
+ const [pending, setPending] = useState5(false);
992
+ const [disconnecting, setDisconnecting] = useState5(false);
993
+ const [disconnectError, setDisconnectError] = useState5(false);
994
+ const busy = pending || disconnecting;
995
+ const [connected, setConnected] = useState5(false);
996
+ const [error, setError] = useState5(false);
997
+ useEffect2(() => {
998
+ if (!open) {
999
+ setAccessKey("");
1000
+ setSecretKey("");
1001
+ setError(false);
1002
+ setDisconnectError(false);
1003
+ setConnected(false);
1004
+ }
1005
+ }, [open]);
1006
+ if (isLoading || !allowExistingConnection && (prophetxExecutionMode !== "direct" || disabledVenues.includes(Venue3.prophetx)))
1007
+ return null;
1008
+ return /* @__PURE__ */ jsx8(
1009
+ Modal,
1010
+ {
1011
+ open,
1012
+ onOpenChange: (value) => {
1013
+ if (!busy) onOpenChange(value);
1014
+ },
1015
+ children: /* @__PURE__ */ jsx8(Modal.Container, { maxWidth: "480px", "aria-label": copy.title, children: /* @__PURE__ */ jsxs8(Modal.Body, { classNames: { root: "relative !p-6" }, children: [
1016
+ /* @__PURE__ */ jsx8(
1017
+ Dialog4.Close,
1018
+ {
1019
+ "aria-label": common.close,
1020
+ disabled: busy,
1021
+ className: "absolute right-4 top-4 cursor-pointer disabled:cursor-not-allowed",
1022
+ children: /* @__PURE__ */ jsx8(Icon, { name: "close", size: "medium" })
1023
+ }
1024
+ ),
1025
+ /* @__PURE__ */ jsxs8(
1026
+ "form",
1027
+ {
1028
+ className: "flex flex-col gap-4",
1029
+ onSubmit: (event) => __async(null, null, function* () {
1030
+ event.preventDefault();
1031
+ if (busy || !accessKey.trim() || !secretKey.trim()) return;
1032
+ setPending(true);
1033
+ setError(false);
1034
+ try {
1035
+ yield onVerify({ accessKey: accessKey.trim(), secretKey: secretKey.trim() });
1036
+ setAccessKey("");
1037
+ setSecretKey("");
1038
+ setConnected(true);
1039
+ } catch (e) {
1040
+ setError(true);
1041
+ } finally {
1042
+ setPending(false);
1043
+ }
1044
+ }),
1045
+ children: [
1046
+ /* @__PURE__ */ jsx8(VenueLogo, { venue: Venue3.prophetx, size: "large" }),
1047
+ /* @__PURE__ */ jsx8(Dialog4.Title, { className: "text-agg-xl font-agg-bold text-agg-foreground", children: copy.title }),
1048
+ /* @__PURE__ */ jsx8(Dialog4.Description, { className: "text-agg-sm text-agg-muted-foreground", children: copy.description }),
1049
+ /* @__PURE__ */ jsx8("p", { className: "text-agg-sm text-agg-muted-foreground", children: copy.fundingNotice }),
1050
+ connected ? /* @__PURE__ */ jsxs8(Fragment, { children: [
1051
+ /* @__PURE__ */ jsx8("p", { role: "status", children: copy.connected }),
1052
+ /* @__PURE__ */ jsx8(Button, { type: "button", onClick: () => onOpenChange(false), children: copy.done })
1053
+ ] }) : /* @__PURE__ */ jsxs8(Fragment, { children: [
1054
+ /* @__PURE__ */ jsx8(
1055
+ "a",
1056
+ {
1057
+ className: "text-agg-sm text-agg-primary underline",
1058
+ href: "https://www.prophetx.co",
1059
+ target: "_blank",
1060
+ rel: "noopener noreferrer",
1061
+ children: copy.instructions
1062
+ }
1063
+ ),
1064
+ /* @__PURE__ */ jsx8("label", { htmlFor: `${id}-access`, className: "text-agg-sm text-agg-foreground", children: copy.accessKey }),
1065
+ /* @__PURE__ */ jsx8(
1066
+ "input",
1067
+ {
1068
+ id: `${id}-access`,
1069
+ type: "password",
1070
+ autoComplete: "off",
1071
+ spellCheck: false,
1072
+ className: "rounded-agg-md border border-agg-border bg-agg-secondary p-3 text-agg-foreground",
1073
+ value: accessKey,
1074
+ onChange: (e) => setAccessKey(e.target.value),
1075
+ disabled: busy,
1076
+ required: true
1077
+ }
1078
+ ),
1079
+ /* @__PURE__ */ jsx8("label", { htmlFor: `${id}-secret`, className: "text-agg-sm text-agg-foreground", children: copy.secretKey }),
1080
+ /* @__PURE__ */ jsx8(
1081
+ "input",
1082
+ {
1083
+ id: `${id}-secret`,
1084
+ type: "password",
1085
+ autoComplete: "new-password",
1086
+ spellCheck: false,
1087
+ className: "rounded-agg-md border border-agg-border bg-agg-secondary p-3 text-agg-foreground",
1088
+ value: secretKey,
1089
+ onChange: (e) => setSecretKey(e.target.value),
1090
+ disabled: busy,
1091
+ required: true
1092
+ }
1093
+ ),
1094
+ error ? /* @__PURE__ */ jsx8("p", { role: "alert", className: "text-agg-sm text-agg-error", children: copy.error }) : null,
1095
+ /* @__PURE__ */ jsx8(Button, { type: "submit", disabled: busy || !accessKey.trim() || !secretKey.trim(), children: pending ? copy.verifying : copy.verify })
1096
+ ] }),
1097
+ allowExistingConnection && onDisconnect ? /* @__PURE__ */ jsx8(
1098
+ Button,
1099
+ {
1100
+ type: "button",
1101
+ variant: "secondary",
1102
+ disabled: busy,
1103
+ onClick: () => __async(null, null, function* () {
1104
+ setDisconnecting(true);
1105
+ setDisconnectError(false);
1106
+ setError(false);
1107
+ try {
1108
+ yield onDisconnect();
1109
+ setAccessKey("");
1110
+ setSecretKey("");
1111
+ onOpenChange(false);
1112
+ } catch (e) {
1113
+ setDisconnectError(true);
1114
+ } finally {
1115
+ setDisconnecting(false);
1116
+ }
1117
+ }),
1118
+ children: disconnecting ? copy.disconnecting : copy.disconnect
1119
+ }
1120
+ ) : null,
1121
+ disconnectError ? /* @__PURE__ */ jsx8("p", { role: "alert", className: "text-agg-sm text-agg-error", children: copy.disconnectError }) : null
1122
+ ]
1123
+ }
1124
+ )
1125
+ ] }) })
1126
+ }
1127
+ );
1128
+ }
1129
+
1130
+ // src/onboarding/index.tsx
1131
+ import { useCallback as useCallback5, useEffect as useEffect3, useState as useState6 } from "react";
1132
+ import { useLabels as useLabels9 } from "@agg-build/hooks";
1133
+ import * as Dialog5 from "@radix-ui/react-dialog";
1134
+ import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
1135
+ var OnboardingModal = ({
1136
+ open,
1137
+ onOpenChange,
1138
+ onProfileSubmit,
1139
+ onConnectOnchain,
1140
+ onComplete,
1141
+ howItWorksIcons,
1142
+ connectedOnchain = false
1143
+ }) => {
1144
+ var _a;
1145
+ const labels = useLabels9();
1146
+ const [step, setStep] = useState6(ONBOARDING_STEPS.HOW_IT_WORKS);
1147
+ const stepLabels = {
1148
+ [ONBOARDING_STEPS.HOW_IT_WORKS]: labels.onboarding.modal.stepHowItWorks,
1149
+ [ONBOARDING_STEPS.PROFILE_SETUP]: labels.onboarding.modal.stepProfileSetup,
1150
+ [ONBOARDING_STEPS.CONNECT_ACCOUNTS]: labels.onboarding.modal.stepConnectAccounts
1151
+ };
1152
+ const resolvedTitle = (_a = stepLabels[step]) != null ? _a : labels.onboarding.modal.title;
1153
+ const [onchainModalOpen, setOnchainModalOpen] = useState6(false);
1154
+ const [onchainConnected, setOnchainConnected] = useState6(false);
1155
+ useEffect3(() => {
1156
+ if (open) {
1157
+ setStep(ONBOARDING_STEPS.HOW_IT_WORKS);
1158
+ setOnchainConnected(false);
1159
+ }
1160
+ }, [open]);
1161
+ const handleHowItWorksContinue = useCallback5(() => {
1162
+ setStep(ONBOARDING_STEPS.PROFILE_SETUP);
1163
+ }, []);
1164
+ const handleProfileContinue = useCallback5(
1165
+ (data) => {
1166
+ onProfileSubmit == null ? void 0 : onProfileSubmit(data);
1167
+ setStep(ONBOARDING_STEPS.CONNECT_ACCOUNTS);
1168
+ },
1169
+ [onProfileSubmit]
1170
+ );
1171
+ const handleConnectContinue = useCallback5(() => {
1172
+ onComplete == null ? void 0 : onComplete();
1173
+ }, [onComplete]);
1174
+ const handleOpenOnchainModal = useCallback5(() => {
1175
+ setOnchainModalOpen(true);
1176
+ }, []);
1177
+ const handleOnchainConnect = useCallback5(() => __async(null, null, function* () {
1178
+ yield onConnectOnchain == null ? void 0 : onConnectOnchain();
1179
+ setOnchainConnected(true);
1180
+ }), [onConnectOnchain]);
1181
+ return /* @__PURE__ */ jsxs9(Fragment2, { children: [
1182
+ /* @__PURE__ */ jsx9(Modal, { open, onOpenChange, children: /* @__PURE__ */ jsxs9(
1183
+ Modal.Container,
1184
+ {
1185
+ maxWidth: "600px",
1186
+ "aria-label": resolvedTitle,
1187
+ classNames: { container: "!rounded-agg-lg" },
1188
+ children: [
1189
+ /* @__PURE__ */ jsx9(Dialog5.Title, { className: "sr-only", children: resolvedTitle }),
1190
+ /* @__PURE__ */ jsxs9(Modal.Body, { classNames: { root: "px-5 py-6 sm:px-10 sm:py-8" }, children: [
1191
+ step === ONBOARDING_STEPS.HOW_IT_WORKS && /* @__PURE__ */ jsx9(HowItWorksStep, { onContinue: handleHowItWorksContinue, icons: howItWorksIcons }),
1192
+ step === ONBOARDING_STEPS.PROFILE_SETUP && /* @__PURE__ */ jsx9(ProfileSetupStep, { onContinue: handleProfileContinue }),
1193
+ step === ONBOARDING_STEPS.CONNECT_ACCOUNTS && /* @__PURE__ */ jsx9(
1194
+ ConnectAccountsStep,
1195
+ {
1196
+ onConnectOnchain: handleOpenOnchainModal,
1197
+ onContinue: handleConnectContinue,
1198
+ connectedOnchain: connectedOnchain || onchainConnected
1199
+ }
1200
+ )
1201
+ ] })
1202
+ ]
1203
+ }
1204
+ ) }),
1205
+ /* @__PURE__ */ jsx9(
1206
+ ConnectOnchainModal,
1207
+ {
1208
+ open: onchainModalOpen,
1209
+ onOpenChange: setOnchainModalOpen,
1210
+ onConnect: handleOnchainConnect
1211
+ }
1212
+ )
1213
+ ] });
1214
+ };
1215
+ OnboardingModal.displayName = "OnboardingModal";
1216
+
1217
+ // src/withdraw/index.tsx
1218
+ import { useEffect as useEffect4, useState as useState7 } from "react";
1219
+ import { useWithdrawalLifecycle, useWithdrawFlow } from "@agg-build/hooks/withdraw";
1220
+
1221
+ // src/shared/constants.ts
1222
+ var USDC = {
1223
+ value: "USDC",
1224
+ label: "USDC",
1225
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/usdc.svg"
1226
+ };
1227
+ var SUPPORTED_NETWORKS = [
1228
+ {
1229
+ value: "abstract",
1230
+ label: "Abstract",
1231
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/Abstract.svg",
1232
+ tokens: [USDC]
1233
+ },
1234
+ {
1235
+ value: "arbitrum",
1236
+ label: "Arbitrum One",
1237
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/Arbitrum.svg",
1238
+ tokens: [USDC]
1239
+ },
1240
+ {
1241
+ value: "base",
1242
+ label: "Base",
1243
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/Base.svg",
1244
+ tokens: [USDC]
1245
+ },
1246
+ {
1247
+ value: "bnb",
1248
+ label: "BNB Chain",
1249
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/BNB.svg",
1250
+ tokens: [USDC]
1251
+ },
1252
+ {
1253
+ value: "flow",
1254
+ label: "Flow",
1255
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/Flow.svg",
1256
+ tokens: [USDC]
1257
+ },
1258
+ {
1259
+ value: "hyperliquid",
1260
+ label: "Hyperliquid",
1261
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/hyperliquid.png",
1262
+ tokens: [USDC]
1263
+ },
1264
+ {
1265
+ value: "mainnet",
1266
+ label: "Ethereum",
1267
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/ETH.svg",
1268
+ tokens: [USDC]
1269
+ },
1270
+ {
1271
+ value: "optimism",
1272
+ label: "Optimism",
1273
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/chains/optimism/colored.svg",
1274
+ tokens: [USDC]
1275
+ },
1276
+ {
1277
+ value: "polygon",
1278
+ label: "Polygon Mainnet",
1279
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/Polygon.svg",
1280
+ tokens: [USDC]
1281
+ },
1282
+ {
1283
+ value: "solana",
1284
+ label: "Solana",
1285
+ iconUrl: "https://assets.snagsolutions.io/public/prediction-markets/logos/Solana.svg",
1286
+ tokens: [USDC]
1287
+ },
1288
+ {
1289
+ value: "zksync",
1290
+ label: "zkSync Era",
1291
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/chains/zksync/colored.svg",
1292
+ tokens: [USDC]
1293
+ }
1294
+ ];
1295
+ var mapNetworksToOptions = () => {
1296
+ return SUPPORTED_NETWORKS.map((n) => ({
1297
+ value: n.value,
1298
+ label: n.label,
1299
+ iconUrl: n.iconUrl
1300
+ }));
1301
+ };
1302
+ var USDC_ICON_URL = "https://assets.snagsolutions.io/public/web/icons/usdc.svg";
1303
+ var DEFAULT_CURRENCY_OPTIONS = [
1304
+ {
1305
+ value: "USDC",
1306
+ label: "USDC",
1307
+ iconUrl: USDC_ICON_URL
1308
+ },
1309
+ {
1310
+ value: "USDC.e",
1311
+ label: "USDC.e",
1312
+ iconUrl: USDC_ICON_URL
1313
+ },
1314
+ {
1315
+ value: "USDH",
1316
+ label: "USDH",
1317
+ iconUrl: USDC_ICON_URL
1318
+ },
1319
+ {
1320
+ value: "pUSD",
1321
+ label: "pUSD",
1322
+ iconUrl: USDC_ICON_URL
1323
+ },
1324
+ {
1325
+ value: "USDT",
1326
+ label: "USDT",
1327
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/usdt.svg"
1328
+ },
1329
+ {
1330
+ value: "USDT",
1331
+ label: "USDT",
1332
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/usdt.svg"
1333
+ },
1334
+ // Add commonly-used tokens with icons. These can be overridden by props.
1335
+ {
1336
+ value: "ARB",
1337
+ label: "ARB",
1338
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/arb.svg"
1339
+ },
1340
+ {
1341
+ value: "BNB",
1342
+ label: "BNB",
1343
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/bnb.svg"
1344
+ },
1345
+ {
1346
+ value: "BTC",
1347
+ label: "BTC",
1348
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/btc.svg"
1349
+ },
1350
+ {
1351
+ value: "MATIC",
1352
+ label: "MATIC",
1353
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/matic.svg"
1354
+ },
1355
+ {
1356
+ value: "ETH",
1357
+ label: "ETH",
1358
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/eth.svg"
1359
+ },
1360
+ {
1361
+ value: "SOL",
1362
+ label: "SOL",
1363
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/sol.svg"
1364
+ },
1365
+ {
1366
+ value: "OP",
1367
+ label: "OP",
1368
+ iconUrl: "https://assets.snagsolutions.io/public/web/icons/tokens/op.svg"
1369
+ }
1370
+ ];
1371
+ var withTokenIcons = (options) => {
1372
+ const byValue = new Map(DEFAULT_CURRENCY_OPTIONS.map((o) => [o.value, o.iconUrl]));
1373
+ return options.map((o) => o.iconUrl ? o : __spreadProps(__spreadValues({}, o), { iconUrl: byValue.get(o.value) }));
1374
+ };
1375
+ var CHAIN_ID_TO_SLUG = {
1376
+ "1": "mainnet",
1377
+ "10": "optimism",
1378
+ "56": "bnb",
1379
+ "137": "polygon",
1380
+ "324": "zksync",
1381
+ "747": "flow",
1382
+ "1337": "hyperliquid",
1383
+ "8453": "base",
1384
+ "42161": "arbitrum",
1385
+ "2741": "abstract",
1386
+ "792703809": "solana"
1387
+ };
1388
+ var withNetworkIcons = (options) => {
1389
+ const bySlug = new Map(SUPPORTED_NETWORKS.map((n) => [n.value, n.iconUrl]));
1390
+ return options.map((o) => {
1391
+ var _a, _b;
1392
+ const slug = (_a = CHAIN_ID_TO_SLUG[o.value]) != null ? _a : o.value;
1393
+ return __spreadProps(__spreadValues({}, o), {
1394
+ iconUrl: (_b = o.iconUrl) != null ? _b : bySlug.get(slug)
1395
+ });
1396
+ });
1397
+ };
1398
+ var mergeSelectOptionsUnique = (base, fill) => {
1399
+ const seen = /* @__PURE__ */ new Set();
1400
+ const out = [];
1401
+ for (const opt of base != null ? base : []) {
1402
+ if (!seen.has(opt.value)) {
1403
+ out.push(opt);
1404
+ seen.add(opt.value);
1405
+ }
1406
+ }
1407
+ for (const opt of fill) {
1408
+ if (!seen.has(opt.value)) {
1409
+ out.push(opt);
1410
+ seen.add(opt.value);
1411
+ }
1412
+ }
1413
+ return out;
1414
+ };
1415
+
1416
+ // src/withdraw/steps/withdraw-method.tsx
1417
+ import { useLabels as useLabels10 } from "@agg-build/hooks";
1418
+ import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
1419
+ var WithdrawMethodStep = ({
1420
+ balance,
1421
+ onSelectMethod
1422
+ }) => {
1423
+ const labels = useLabels10();
1424
+ return /* @__PURE__ */ jsxs10(Fragment3, { children: [
1425
+ /* @__PURE__ */ jsx10(Modal.Header, { title: labels.withdraw.title, hideBorder: true }),
1426
+ /* @__PURE__ */ jsx10(Modal.Body, { classNames: { root: "px-5 pt-0 pb-6 sm:px-8 sm:pt-0 sm:pb-8" }, children: /* @__PURE__ */ jsxs10("div", { className: "flex flex-col gap-5", children: [
1427
+ /* @__PURE__ */ jsxs10("p", { className: "agg-type-body text-agg-foreground", children: [
1428
+ labels.withdraw.balancePrefix,
1429
+ " ",
1430
+ formatCompactUsd(balance)
1431
+ ] }),
1432
+ /* @__PURE__ */ jsxs10(
1433
+ "div",
1434
+ {
1435
+ className: cn(
1436
+ "flex items-center gap-3 sm:gap-4 rounded-xl border border-agg-separator bg-agg-secondary p-3 sm:p-4",
1437
+ "hover:bg-agg-secondary-hover transition-colors cursor-pointer"
1438
+ ),
1439
+ role: "button",
1440
+ tabIndex: 0,
1441
+ onClick: () => onSelectMethod("wallet"),
1442
+ onKeyDown: (e) => {
1443
+ if (e.key === "Enter" || e.key === " ") {
1444
+ e.preventDefault();
1445
+ onSelectMethod("wallet");
1446
+ }
1447
+ },
1448
+ children: [
1449
+ /* @__PURE__ */ jsx10("div", { className: "shrink-0 flex items-center justify-center h-10 w-10 rounded-lg bg-agg-secondary-hover", children: /* @__PURE__ */ jsx10(WalletIcon, { className: "h-6 w-6 text-agg-muted-foreground" }) }),
1450
+ /* @__PURE__ */ jsxs10("div", { className: "flex-1 min-w-0", children: [
1451
+ /* @__PURE__ */ jsx10("p", { className: "agg-type-body-strong text-agg-foreground", children: labels.withdraw.methods.walletTitle }),
1452
+ /* @__PURE__ */ jsx10("p", { className: "agg-type-label text-agg-muted-foreground", children: labels.withdraw.methods.walletDescription })
1453
+ ] }),
1454
+ /* @__PURE__ */ jsx10("div", { className: "shrink-0 text-agg-muted-foreground", children: /* @__PURE__ */ jsx10(ChevronRightIcon, { className: "h-5 w-5" }) })
1455
+ ]
1456
+ }
1457
+ )
1458
+ ] }) })
1459
+ ] });
1460
+ };
1461
+
1462
+ // src/withdraw/steps/withdraw-amount.tsx
1463
+ import { useLabels as useLabels12, useWithdrawPreview } from "@agg-build/hooks";
1464
+
1465
+ // src/shared/transfer-fee-summary.tsx
1466
+ import { useLabels as useLabels11 } from "@agg-build/hooks";
1467
+ import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
1468
+ var separator = /* @__PURE__ */ jsx11("span", { className: "text-agg-muted-foreground", "aria-hidden": "true", children: "\xB7" });
1469
+ var normalizeFeeLabel = (label) => label.replace(/\s*~\s*$/, "");
1470
+ var TransferFeeSummary = ({
1471
+ estimate,
1472
+ view,
1473
+ minDeposit,
1474
+ eta
1475
+ }) => {
1476
+ const labels = useLabels11();
1477
+ if (!estimate) return null;
1478
+ if (view === "deposit") {
1479
+ return /* @__PURE__ */ jsxs11("p", { className: "agg-type-label flex flex-wrap items-center gap-x-2 gap-y-1 text-agg-foreground", children: [
1480
+ minDeposit ? /* @__PURE__ */ jsxs11("span", { children: [
1481
+ labels.deposit.sendCrypto.minDepositPrefix,
1482
+ " ",
1483
+ minDeposit
1484
+ ] }) : null,
1485
+ minDeposit ? separator : null,
1486
+ /* @__PURE__ */ jsxs11("span", { children: [
1487
+ normalizeFeeLabel(labels.deposit.walletFlow.feePrefix),
1488
+ ": ",
1489
+ estimate.estimatedFees
1490
+ ] }),
1491
+ eta ? separator : null,
1492
+ eta ? /* @__PURE__ */ jsx11("span", { children: eta }) : null
1493
+ ] });
1494
+ }
1495
+ return /* @__PURE__ */ jsxs11("div", { className: "agg-type-label flex flex-wrap items-center gap-x-2 gap-y-1 text-agg-foreground", children: [
1496
+ /* @__PURE__ */ jsxs11("span", { children: [
1497
+ labels.withdraw.walletFlow.estimatedFees,
1498
+ ": ",
1499
+ estimate.estimatedFees
1500
+ ] }),
1501
+ separator,
1502
+ /* @__PURE__ */ jsxs11("span", { className: "inline-flex items-center gap-1", children: [
1503
+ /* @__PURE__ */ jsxs11("span", { children: [
1504
+ labels.withdraw.walletFlow.networkReserve,
1505
+ ": ",
1506
+ estimate.networkReserve
1507
+ ] }),
1508
+ /* @__PURE__ */ jsx11(
1509
+ Tooltip,
1510
+ {
1511
+ "aria-label": labels.withdraw.walletFlow.networkReserveTooltipAria,
1512
+ size: "medium",
1513
+ content: /* @__PURE__ */ jsxs11("div", { className: "text-center", children: [
1514
+ /* @__PURE__ */ jsx11("p", { children: labels.withdraw.walletFlow.networkReserveTooltipLineOne }),
1515
+ /* @__PURE__ */ jsx11("p", { children: labels.withdraw.walletFlow.networkReserveTooltipLineTwo })
1516
+ ] }),
1517
+ classNames: {
1518
+ content: "min-w-96 max-w-none!",
1519
+ arrow: "[&_polygon]:fill-agg-background",
1520
+ icon: "text-agg-foreground! h-3! w-3!"
1521
+ }
1522
+ }
1523
+ )
1524
+ ] }),
1525
+ separator,
1526
+ /* @__PURE__ */ jsxs11("span", { children: [
1527
+ labels.withdraw.walletFlow.youReceive,
1528
+ ": ",
1529
+ estimate.youReceive
1530
+ ] })
1531
+ ] });
1532
+ };
1533
+
1534
+ // src/withdraw/steps/withdraw-amount.tsx
1535
+ import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
1536
+ var formatRawTokenAmount = (rawAmount, decimals) => {
1537
+ if (!rawAmount) return "0";
1538
+ const raw = BigInt(rawAmount);
1539
+ const divisor = BigInt(`1${"0".repeat(decimals)}`);
1540
+ const whole = raw / divisor;
1541
+ const remainder = raw % divisor;
1542
+ if (remainder === BigInt(0)) return whole.toString();
1543
+ return `${whole.toString()}.${remainder.toString().padStart(decimals, "0").replace(/0+$/, "")}`;
1544
+ };
1545
+ var parseTokenAmountToRaw = (amount2, decimals) => {
1546
+ const normalizedAmount = amount2.trim();
1547
+ if (!normalizedAmount || !/^\d*(?:\.\d*)?$/.test(normalizedAmount)) return null;
1548
+ const [wholePart = "0", fractionalPart = ""] = normalizedAmount.split(".");
1549
+ if (fractionalPart.length > decimals) return null;
1550
+ const normalizedWhole = wholePart === "" ? "0" : wholePart;
1551
+ const normalizedFraction = fractionalPart.padEnd(decimals, "0");
1552
+ try {
1553
+ return `${BigInt(normalizedWhole)}${normalizedFraction}`.replace(/^0+(?=\d)/, "");
1554
+ } catch (e) {
1555
+ return null;
1556
+ }
1557
+ };
1558
+ var WithdrawAmountStep = ({
1559
+ title,
1560
+ fixedDestination = false,
1561
+ amount: amount2,
1562
+ destinationWallet,
1563
+ balanceDisplay,
1564
+ tokenOptions,
1565
+ networkOptions,
1566
+ selectedToken,
1567
+ selectedNetwork,
1568
+ destDecimals,
1569
+ isConfirming = false,
1570
+ error,
1571
+ max = false,
1572
+ onBack,
1573
+ onAmountChange,
1574
+ onDestinationChange,
1575
+ onTokenChange,
1576
+ onNetworkChange,
1577
+ onMaxClick,
1578
+ onContinue
1579
+ }) => {
1580
+ var _a, _b, _c, _d;
1581
+ const labels = useLabels12();
1582
+ const SOLANA_CHAIN_ID = "792703809";
1583
+ const isSolanaDest = selectedNetwork === SOLANA_CHAIN_ID;
1584
+ const trimmedDestination = destinationWallet.trim();
1585
+ const isValidAddress = isSolanaDest ? /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(trimmedDestination) : /^0x[a-fA-F0-9]{40}$/.test(trimmedDestination);
1586
+ const isValid = Number(amount2) > 0 && isValidAddress;
1587
+ const amountRaw = amount2 && Number(amount2) > 0 ? parseTokenAmountToRaw(amount2, destDecimals) : null;
1588
+ const destinationChainId = Number(selectedNetwork) || null;
1589
+ const preview = useWithdrawPreview({
1590
+ amountRaw,
1591
+ tokenSymbol: selectedToken || null,
1592
+ destinationChainId,
1593
+ destinationAddress: trimmedDestination || null,
1594
+ max
1595
+ });
1596
+ const previewUnviable = ((_a = preview.data) == null ? void 0 : _a.pricingStatus) === "unviable";
1597
+ 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;
1598
+ const previewLoading = preview.isFetching;
1599
+ const isDisabled = !isValid || isConfirming || previewUnviable || previewLoading;
1600
+ const withdrawEstimate = preview.data && preview.data.pricingStatus === "quoted" ? {
1601
+ estimatedFees: preview.data.feeRaw != null ? `~${formatRawTokenAmount(preview.data.feeRaw, destDecimals)} ${selectedToken}` : "\u2014",
1602
+ networkReserve: preview.data.networkFeeRaw != null ? `~${formatRawTokenAmount(preview.data.networkFeeRaw, destDecimals)} ${selectedToken}` : "\u2014",
1603
+ youReceive: preview.data.receiveAmountRaw != null ? `~${formatRawTokenAmount(preview.data.receiveAmountRaw, destDecimals)} ${selectedToken}` : "\u2014"
1604
+ } : null;
1605
+ const shouldShowWithdrawEstimate = Boolean(withdrawEstimate);
1606
+ return /* @__PURE__ */ jsxs12(Fragment4, { children: [
1607
+ /* @__PURE__ */ jsx12(
1608
+ Modal.Header,
1609
+ {
1610
+ title: title != null ? title : labels.withdraw.walletFlow.title,
1611
+ hideBorder: true,
1612
+ leftElement: /* @__PURE__ */ jsx12(
1613
+ "button",
1614
+ {
1615
+ type: "button",
1616
+ className: "mr-2 flex items-center justify-center text-agg-foreground transition-colors hover:cursor-pointer hover:text-agg-foreground/80",
1617
+ onClick: onBack,
1618
+ "aria-label": labels.withdraw.back,
1619
+ children: /* @__PURE__ */ jsx12(ChevronLeftIcon, { className: "h-6 w-6" })
1620
+ }
1621
+ )
1622
+ }
1623
+ ),
1624
+ /* @__PURE__ */ jsx12(Modal.Body, { classNames: { root: "px-5 pt-0 pb-6 sm:px-8 sm:pt-0 sm:pb-8" }, children: /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-5", children: [
1625
+ /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-5", children: [
1626
+ /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-2", children: [
1627
+ /* @__PURE__ */ jsx12("p", { className: "agg-type-label-strong text-agg-foreground", children: labels.withdraw.walletFlow.recipientAddressLabel }),
1628
+ /* @__PURE__ */ jsx12(
1629
+ "input",
1630
+ {
1631
+ type: "text",
1632
+ "aria-label": labels.withdraw.walletFlow.recipientAddressLabel,
1633
+ className: cn(
1634
+ "agg-type-body w-full h-10 rounded border border-agg-separator bg-agg-secondary px-3 outline-none",
1635
+ "text-agg-foreground placeholder:text-agg-muted-foreground",
1636
+ "focus:border-agg-primary transition-colors"
1637
+ ),
1638
+ placeholder: isSolanaDest ? "FwR3..." : "0x971d...",
1639
+ value: destinationWallet,
1640
+ readOnly: fixedDestination,
1641
+ onChange: (e) => onDestinationChange(e.target.value)
1642
+ }
1643
+ )
1644
+ ] }),
1645
+ /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-2", children: [
1646
+ /* @__PURE__ */ jsxs12("div", { className: "flex items-center justify-between", children: [
1647
+ /* @__PURE__ */ jsx12("p", { className: "agg-type-label-strong text-agg-foreground", children: labels.withdraw.walletFlow.amountLabel }),
1648
+ /* @__PURE__ */ jsxs12("p", { className: "agg-type-label text-agg-muted-foreground", children: [
1649
+ labels.withdraw.balancePrefix,
1650
+ " ",
1651
+ balanceDisplay
1652
+ ] })
1653
+ ] }),
1654
+ /* @__PURE__ */ jsxs12("div", { className: "flex h-10 items-center gap-2 rounded border border-agg-separator bg-agg-secondary px-3 focus-within:border-agg-primary transition-colors", children: [
1655
+ /* @__PURE__ */ jsx12(
1656
+ "input",
1657
+ {
1658
+ type: "text",
1659
+ inputMode: "decimal",
1660
+ "aria-label": labels.withdraw.walletFlow.amountLabel,
1661
+ className: cn(
1662
+ "agg-type-body flex-1 min-w-0 bg-transparent outline-none",
1663
+ Number(amount2) > 0 ? "text-agg-foreground" : "text-agg-muted-foreground"
1664
+ ),
1665
+ placeholder: "0.00",
1666
+ value: amount2,
1667
+ onChange: (e) => onAmountChange(e.target.value)
1668
+ }
1669
+ ),
1670
+ /* @__PURE__ */ jsx12("span", { className: "agg-type-body text-agg-muted-foreground shrink-0", children: selectedToken }),
1671
+ onMaxClick ? /* @__PURE__ */ jsx12(
1672
+ "button",
1673
+ {
1674
+ type: "button",
1675
+ className: "agg-type-label-strong text-agg-primary hover:opacity-80 transition-opacity cursor-pointer shrink-0",
1676
+ onClick: onMaxClick,
1677
+ children: labels.withdraw.walletFlow.max
1678
+ }
1679
+ ) : null
1680
+ ] })
1681
+ ] }),
1682
+ /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-3 sm:flex-row sm:gap-5", children: [
1683
+ /* @__PURE__ */ jsxs12("div", { className: "flex-1 flex flex-col gap-2 min-w-0", children: [
1684
+ /* @__PURE__ */ jsx12("p", { className: "agg-type-label-strong text-agg-foreground", children: labels.withdraw.walletFlow.tokenLabel }),
1685
+ /* @__PURE__ */ jsx12(
1686
+ Select,
1687
+ {
1688
+ items: tokenOptions,
1689
+ disabled: fixedDestination,
1690
+ value: selectedToken,
1691
+ onChange: onTokenChange,
1692
+ ariaLabel: labels.withdraw.walletFlow.tokenLabel
1693
+ }
1694
+ )
1695
+ ] }),
1696
+ /* @__PURE__ */ jsxs12("div", { className: "flex-1 flex flex-col gap-2 min-w-0", children: [
1697
+ /* @__PURE__ */ jsx12("p", { className: "agg-type-label-strong text-agg-foreground", children: labels.withdraw.walletFlow.networkLabel }),
1698
+ /* @__PURE__ */ jsx12(
1699
+ Select,
1700
+ {
1701
+ items: networkOptions,
1702
+ disabled: fixedDestination,
1703
+ value: selectedNetwork,
1704
+ onChange: onNetworkChange,
1705
+ ariaLabel: labels.withdraw.walletFlow.networkLabel
1706
+ }
1707
+ )
1708
+ ] })
1709
+ ] }),
1710
+ shouldShowWithdrawEstimate && withdrawEstimate ? /* @__PURE__ */ jsx12(TransferFeeSummary, { estimate: withdrawEstimate, view: "withdraw" }) : null,
1711
+ previewUnviableMessage ? /* @__PURE__ */ jsx12("p", { className: "agg-type-label text-agg-error", role: "alert", children: previewUnviableMessage }) : null
1712
+ ] }),
1713
+ /* @__PURE__ */ jsx12(
1714
+ Button,
1715
+ {
1716
+ variant: isValid && !isConfirming && !previewUnviable && !previewLoading ? "primary" : "secondary",
1717
+ size: "large",
1718
+ className: "w-full",
1719
+ disabled: isDisabled,
1720
+ prefix: previewLoading && !isConfirming ? /* @__PURE__ */ jsx12(LoadingIcon, { size: "small", className: "mr-2 text-current" }) : void 0,
1721
+ onClick: onContinue,
1722
+ children: isConfirming ? labels.common.loading : previewLoading ? labels.withdraw.walletFlow.calculatingFees : labels.withdraw.walletFlow.confirm
1723
+ }
1724
+ ),
1725
+ error ? /* @__PURE__ */ jsx12("p", { className: "agg-type-label text-agg-error text-center", role: "alert", children: error }) : null
1726
+ ] }) })
1727
+ ] });
1728
+ };
1729
+
1730
+ // src/withdraw/steps/withdraw-success.tsx
1731
+ import { useLabels as useLabels13, useSdkUiConfig } from "@agg-build/hooks";
1732
+ import { jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
1733
+ var SummaryRow = ({ label, value }) => /* @__PURE__ */ jsxs13("div", { className: "flex items-center justify-between gap-4 border-b border-agg-separator py-2 last:border-b-0", children: [
1734
+ /* @__PURE__ */ jsx13("p", { className: "min-w-0 text-[12px] leading-4 font-agg-bold uppercase text-agg-muted-foreground", children: label }),
1735
+ /* @__PURE__ */ jsx13("p", { className: "min-w-0 text-right text-[14px] leading-5 text-agg-foreground", children: value })
1736
+ ] });
1737
+ var WithdrawCloseButton = ({ onClose, label }) => /* @__PURE__ */ jsx13(
1738
+ "button",
1739
+ {
1740
+ type: "button",
1741
+ className: "absolute right-8 top-7 flex cursor-pointer items-center justify-center text-agg-foreground transition-colors hover:text-agg-foreground/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary",
1742
+ onClick: onClose,
1743
+ "aria-label": label,
1744
+ children: /* @__PURE__ */ jsx13(CloseIcon, { className: "h-6 w-6" })
1745
+ }
1746
+ );
1747
+ var LoadingGlyph = ({
1748
+ className,
1749
+ enableAnimations
1750
+ }) => /* @__PURE__ */ jsx13(
1751
+ "span",
1752
+ {
1753
+ "aria-hidden": "true",
1754
+ className: cn(
1755
+ "inline-block rounded-full border-2 border-current border-r-transparent",
1756
+ getMotionClassName(enableAnimations, "animate-spin"),
1757
+ className
1758
+ )
1759
+ }
1760
+ );
1761
+ var loadingActiveIndexFor = (state) => {
1762
+ if (state.status === "transferring") return 2;
1763
+ if (state.status === "bridging") return 1;
1764
+ return 0;
1765
+ };
1766
+ var getLoadingSteps = (labels) => [
1767
+ { id: "preparing", label: labels.lifecycle.loadingSteps.preparing },
1768
+ { id: "bridging", label: labels.lifecycle.loadingSteps.bridging },
1769
+ { id: "sending", label: labels.lifecycle.loadingSteps.sending },
1770
+ { id: "confirming", label: labels.lifecycle.loadingSteps.confirming }
1771
+ ];
1772
+ var WithdrawLoadingStep = ({
1773
+ lifecycleState,
1774
+ onClose
1775
+ }) => {
1776
+ const labels = useLabels13();
1777
+ const {
1778
+ features: { enableAnimations }
1779
+ } = useSdkUiConfig();
1780
+ const walletFlowLabels = labels.withdraw.walletFlow;
1781
+ const activeIndex = loadingActiveIndexFor(lifecycleState);
1782
+ const loadingSteps = getLoadingSteps(walletFlowLabels);
1783
+ return /* @__PURE__ */ jsx13("div", { className: "relative", children: /* @__PURE__ */ jsx13(Modal.Body, { classNames: { root: "px-8 py-7" }, children: /* @__PURE__ */ jsxs13("div", { className: "flex flex-col gap-7", children: [
1784
+ /* @__PURE__ */ jsxs13("div", { className: "flex items-center justify-between gap-4", children: [
1785
+ /* @__PURE__ */ jsx13("h3", { className: "text-agg-2xl leading-agg-8 font-agg-bold text-agg-foreground", children: walletFlowLabels.successTitle }),
1786
+ /* @__PURE__ */ jsx13(
1787
+ "button",
1788
+ {
1789
+ type: "button",
1790
+ className: "flex cursor-pointer items-center justify-center text-agg-foreground transition-colors hover:text-agg-foreground/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary",
1791
+ onClick: onClose,
1792
+ "aria-label": labels.common.close,
1793
+ children: /* @__PURE__ */ jsx13(CloseIcon, { className: "h-6 w-6" })
1794
+ }
1795
+ )
1796
+ ] }),
1797
+ /* @__PURE__ */ jsx13("div", { className: "flex flex-col gap-5", role: "status", "aria-live": "polite", children: loadingSteps.map((step, index) => {
1798
+ const isComplete = index < activeIndex;
1799
+ const isActive = index === activeIndex;
1800
+ const textClassName = isActive || isComplete ? "text-agg-foreground" : "text-agg-muted-foreground";
1801
+ return /* @__PURE__ */ jsxs13("div", { className: "flex items-center gap-3", children: [
1802
+ isComplete ? /* @__PURE__ */ jsx13(
1803
+ Icon,
1804
+ {
1805
+ name: "check-circle",
1806
+ size: "small",
1807
+ className: "h-4 w-4 shrink-0 text-agg-primary",
1808
+ "aria-hidden": "true"
1809
+ }
1810
+ ) : null,
1811
+ isActive ? /* @__PURE__ */ jsx13(
1812
+ LoadingGlyph,
1813
+ {
1814
+ enableAnimations,
1815
+ className: "h-4 w-4 shrink-0 text-agg-primary"
1816
+ }
1817
+ ) : null,
1818
+ !isComplete && !isActive ? /* @__PURE__ */ jsx13(
1819
+ "span",
1820
+ {
1821
+ "aria-hidden": "true",
1822
+ className: "h-4 w-4 shrink-0 rounded-full border border-agg-separator"
1823
+ }
1824
+ ) : null,
1825
+ /* @__PURE__ */ jsx13("p", { className: cn("min-w-0 flex-1 text-agg-base leading-agg-6", textClassName), children: step.label })
1826
+ ] }, step.id);
1827
+ }) }),
1828
+ /* @__PURE__ */ jsx13("p", { className: "text-agg-sm leading-agg-5 text-agg-foreground", children: walletFlowLabels.loadingDescription })
1829
+ ] }) }) });
1830
+ };
1831
+ var resultCopyFor = ({
1832
+ status,
1833
+ tokenSymbol,
1834
+ labels
1835
+ }) => {
1836
+ if (status === "failed") {
1837
+ return {
1838
+ title: labels.successTitleFailed,
1839
+ description: labels.successDescriptionFailed(tokenSymbol)
1840
+ };
1841
+ }
1842
+ if (status === "partial_success") {
1843
+ return {
1844
+ title: labels.successTitlePartial,
1845
+ description: labels.successDescriptionPartial(tokenSymbol)
1846
+ };
1847
+ }
1848
+ return {
1849
+ title: labels.successTitleCompleted,
1850
+ description: labels.successDescriptionCompleted(tokenSymbol)
1851
+ };
1852
+ };
1853
+ var WithdrawSuccessStep = ({
1854
+ summary,
1855
+ tokenSymbol,
1856
+ requestedWithdrawal,
1857
+ resultStatus,
1858
+ errorMessage,
1859
+ onDone,
1860
+ onRetry,
1861
+ onClose
1862
+ }) => {
1863
+ const labels = useLabels13();
1864
+ const walletFlowLabels = labels.withdraw.walletFlow;
1865
+ const { title, description } = resultCopyFor({
1866
+ status: resultStatus,
1867
+ tokenSymbol,
1868
+ labels: walletFlowLabels
1869
+ });
1870
+ const isFailed = resultStatus === "failed";
1871
+ return /* @__PURE__ */ jsx13("div", { className: "relative", children: /* @__PURE__ */ jsxs13(Modal.Body, { classNames: { root: "px-10 py-12" }, children: [
1872
+ /* @__PURE__ */ jsx13(WithdrawCloseButton, { onClose, label: labels.common.close }),
1873
+ /* @__PURE__ */ jsxs13("div", { className: "flex flex-col items-center justify-center gap-8 text-center", children: [
1874
+ /* @__PURE__ */ jsx13(
1875
+ "div",
1876
+ {
1877
+ className: cn(
1878
+ "flex h-[60px] w-[60px] items-center justify-center rounded-full",
1879
+ isFailed ? "bg-agg-error/15" : "bg-agg-success/15"
1880
+ ),
1881
+ "aria-hidden": "true",
1882
+ children: isFailed ? /* @__PURE__ */ jsx13(CloseIcon, { className: "h-6 w-6 text-agg-error" }) : /* @__PURE__ */ jsx13(SuccessCheckIcon, { className: "h-6 w-6 text-agg-success" })
1883
+ }
1884
+ ),
1885
+ /* @__PURE__ */ jsxs13("div", { className: "flex w-full flex-col items-center gap-3 text-center text-agg-foreground", children: [
1886
+ /* @__PURE__ */ jsx13("h3", { className: "text-agg-2xl leading-agg-8 font-agg-bold", children: title }),
1887
+ /* @__PURE__ */ jsx13(
1888
+ "p",
1889
+ {
1890
+ className: "max-w-[400px] text-agg-base leading-agg-6",
1891
+ "data-withdraw-result-status": resultStatus,
1892
+ children: errorMessage && isFailed ? errorMessage : description
1893
+ }
1894
+ )
1895
+ ] }),
1896
+ !isFailed ? /* @__PURE__ */ jsxs13("div", { className: "flex w-full max-w-[400px] flex-col rounded-agg-lg border border-agg-separator bg-agg-secondary px-3 py-1 text-left", children: [
1897
+ /* @__PURE__ */ jsx13(
1898
+ SummaryRow,
1899
+ {
1900
+ label: walletFlowLabels.summary.requestedWithdrawal,
1901
+ value: requestedWithdrawal
1902
+ }
1903
+ ),
1904
+ /* @__PURE__ */ jsx13(
1905
+ SummaryRow,
1906
+ {
1907
+ label: walletFlowLabels.summary.amountReceived,
1908
+ value: summary.amountReceived
1909
+ }
1910
+ ),
1911
+ /* @__PURE__ */ jsx13(SummaryRow, { label: walletFlowLabels.summary.fees, value: summary.fees }),
1912
+ /* @__PURE__ */ jsx13(SummaryRow, { label: walletFlowLabels.summary.network, value: summary.network }),
1913
+ /* @__PURE__ */ jsx13(SummaryRow, { label: walletFlowLabels.summary.toWallet, value: summary.toWallet })
1914
+ ] }) : null,
1915
+ isFailed ? /* @__PURE__ */ jsxs13("div", { className: "flex items-center justify-center gap-3", children: [
1916
+ /* @__PURE__ */ jsx13(Button, { variant: "secondary", size: "large", className: "w-[120px]", onClick: onClose, children: walletFlowLabels.close }),
1917
+ /* @__PURE__ */ jsx13(Button, { variant: "primary", size: "large", className: "w-[123px]", onClick: onRetry, children: walletFlowLabels.retry })
1918
+ ] }) : /* @__PURE__ */ jsx13(Button, { variant: "secondary", size: "large", className: "w-[120px]", onClick: onDone, children: labels.withdraw.done })
1919
+ ] })
1920
+ ] }) });
1921
+ };
1922
+
1923
+ // src/withdraw/index.tsx
1924
+ import { jsx as jsx14, jsxs as jsxs14 } from "react/jsx-runtime";
1925
+ var DEFAULT_TOKEN_DECIMALS = 6;
1926
+ var TOKEN_DECIMALS_BY_SYMBOL = {
1927
+ BNB: 18,
1928
+ ETH: 18,
1929
+ MATIC: 18,
1930
+ POL: 18,
1931
+ WETH: 18,
1932
+ USDC: 6,
1933
+ USDT: 6
1934
+ };
1935
+ var TOKEN_DECIMALS_BY_CHAIN_AND_SYMBOL = {
1936
+ "56": {
1937
+ USDC: 18,
1938
+ USDT: 18
1939
+ }
1940
+ };
1941
+ var getTokenDecimals = (tokenSymbol, chainId) => {
1942
+ var _a;
1943
+ const normalizedSymbol = tokenSymbol.trim().toUpperCase();
1944
+ const normalizedChainId = chainId == null ? void 0 : chainId.trim();
1945
+ if (normalizedChainId) {
1946
+ const chainDecimals = TOKEN_DECIMALS_BY_CHAIN_AND_SYMBOL[normalizedChainId];
1947
+ const chainTokenDecimals = chainDecimals == null ? void 0 : chainDecimals[normalizedSymbol];
1948
+ if (chainTokenDecimals != null) return chainTokenDecimals;
1949
+ }
1950
+ return (_a = TOKEN_DECIMALS_BY_SYMBOL[normalizedSymbol]) != null ? _a : DEFAULT_TOKEN_DECIMALS;
1951
+ };
1952
+ var formatRawTokenAmount2 = (rawAmount, decimals) => {
1953
+ const raw = BigInt(rawAmount);
1954
+ const divisor = BigInt(`1${"0".repeat(decimals)}`);
1955
+ const whole = raw / divisor;
1956
+ const remainder = raw % divisor;
1957
+ if (remainder === BigInt(0)) return whole.toString();
1958
+ return `${whole.toString()}.${remainder.toString().padStart(decimals, "0").replace(/0+$/, "")}`;
1959
+ };
1960
+ var formatLifecycleTokenAmount = ({
1961
+ rawAmount,
1962
+ tokenSymbol,
1963
+ chainId
1964
+ }) => `${formatRawTokenAmount2(rawAmount, getTokenDecimals(tokenSymbol, chainId))} ${tokenSymbol}`;
1965
+ var buildTerminalSummary = ({
1966
+ fallbackSummary,
1967
+ lifecycleCompletedAmountRaw,
1968
+ lifecycleRequestedAmountRaw,
1969
+ lifecycleFeeRaw,
1970
+ tokenSymbol,
1971
+ chainId
1972
+ }) => {
1973
+ if (!lifecycleCompletedAmountRaw) return fallbackSummary;
1974
+ const amountReceived = formatLifecycleTokenAmount({
1975
+ rawAmount: lifecycleCompletedAmountRaw,
1976
+ tokenSymbol,
1977
+ chainId
1978
+ });
1979
+ let feeRaw = lifecycleFeeRaw;
1980
+ if (feeRaw == null && lifecycleRequestedAmountRaw) {
1981
+ try {
1982
+ const r = BigInt(lifecycleRequestedAmountRaw);
1983
+ const c = BigInt(lifecycleCompletedAmountRaw);
1984
+ feeRaw = (r > c ? r - c : BigInt(0)).toString();
1985
+ } catch (e) {
1986
+ feeRaw = null;
1987
+ }
1988
+ }
1989
+ return __spreadValues(__spreadProps(__spreadValues({}, fallbackSummary), {
1990
+ amountReceived
1991
+ }), feeRaw != null ? {
1992
+ fees: formatLifecycleTokenAmount({
1993
+ rawAmount: feeRaw,
1994
+ tokenSymbol,
1995
+ chainId
1996
+ })
1997
+ } : {});
1998
+ };
1999
+ function isControlledWithdrawModalProps(props) {
2000
+ return "withdrawFlow" in props;
2001
+ }
2002
+ function WithdrawModalSelfDriven({
2003
+ open,
2004
+ onOpenChange
2005
+ }) {
2006
+ const withdrawProps = useWithdrawFlow({ open, onOpenChange });
2007
+ return /* @__PURE__ */ jsx14(WithdrawModalControlled, __spreadValues({}, withdrawProps));
2008
+ }
2009
+ function WithdrawModalControlled({
2010
+ open,
2011
+ onOpenChange,
2012
+ withdrawFlow,
2013
+ transferTarget,
2014
+ onWithdrawDestinationChange,
2015
+ onWithdrawAmountChange,
2016
+ onWithdrawTokenChange,
2017
+ onWithdrawNetworkChange,
2018
+ onMaxClick,
2019
+ onSelectWithdrawProvider,
2020
+ onDoneWithdraw
2021
+ }) {
2022
+ var _a;
2023
+ const initialFormStep = transferTarget ? "withdraw-amount" : "method";
2024
+ const [flowState, setFlowState] = useState7({
2025
+ status: "form",
2026
+ formStep: initialFormStep
2027
+ });
2028
+ const [isConfirming, setIsConfirming] = useState7(false);
2029
+ const [confirmError, setConfirmError] = useState7(null);
2030
+ const { state: withdrawalLifecycleState, reset: resetWithdrawalLifecycle } = useWithdrawalLifecycle(withdrawFlow.withdrawalId);
2031
+ useEffect4(() => {
2032
+ if (!open) {
2033
+ setFlowState({ status: "form", formStep: initialFormStep });
2034
+ setIsConfirming(false);
2035
+ setConfirmError(null);
2036
+ resetWithdrawalLifecycle();
2037
+ }
2038
+ }, [open, resetWithdrawalLifecycle, initialFormStep]);
2039
+ useEffect4(() => {
2040
+ if (flowState.status !== "loading") return;
2041
+ if (!withdrawalLifecycleState.terminal) return;
2042
+ if (withdrawalLifecycleState.status === "completed") {
2043
+ setFlowState({ status: "success" });
2044
+ return;
2045
+ }
2046
+ if (withdrawalLifecycleState.status === "partial") {
2047
+ setFlowState({ status: "partial_success" });
2048
+ return;
2049
+ }
2050
+ if (withdrawalLifecycleState.status === "failed") {
2051
+ setFlowState({
2052
+ status: "failed",
2053
+ errorMessage: withdrawalLifecycleState.errorMessage
2054
+ });
2055
+ }
2056
+ }, [
2057
+ flowState.status,
2058
+ withdrawalLifecycleState.errorMessage,
2059
+ withdrawalLifecycleState.status,
2060
+ withdrawalLifecycleState.terminal
2061
+ ]);
2062
+ const handleOpenChange = (isOpen) => {
2063
+ if (!isOpen) {
2064
+ setFlowState({ status: "form", formStep: initialFormStep });
2065
+ setIsConfirming(false);
2066
+ setConfirmError(null);
2067
+ resetWithdrawalLifecycle();
2068
+ }
2069
+ onOpenChange(isOpen);
2070
+ };
2071
+ const handleBack = () => {
2072
+ if (transferTarget) {
2073
+ handleOpenChange(false);
2074
+ return;
2075
+ }
2076
+ setConfirmError(null);
2077
+ setFlowState({ status: "form", formStep: initialFormStep });
2078
+ };
2079
+ const handleRetry = () => {
2080
+ setConfirmError(null);
2081
+ setIsConfirming(false);
2082
+ resetWithdrawalLifecycle();
2083
+ setFlowState({ status: "form", formStep: "withdraw-amount" });
2084
+ };
2085
+ const handleConfirm = () => __async(null, null, function* () {
2086
+ if (isConfirming || transferTarget && (withdrawFlow.destinationWallet !== transferTarget.address || withdrawFlow.selectedNetwork !== transferTarget.chainId || withdrawFlow.selectedToken !== transferTarget.tokenSymbol))
2087
+ return;
2088
+ setFlowState({ status: "loading" });
2089
+ setIsConfirming(true);
2090
+ setConfirmError(null);
2091
+ try {
2092
+ yield onSelectWithdrawProvider("wallet");
2093
+ } catch (err) {
2094
+ const errorMessage = err instanceof Error ? err.message : "Withdrawal failed. Please try again.";
2095
+ setConfirmError(errorMessage);
2096
+ setFlowState({ status: "failed", errorMessage });
2097
+ } finally {
2098
+ setIsConfirming(false);
2099
+ }
2100
+ });
2101
+ const withdrawTokenOptions = withTokenIcons(withdrawFlow.tokenOptions);
2102
+ const withdrawNetworkOptions = withNetworkIcons(withdrawFlow.networkOptions);
2103
+ const requestedWithdrawal = `${withdrawFlow.amount} ${withdrawFlow.selectedToken}`.trim();
2104
+ const modalMaxWidth = flowState.status === "form" && flowState.formStep === "method" ? "600px" : "480px";
2105
+ const resultStatus = flowState.status;
2106
+ const terminalSummary = buildTerminalSummary({
2107
+ fallbackSummary: withdrawFlow.purchaseSummary,
2108
+ lifecycleCompletedAmountRaw: withdrawalLifecycleState.completedAmountRaw,
2109
+ lifecycleRequestedAmountRaw: withdrawalLifecycleState.requestedAmountRaw,
2110
+ lifecycleFeeRaw: withdrawalLifecycleState.feeRaw,
2111
+ tokenSymbol: withdrawFlow.selectedToken,
2112
+ chainId: withdrawFlow.selectedNetwork
2113
+ });
2114
+ return /* @__PURE__ */ jsx14(Modal, { open, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs14(Modal.Container, { maxWidth: modalMaxWidth, "aria-label": (_a = transferTarget == null ? void 0 : transferTarget.title) != null ? _a : "Withdraw", children: [
2115
+ flowState.status === "form" && flowState.formStep === "method" ? /* @__PURE__ */ jsx14(
2116
+ WithdrawMethodStep,
2117
+ {
2118
+ balance: withdrawFlow.balance,
2119
+ onSelectMethod: () => setFlowState({ status: "form", formStep: "withdraw-amount" })
2120
+ }
2121
+ ) : null,
2122
+ flowState.status === "form" && flowState.formStep === "withdraw-amount" ? /* @__PURE__ */ jsx14(
2123
+ WithdrawAmountStep,
2124
+ {
2125
+ title: transferTarget == null ? void 0 : transferTarget.title,
2126
+ fixedDestination: !!transferTarget,
2127
+ amount: withdrawFlow.amount,
2128
+ destinationWallet: withdrawFlow.destinationWallet,
2129
+ balanceDisplay: withdrawFlow.balanceDisplay,
2130
+ tokenOptions: withdrawTokenOptions,
2131
+ networkOptions: withdrawNetworkOptions,
2132
+ selectedToken: withdrawFlow.selectedToken,
2133
+ selectedNetwork: withdrawFlow.selectedNetwork,
2134
+ destDecimals: getTokenDecimals(
2135
+ withdrawFlow.selectedToken,
2136
+ withdrawFlow.selectedNetwork
2137
+ ),
2138
+ isConfirming,
2139
+ error: confirmError,
2140
+ max: withdrawFlow.isMax,
2141
+ onBack: handleBack,
2142
+ onAmountChange: onWithdrawAmountChange,
2143
+ onDestinationChange: onWithdrawDestinationChange,
2144
+ onTokenChange: onWithdrawTokenChange,
2145
+ onNetworkChange: onWithdrawNetworkChange,
2146
+ onMaxClick,
2147
+ onContinue: handleConfirm
2148
+ }
2149
+ ) : null,
2150
+ flowState.status === "loading" ? /* @__PURE__ */ jsx14(
2151
+ WithdrawLoadingStep,
2152
+ {
2153
+ lifecycleState: withdrawalLifecycleState,
2154
+ onClose: () => handleOpenChange(false)
2155
+ }
2156
+ ) : null,
2157
+ flowState.status === "success" || flowState.status === "partial_success" || flowState.status === "failed" ? /* @__PURE__ */ jsx14(
2158
+ WithdrawSuccessStep,
2159
+ {
2160
+ summary: terminalSummary,
2161
+ tokenSymbol: withdrawFlow.selectedToken,
2162
+ requestedWithdrawal,
2163
+ resultStatus,
2164
+ errorMessage: flowState.status === "failed" ? flowState.errorMessage : null,
2165
+ onDone: onDoneWithdraw,
2166
+ onRetry: handleRetry,
2167
+ onClose: () => handleOpenChange(false)
2168
+ }
2169
+ ) : null
2170
+ ] }) });
2171
+ }
2172
+ var WithdrawModal = (props) => {
2173
+ if (isControlledWithdrawModalProps(props)) {
2174
+ return /* @__PURE__ */ jsx14(WithdrawModalControlled, __spreadValues({}, props));
2175
+ }
2176
+ return /* @__PURE__ */ jsx14(WithdrawModalSelfDriven, __spreadValues({}, props));
2177
+ };
2178
+ WithdrawModal.displayName = "WithdrawModal";
2179
+
2180
+ // src/notifications/deposit-notification-events.ts
2181
+ var AGG_DEPOSIT_NOTIFICATION_EVENT = "agg:deposit-notification";
2182
+ var dispatchAggDepositNotification = (detail) => {
2183
+ if (typeof window === "undefined") return;
2184
+ window.dispatchEvent(new CustomEvent(AGG_DEPOSIT_NOTIFICATION_EVENT, { detail }));
2185
+ };
2186
+ var subscribeAggDepositNotification = (handler) => {
2187
+ if (typeof window === "undefined") return () => {
2188
+ };
2189
+ const handleDepositNotification = (event) => {
2190
+ if (!(event instanceof CustomEvent)) return;
2191
+ handler(event.detail);
2192
+ };
2193
+ window.addEventListener(AGG_DEPOSIT_NOTIFICATION_EVENT, handleDepositNotification);
2194
+ return () => {
2195
+ window.removeEventListener(AGG_DEPOSIT_NOTIFICATION_EVENT, handleDepositNotification);
2196
+ };
2197
+ };
2198
+
2199
+ // src/trading/manage-betdex-account-modal.tsx
2200
+ import { useEffect as useEffect6, useState as useState11 } from "react";
2201
+ import { useLabels as useLabels18 } from "@agg-build/hooks";
2202
+ import * as Dialog6 from "@radix-ui/react-dialog";
2203
+
2204
+ // src/pages/user-profile/components/betdex-account-card.tsx
2205
+ import { useState as useState10 } from "react";
2206
+ import { useHostedVenueAccount, useLabels as useLabels16 } from "@agg-build/hooks";
2207
+ import { Venue as Venue4 } from "@agg-build/sdk";
2208
+
2209
+ // src/pages/user-profile/components/betdex-account-transfers.tsx
2210
+ import { useState as useState8 } from "react";
2211
+ import { useDepositAddresses, useHostedVenueTransfers, useLabels as useLabels14 } from "@agg-build/hooks";
2212
+ import { jsx as jsx15, jsxs as jsxs15 } from "react/jsx-runtime";
2213
+ function hostedWithdrawalRaw(value) {
2214
+ var _a;
2215
+ const match = /^([0-9]{1,26})(?:\.([0-9]{1,6}))?$/.exec(value.trim());
2216
+ if (!match) return null;
2217
+ const raw = BigInt(match[1]) * BigInt(1e6) + BigInt(((_a = match[2]) != null ? _a : "").padEnd(6, "0"));
2218
+ return raw > BigInt(0) ? raw.toString() : null;
2219
+ }
2220
+ var amountText = (raw) => {
2221
+ const value = BigInt(raw);
2222
+ const fraction = (value % BigInt(1e6)).toString().padStart(6, "0").replace(/0+$/, "");
2223
+ return (value / BigInt(1e6)).toString() + (fraction ? "." + fraction : "");
2224
+ };
2225
+ function BetdexAccountTransfers({
2226
+ accountId,
2227
+ environment,
2228
+ availableRaw,
2229
+ canDeposit,
2230
+ onWalletDeposit
2231
+ }) {
2232
+ const labels = useLabels14().userProfile.hostedBetdex;
2233
+ const transfer = useHostedVenueTransfers(accountId, environment);
2234
+ const [showWithdraw, setShowWithdraw] = useState8(false);
2235
+ const wallet = useDepositAddresses({
2236
+ enabled: transfer.isAvailable && environment === "production" && showWithdraw
2237
+ });
2238
+ const [amount2, setAmount] = useState8("");
2239
+ const [destination, setDestination] = useState8("");
2240
+ const [actionError, setActionError] = useState8(false);
2241
+ const raw = hostedWithdrawalRaw(amount2);
2242
+ const withinBalance = raw !== null && (availableRaw === void 0 || BigInt(raw) <= BigInt(availableRaw));
2243
+ const validDestination = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(destination.trim());
2244
+ const result = transfer.withdrawal.data;
2245
+ const terminal = (result == null ? void 0 : result.status) === "confirmed" || (result == null ? void 0 : result.status) === "failed";
2246
+ const run = (work) => {
2247
+ setActionError(false);
2248
+ void work().catch(() => setActionError(true));
2249
+ };
2250
+ if (!transfer.isAvailable) return null;
2251
+ return /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-3 border-t border-agg-separator pt-3", children: [
2252
+ /* @__PURE__ */ jsxs15("div", { className: "flex flex-wrap gap-2", children: [
2253
+ canDeposit && environment === "production" && onWalletDeposit ? /* @__PURE__ */ jsx15(
2254
+ Button,
2255
+ {
2256
+ type: "button",
2257
+ variant: "secondary",
2258
+ size: "small",
2259
+ disabled: transfer.deposit.isPending,
2260
+ isLoading: transfer.deposit.isPending,
2261
+ onClick: () => run(() => __async(null, null, function* () {
2262
+ const response = yield transfer.deposit.mutateAsync();
2263
+ onWalletDeposit(response.result.address);
2264
+ })),
2265
+ children: labels.fromWallet
2266
+ }
2267
+ ) : null,
2268
+ canDeposit ? /* @__PURE__ */ jsx15(
2269
+ Button,
2270
+ {
2271
+ type: "button",
2272
+ variant: "secondary",
2273
+ size: "small",
2274
+ "aria-label": labels.deposit,
2275
+ isLoading: transfer.deposit.isPending,
2276
+ disabled: transfer.deposit.isPending,
2277
+ onClick: () => run(() => transfer.deposit.mutateAsync()),
2278
+ children: labels.deposit
2279
+ }
2280
+ ) : null,
2281
+ /* @__PURE__ */ jsx15(
2282
+ Button,
2283
+ {
2284
+ type: "button",
2285
+ variant: "secondary",
2286
+ size: "small",
2287
+ "aria-expanded": showWithdraw || !!transfer.request,
2288
+ onClick: () => setShowWithdraw((value) => !value),
2289
+ children: labels.withdraw
2290
+ }
2291
+ )
2292
+ ] }),
2293
+ transfer.deposit.data ? /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-2 agg-type-caption", children: [
2294
+ /* @__PURE__ */ jsx15("p", { className: "text-agg-muted-foreground", children: labels.depositInstructions[environment] }),
2295
+ /* @__PURE__ */ jsxs15("label", { className: "flex flex-col gap-1 text-agg-muted-foreground", children: [
2296
+ labels.depositAddress,
2297
+ /* @__PURE__ */ jsx15(
2298
+ "input",
2299
+ {
2300
+ readOnly: true,
2301
+ value: transfer.deposit.data.address,
2302
+ onFocus: (event) => event.currentTarget.select(),
2303
+ className: "w-full rounded-agg-md border border-agg-separator bg-agg-primary p-2 text-agg-foreground"
2304
+ }
2305
+ )
2306
+ ] })
2307
+ ] }) : null,
2308
+ transfer.deposit.isError || transfer.withdrawal.isError || transfer.storageError || actionError ? /* @__PURE__ */ jsx15("p", { role: "alert", className: "agg-type-caption text-agg-error", children: labels.transferUnavailable }) : null,
2309
+ transfer.request ? /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-2 agg-type-caption", children: [
2310
+ /* @__PURE__ */ jsxs15("p", { children: [
2311
+ labels.withdrawalAmount,
2312
+ ": ",
2313
+ amountText(transfer.request.amountRaw)
2314
+ ] }),
2315
+ /* @__PURE__ */ jsxs15("p", { className: "break-all", children: [
2316
+ labels.withdrawalDestination,
2317
+ ": ",
2318
+ transfer.request.destinationAddress
2319
+ ] }),
2320
+ /* @__PURE__ */ jsx15("p", { role: "status", children: result ? labels.withdrawalStatuses[result.status] : labels.withdrawalUnknown }),
2321
+ terminal ? /* @__PURE__ */ jsx15(
2322
+ Button,
2323
+ {
2324
+ type: "button",
2325
+ variant: "tertiary",
2326
+ size: "small",
2327
+ onClick: () => {
2328
+ transfer.clear();
2329
+ setAmount("");
2330
+ setDestination("");
2331
+ setActionError(false);
2332
+ setShowWithdraw(false);
2333
+ },
2334
+ children: labels.withdrawalNew
2335
+ }
2336
+ ) : /* @__PURE__ */ jsx15(
2337
+ Button,
2338
+ {
2339
+ type: "button",
2340
+ variant: "tertiary",
2341
+ size: "small",
2342
+ "aria-label": result ? labels.withdrawalCheck : labels.withdrawalRetry,
2343
+ isLoading: transfer.withdrawal.isPending,
2344
+ disabled: transfer.withdrawal.isPending,
2345
+ onClick: () => run(transfer.check),
2346
+ children: result ? labels.withdrawalCheck : labels.withdrawalRetry
2347
+ }
2348
+ )
2349
+ ] }) : showWithdraw ? /* @__PURE__ */ jsxs15(
2350
+ "form",
2351
+ {
2352
+ className: "flex flex-col gap-3",
2353
+ onSubmit: (event) => {
2354
+ event.preventDefault();
2355
+ if (!raw || !withinBalance || !validDestination || !transfer.ready) return;
2356
+ run(() => transfer.submit(raw, destination.trim()));
2357
+ },
2358
+ children: [
2359
+ /* @__PURE__ */ jsxs15("label", { className: "flex flex-col gap-1 agg-type-caption text-agg-muted-foreground", children: [
2360
+ labels.withdrawalAmount,
2361
+ /* @__PURE__ */ jsx15(
2362
+ "input",
2363
+ {
2364
+ inputMode: "decimal",
2365
+ autoComplete: "off",
2366
+ value: amount2,
2367
+ onChange: (event) => setAmount(event.target.value),
2368
+ className: "rounded-agg-md border border-agg-separator bg-agg-primary p-2 text-agg-foreground"
2369
+ }
2370
+ )
2371
+ ] }),
2372
+ environment === "production" ? /* @__PURE__ */ jsx15(
2373
+ Button,
2374
+ {
2375
+ type: "button",
2376
+ variant: "secondary",
2377
+ size: "small",
2378
+ disabled: !wallet.isReady || !wallet.svmAddress || wallet.isError,
2379
+ isLoading: wallet.isLoading,
2380
+ onClick: () => {
2381
+ if (wallet.isReady && wallet.svmAddress && !wallet.isError)
2382
+ setDestination(wallet.svmAddress);
2383
+ },
2384
+ children: labels.toWallet
2385
+ }
2386
+ ) : null,
2387
+ /* @__PURE__ */ jsxs15("label", { className: "flex flex-col gap-1 agg-type-caption text-agg-muted-foreground", children: [
2388
+ labels.withdrawalDestination,
2389
+ /* @__PURE__ */ jsx15(
2390
+ "input",
2391
+ {
2392
+ autoComplete: "off",
2393
+ spellCheck: false,
2394
+ value: destination,
2395
+ onChange: (event) => setDestination(event.target.value),
2396
+ className: "rounded-agg-md border border-agg-separator bg-agg-primary p-2 text-agg-foreground"
2397
+ }
2398
+ )
2399
+ ] }),
2400
+ /* @__PURE__ */ jsx15(
2401
+ Button,
2402
+ {
2403
+ type: "submit",
2404
+ variant: "primary",
2405
+ size: "small",
2406
+ "aria-label": labels.withdrawalSubmit,
2407
+ disabled: !withinBalance || !validDestination || !transfer.ready || transfer.withdrawal.isPending,
2408
+ isLoading: transfer.withdrawal.isPending,
2409
+ children: labels.withdrawalSubmit
2410
+ }
2411
+ )
2412
+ ]
2413
+ }
2414
+ ) : null
2415
+ ] });
2416
+ }
2417
+
2418
+ // src/pages/user-profile/components/betdex-account-activity.tsx
2419
+ import { useState as useState9 } from "react";
2420
+ import { useHostedVenueActivity, useLabels as useLabels15 } from "@agg-build/hooks";
2421
+ import { jsx as jsx16, jsxs as jsxs16 } from "react/jsx-runtime";
2422
+ function amount(raw) {
2423
+ const negative = raw.startsWith("-");
2424
+ const digits = (negative ? raw.slice(1) : raw).padStart(19, "0");
2425
+ const fraction = digits.slice(-18).replace(/0+$/, "");
2426
+ return `${negative ? "-" : "+"}${digits.slice(0, -18)}${fraction ? `.${fraction}` : ""}`;
2427
+ }
2428
+ function BetdexAccountActivity({
2429
+ accountId,
2430
+ environment
2431
+ }) {
2432
+ const labels = useLabels15().userProfile.hostedBetdex;
2433
+ const [page, setPage] = useState9(0);
2434
+ const { activity, isAvailable } = useHostedVenueActivity("betdex", page);
2435
+ if (!isAvailable) return null;
2436
+ const data = activity.data;
2437
+ const valid = (data == null ? void 0 : data.accountId) === accountId && data.environment === environment && data.page === page;
2438
+ const unavailable = activity.isError || !!data && !valid;
2439
+ return /* @__PURE__ */ jsxs16(
2440
+ "section",
2441
+ {
2442
+ "aria-label": labels.activityTitle,
2443
+ className: "flex flex-col gap-3 border-t border-agg-separator pt-3",
2444
+ children: [
2445
+ /* @__PURE__ */ jsx16("h4", { className: "agg-type-label text-agg-foreground", children: labels.activityTitle }),
2446
+ /* @__PURE__ */ jsx16("p", { className: "agg-type-caption text-agg-muted-foreground", children: labels.activityDescription }),
2447
+ activity.isPending ? /* @__PURE__ */ jsx16(SkeletonBlock, { className: "h-16 w-full" }) : null,
2448
+ unavailable ? /* @__PURE__ */ jsx16("p", { role: "status", className: "agg-type-caption text-agg-muted-foreground", children: labels.activityUnavailable }) : null,
2449
+ valid && !unavailable ? data.items.length ? /* @__PURE__ */ jsx16("ul", { className: "flex flex-col gap-3 agg-type-caption", children: data.items.map((item) => /* @__PURE__ */ jsxs16("li", { className: "flex flex-col gap-1", children: [
2450
+ /* @__PURE__ */ jsxs16("div", { className: "flex justify-between gap-3 text-agg-foreground", children: [
2451
+ /* @__PURE__ */ jsx16("span", { children: labels.activityCodes[item.code] }),
2452
+ /* @__PURE__ */ jsxs16("span", { className: "break-all tabular-nums", children: [
2453
+ amount(item.amountRaw),
2454
+ " ",
2455
+ data.asset
2456
+ ] })
2457
+ ] }),
2458
+ /* @__PURE__ */ jsx16("time", { dateTime: item.createdAt, className: "text-agg-muted-foreground", children: new Date(item.createdAt).toLocaleString() })
2459
+ ] }, item.id)) }) : /* @__PURE__ */ jsx16("p", { className: "agg-type-caption text-agg-muted-foreground", children: labels.activityEmpty }) : null,
2460
+ /* @__PURE__ */ jsxs16("div", { className: "flex flex-wrap gap-2", children: [
2461
+ /* @__PURE__ */ jsx16(
2462
+ Button,
2463
+ {
2464
+ type: "button",
2465
+ variant: "tertiary",
2466
+ size: "small",
2467
+ disabled: activity.isFetching || page === 0,
2468
+ onClick: () => setPage((value) => Math.max(0, value - 1)),
2469
+ children: labels.activityPrevious
2470
+ }
2471
+ ),
2472
+ /* @__PURE__ */ jsx16(
2473
+ Button,
2474
+ {
2475
+ type: "button",
2476
+ variant: "tertiary",
2477
+ size: "small",
2478
+ disabled: activity.isFetching || unavailable || !valid || data.nextPage === null,
2479
+ onClick: () => {
2480
+ if (valid && data.nextPage !== null) setPage(data.nextPage);
2481
+ },
2482
+ children: labels.activityNext
2483
+ }
2484
+ ),
2485
+ /* @__PURE__ */ jsx16(
2486
+ Button,
2487
+ {
2488
+ type: "button",
2489
+ variant: "tertiary",
2490
+ size: "small",
2491
+ disabled: activity.isFetching,
2492
+ onClick: () => {
2493
+ void activity.refetch();
2494
+ },
2495
+ children: labels.activityRefresh
2496
+ }
2497
+ )
2498
+ ] })
2499
+ ]
2500
+ }
2501
+ );
2502
+ }
2503
+
2504
+ // src/pages/user-profile/components/betdex-account-card.tsx
2505
+ import { Fragment as Fragment5, jsx as jsx17, jsxs as jsxs17 } from "react/jsx-runtime";
2506
+ function BetdexAccountCard({
2507
+ onWalletDeposit
2508
+ } = {}) {
2509
+ var _a;
2510
+ const [showActivity, setShowActivity] = useState10(false);
2511
+ const labels = useLabels16().userProfile.hostedBetdex;
2512
+ const { account, provision, isAvailable } = useHostedVenueAccount("betdex");
2513
+ const data = account.data;
2514
+ if (!isAvailable || (data == null ? void 0 : data.status) === "disabled") return null;
2515
+ const pending = provision.isPending || (data == null ? void 0 : data.status) === "provisioning";
2516
+ const canCreate = (data == null ? void 0 : data.status) === "not_created" && data.provisioningEnabled;
2517
+ const rawLabel = (raw) => formatUsd(Number(raw) / 1e6);
2518
+ return /* @__PURE__ */ jsxs17(
2519
+ "section",
2520
+ {
2521
+ "aria-label": labels.title,
2522
+ className: "flex flex-col gap-3 rounded-agg-xl border border-agg-separator bg-agg-secondary p-5",
2523
+ children: [
2524
+ /* @__PURE__ */ jsxs17("div", { className: "flex items-center gap-2", children: [
2525
+ /* @__PURE__ */ jsx17(VenueLogo, { venue: Venue4.betdex, size: "small", className: "size-4" }),
2526
+ /* @__PURE__ */ jsx17("h3", { className: "agg-type-label text-agg-foreground", children: labels.title })
2527
+ ] }),
2528
+ /* @__PURE__ */ jsx17("p", { className: "agg-type-caption text-agg-muted-foreground", children: labels.description }),
2529
+ (data == null ? void 0 : data.environment) === "sandbox" ? /* @__PURE__ */ jsx17("p", { className: "agg-type-caption text-agg-warning", children: labels.sandbox }) : null,
2530
+ account.isPending ? /* @__PURE__ */ jsx17(SkeletonBlock, { className: "h-10 w-full" }) : null,
2531
+ (data == null ? void 0 : data.status) === "active" && data.balanceStatus === "available" && data.balance && !account.isError ? /* @__PURE__ */ jsx17("dl", { className: "flex flex-col gap-2 agg-type-caption", children: [
2532
+ [labels.total, data.balance.totalRaw],
2533
+ [labels.available, data.balance.availableRaw],
2534
+ [labels.reserved, data.balance.unmatchedExposureRaw]
2535
+ ].map(([label, raw]) => /* @__PURE__ */ jsxs17("div", { className: "flex justify-between gap-3", children: [
2536
+ /* @__PURE__ */ jsx17("dt", { className: "text-agg-muted-foreground", children: label }),
2537
+ /* @__PURE__ */ jsx17("dd", { className: "text-agg-foreground", children: rawLabel(raw) })
2538
+ ] }, label)) }) : null,
2539
+ pending ? /* @__PURE__ */ jsx17("p", { role: "status", className: "agg-type-caption text-agg-muted-foreground", children: labels.provisioning }) : null,
2540
+ (data == null ? void 0 : data.status) === "suspended" ? /* @__PURE__ */ jsx17("p", { role: "status", className: "agg-type-caption text-agg-muted-foreground", children: labels.suspended }) : null,
2541
+ account.isError || (data == null ? void 0 : data.status) === "unavailable" || (data == null ? void 0 : data.balanceStatus) === "unavailable" ? /* @__PURE__ */ jsx17("p", { role: "status", className: "agg-type-caption text-agg-muted-foreground", children: labels.unavailable }) : null,
2542
+ (data == null ? void 0 : data.status) === "not_created" && !data.provisioningEnabled ? /* @__PURE__ */ jsx17("p", { className: "agg-type-caption text-agg-muted-foreground", children: labels.provisioningUnavailable }) : null,
2543
+ provision.isError ? /* @__PURE__ */ jsx17("p", { role: "alert", className: "agg-type-caption text-agg-error", children: labels.creationFailed }) : null,
2544
+ canCreate || (data == null ? void 0 : data.status) === "provisioning" ? /* @__PURE__ */ jsx17(
2545
+ Button,
2546
+ {
2547
+ type: "button",
2548
+ "aria-label": (data == null ? void 0 : data.status) === "provisioning" ? labels.checkSetup : labels.createAccount,
2549
+ variant: "secondary",
2550
+ size: "small",
2551
+ isLoading: provision.isPending,
2552
+ disabled: provision.isPending || account.isError,
2553
+ onClick: () => provision.mutate(),
2554
+ children: (data == null ? void 0 : data.status) === "provisioning" ? labels.checkSetup : labels.createAccount
2555
+ }
2556
+ ) : null,
2557
+ /* @__PURE__ */ jsx17(
2558
+ Button,
2559
+ {
2560
+ type: "button",
2561
+ variant: "tertiary",
2562
+ size: "small",
2563
+ disabled: account.isFetching || provision.isPending,
2564
+ onClick: () => {
2565
+ void account.refetch();
2566
+ },
2567
+ children: labels.refresh
2568
+ }
2569
+ ),
2570
+ (data == null ? void 0 : data.accountId) && data.environment && ["active", "suspended"].includes(data.status) ? /* @__PURE__ */ jsxs17(Fragment5, { children: [
2571
+ /* @__PURE__ */ jsxs17("details", { className: "group/agg-betdex-funds border-t border-agg-separator pt-3", children: [
2572
+ /* @__PURE__ */ jsxs17("summary", { className: "flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 text-agg-sm font-agg-bold text-agg-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-primary [&::-webkit-details-marker]:hidden", children: [
2573
+ labels.manageFunds,
2574
+ /* @__PURE__ */ jsx17(
2575
+ Icon,
2576
+ {
2577
+ name: "chevron-down",
2578
+ size: "small",
2579
+ className: "transition-transform group-open/agg-betdex-funds:rotate-180"
2580
+ }
2581
+ )
2582
+ ] }),
2583
+ /* @__PURE__ */ jsx17(
2584
+ BetdexAccountTransfers,
2585
+ {
2586
+ accountId: data.accountId,
2587
+ environment: data.environment,
2588
+ availableRaw: data.balanceStatus === "available" ? (_a = data.balance) == null ? void 0 : _a.availableRaw : void 0,
2589
+ canDeposit: data.status === "active",
2590
+ onWalletDeposit
2591
+ },
2592
+ `transfers:${data.accountId}:${data.environment}`
2593
+ )
2594
+ ] }),
2595
+ /* @__PURE__ */ jsx17(
2596
+ Button,
2597
+ {
2598
+ type: "button",
2599
+ variant: "tertiary",
2600
+ size: "small",
2601
+ "aria-expanded": showActivity,
2602
+ onClick: () => setShowActivity((shown) => !shown),
2603
+ children: showActivity ? labels.hideActivity : labels.showActivity
2604
+ }
2605
+ ),
2606
+ showActivity ? /* @__PURE__ */ jsx17(
2607
+ BetdexAccountActivity,
2608
+ {
2609
+ accountId: data.accountId,
2610
+ environment: data.environment
2611
+ },
2612
+ `${data.accountId}:${data.environment}`
2613
+ ) : null
2614
+ ] }) : null
2615
+ ]
2616
+ }
2617
+ );
2618
+ }
2619
+
2620
+ // src/pages/user-profile/components/betdex-wallet-deposit.tsx
2621
+ import { useEffect as useEffect5 } from "react";
2622
+ import { useLabels as useLabels17 } from "@agg-build/hooks";
2623
+ import { useWithdrawFlow as useWithdrawFlow2 } from "@agg-build/hooks/withdraw";
2624
+ import { jsx as jsx18 } from "react/jsx-runtime";
2625
+ function BetdexWalletDeposit({
2626
+ address,
2627
+ onClose
2628
+ }) {
2629
+ const labels = useLabels17().userProfile.hostedBetdex;
2630
+ const flow = useWithdrawFlow2({
2631
+ open: true,
2632
+ onOpenChange: (open) => {
2633
+ if (!open) onClose();
2634
+ }
2635
+ });
2636
+ const { onWithdrawDestinationChange, onWithdrawNetworkChange, onWithdrawTokenChange } = flow;
2637
+ useEffect5(() => {
2638
+ onWithdrawDestinationChange(address);
2639
+ onWithdrawNetworkChange("792703809");
2640
+ onWithdrawTokenChange("USDC");
2641
+ }, [address, onWithdrawDestinationChange, onWithdrawNetworkChange, onWithdrawTokenChange]);
2642
+ return /* @__PURE__ */ jsx18(
2643
+ WithdrawModal,
2644
+ __spreadProps(__spreadValues({}, flow), {
2645
+ transferTarget: {
2646
+ title: labels.transferToBetdex,
2647
+ address,
2648
+ chainId: "792703809",
2649
+ tokenSymbol: "USDC"
2650
+ }
2651
+ })
2652
+ );
2653
+ }
2654
+
2655
+ // src/trading/manage-betdex-account-modal.tsx
2656
+ import { Fragment as Fragment6, jsx as jsx19, jsxs as jsxs18 } from "react/jsx-runtime";
2657
+ function ManageBetdexAccountModal({
2658
+ open,
2659
+ onOpenChange,
2660
+ userId
2661
+ }) {
2662
+ const labels = useLabels18();
2663
+ const [fundingTarget, setFundingTarget] = useState11(
2664
+ null
2665
+ );
2666
+ const currentTarget = (fundingTarget == null ? void 0 : fundingTarget.userId) === userId ? fundingTarget : null;
2667
+ useEffect6(() => {
2668
+ if (!open) setFundingTarget(null);
2669
+ }, [open]);
2670
+ useEffect6(() => setFundingTarget(null), [userId]);
2671
+ return /* @__PURE__ */ jsxs18(Fragment6, { children: [
2672
+ /* @__PURE__ */ jsx19(Modal, { open: open && !currentTarget, onOpenChange, children: /* @__PURE__ */ jsxs18(Modal.Container, { maxWidth: "600px", "aria-label": labels.trading.manageBetdexAccount, children: [
2673
+ /* @__PURE__ */ jsx19(
2674
+ Dialog6.Close,
2675
+ {
2676
+ "aria-label": labels.common.close,
2677
+ className: "absolute right-4 top-4 z-10 flex size-11 cursor-pointer items-center justify-center rounded-agg-full text-agg-muted-foreground hover:bg-agg-quaternary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-agg-accent",
2678
+ children: /* @__PURE__ */ jsx19(Icon, { name: "close", size: "medium" })
2679
+ }
2680
+ ),
2681
+ /* @__PURE__ */ jsxs18(Modal.Body, { classNames: { root: "!px-5 !py-16" }, children: [
2682
+ /* @__PURE__ */ jsx19(Dialog6.Title, { className: "sr-only", children: labels.trading.manageBetdexAccount }),
2683
+ /* @__PURE__ */ jsx19(Dialog6.Description, { className: "sr-only", children: labels.userProfile.hostedBetdex.description }),
2684
+ open ? /* @__PURE__ */ jsx19(
2685
+ BetdexAccountCard,
2686
+ {
2687
+ onWalletDeposit: userId ? (address) => setFundingTarget({ userId, address }) : void 0
2688
+ }
2689
+ ) : null
2690
+ ] })
2691
+ ] }) }),
2692
+ open && currentTarget ? /* @__PURE__ */ jsx19(
2693
+ BetdexWalletDeposit,
2694
+ {
2695
+ address: currentTarget.address,
2696
+ onClose: () => setFundingTarget(null)
2697
+ },
2698
+ currentTarget.userId
2699
+ ) : null
2700
+ ] });
2701
+ }
2702
+
2703
+ export {
2704
+ dispatchAggDepositNotification,
2705
+ subscribeAggDepositNotification,
2706
+ GeoBlockBanner,
2707
+ SharedKycModal,
2708
+ HowItWorksStep,
2709
+ ProfileSetupStep,
2710
+ ConnectAccountsStep,
2711
+ ConnectOnchainModal,
2712
+ ConnectKalshiModal,
2713
+ ConnectProphetxModal,
2714
+ OnboardingModal,
2715
+ mapNetworksToOptions,
2716
+ DEFAULT_CURRENCY_OPTIONS,
2717
+ withTokenIcons,
2718
+ withNetworkIcons,
2719
+ mergeSelectOptionsUnique,
2720
+ TransferFeeSummary,
2721
+ buildTerminalSummary,
2722
+ WithdrawModal,
2723
+ ManageBetdexAccountModal
2724
+ };