@spicenet-io/spiceflow-ui 1.9.34 → 1.9.35

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.
@@ -1,1028 +1,12 @@
1
1
  "use client";
2
- 'use strict';
3
-
4
- const jsxRuntime = require('react/jsx-runtime');
5
- const React = require('react');
6
- const Button = require('./Button-D2yFTia-.js');
7
- const sdkReactCore = require('@dynamic-labs/sdk-react-core');
8
-
9
- const Input = ({
10
- label,
11
- error,
12
- helper,
13
- fullWidth = false,
14
- startAdornment,
15
- endAdornment,
16
- className = "",
17
- style,
18
- theme: providedTheme,
19
- ...props
20
- }) => {
21
- const theme = providedTheme || Button.createTheme("light");
22
- const containerStyles = {
23
- width: fullWidth ? "100%" : "auto",
24
- display: "flex",
25
- flexDirection: "column",
26
- gap: theme.spacing.xs
27
- };
28
- const inputContainerStyles = {
29
- position: "relative",
30
- display: "flex",
31
- alignItems: "center"
32
- };
33
- const inputStyles = {
34
- backgroundColor: theme.colors.surface,
35
- border: `1px solid ${error ? theme.colors.error : theme.colors.border}`,
36
- borderRadius: theme.borderRadius.md,
37
- color: theme.colors.text,
38
- fontSize: theme.typography.fontSize.base,
39
- padding: theme.spacing.md,
40
- paddingLeft: startAdornment ? theme.spacing.xl : theme.spacing.md,
41
- paddingRight: endAdornment ? theme.spacing.xl : theme.spacing.md,
42
- width: "100%",
43
- outline: "none",
44
- transition: `border-color ${theme.animation.normal}`,
45
- ":focus": {
46
- borderColor: error ? theme.colors.error : theme.colors.primary
47
- },
48
- ":hover": {
49
- borderColor: error ? theme.colors.error : theme.colors.borderHover
50
- },
51
- "::placeholder": {
52
- color: theme.colors.textMuted
53
- }
54
- };
55
- const labelStyles = {
56
- fontSize: theme.typography.fontSize.sm,
57
- fontWeight: theme.typography.fontWeight.medium,
58
- color: theme.colors.textSecondary
59
- };
60
- const helperStyles = {
61
- fontSize: theme.typography.fontSize.xs,
62
- color: error ? theme.colors.error : theme.colors.textMuted
63
- };
64
- const adornmentStyles = {
65
- position: "absolute",
66
- top: "50%",
67
- transform: "translateY(-50%)",
68
- color: theme.colors.textMuted,
69
- pointerEvents: "none"
70
- };
71
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyles, children: [
72
- label && /* @__PURE__ */ jsxRuntime.jsx("label", { style: labelStyles, children: label }),
73
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: inputContainerStyles, children: [
74
- startAdornment && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...adornmentStyles, left: theme.spacing.md }, children: startAdornment }),
75
- /* @__PURE__ */ jsxRuntime.jsx(
76
- "input",
77
- {
78
- style: { ...inputStyles, ...style },
79
- className,
80
- ...props
81
- }
82
- ),
83
- endAdornment && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...adornmentStyles, right: theme.spacing.md }, children: endAdornment })
84
- ] }),
85
- (error || helper) && /* @__PURE__ */ jsxRuntime.jsx("span", { style: helperStyles, children: error || helper })
86
- ] });
87
- };
88
-
89
- const Modal = ({
90
- isOpen,
91
- onClose,
92
- title,
93
- children,
94
- maxWidth = "32rem",
95
- className = "",
96
- theme: providedTheme
97
- }) => {
98
- const theme = providedTheme || Button.createTheme("light");
99
- React.useEffect(() => {
100
- const handleEscape = (event) => {
101
- if (event.key === "Escape") {
102
- onClose();
103
- }
104
- };
105
- if (isOpen) {
106
- document.addEventListener("keydown", handleEscape);
107
- document.body.style.overflow = "hidden";
108
- }
109
- return () => {
110
- document.removeEventListener("keydown", handleEscape);
111
- document.body.style.overflow = "unset";
112
- };
113
- }, [isOpen, onClose]);
114
- if (!isOpen) return null;
115
- const overlayStyles = {
116
- position: "fixed",
117
- top: 0,
118
- left: 0,
119
- right: 0,
120
- bottom: 0,
121
- backgroundColor: "rgba(0, 0, 0, 0.5)",
122
- display: "flex",
123
- alignItems: "center",
124
- justifyContent: "center",
125
- zIndex: 1e3,
126
- padding: theme.spacing.md
127
- };
128
- const modalStyles = {
129
- backgroundColor: theme.colors.background,
130
- border: `1px solid ${theme.colors.border}`,
131
- borderRadius: theme.borderRadius.lg,
132
- boxShadow: theme.shadows.lg,
133
- maxWidth,
134
- width: "100%",
135
- maxHeight: "90vh",
136
- overflow: "auto"
137
- };
138
- const headerStyles = {
139
- padding: theme.spacing.lg,
140
- borderBottom: `1px solid ${theme.colors.border}`,
141
- display: "flex",
142
- alignItems: "center",
143
- justifyContent: "space-between"
144
- };
145
- const titleStyles = {
146
- fontSize: theme.typography.fontSize.lg,
147
- fontWeight: theme.typography.fontWeight.semibold,
148
- color: theme.colors.text,
149
- margin: 0
150
- };
151
- const closeButtonStyles = {
152
- background: "none",
153
- border: "none",
154
- color: theme.colors.textMuted,
155
- cursor: "pointer",
156
- padding: theme.spacing.sm,
157
- borderRadius: theme.borderRadius.sm,
158
- display: "flex",
159
- alignItems: "center",
160
- justifyContent: "center",
161
- transition: `color ${theme.animation.normal}`,
162
- ":hover": {
163
- color: theme.colors.text
164
- }
165
- };
166
- const contentStyles = {
167
- padding: theme.spacing.lg
168
- };
169
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: overlayStyles, onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(
170
- "div",
171
- {
172
- style: modalStyles,
173
- className,
174
- onClick: (e) => e.stopPropagation(),
175
- children: [
176
- title && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: headerStyles, children: [
177
- /* @__PURE__ */ jsxRuntime.jsx("h2", { style: titleStyles, children: title }),
178
- /* @__PURE__ */ jsxRuntime.jsx("button", { style: closeButtonStyles, onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(
179
- "svg",
180
- {
181
- width: "20",
182
- height: "20",
183
- viewBox: "0 0 24 24",
184
- fill: "none",
185
- stroke: "currentColor",
186
- strokeWidth: "2",
187
- strokeLinecap: "round",
188
- strokeLinejoin: "round",
189
- children: [
190
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
191
- /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
192
- ]
193
- }
194
- ) })
195
- ] }),
196
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: contentStyles, children })
197
- ]
198
- }
199
- ) });
200
- };
201
-
202
- const DynamicLoginInternal = ({
203
- onAuthSuccess,
204
- onAuthError,
205
- theme: themeMode = "light",
206
- className = "",
207
- buttonText = "Login with Dynamic",
208
- autoTrigger = false
209
- }) => {
210
- const theme = Button.createTheme(themeMode);
211
- const [isClient, setIsClient] = React.useState(false);
212
- const [isModalOpen, setIsModalOpen] = React.useState(autoTrigger);
213
- const [hasAutoTriggered, setHasAutoTriggered] = React.useState(false);
214
- const [email, setEmail] = React.useState("");
215
- const [otp, setOtp] = React.useState("");
216
- const [error, setError] = React.useState(null);
217
- const [walletCreationStartTime, setWalletCreationStartTime] = React.useState(null);
218
- const [timeoutReached, setTimeoutReached] = React.useState(false);
219
- const [loginMethod, setLoginMethod] = React.useState(
220
- "options"
221
- );
222
- let dynamicState = null;
223
- let otpHooks = null;
224
- let isDynamicReady = false;
225
- let hookError = null;
226
- try {
227
- dynamicState = sdkReactCore.useDynamicContext();
228
- otpHooks = sdkReactCore.useConnectWithOtp();
229
- isDynamicReady = true;
230
- } catch (error2) {
231
- hookError = error2 instanceof Error ? error2.message : String(error2);
232
- }
233
- const connectWithEmail = otpHooks?.connectWithEmail;
234
- const verifyOneTimePassword = otpHooks?.verifyOneTimePassword;
235
- const handleLogOut = dynamicState?.handleLogOut;
236
- const { user, primaryWallet } = dynamicState || {
237
- user: null,
238
- primaryWallet: null
239
- };
240
- const isAuthenticated = !!user;
241
- const address = primaryWallet?.address;
242
- const isConnected = isAuthenticated && !!address;
243
- React.useEffect(() => {
244
- setIsClient(true);
245
- }, []);
246
- React.useEffect(() => {
247
- if (autoTrigger && isClient && isDynamicReady && !isConnected && !hasAutoTriggered) {
248
- setHasAutoTriggered(true);
249
- setIsModalOpen(true);
250
- }
251
- }, [autoTrigger, isClient, isDynamicReady, isConnected, hasAutoTriggered]);
252
- React.useEffect(() => {
253
- if (isClient && !isDynamicReady && hookError) {
254
- const retryTimer = setTimeout(() => {
255
- setError(null);
256
- }, 2e3);
257
- return () => clearTimeout(retryTimer);
258
- }
259
- }, [isClient, isDynamicReady, hookError]);
260
- React.useEffect(() => {
261
- if (walletCreationStartTime) {
262
- const timer = setTimeout(() => {
263
- setTimeoutReached(true);
264
- }, 3e4);
265
- return () => clearTimeout(timer);
266
- }
267
- }, [walletCreationStartTime]);
268
- React.useEffect(() => {
269
- if (isConnected && address) {
270
- setIsModalOpen(false);
271
- setLoginMethod("options");
272
- setEmail("");
273
- setOtp("");
274
- setError(null);
275
- setWalletCreationStartTime(null);
276
- setTimeoutReached(false);
277
- if (onAuthSuccess) {
278
- onAuthSuccess(address);
279
- }
280
- }
281
- }, [isConnected, address, onAuthSuccess]);
282
- const handleEmailSubmit = React.useCallback(
283
- async (e) => {
284
- e.preventDefault();
285
- if (!email.trim()) {
286
- setError("Please enter a valid email address");
287
- return;
288
- }
289
- if (!connectWithEmail) {
290
- setError("Dynamic context not ready. Please try again.");
291
- return;
292
- }
293
- setError(null);
294
- try {
295
- await connectWithEmail(email);
296
- setLoginMethod("otp");
297
- } catch (error2) {
298
- setError("Failed to send verification code. Please try again.");
299
- if (onAuthError) {
300
- onAuthError(`Failed to send verification code: ${String(error2)}`);
301
- }
302
- }
303
- },
304
- [email, connectWithEmail, onAuthError]
305
- );
306
- const handleOtpSubmit = React.useCallback(
307
- async (e) => {
308
- e.preventDefault();
309
- if (!otp.trim()) {
310
- setError("Please enter the verification code");
311
- return;
312
- }
313
- if (!verifyOneTimePassword) {
314
- setError("Dynamic context not ready. Please try again.");
315
- return;
316
- }
317
- setError(null);
318
- try {
319
- await verifyOneTimePassword(otp);
320
- if (user && !primaryWallet) {
321
- setWalletCreationStartTime(Date.now());
322
- }
323
- } catch (error2) {
324
- setError("Invalid verification code. Please try again.");
325
- if (onAuthError) {
326
- onAuthError(`OTP verification failed: ${String(error2)}`);
327
- }
328
- }
329
- },
330
- [otp, verifyOneTimePassword, user, primaryWallet, onAuthError]
331
- );
332
- const handleLogout = React.useCallback(async () => {
333
- try {
334
- if (handleLogOut) {
335
- await handleLogOut();
336
- }
337
- setIsModalOpen(false);
338
- setLoginMethod("options");
339
- setEmail("");
340
- setOtp("");
341
- setError(null);
342
- setWalletCreationStartTime(null);
343
- setTimeoutReached(false);
344
- } catch (error2) {
345
- setIsModalOpen(false);
346
- setLoginMethod("options");
347
- setEmail("");
348
- setOtp("");
349
- setError(null);
350
- setWalletCreationStartTime(null);
351
- setTimeoutReached(false);
352
- }
353
- }, [handleLogOut]);
354
- if (!isClient) {
355
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: /* @__PURE__ */ jsxRuntime.jsx(Button.Button, { variant: "primary", disabled: true, theme, children: buttonText }) });
356
- }
357
- if (!isDynamicReady) {
358
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
359
- /* @__PURE__ */ jsxRuntime.jsx(Button.Button, { variant: "primary", disabled: true, theme, children: "Loading Dynamic..." }),
360
- hookError && /* @__PURE__ */ jsxRuntime.jsx(
361
- "div",
362
- {
363
- style: {
364
- marginTop: "8px",
365
- fontSize: "12px",
366
- color: theme.colors.error,
367
- padding: theme.spacing.xs,
368
- backgroundColor: theme.mode === "light" ? "#fef2f2" : `${theme.colors.error}20`,
369
- borderRadius: theme.borderRadius.sm
370
- },
371
- children: "Initializing Dynamic context..."
372
- }
373
- )
374
- ] });
375
- }
376
- const renderAuthOptionsStep = () => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-[450px] space-y-8", children: [
377
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { textAlign: "center", marginBottom: theme.spacing.lg }, children: /* @__PURE__ */ jsxRuntime.jsx(
378
- "h1",
379
- {
380
- style: {
381
- fontSize: "1.875rem",
382
- fontWeight: "bold",
383
- color: theme.colors.text,
384
- marginBottom: theme.spacing.sm
385
- },
386
- children: "Get Started"
387
- }
388
- ) }),
389
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: theme.spacing.md }, children: /* @__PURE__ */ jsxRuntime.jsx(
390
- Button.Button,
391
- {
392
- variant: "primary",
393
- fullWidth: true,
394
- onClick: () => setLoginMethod("email"),
395
- theme,
396
- children: "Continue with Email"
397
- }
398
- ) }),
399
- error && /* @__PURE__ */ jsxRuntime.jsx(
400
- "div",
401
- {
402
- style: {
403
- padding: theme.spacing.md,
404
- backgroundColor: theme.mode === "light" ? "#fef2f2" : `${theme.colors.error}20`,
405
- border: `1px solid ${theme.mode === "light" ? "#fecaca" : theme.colors.error}`,
406
- borderRadius: theme.borderRadius.md,
407
- marginTop: theme.spacing.md
408
- },
409
- children: /* @__PURE__ */ jsxRuntime.jsx(
410
- "p",
411
- {
412
- style: {
413
- color: theme.colors.error,
414
- fontSize: theme.typography.fontSize.sm,
415
- margin: 0
416
- },
417
- children: error
418
- }
419
- )
420
- }
421
- )
422
- ] });
423
- const renderEmailStep = () => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-[450px] space-y-6", children: [
424
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", marginBottom: theme.spacing.lg }, children: [
425
- /* @__PURE__ */ jsxRuntime.jsx(
426
- "div",
427
- {
428
- style: {
429
- width: "4rem",
430
- height: "4rem",
431
- backgroundColor: theme.colors.primary,
432
- borderRadius: "50%",
433
- display: "flex",
434
- alignItems: "center",
435
- justifyContent: "center",
436
- margin: `0 auto ${theme.spacing.md}`
437
- },
438
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "1.25rem" }, children: "\u2709\uFE0F" })
439
- }
440
- ),
441
- /* @__PURE__ */ jsxRuntime.jsx(
442
- "h1",
443
- {
444
- style: {
445
- fontSize: "1.5rem",
446
- fontWeight: "bold",
447
- color: theme.colors.text,
448
- marginBottom: theme.spacing.sm
449
- },
450
- children: "Email Authentication"
451
- }
452
- ),
453
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: theme.colors.textMuted }, children: "Enter your email to get started" })
454
- ] }),
455
- /* @__PURE__ */ jsxRuntime.jsxs(
456
- "form",
457
- {
458
- onSubmit: handleEmailSubmit,
459
- style: { marginBottom: theme.spacing.md },
460
- children: [
461
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: theme.spacing.md }, children: [
462
- /* @__PURE__ */ jsxRuntime.jsx(
463
- "label",
464
- {
465
- style: {
466
- display: "block",
467
- fontSize: theme.typography.fontSize.sm,
468
- fontWeight: theme.typography.fontWeight.medium,
469
- color: theme.colors.text,
470
- marginBottom: theme.spacing.xs
471
- },
472
- children: "Email Address"
473
- }
474
- ),
475
- /* @__PURE__ */ jsxRuntime.jsx(
476
- Input,
477
- {
478
- type: "email",
479
- value: email,
480
- onChange: (e) => setEmail(e.target.value),
481
- placeholder: "Enter your email address",
482
- required: true,
483
- theme
484
- }
485
- )
486
- ] }),
487
- error && /* @__PURE__ */ jsxRuntime.jsx(
488
- "div",
489
- {
490
- style: {
491
- padding: theme.spacing.md,
492
- backgroundColor: theme.mode === "light" ? "#fef2f2" : `${theme.colors.error}20`,
493
- border: `1px solid ${theme.mode === "light" ? "#fecaca" : theme.colors.error}`,
494
- borderRadius: theme.borderRadius.md,
495
- marginBottom: theme.spacing.md
496
- },
497
- children: /* @__PURE__ */ jsxRuntime.jsx(
498
- "p",
499
- {
500
- style: {
501
- color: theme.colors.error,
502
- fontSize: theme.typography.fontSize.sm,
503
- margin: 0
504
- },
505
- children: error
506
- }
507
- )
508
- }
509
- ),
510
- /* @__PURE__ */ jsxRuntime.jsxs(
511
- "div",
512
- {
513
- style: {
514
- display: "flex",
515
- flexDirection: "column",
516
- gap: theme.spacing.sm
517
- },
518
- children: [
519
- /* @__PURE__ */ jsxRuntime.jsx(
520
- Button.Button,
521
- {
522
- type: "submit",
523
- variant: "primary",
524
- fullWidth: true,
525
- disabled: !email.trim(),
526
- theme,
527
- children: "Send Verification Code"
528
- }
529
- ),
530
- /* @__PURE__ */ jsxRuntime.jsx(
531
- Button.Button,
532
- {
533
- type: "button",
534
- variant: "secondary",
535
- fullWidth: true,
536
- onClick: () => {
537
- setLoginMethod("options");
538
- setError(null);
539
- setEmail("");
540
- },
541
- theme,
542
- children: "\u2190 Back"
543
- }
544
- )
545
- ]
546
- }
547
- )
548
- ]
549
- }
550
- )
551
- ] });
552
- const renderOtpStep = () => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-[450px] space-y-6", children: [
553
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", marginBottom: theme.spacing.lg }, children: [
554
- /* @__PURE__ */ jsxRuntime.jsx(
555
- "div",
556
- {
557
- style: {
558
- width: "4rem",
559
- height: "4rem",
560
- backgroundColor: theme.colors.success,
561
- borderRadius: "50%",
562
- display: "flex",
563
- alignItems: "center",
564
- justifyContent: "center",
565
- margin: `0 auto ${theme.spacing.md}`
566
- },
567
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "1.25rem", color: "#ffffff" }, children: "\u2713" })
568
- }
569
- ),
570
- /* @__PURE__ */ jsxRuntime.jsx(
571
- "h1",
572
- {
573
- style: {
574
- fontSize: "1.5rem",
575
- fontWeight: "bold",
576
- color: theme.colors.text,
577
- marginBottom: theme.spacing.sm
578
- },
579
- children: "Check Your Email"
580
- }
581
- ),
582
- /* @__PURE__ */ jsxRuntime.jsxs("p", { style: { color: theme.colors.textMuted }, children: [
583
- "Enter the verification code sent to",
584
- " ",
585
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: theme.colors.primary, fontWeight: "medium" }, children: email })
586
- ] })
587
- ] }),
588
- /* @__PURE__ */ jsxRuntime.jsxs(
589
- "form",
590
- {
591
- onSubmit: handleOtpSubmit,
592
- style: { marginBottom: theme.spacing.md },
593
- children: [
594
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: theme.spacing.md }, children: [
595
- /* @__PURE__ */ jsxRuntime.jsx(
596
- "label",
597
- {
598
- style: {
599
- display: "block",
600
- fontSize: theme.typography.fontSize.sm,
601
- fontWeight: theme.typography.fontWeight.medium,
602
- color: theme.colors.text,
603
- marginBottom: theme.spacing.xs
604
- },
605
- children: "Verification Code"
606
- }
607
- ),
608
- /* @__PURE__ */ jsxRuntime.jsx(
609
- Input,
610
- {
611
- type: "text",
612
- value: otp,
613
- onChange: (e) => setOtp(e.target.value),
614
- placeholder: "Enter 6-digit code",
615
- maxLength: 6,
616
- required: true,
617
- theme,
618
- className: "ibm-plex-mono",
619
- style: {
620
- textAlign: "center",
621
- fontSize: "1.3rem",
622
- letterSpacing: "0.2em",
623
- fontFamily: "IBM Plex Mono"
624
- }
625
- }
626
- )
627
- ] }),
628
- error && /* @__PURE__ */ jsxRuntime.jsx(
629
- "div",
630
- {
631
- style: {
632
- padding: theme.spacing.md,
633
- backgroundColor: theme.mode === "light" ? "#fef2f2" : `${theme.colors.error}20`,
634
- border: `1px solid ${theme.mode === "light" ? "#fecaca" : theme.colors.error}`,
635
- borderRadius: theme.borderRadius.md,
636
- marginBottom: theme.spacing.md
637
- },
638
- children: /* @__PURE__ */ jsxRuntime.jsx(
639
- "p",
640
- {
641
- style: {
642
- color: theme.colors.error,
643
- fontSize: theme.typography.fontSize.sm,
644
- margin: 0
645
- },
646
- children: error
647
- }
648
- )
649
- }
650
- ),
651
- /* @__PURE__ */ jsxRuntime.jsxs(
652
- "div",
653
- {
654
- style: {
655
- display: "flex",
656
- flexDirection: "column",
657
- gap: theme.spacing.sm
658
- },
659
- children: [
660
- /* @__PURE__ */ jsxRuntime.jsx(
661
- Button.Button,
662
- {
663
- type: "submit",
664
- variant: "primary",
665
- fullWidth: true,
666
- disabled: !otp.trim(),
667
- theme,
668
- children: "Verify Code"
669
- }
670
- ),
671
- /* @__PURE__ */ jsxRuntime.jsx(
672
- Button.Button,
673
- {
674
- type: "button",
675
- variant: "secondary",
676
- fullWidth: true,
677
- onClick: () => {
678
- setError(null);
679
- setOtp("");
680
- setLoginMethod("email");
681
- },
682
- theme,
683
- children: "\u2190 Back to Email"
684
- }
685
- )
686
- ]
687
- }
688
- )
689
- ]
690
- }
691
- )
692
- ] });
693
- const renderWalletCreationStep = () => {
694
- const isStuck = timeoutReached || walletCreationStartTime && Date.now() - (walletCreationStartTime || 0) > 3e4;
695
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-[450px] space-y-6", children: [
696
- /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", marginBottom: theme.spacing.lg }, children: [
697
- /* @__PURE__ */ jsxRuntime.jsx(
698
- "div",
699
- {
700
- style: {
701
- width: "4rem",
702
- height: "4rem",
703
- backgroundColor: theme.colors.warning,
704
- borderRadius: "50%",
705
- display: "flex",
706
- alignItems: "center",
707
- justifyContent: "center",
708
- margin: `0 auto ${theme.spacing.md}`
709
- },
710
- children: /* @__PURE__ */ jsxRuntime.jsx(
711
- "div",
712
- {
713
- style: {
714
- width: "1.5rem",
715
- height: "1.5rem",
716
- border: `2px solid ${theme.colors.text}`,
717
- borderTop: "2px solid transparent",
718
- borderRadius: "50%",
719
- animation: "spin 1s linear infinite"
720
- }
721
- }
722
- )
723
- }
724
- ),
725
- /* @__PURE__ */ jsxRuntime.jsx(
726
- "h1",
727
- {
728
- style: {
729
- fontSize: "1.5rem",
730
- fontWeight: "bold",
731
- color: theme.colors.text,
732
- marginBottom: theme.spacing.sm
733
- },
734
- children: "Setting up your wallet..."
735
- }
736
- ),
737
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: theme.colors.textMuted }, children: "Creating your wallet automatically. This may take a few moments." }),
738
- walletCreationStartTime && /* @__PURE__ */ jsxRuntime.jsxs(
739
- "div",
740
- {
741
- style: {
742
- fontSize: theme.typography.fontSize.sm,
743
- color: theme.colors.textMuted,
744
- marginTop: theme.spacing.sm
745
- },
746
- children: [
747
- /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
748
- "Waiting time:",
749
- " ",
750
- Math.floor(
751
- (Date.now() - (walletCreationStartTime || 0)) / 1e3
752
- ),
753
- "s"
754
- ] }),
755
- timeoutReached && /* @__PURE__ */ jsxRuntime.jsx(
756
- "p",
757
- {
758
- style: { color: theme.colors.warning, fontWeight: "medium" },
759
- children: "\u26A0\uFE0F Taking longer than expected"
760
- }
761
- )
762
- ]
763
- }
764
- )
765
- ] }),
766
- /* @__PURE__ */ jsxRuntime.jsxs(
767
- "div",
768
- {
769
- style: {
770
- display: "flex",
771
- flexDirection: "column",
772
- gap: theme.spacing.sm
773
- },
774
- children: [
775
- /* @__PURE__ */ jsxRuntime.jsx(
776
- Button.Button,
777
- {
778
- variant: "secondary",
779
- fullWidth: true,
780
- onClick: () => window.location.reload(),
781
- theme,
782
- children: "Retry Automatic Creation"
783
- }
784
- ),
785
- /* @__PURE__ */ jsxRuntime.jsx(
786
- Button.Button,
787
- {
788
- variant: "secondary",
789
- fullWidth: true,
790
- onClick: handleLogout,
791
- theme,
792
- children: "Cancel & Start Over"
793
- }
794
- )
795
- ]
796
- }
797
- ),
798
- isStuck && /* @__PURE__ */ jsxRuntime.jsxs(
799
- "div",
800
- {
801
- style: {
802
- marginTop: theme.spacing.md,
803
- padding: theme.spacing.md,
804
- backgroundColor: theme.mode === "light" ? "#fef3c7" : `${theme.colors.warning}20`,
805
- border: `1px solid ${theme.mode === "light" ? "#fde68a" : theme.colors.warning}`,
806
- borderRadius: theme.borderRadius.md
807
- },
808
- children: [
809
- /* @__PURE__ */ jsxRuntime.jsx(
810
- "p",
811
- {
812
- style: {
813
- color: theme.colors.warning,
814
- fontSize: theme.typography.fontSize.sm,
815
- marginBottom: theme.spacing.sm
816
- },
817
- children: "\u26A0\uFE0F Wallet creation is taking longer than expected. This might be due to network issues."
818
- }
819
- ),
820
- /* @__PURE__ */ jsxRuntime.jsxs(
821
- "div",
822
- {
823
- style: {
824
- fontSize: theme.typography.fontSize.xs,
825
- color: theme.colors.textMuted
826
- },
827
- children: [
828
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: "\u2022 Try refreshing the page to restart automatic creation" }),
829
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: "\u2022 Check your internet connection" }),
830
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: "\u2022 If the issue persists, start over with a new email" })
831
- ]
832
- }
833
- )
834
- ]
835
- }
836
- )
837
- ] });
838
- };
839
- const getModalContent = () => {
840
- if (!isDynamicReady) {
841
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "center", padding: theme.spacing.xl }, children: [
842
- /* @__PURE__ */ jsxRuntime.jsx(
843
- "div",
844
- {
845
- style: {
846
- width: "2.5rem",
847
- height: "2.5rem",
848
- border: `2px solid ${theme.colors.border}`,
849
- borderTop: `2px solid ${theme.colors.primary}`,
850
- borderRadius: "50%",
851
- animation: "spin 1s linear infinite",
852
- margin: `0 auto ${theme.spacing.md}`
853
- }
854
- }
855
- ),
856
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: theme.colors.textMuted }, children: "Initializing Dynamic..." })
857
- ] });
858
- }
859
- if (isAuthenticated && !address) {
860
- return renderWalletCreationStep();
861
- }
862
- if (loginMethod === "otp") {
863
- return renderOtpStep();
864
- }
865
- if (loginMethod === "email") {
866
- return renderEmailStep();
867
- }
868
- return renderAuthOptionsStep();
869
- };
870
- if (isConnected && address) {
871
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: /* @__PURE__ */ jsxRuntime.jsxs(Button.Button, { variant: "primary", onClick: handleLogout, theme, children: [
872
- "Logout (",
873
- address.slice(0, 6),
874
- "...",
875
- address.slice(-4),
876
- ")"
877
- ] }) });
878
- }
879
- if (autoTrigger) {
880
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
881
- /* @__PURE__ */ jsxRuntime.jsxs(
882
- "div",
883
- {
884
- style: {
885
- display: "flex",
886
- alignItems: "center",
887
- justifyContent: "center",
888
- padding: "20px",
889
- flexDirection: "column",
890
- gap: "12px"
891
- },
892
- children: [
893
- /* @__PURE__ */ jsxRuntime.jsx(
894
- "div",
895
- {
896
- style: {
897
- width: "40px",
898
- height: "40px",
899
- border: "3px solid #e5e7eb",
900
- borderTop: "3px solid #3b82f6",
901
- borderRadius: "50%",
902
- animation: "spin 1s linear infinite"
903
- }
904
- }
905
- ),
906
- /* @__PURE__ */ jsxRuntime.jsx("p", { style: { color: "#6b7280", fontSize: "14px" }, children: "Opening login..." })
907
- ]
908
- }
909
- ),
910
- /* @__PURE__ */ jsxRuntime.jsx(
911
- Modal,
912
- {
913
- isOpen: isModalOpen,
914
- onClose: () => {
915
- if (!isAuthenticated || isConnected) {
916
- setIsModalOpen(false);
917
- setLoginMethod("options");
918
- setEmail("");
919
- setOtp("");
920
- setError(null);
921
- }
922
- },
923
- title: "",
924
- theme,
925
- children: getModalContent()
926
- }
927
- ),
928
- /* @__PURE__ */ jsxRuntime.jsx(
929
- "style",
930
- {
931
- dangerouslySetInnerHTML: {
932
- __html: `
2
+ "use strict";const t=require("react/jsx-runtime"),n=require("react"),a=require("./Button-Cn16gFtO.js"),_=require("@dynamic-labs/sdk-react-core"),V=({label:d,error:i,helper:x,fullWidth:u=!1,startAdornment:h,endAdornment:m,className:e="",style:o,theme:z,...S})=>{const r=z||a.createTheme("light"),w={width:u?"100%":"auto",display:"flex",flexDirection:"column",gap:r.spacing.xs},B={position:"relative",display:"flex",alignItems:"center"},p={backgroundColor:r.colors.surface,border:`1px solid ${i?r.colors.error:r.colors.border}`,borderRadius:r.borderRadius.md,color:r.colors.text,fontSize:r.typography.fontSize.base,padding:r.spacing.md,paddingLeft:h?r.spacing.xl:r.spacing.md,paddingRight:m?r.spacing.xl:r.spacing.md,width:"100%",outline:"none",transition:`border-color ${r.animation.normal}`,":focus":{borderColor:i?r.colors.error:r.colors.primary},":hover":{borderColor:i?r.colors.error:r.colors.borderHover},"::placeholder":{color:r.colors.textMuted}},c={fontSize:r.typography.fontSize.sm,fontWeight:r.typography.fontWeight.medium,color:r.colors.textSecondary},y={fontSize:r.typography.fontSize.xs,color:i?r.colors.error:r.colors.textMuted},g={position:"absolute",top:"50%",transform:"translateY(-50%)",color:r.colors.textMuted,pointerEvents:"none"};return t.jsxs("div",{style:w,children:[d&&t.jsx("label",{style:c,children:d}),t.jsxs("div",{style:B,children:[h&&t.jsx("div",{style:{...g,left:r.spacing.md},children:h}),t.jsx("input",{style:{...p,...o},className:e,...S}),m&&t.jsx("div",{style:{...g,right:r.spacing.md},children:m})]}),(i||x)&&t.jsx("span",{style:y,children:i||x})]})},Y=({isOpen:d,onClose:i,title:x,children:u,maxWidth:h="32rem",className:m="",theme:e})=>{const o=e||a.createTheme("light");if(n.useEffect(()=>{const c=y=>{y.key==="Escape"&&i()};return d&&(document.addEventListener("keydown",c),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",c),document.body.style.overflow="unset"}},[d,i]),!d)return null;const z={position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,padding:o.spacing.md},S={backgroundColor:o.colors.background,border:`1px solid ${o.colors.border}`,borderRadius:o.borderRadius.lg,boxShadow:o.shadows.lg,maxWidth:h,width:"100%",maxHeight:"90vh",overflow:"auto"},r={padding:o.spacing.lg,borderBottom:`1px solid ${o.colors.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},w={fontSize:o.typography.fontSize.lg,fontWeight:o.typography.fontWeight.semibold,color:o.colors.text,margin:0},B={background:"none",border:"none",color:o.colors.textMuted,cursor:"pointer",padding:o.spacing.sm,borderRadius:o.borderRadius.sm,display:"flex",alignItems:"center",justifyContent:"center",transition:`color ${o.animation.normal}`,":hover":{color:o.colors.text}},p={padding:o.spacing.lg};return t.jsx("div",{style:z,onClick:i,children:t.jsxs("div",{style:S,className:m,onClick:c=>c.stopPropagation(),children:[x&&t.jsxs("div",{style:r,children:[t.jsx("h2",{style:w,children:x}),t.jsx("button",{style:B,onClick:i,children:t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),t.jsx("div",{style:p,children:u})]})})},Z=({onAuthSuccess:d,onAuthError:i,theme:x="light",className:u="",buttonText:h="Login with Dynamic",autoTrigger:m=!1})=>{const e=a.createTheme(x),[o,z]=n.useState(!1),[S,r]=n.useState(m),[w,B]=n.useState(!1),[p,c]=n.useState(""),[y,g]=n.useState(""),[C,l]=n.useState(null),[k,W]=n.useState(null),[F,E]=n.useState(!1),[O,f]=n.useState("options");let D=null,$=null,b=!1,R=null;try{D=_.useDynamicContext(),$=_.useConnectWithOtp(),b=!0}catch(s){R=s instanceof Error?s.message:String(s)}const I=$?.connectWithEmail,A=$?.verifyOneTimePassword,L=D?.handleLogOut,{user:M,primaryWallet:N}=D||{user:null,primaryWallet:null},T=!!M,j=N?.address,v=T&&!!j;n.useEffect(()=>{z(!0)},[]),n.useEffect(()=>{m&&o&&b&&!v&&!w&&(B(!0),r(!0))},[m,o,b,v,w]),n.useEffect(()=>{if(o&&!b&&R){const s=setTimeout(()=>{l(null)},2e3);return()=>clearTimeout(s)}},[o,b,R]),n.useEffect(()=>{if(k){const s=setTimeout(()=>{E(!0)},3e4);return()=>clearTimeout(s)}},[k]),n.useEffect(()=>{v&&j&&(r(!1),f("options"),c(""),g(""),l(null),W(null),E(!1),d&&d(j))},[v,j,d]);const G=n.useCallback(async s=>{if(s.preventDefault(),!p.trim()){l("Please enter a valid email address");return}if(!I){l("Dynamic context not ready. Please try again.");return}l(null);try{await I(p),f("otp")}catch(P){l("Failed to send verification code. Please try again."),i&&i(`Failed to send verification code: ${String(P)}`)}},[p,I,i]),J=n.useCallback(async s=>{if(s.preventDefault(),!y.trim()){l("Please enter the verification code");return}if(!A){l("Dynamic context not ready. Please try again.");return}l(null);try{await A(y),M&&!N&&W(Date.now())}catch(P){l("Invalid verification code. Please try again."),i&&i(`OTP verification failed: ${String(P)}`)}},[y,A,M,N,i]),q=n.useCallback(async()=>{try{L&&await L(),r(!1),f("options"),c(""),g(""),l(null),W(null),E(!1)}catch{r(!1),f("options"),c(""),g(""),l(null),W(null),E(!1)}},[L]);if(!o)return t.jsx("div",{className:u,children:t.jsx(a.Button,{variant:"primary",disabled:!0,theme:e,children:h})});if(!b)return t.jsxs("div",{className:u,children:[t.jsx(a.Button,{variant:"primary",disabled:!0,theme:e,children:"Loading Dynamic..."}),R&&t.jsx("div",{style:{marginTop:"8px",fontSize:"12px",color:e.colors.error,padding:e.spacing.xs,backgroundColor:e.mode==="light"?"#fef2f2":`${e.colors.error}20`,borderRadius:e.borderRadius.sm},children:"Initializing Dynamic context..."})]});const K=()=>t.jsxs("div",{className:"w-full max-w-[450px] space-y-8",children:[t.jsx("div",{style:{textAlign:"center",marginBottom:e.spacing.lg},children:t.jsx("h1",{style:{fontSize:"1.875rem",fontWeight:"bold",color:e.colors.text,marginBottom:e.spacing.sm},children:"Get Started"})}),t.jsx("div",{style:{marginBottom:e.spacing.md},children:t.jsx(a.Button,{variant:"primary",fullWidth:!0,onClick:()=>f("email"),theme:e,children:"Continue with Email"})}),C&&t.jsx("div",{style:{padding:e.spacing.md,backgroundColor:e.mode==="light"?"#fef2f2":`${e.colors.error}20`,border:`1px solid ${e.mode==="light"?"#fecaca":e.colors.error}`,borderRadius:e.borderRadius.md,marginTop:e.spacing.md},children:t.jsx("p",{style:{color:e.colors.error,fontSize:e.typography.fontSize.sm,margin:0},children:C})})]}),Q=()=>t.jsxs("div",{className:"w-full max-w-[450px] space-y-6",children:[t.jsxs("div",{style:{textAlign:"center",marginBottom:e.spacing.lg},children:[t.jsx("div",{style:{width:"4rem",height:"4rem",backgroundColor:e.colors.primary,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:`0 auto ${e.spacing.md}`},children:t.jsx("span",{style:{fontSize:"1.25rem"},children:"\u2709\uFE0F"})}),t.jsx("h1",{style:{fontSize:"1.5rem",fontWeight:"bold",color:e.colors.text,marginBottom:e.spacing.sm},children:"Email Authentication"}),t.jsx("p",{style:{color:e.colors.textMuted},children:"Enter your email to get started"})]}),t.jsxs("form",{onSubmit:G,style:{marginBottom:e.spacing.md},children:[t.jsxs("div",{style:{marginBottom:e.spacing.md},children:[t.jsx("label",{style:{display:"block",fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.medium,color:e.colors.text,marginBottom:e.spacing.xs},children:"Email Address"}),t.jsx(V,{type:"email",value:p,onChange:s=>c(s.target.value),placeholder:"Enter your email address",required:!0,theme:e})]}),C&&t.jsx("div",{style:{padding:e.spacing.md,backgroundColor:e.mode==="light"?"#fef2f2":`${e.colors.error}20`,border:`1px solid ${e.mode==="light"?"#fecaca":e.colors.error}`,borderRadius:e.borderRadius.md,marginBottom:e.spacing.md},children:t.jsx("p",{style:{color:e.colors.error,fontSize:e.typography.fontSize.sm,margin:0},children:C})}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:e.spacing.sm},children:[t.jsx(a.Button,{type:"submit",variant:"primary",fullWidth:!0,disabled:!p.trim(),theme:e,children:"Send Verification Code"}),t.jsx(a.Button,{type:"button",variant:"secondary",fullWidth:!0,onClick:()=>{f("options"),l(null),c("")},theme:e,children:"\u2190 Back"})]})]})]}),U=()=>t.jsxs("div",{className:"w-full max-w-[450px] space-y-6",children:[t.jsxs("div",{style:{textAlign:"center",marginBottom:e.spacing.lg},children:[t.jsx("div",{style:{width:"4rem",height:"4rem",backgroundColor:e.colors.success,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:`0 auto ${e.spacing.md}`},children:t.jsx("span",{style:{fontSize:"1.25rem",color:"#ffffff"},children:"\u2713"})}),t.jsx("h1",{style:{fontSize:"1.5rem",fontWeight:"bold",color:e.colors.text,marginBottom:e.spacing.sm},children:"Check Your Email"}),t.jsxs("p",{style:{color:e.colors.textMuted},children:["Enter the verification code sent to"," ",t.jsx("span",{style:{color:e.colors.primary,fontWeight:"medium"},children:p})]})]}),t.jsxs("form",{onSubmit:J,style:{marginBottom:e.spacing.md},children:[t.jsxs("div",{style:{marginBottom:e.spacing.md},children:[t.jsx("label",{style:{display:"block",fontSize:e.typography.fontSize.sm,fontWeight:e.typography.fontWeight.medium,color:e.colors.text,marginBottom:e.spacing.xs},children:"Verification Code"}),t.jsx(V,{type:"text",value:y,onChange:s=>g(s.target.value),placeholder:"Enter 6-digit code",maxLength:6,required:!0,theme:e,className:"ibm-plex-mono",style:{textAlign:"center",fontSize:"1.3rem",letterSpacing:"0.2em",fontFamily:"IBM Plex Mono"}})]}),C&&t.jsx("div",{style:{padding:e.spacing.md,backgroundColor:e.mode==="light"?"#fef2f2":`${e.colors.error}20`,border:`1px solid ${e.mode==="light"?"#fecaca":e.colors.error}`,borderRadius:e.borderRadius.md,marginBottom:e.spacing.md},children:t.jsx("p",{style:{color:e.colors.error,fontSize:e.typography.fontSize.sm,margin:0},children:C})}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:e.spacing.sm},children:[t.jsx(a.Button,{type:"submit",variant:"primary",fullWidth:!0,disabled:!y.trim(),theme:e,children:"Verify Code"}),t.jsx(a.Button,{type:"button",variant:"secondary",fullWidth:!0,onClick:()=>{l(null),g(""),f("email")},theme:e,children:"\u2190 Back to Email"})]})]})]}),X=()=>{const s=F||k&&Date.now()-(k||0)>3e4;return t.jsxs("div",{className:"w-full max-w-[450px] space-y-6",children:[t.jsxs("div",{style:{textAlign:"center",marginBottom:e.spacing.lg},children:[t.jsx("div",{style:{width:"4rem",height:"4rem",backgroundColor:e.colors.warning,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:`0 auto ${e.spacing.md}`},children:t.jsx("div",{style:{width:"1.5rem",height:"1.5rem",border:`2px solid ${e.colors.text}`,borderTop:"2px solid transparent",borderRadius:"50%",animation:"spin 1s linear infinite"}})}),t.jsx("h1",{style:{fontSize:"1.5rem",fontWeight:"bold",color:e.colors.text,marginBottom:e.spacing.sm},children:"Setting up your wallet..."}),t.jsx("p",{style:{color:e.colors.textMuted},children:"Creating your wallet automatically. This may take a few moments."}),k&&t.jsxs("div",{style:{fontSize:e.typography.fontSize.sm,color:e.colors.textMuted,marginTop:e.spacing.sm},children:[t.jsxs("p",{children:["Waiting time:"," ",Math.floor((Date.now()-(k||0))/1e3),"s"]}),F&&t.jsx("p",{style:{color:e.colors.warning,fontWeight:"medium"},children:"\u26A0\uFE0F Taking longer than expected"})]})]}),t.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:e.spacing.sm},children:[t.jsx(a.Button,{variant:"secondary",fullWidth:!0,onClick:()=>window.location.reload(),theme:e,children:"Retry Automatic Creation"}),t.jsx(a.Button,{variant:"secondary",fullWidth:!0,onClick:q,theme:e,children:"Cancel & Start Over"})]}),s&&t.jsxs("div",{style:{marginTop:e.spacing.md,padding:e.spacing.md,backgroundColor:e.mode==="light"?"#fef3c7":`${e.colors.warning}20`,border:`1px solid ${e.mode==="light"?"#fde68a":e.colors.warning}`,borderRadius:e.borderRadius.md},children:[t.jsx("p",{style:{color:e.colors.warning,fontSize:e.typography.fontSize.sm,marginBottom:e.spacing.sm},children:"\u26A0\uFE0F Wallet creation is taking longer than expected. This might be due to network issues."}),t.jsxs("div",{style:{fontSize:e.typography.fontSize.xs,color:e.colors.textMuted},children:[t.jsx("p",{children:"\u2022 Try refreshing the page to restart automatic creation"}),t.jsx("p",{children:"\u2022 Check your internet connection"}),t.jsx("p",{children:"\u2022 If the issue persists, start over with a new email"})]})]})]})},H=()=>b?T&&!j?X():O==="otp"?U():O==="email"?Q():K():t.jsxs("div",{style:{textAlign:"center",padding:e.spacing.xl},children:[t.jsx("div",{style:{width:"2.5rem",height:"2.5rem",border:`2px solid ${e.colors.border}`,borderTop:`2px solid ${e.colors.primary}`,borderRadius:"50%",animation:"spin 1s linear infinite",margin:`0 auto ${e.spacing.md}`}}),t.jsx("p",{style:{color:e.colors.textMuted},children:"Initializing Dynamic..."})]});return v&&j?t.jsx("div",{className:u,children:t.jsxs(a.Button,{variant:"primary",onClick:q,theme:e,children:["Logout (",j.slice(0,6),"...",j.slice(-4),")"]})}):m?t.jsxs("div",{className:u,children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"20px",flexDirection:"column",gap:"12px"},children:[t.jsx("div",{style:{width:"40px",height:"40px",border:"3px solid #e5e7eb",borderTop:"3px solid #3b82f6",borderRadius:"50%",animation:"spin 1s linear infinite"}}),t.jsx("p",{style:{color:"#6b7280",fontSize:"14px"},children:"Opening login..."})]}),t.jsx(Y,{isOpen:S,onClose:()=>{(!T||v)&&(r(!1),f("options"),c(""),g(""),l(null))},title:"",theme:e,children:H()}),t.jsx("style",{dangerouslySetInnerHTML:{__html:`
933
3
  @keyframes spin {
934
4
  0% { transform: rotate(0deg); }
935
5
  100% { transform: rotate(360deg); }
936
6
  }
937
- `
938
- }
939
- }
940
- )
941
- ] });
942
- }
943
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
944
- /* @__PURE__ */ jsxRuntime.jsx(
945
- Button.Button,
946
- {
947
- variant: "primary",
948
- onClick: () => setIsModalOpen(true),
949
- theme,
950
- children: buttonText
951
- }
952
- ),
953
- /* @__PURE__ */ jsxRuntime.jsx(
954
- Modal,
955
- {
956
- isOpen: isModalOpen,
957
- onClose: () => {
958
- if (!isAuthenticated || isConnected) {
959
- setIsModalOpen(false);
960
- setLoginMethod("options");
961
- setEmail("");
962
- setOtp("");
963
- setError(null);
964
- }
965
- },
966
- title: "",
967
- theme,
968
- children: getModalContent()
969
- }
970
- ),
971
- /* @__PURE__ */ jsxRuntime.jsx(
972
- "style",
973
- {
974
- dangerouslySetInnerHTML: {
975
- __html: `
7
+ `}})]}):t.jsxs("div",{className:u,children:[t.jsx(a.Button,{variant:"primary",onClick:()=>r(!0),theme:e,children:h}),t.jsx(Y,{isOpen:S,onClose:()=>{(!T||v)&&(r(!1),f("options"),c(""),g(""),l(null))},title:"",theme:e,children:H()}),t.jsx("style",{dangerouslySetInnerHTML:{__html:`
976
8
  @keyframes spin {
977
9
  0% { transform: rotate(0deg); }
978
10
  100% { transform: rotate(360deg); }
979
11
  }
980
- `
981
- }
982
- }
983
- )
984
- ] });
985
- };
986
- class DynamicErrorBoundary extends React.Component {
987
- constructor(props) {
988
- super(props);
989
- this.state = { hasError: false };
990
- }
991
- static getDerivedStateFromError() {
992
- return { hasError: true };
993
- }
994
- componentDidCatch(error) {
995
- }
996
- render() {
997
- if (this.state.hasError) {
998
- return this.props.fallback;
999
- }
1000
- return this.props.children;
1001
- }
1002
- }
1003
- const DynamicLogin = (props) => {
1004
- const {
1005
- theme: themeMode = "light",
1006
- className = "",
1007
- buttonText = "Login with Dynamic",
1008
- onAuthError
1009
- } = props;
1010
- const theme = Button.createTheme(themeMode);
1011
- const fallbackComponent = /* @__PURE__ */ jsxRuntime.jsx("div", { className, children: /* @__PURE__ */ jsxRuntime.jsx(
1012
- Button.Button,
1013
- {
1014
- variant: "primary",
1015
- onClick: () => {
1016
- const errorMessage = "DynamicLogin must be used within SpiceFlowProvider. Please wrap your app with <SpiceFlowProvider>.";
1017
- if (onAuthError) {
1018
- onAuthError(errorMessage);
1019
- }
1020
- },
1021
- theme,
1022
- children: buttonText
1023
- }
1024
- ) });
1025
- return /* @__PURE__ */ jsxRuntime.jsx(DynamicErrorBoundary, { fallback: fallbackComponent, children: /* @__PURE__ */ jsxRuntime.jsx(DynamicLoginInternal, { ...props }) });
1026
- };
1027
-
1028
- exports.DynamicLogin = DynamicLogin;
12
+ `}})]})};class ee extends n.Component{constructor(i){super(i),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(i){}render(){return this.state.hasError?this.props.fallback:this.props.children}}const te=d=>{const{theme:i="light",className:x="",buttonText:u="Login with Dynamic",onAuthError:h}=d,m=a.createTheme(i);return t.jsx(ee,{fallback:t.jsx("div",{className:x,children:t.jsx(a.Button,{variant:"primary",onClick:()=>{h&&h("DynamicLogin must be used within SpiceFlowProvider. Please wrap your app with <SpiceFlowProvider>.")},theme:m,children:u})}),children:t.jsx(Z,{...d})})};exports.DynamicLogin=te;