@avalabs/avacloud-waas-react 1.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,4148 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AvaCloudWalletProvider: () => AvaCloudWalletProvider,
24
+ ExportView: () => ExportView,
25
+ LoginButton: () => LoginButton,
26
+ ReceiveView: () => ReceiveView,
27
+ SendView: () => SendView,
28
+ ThemeProvider: () => ThemeProvider,
29
+ TokensView: () => TokensView,
30
+ UserProfile: () => UserProfile,
31
+ VM: () => VM,
32
+ WalletButton: () => WalletButton,
33
+ WalletCard: () => WalletCard,
34
+ WalletDisplay: () => WalletDisplay,
35
+ useAuth: () => useAuth,
36
+ useAvaCloudWallet: () => useAvaCloudWallet,
37
+ useChainId: () => useChainId,
38
+ usePostMessage: () => usePostMessage,
39
+ useSignMessage: () => useSignMessage,
40
+ useSignTransaction: () => useSignTransaction,
41
+ useThemeMode: () => useThemeMode,
42
+ useTransferTokens: () => useTransferTokens,
43
+ useUserWallets: () => useUserWallets
44
+ });
45
+ module.exports = __toCommonJS(index_exports);
46
+
47
+ // src/AvaCloudWalletProvider.tsx
48
+ var import_react9 = require("react");
49
+ var import_react_query2 = require("@tanstack/react-query");
50
+ var import_cubesigner_sdk = require("@cubist-labs/cubesigner-sdk");
51
+
52
+ // src/types/vm.ts
53
+ var VM = /* @__PURE__ */ ((VM2) => {
54
+ VM2["EVM"] = "EVM";
55
+ VM2["AVM"] = "AVM";
56
+ VM2["PVM"] = "PVM";
57
+ return VM2;
58
+ })(VM || {});
59
+
60
+ // src/utils/derivationPath.ts
61
+ var getCoinIndexForVm = (vm) => {
62
+ switch (vm) {
63
+ case "EVM" /* EVM */:
64
+ return 60;
65
+ case "AVM" /* AVM */:
66
+ case "PVM" /* PVM */:
67
+ return 9e3;
68
+ default:
69
+ throw new Error(`Unknown coin index for vm: ${vm}`);
70
+ }
71
+ };
72
+ function getDerivationPath(vm, accountIndex) {
73
+ if (accountIndex < 0 || Math.round(accountIndex) !== accountIndex) {
74
+ throw new Error("Account index must be a non-negative integer");
75
+ }
76
+ const coinIndex = getCoinIndexForVm(vm);
77
+ return `m/44'/${coinIndex}'/0'/0/${accountIndex}`;
78
+ }
79
+
80
+ // src/hooks/usePostMessage.ts
81
+ var import_react = require("react");
82
+ var import_waas_common = require("@avacloud/waas-common");
83
+ function usePostMessage({
84
+ authServiceUrl,
85
+ orgId,
86
+ environment,
87
+ iframe,
88
+ isIframeReady,
89
+ onAuthSuccess,
90
+ onAuthError,
91
+ onOidcReceived,
92
+ onOrgConfigUpdate,
93
+ setIsAuthenticated,
94
+ setUser,
95
+ setIsLoading,
96
+ setIsIframeReady,
97
+ cubistClient
98
+ }) {
99
+ const lastAuthStateRef = (0, import_react.useRef)({
100
+ isAuthenticated: false,
101
+ userId: null,
102
+ lastUpdateTime: 0
103
+ });
104
+ const hasRequestedOidcRef = (0, import_react.useRef)(false);
105
+ const isHandlingMessageRef = (0, import_react.useRef)(false);
106
+ const sendMessage = (0, import_react.useCallback)((message) => {
107
+ if (iframe == null ? void 0 : iframe.contentWindow) {
108
+ try {
109
+ console.log("Sending message to auth iframe:", message);
110
+ iframe.contentWindow.postMessage(message, authServiceUrl);
111
+ } catch (error) {
112
+ console.error("Error sending message to iframe:", error);
113
+ }
114
+ } else {
115
+ console.error("No iframe available to send message");
116
+ }
117
+ }, [iframe, authServiceUrl]);
118
+ (0, import_react.useEffect)(() => {
119
+ const handleMessage = async (event) => {
120
+ var _a, _b, _c, _d, _e, _f, _g;
121
+ if (isHandlingMessageRef.current) {
122
+ console.log("Already handling a message, skipping");
123
+ return;
124
+ }
125
+ if (event.origin !== new URL(authServiceUrl).origin) {
126
+ return;
127
+ }
128
+ if (typeof ((_a = event.data) == null ? void 0 : _a.type) !== "string") {
129
+ return;
130
+ }
131
+ try {
132
+ isHandlingMessageRef.current = true;
133
+ console.log("Received message from iframe:", event.data);
134
+ switch (event.data.type) {
135
+ case "IFRAME_READY":
136
+ console.log("Iframe ready message received, setting isIframeReady to true");
137
+ console.log("\u2705 Connection established: Parent received IFRAME_READY from auth service.");
138
+ setIsIframeReady(true);
139
+ break;
140
+ case "RECEIVE_OIDC":
141
+ console.log("Received OIDC token payload:", event.data.payload);
142
+ if (typeof ((_b = event.data.payload) == null ? void 0 : _b.idToken) === "string") {
143
+ const oidcToken = event.data.payload.idToken;
144
+ console.log("Triggering onOidcReceived callback with token...");
145
+ hasRequestedOidcRef.current = false;
146
+ onOidcReceived == null ? void 0 : onOidcReceived(oidcToken);
147
+ } else {
148
+ console.warn("RECEIVE_OIDC message missing idToken in payload.");
149
+ hasRequestedOidcRef.current = false;
150
+ }
151
+ break;
152
+ case "AUTH_STATUS": {
153
+ const newIsAuthenticated = !!event.data.isAuthenticated;
154
+ const newUserId = (_d = (_c = event.data.user) == null ? void 0 : _c.sub) != null ? _d : null;
155
+ const now = Date.now();
156
+ if (now - lastAuthStateRef.current.lastUpdateTime < 500) {
157
+ return;
158
+ }
159
+ const authStateChanged = lastAuthStateRef.current.isAuthenticated !== newIsAuthenticated || lastAuthStateRef.current.userId !== newUserId;
160
+ if (authStateChanged) {
161
+ console.log("Auth status changed:", { newIsAuthenticated, newUserId });
162
+ setIsAuthenticated(newIsAuthenticated);
163
+ if (event.data.user) {
164
+ const userInfo = {
165
+ email: event.data.user.email,
166
+ sub: event.data.user.sub,
167
+ configured_mfa: [],
168
+ displayName: event.data.user.nickname || event.data.user.name || ((_e = event.data.user.email) == null ? void 0 : _e.split("@")[0]) || "User",
169
+ rawUserData: event.data.user
170
+ };
171
+ console.log("Setting user info:", userInfo);
172
+ setUser(userInfo);
173
+ if (newIsAuthenticated && !cubistClient && !hasRequestedOidcRef.current) {
174
+ hasRequestedOidcRef.current = true;
175
+ console.log("User newly authenticated, sending GET_OIDC message");
176
+ sendMessage({ type: "GET_OIDC" });
177
+ return;
178
+ }
179
+ } else {
180
+ setUser(null);
181
+ localStorage.removeItem(import_waas_common.AUTH_TOKENS_KEY);
182
+ localStorage.removeItem(import_waas_common.AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
183
+ sessionStorage.removeItem(import_waas_common.OIDC_TOKEN_KEY);
184
+ }
185
+ lastAuthStateRef.current = {
186
+ isAuthenticated: newIsAuthenticated,
187
+ userId: newUserId,
188
+ lastUpdateTime: now
189
+ };
190
+ if (newIsAuthenticated && event.data.user) {
191
+ if (!hasRequestedOidcRef.current) {
192
+ if (event.data.tokens) {
193
+ localStorage.setItem(import_waas_common.AUTH_TOKENS_KEY, JSON.stringify(event.data.tokens));
194
+ }
195
+ onAuthSuccess == null ? void 0 : onAuthSuccess();
196
+ }
197
+ }
198
+ }
199
+ if (event.data.orgConfig && onOrgConfigUpdate) {
200
+ console.log("Received organization config:", event.data.orgConfig);
201
+ onOrgConfigUpdate(event.data.orgConfig);
202
+ }
203
+ if (!hasRequestedOidcRef.current) {
204
+ setIsLoading(false);
205
+ }
206
+ break;
207
+ }
208
+ case "REGISTER_SUCCESS": {
209
+ console.log("Registration successful:", event.data.payload);
210
+ const userId = (_f = event.data.payload) == null ? void 0 : _f.userId;
211
+ if (userId) {
212
+ localStorage.setItem(import_waas_common.CUBIST_USER_ID_KEY, userId);
213
+ if (!hasRequestedOidcRef.current) {
214
+ console.log("Registration complete, sending GET_OIDC message");
215
+ hasRequestedOidcRef.current = true;
216
+ sendMessage({ type: "GET_OIDC" });
217
+ }
218
+ }
219
+ break;
220
+ }
221
+ case "ERROR":
222
+ console.error("Error from auth service:", event.data.error);
223
+ onAuthError == null ? void 0 : onAuthError(new Error((_g = event.data.error) != null ? _g : "Unknown error"));
224
+ setIsLoading(false);
225
+ break;
226
+ }
227
+ } finally {
228
+ isHandlingMessageRef.current = false;
229
+ }
230
+ };
231
+ window.addEventListener("message", handleMessage);
232
+ return () => window.removeEventListener("message", handleMessage);
233
+ }, [
234
+ authServiceUrl,
235
+ onAuthError,
236
+ onAuthSuccess,
237
+ onOidcReceived,
238
+ onOrgConfigUpdate,
239
+ setIsAuthenticated,
240
+ setIsIframeReady,
241
+ setIsLoading,
242
+ setUser,
243
+ sendMessage,
244
+ cubistClient
245
+ ]);
246
+ (0, import_react.useEffect)(() => {
247
+ if (isIframeReady && (iframe == null ? void 0 : iframe.contentWindow)) {
248
+ console.log("\u23F3 Connection attempt: Parent sending CHECK_AUTH_STATUS to auth service.");
249
+ sendMessage({
250
+ type: "CHECK_AUTH_STATUS",
251
+ payload: {
252
+ orgId,
253
+ environment
254
+ }
255
+ });
256
+ }
257
+ }, [isIframeReady, iframe, sendMessage, orgId, environment]);
258
+ return {
259
+ sendMessage
260
+ };
261
+ }
262
+
263
+ // src/AuthModalContext.tsx
264
+ var import_react4 = require("react");
265
+ var import_core_k2_components4 = require("@avalabs/core-k2-components");
266
+
267
+ // src/components/Modal.tsx
268
+ var import_react3 = require("react");
269
+ var import_core_k2_components3 = require("@avalabs/core-k2-components");
270
+
271
+ // src/components/SignInContent.tsx
272
+ var import_react2 = require("react");
273
+ var import_core_k2_components2 = require("@avalabs/core-k2-components");
274
+
275
+ // src/components/PoweredByAvaCloud.tsx
276
+ var import_core_k2_components = require("@avalabs/core-k2-components");
277
+ var import_jsx_runtime = require("react/jsx-runtime");
278
+ function PoweredByAvaCloud() {
279
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core_k2_components.Stack, { direction: "row", alignItems: "center", justifyContent: "center", spacing: 1, children: [
280
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core_k2_components.Typography, { variant: "body2", children: "Powered by" }),
281
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core_k2_components.Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [
282
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core_k2_components.AvaCloudConnectIcon, {}),
283
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core_k2_components.Typography, { variant: "body2", children: "AvaCloud" })
284
+ ] })
285
+ ] });
286
+ }
287
+
288
+ // src/components/SignInContent.tsx
289
+ var import_jsx_runtime2 = require("react/jsx-runtime");
290
+ function SignInContent({ onEmailLogin, onProviderLogin, error, isSubmitting }) {
291
+ const [email, setEmail] = (0, import_react2.useState)("");
292
+ const [password, setPassword] = (0, import_react2.useState)("");
293
+ const [isPasswordStep, setIsPasswordStep] = (0, import_react2.useState)(false);
294
+ const theme = (0, import_core_k2_components2.useTheme)();
295
+ const handleEmailSubmit = (e) => {
296
+ e.preventDefault();
297
+ if (!email) return;
298
+ setIsPasswordStep(true);
299
+ };
300
+ const handlePasswordSubmit = (e) => {
301
+ e.preventDefault();
302
+ if (!password) return;
303
+ onEmailLogin(email, password);
304
+ };
305
+ const handleForgotPassword = () => {
306
+ console.log("Forgot password clicked");
307
+ };
308
+ const titleTypography = {
309
+ alignSelf: "stretch",
310
+ color: (theme2) => theme2.palette.mode === "dark" ? "#FFFFFF" : "rgba(0, 0, 0, 0.80)",
311
+ fontFamily: "Inter",
312
+ fontSize: "16px",
313
+ fontStyle: "normal",
314
+ fontWeight: 700,
315
+ lineHeight: "150%"
316
+ };
317
+ if (isPasswordStep) {
318
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 3, children: [
319
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Typography, { variant: "h6", sx: titleTypography, children: "Sign in with" }),
320
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("form", { onSubmit: handlePasswordSubmit, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 2, children: [
321
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
322
+ import_core_k2_components2.TextField,
323
+ {
324
+ placeholder: "Enter password",
325
+ type: "password",
326
+ value: password,
327
+ onChange: (e) => setPassword(e.target.value),
328
+ fullWidth: true,
329
+ required: true,
330
+ disabled: isSubmitting,
331
+ error: !!error,
332
+ helperText: error,
333
+ sx: {
334
+ "& .MuiOutlinedInput-root": {
335
+ backgroundColor: (theme2) => theme2.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "grey.50"
336
+ }
337
+ }
338
+ }
339
+ ),
340
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
341
+ import_core_k2_components2.Button,
342
+ {
343
+ type: "submit",
344
+ variant: "contained",
345
+ fullWidth: true,
346
+ disabled: isSubmitting || !password,
347
+ sx: {
348
+ height: 48,
349
+ backgroundColor: "#3A65FF",
350
+ borderRadius: 24,
351
+ textTransform: "none",
352
+ "&:hover": {
353
+ backgroundColor: "#2952E6"
354
+ }
355
+ },
356
+ children: "Continue"
357
+ }
358
+ ),
359
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
360
+ import_core_k2_components2.Typography,
361
+ {
362
+ variant: "body2",
363
+ sx: {
364
+ textAlign: "center",
365
+ "& a": {
366
+ color: "#3A65FF",
367
+ textDecoration: "none",
368
+ cursor: "pointer",
369
+ "&:hover": {
370
+ textDecoration: "underline"
371
+ }
372
+ }
373
+ },
374
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
375
+ import_core_k2_components2.Button,
376
+ {
377
+ variant: "text",
378
+ onClick: handleForgotPassword,
379
+ sx: {
380
+ color: "#3A65FF",
381
+ textTransform: "none",
382
+ "&:hover": {
383
+ textDecoration: "underline",
384
+ backgroundColor: "transparent"
385
+ }
386
+ },
387
+ children: "Forget password?"
388
+ }
389
+ )
390
+ }
391
+ )
392
+ ] }) }),
393
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PoweredByAvaCloud, {}),
394
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
395
+ import_core_k2_components2.Typography,
396
+ {
397
+ variant: "body2",
398
+ sx: {
399
+ textAlign: "center",
400
+ color: "text.secondary",
401
+ fontSize: "0.75rem",
402
+ "& a": {
403
+ color: "inherit",
404
+ textDecoration: "none",
405
+ "&:hover": {
406
+ textDecoration: "underline"
407
+ }
408
+ }
409
+ },
410
+ children: [
411
+ "By connecting, you agree to the",
412
+ " ",
413
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
414
+ import_core_k2_components2.Button,
415
+ {
416
+ variant: "text",
417
+ component: "a",
418
+ href: "https://avacloud.io/terms",
419
+ target: "_blank",
420
+ rel: "noopener noreferrer",
421
+ sx: {
422
+ color: "inherit",
423
+ p: 0,
424
+ minWidth: "auto",
425
+ textTransform: "none",
426
+ fontSize: "inherit",
427
+ fontWeight: "inherit",
428
+ "&:hover": {
429
+ textDecoration: "underline",
430
+ backgroundColor: "transparent"
431
+ }
432
+ },
433
+ children: "Terms of Service"
434
+ }
435
+ ),
436
+ " ",
437
+ "and",
438
+ " ",
439
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
440
+ import_core_k2_components2.Button,
441
+ {
442
+ variant: "text",
443
+ component: "a",
444
+ href: "https://avacloud.io/privacy",
445
+ target: "_blank",
446
+ rel: "noopener noreferrer",
447
+ sx: {
448
+ color: "inherit",
449
+ p: 0,
450
+ minWidth: "auto",
451
+ textTransform: "none",
452
+ fontSize: "inherit",
453
+ fontWeight: "inherit",
454
+ "&:hover": {
455
+ textDecoration: "underline",
456
+ backgroundColor: "transparent"
457
+ }
458
+ },
459
+ children: "Privacy Policy"
460
+ }
461
+ )
462
+ ]
463
+ }
464
+ )
465
+ ] });
466
+ }
467
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 3, children: [
468
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Typography, { variant: "h6", sx: titleTypography, children: "Sign in with" }),
469
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { direction: "row", spacing: 3, sx: { justifyContent: "center" }, children: [
470
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
471
+ import_core_k2_components2.IconButton,
472
+ {
473
+ color: "default",
474
+ variant: "contained",
475
+ onClick: () => onProviderLogin("google-oauth2"),
476
+ disabled: isSubmitting,
477
+ sx: {
478
+ display: "flex",
479
+ padding: "16px",
480
+ alignItems: "center",
481
+ gap: "8px",
482
+ borderRadius: "8px",
483
+ background: "rgba(0, 0, 0, 0.02)",
484
+ boxShadow: "2px 1px 4px 0px rgba(0, 0, 0, 0.20)",
485
+ width: 72,
486
+ height: 72,
487
+ "&:hover": {
488
+ background: "rgba(0, 0, 0, 0.04)"
489
+ }
490
+ },
491
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.GoogleColorIcon, { sx: { width: 24, height: 24 } })
492
+ }
493
+ ),
494
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
495
+ import_core_k2_components2.IconButton,
496
+ {
497
+ color: "default",
498
+ variant: "contained",
499
+ onClick: () => onProviderLogin("twitter"),
500
+ disabled: isSubmitting,
501
+ sx: {
502
+ display: "flex",
503
+ padding: "16px",
504
+ alignItems: "center",
505
+ gap: "8px",
506
+ borderRadius: "8px",
507
+ background: "rgba(0, 0, 0, 0.02)",
508
+ boxShadow: "2px 1px 4px 0px rgba(0, 0, 0, 0.20)",
509
+ width: 72,
510
+ height: 72,
511
+ "&:hover": {
512
+ background: "rgba(0, 0, 0, 0.04)"
513
+ }
514
+ },
515
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.XTwitterIcon, { sx: { width: 24, height: 24 } })
516
+ }
517
+ ),
518
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
519
+ import_core_k2_components2.IconButton,
520
+ {
521
+ color: "default",
522
+ variant: "contained",
523
+ onClick: () => onProviderLogin("apple"),
524
+ disabled: isSubmitting,
525
+ sx: {
526
+ display: "flex",
527
+ padding: "16px",
528
+ alignItems: "center",
529
+ gap: "8px",
530
+ borderRadius: "8px",
531
+ background: "rgba(0, 0, 0, 0.02)",
532
+ boxShadow: "2px 1px 4px 0px rgba(0, 0, 0, 0.20)",
533
+ width: 72,
534
+ height: 72,
535
+ "&:hover": {
536
+ background: "rgba(0, 0, 0, 0.04)"
537
+ }
538
+ },
539
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.AppleIcon, { sx: { width: 24, height: 24 } })
540
+ }
541
+ )
542
+ ] }),
543
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Divider, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core_k2_components2.Typography, { variant: "body2", color: "text.secondary", children: "or" }) }),
544
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("form", { onSubmit: handleEmailSubmit, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_core_k2_components2.Stack, { gap: 2, children: [
545
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
546
+ import_core_k2_components2.TextField,
547
+ {
548
+ placeholder: "Enter email",
549
+ type: "email",
550
+ value: email,
551
+ onChange: (e) => setEmail(e.target.value),
552
+ fullWidth: true,
553
+ required: true,
554
+ disabled: isSubmitting,
555
+ error: !!error,
556
+ helperText: error,
557
+ sx: {
558
+ "& .MuiOutlinedInput-root": {
559
+ backgroundColor: (theme2) => theme2.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "grey.50"
560
+ }
561
+ }
562
+ }
563
+ ),
564
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
565
+ import_core_k2_components2.Button,
566
+ {
567
+ type: "submit",
568
+ variant: "contained",
569
+ fullWidth: true,
570
+ disabled: isSubmitting || !email,
571
+ sx: {
572
+ height: 48,
573
+ backgroundColor: "#3A65FF",
574
+ borderRadius: 24,
575
+ textTransform: "none",
576
+ "&:hover": {
577
+ backgroundColor: "#2952E6"
578
+ }
579
+ },
580
+ children: "Continue"
581
+ }
582
+ )
583
+ ] }) }),
584
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PoweredByAvaCloud, {}),
585
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
586
+ import_core_k2_components2.Typography,
587
+ {
588
+ variant: "body2",
589
+ sx: {
590
+ textAlign: "center",
591
+ color: "text.secondary",
592
+ fontSize: "0.75rem",
593
+ "& a": {
594
+ color: "inherit",
595
+ textDecoration: "none",
596
+ "&:hover": {
597
+ textDecoration: "underline"
598
+ }
599
+ }
600
+ },
601
+ children: [
602
+ "By connecting, you agree to the",
603
+ " ",
604
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
605
+ import_core_k2_components2.Button,
606
+ {
607
+ variant: "text",
608
+ component: "a",
609
+ href: "https://avacloud.io/terms",
610
+ target: "_blank",
611
+ rel: "noopener noreferrer",
612
+ sx: {
613
+ color: "inherit",
614
+ p: 0,
615
+ minWidth: "auto",
616
+ textTransform: "none",
617
+ fontSize: "inherit",
618
+ fontWeight: "inherit",
619
+ "&:hover": {
620
+ textDecoration: "underline",
621
+ backgroundColor: "transparent"
622
+ }
623
+ },
624
+ children: "Terms of Service"
625
+ }
626
+ ),
627
+ " ",
628
+ "and",
629
+ " ",
630
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
631
+ import_core_k2_components2.Button,
632
+ {
633
+ variant: "text",
634
+ component: "a",
635
+ href: "https://avacloud.io/privacy",
636
+ target: "_blank",
637
+ rel: "noopener noreferrer",
638
+ sx: {
639
+ color: "inherit",
640
+ p: 0,
641
+ minWidth: "auto",
642
+ textTransform: "none",
643
+ fontSize: "inherit",
644
+ fontWeight: "inherit",
645
+ "&:hover": {
646
+ textDecoration: "underline",
647
+ backgroundColor: "transparent"
648
+ }
649
+ },
650
+ children: "Privacy Policy"
651
+ }
652
+ )
653
+ ]
654
+ }
655
+ )
656
+ ] });
657
+ }
658
+
659
+ // src/components/Modal.tsx
660
+ var import_jsx_runtime3 = require("react/jsx-runtime");
661
+ function LoginModal({ open, onClose }) {
662
+ const { iframe } = useAvaCloudWallet();
663
+ const [isSubmitting, setIsSubmitting] = (0, import_react3.useState)(false);
664
+ const [error, setError] = (0, import_react3.useState)("");
665
+ (0, import_react3.useEffect)(() => {
666
+ const handleMessage = (event) => {
667
+ if (event.data.type === "ERROR") {
668
+ setError(event.data.payload);
669
+ setIsSubmitting(false);
670
+ } else if (event.data.type === "AUTH_STATUS" && event.data.isAuthenticated) {
671
+ setIsSubmitting(false);
672
+ onClose();
673
+ }
674
+ };
675
+ window.addEventListener("message", handleMessage);
676
+ return () => window.removeEventListener("message", handleMessage);
677
+ }, [onClose]);
678
+ const handleProviderLogin = (provider) => {
679
+ var _a;
680
+ setError("");
681
+ if (iframe) {
682
+ console.log(`Sending LOGIN_REQUEST to auth service iframe with ${provider} connection`);
683
+ (_a = iframe.contentWindow) == null ? void 0 : _a.postMessage({
684
+ type: "LOGIN_REQUEST",
685
+ connection: provider
686
+ }, "*");
687
+ onClose();
688
+ } else {
689
+ console.error("Auth service iframe not found");
690
+ setError("Authentication service not available");
691
+ }
692
+ };
693
+ const handleEmailLogin = (email, password) => {
694
+ var _a;
695
+ setError("");
696
+ setIsSubmitting(true);
697
+ if (iframe) {
698
+ console.log("Sending email/password LOGIN_REQUEST to auth service iframe");
699
+ (_a = iframe.contentWindow) == null ? void 0 : _a.postMessage({
700
+ type: "LOGIN_REQUEST",
701
+ email,
702
+ password
703
+ }, "*");
704
+ } else {
705
+ console.error("Auth service iframe not found");
706
+ setError("Authentication service not available");
707
+ setIsSubmitting(false);
708
+ }
709
+ };
710
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
711
+ import_core_k2_components3.Dialog,
712
+ {
713
+ open,
714
+ maxWidth: "xs",
715
+ PaperProps: {
716
+ sx: {
717
+ borderRadius: "8px",
718
+ width: "100%",
719
+ maxWidth: 400,
720
+ maxHeight: "calc(100% - 64px)",
721
+ m: 2,
722
+ overflow: "visible",
723
+ bgcolor: (theme) => theme.palette.mode === "dark" ? "#1A1A1A" : "#ffffff",
724
+ backgroundImage: "none",
725
+ display: "flex",
726
+ flexDirection: "column",
727
+ position: "relative",
728
+ boxShadow: (theme) => theme.palette.mode === "dark" ? "0px 4px 6px 0px rgba(0, 0, 0, 0.3), 0px 15px 15px 0px rgba(0, 0, 0, 0.25)" : "0px 4px 6px 0px rgba(0, 0, 0, 0.16), 0px 15px 15px 0px rgba(0, 0, 0, 0.15)",
729
+ transition: "all 0.2s ease-in-out"
730
+ }
731
+ },
732
+ children: [
733
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
734
+ import_core_k2_components3.Stack,
735
+ {
736
+ direction: "row",
737
+ sx: {
738
+ display: "flex",
739
+ justifyContent: "space-between",
740
+ alignItems: "flex-start",
741
+ alignSelf: "stretch",
742
+ p: 3,
743
+ pb: 0
744
+ },
745
+ children: [
746
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
747
+ "img",
748
+ {
749
+ src: "/avacloud.png",
750
+ alt: "AvaCloud",
751
+ style: {
752
+ height: 24,
753
+ objectFit: "contain"
754
+ }
755
+ }
756
+ ),
757
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
758
+ import_core_k2_components3.IconButton,
759
+ {
760
+ onClick: onClose,
761
+ size: "small",
762
+ sx: {
763
+ color: (theme) => theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.54)" : "rgba(0, 0, 0, 0.54)",
764
+ padding: "4px",
765
+ marginTop: "-4px",
766
+ marginRight: "-4px",
767
+ "&:hover": {
768
+ backgroundColor: (theme) => theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.04)" : "rgba(0, 0, 0, 0.04)"
769
+ }
770
+ },
771
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core_k2_components3.XIcon, { sx: { fontSize: 20 } })
772
+ }
773
+ )
774
+ ]
775
+ }
776
+ ),
777
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core_k2_components3.DialogContent, { sx: { p: 3 }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
778
+ SignInContent,
779
+ {
780
+ onEmailLogin: handleEmailLogin,
781
+ onProviderLogin: handleProviderLogin,
782
+ error,
783
+ isSubmitting
784
+ }
785
+ ) })
786
+ ]
787
+ }
788
+ );
789
+ }
790
+
791
+ // src/AuthModalContext.tsx
792
+ var import_jsx_runtime4 = require("react/jsx-runtime");
793
+ var AuthModalContext = (0, import_react4.createContext)(void 0);
794
+ function AuthModalProvider({ children }) {
795
+ const [isModalOpen, setIsModalOpen] = (0, import_react4.useState)(false);
796
+ const openLoginModal = (0, import_react4.useCallback)(() => setIsModalOpen(true), []);
797
+ const closeLoginModal = (0, import_react4.useCallback)(() => setIsModalOpen(false), []);
798
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(AuthModalContext.Provider, { value: { openLoginModal, closeLoginModal, isModalOpen }, children: [
799
+ children,
800
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
801
+ import_core_k2_components4.Dialog,
802
+ {
803
+ open: isModalOpen,
804
+ onClose: closeLoginModal,
805
+ maxWidth: "xs",
806
+ children: [
807
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core_k2_components4.DialogTitle, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("img", { src: "", alt: "AvaCloud Connect", style: { height: "32px" } }) }),
808
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core_k2_components4.DialogContent, { sx: { padding: 4 }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
809
+ LoginModal,
810
+ {
811
+ open: isModalOpen,
812
+ onClose: closeLoginModal
813
+ }
814
+ ) })
815
+ ]
816
+ }
817
+ )
818
+ ] });
819
+ }
820
+ function useAuthModal() {
821
+ const context = (0, import_react4.useContext)(AuthModalContext);
822
+ if (context === void 0) {
823
+ throw new Error("useAuthModal must be used within an AuthModalProvider");
824
+ }
825
+ return context;
826
+ }
827
+
828
+ // src/AvaCloudWalletProvider.tsx
829
+ var import_cubesigner_sdk2 = require("@cubist-labs/cubesigner-sdk");
830
+
831
+ // src/providers/ViemContext.tsx
832
+ var import_react6 = require("react");
833
+ var import_viem = require("viem");
834
+
835
+ // src/hooks/useAuth.ts
836
+ var import_react5 = require("react");
837
+ function useAuth() {
838
+ const {
839
+ isAuthenticated,
840
+ isLoading,
841
+ user,
842
+ wallet,
843
+ logout,
844
+ loginWithCubist,
845
+ cubistClient,
846
+ cubistError
847
+ } = useAvaCloudWallet();
848
+ const { openLoginModal } = useAuthModal();
849
+ const login = (0, import_react5.useCallback)(() => {
850
+ openLoginModal();
851
+ }, [openLoginModal]);
852
+ return {
853
+ isAuthenticated,
854
+ isLoading,
855
+ user,
856
+ wallet,
857
+ login,
858
+ logout,
859
+ loginWithCubist,
860
+ cubistClient,
861
+ cubistError
862
+ };
863
+ }
864
+
865
+ // src/providers/ViemContext.tsx
866
+ var import_jsx_runtime5 = require("react/jsx-runtime");
867
+ var ViemContext = (0, import_react6.createContext)(null);
868
+ function ViemProvider({ children, rpcUrl, chainId, explorerUrl }) {
869
+ var _a, _b;
870
+ const [publicClient, setPublicClient] = (0, import_react6.useState)(null);
871
+ const [walletClient, setWalletClient] = (0, import_react6.useState)(null);
872
+ const [isConnected, setIsConnected] = (0, import_react6.useState)(false);
873
+ const [error, setError] = (0, import_react6.useState)(null);
874
+ const { cubistClient, wallet: authWallet } = useAuth();
875
+ (0, import_react6.useEffect)(() => {
876
+ const initClient = async () => {
877
+ var _a2;
878
+ try {
879
+ const transport = (0, import_viem.http)(rpcUrl);
880
+ const customChain = {
881
+ id: chainId,
882
+ name: `Chain ${chainId}`,
883
+ nativeCurrency: {
884
+ name: "AVAX",
885
+ symbol: "AVAX",
886
+ decimals: 18
887
+ },
888
+ rpcUrls: {
889
+ default: { http: [rpcUrl] },
890
+ public: { http: [rpcUrl] }
891
+ },
892
+ blockExplorers: explorerUrl ? {
893
+ default: {
894
+ name: "Explorer",
895
+ url: explorerUrl
896
+ }
897
+ } : void 0
898
+ };
899
+ const client = (0, import_viem.createPublicClient)({
900
+ transport,
901
+ chain: customChain
902
+ });
903
+ if ((_a2 = authWallet == null ? void 0 : authWallet.cubistWallet) == null ? void 0 : _a2.address) {
904
+ const walletInstance = (0, import_viem.createWalletClient)({
905
+ transport,
906
+ chain: customChain,
907
+ account: authWallet.cubistWallet.address
908
+ });
909
+ setWalletClient(walletInstance);
910
+ }
911
+ await client.getBlockNumber();
912
+ setPublicClient(client);
913
+ setIsConnected(true);
914
+ setError(null);
915
+ } catch (err) {
916
+ setError(err instanceof Error ? err : new Error("Failed to connect"));
917
+ setIsConnected(false);
918
+ }
919
+ };
920
+ initClient();
921
+ }, [rpcUrl, chainId, explorerUrl, (_a = authWallet == null ? void 0 : authWallet.cubistWallet) == null ? void 0 : _a.address]);
922
+ (0, import_react6.useEffect)(() => {
923
+ var _a2;
924
+ if (((_a2 = authWallet == null ? void 0 : authWallet.cubistWallet) == null ? void 0 : _a2.address) && publicClient && walletClient) {
925
+ setIsConnected(true);
926
+ } else {
927
+ setIsConnected(false);
928
+ }
929
+ }, [(_b = authWallet == null ? void 0 : authWallet.cubistWallet) == null ? void 0 : _b.address, publicClient, walletClient]);
930
+ const clearError = () => setError(null);
931
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
932
+ ViemContext.Provider,
933
+ {
934
+ value: {
935
+ publicClient,
936
+ walletClient,
937
+ setPublicClient,
938
+ setWalletClient,
939
+ chainId,
940
+ explorerUrl,
941
+ isConnected,
942
+ error,
943
+ clearError
944
+ },
945
+ children
946
+ }
947
+ );
948
+ }
949
+ function useViem() {
950
+ const context = (0, import_react6.useContext)(ViemContext);
951
+ if (!context) {
952
+ throw new Error("useViem must be used within a ViemProvider");
953
+ }
954
+ return context;
955
+ }
956
+
957
+ // src/hooks/useGlacier.ts
958
+ var import_react_query = require("@tanstack/react-query");
959
+
960
+ // src/services/glacier/client.ts
961
+ var GLACIER_API_BASE_URL = "https://glacier-api.avax.network";
962
+ var GlacierApiClient = class {
963
+ constructor() {
964
+ this.baseUrl = GLACIER_API_BASE_URL;
965
+ }
966
+ async getBlockchains() {
967
+ const response = await fetch(`${this.baseUrl}/v1/chains`);
968
+ if (!response.ok) {
969
+ throw new Error("Failed to fetch blockchains");
970
+ }
971
+ return response.json();
972
+ }
973
+ async getValidators(subnetId) {
974
+ const response = await fetch(`${this.baseUrl}/v1/subnets/${subnetId}/validators`);
975
+ if (!response.ok) {
976
+ throw new Error("Failed to fetch validators");
977
+ }
978
+ return response.json();
979
+ }
980
+ async getSubnets() {
981
+ const response = await fetch(`${this.baseUrl}/v1/subnets`);
982
+ if (!response.ok) {
983
+ throw new Error("Failed to fetch subnets");
984
+ }
985
+ return response.json();
986
+ }
987
+ async getBlockchain(chainId) {
988
+ const response = await fetch(`${this.baseUrl}/v1/chains/${chainId}`);
989
+ if (!response.ok) {
990
+ throw new Error("Failed to fetch blockchain");
991
+ }
992
+ return response.json();
993
+ }
994
+ async getBalance(address, chainId) {
995
+ const chain = await this.getBlockchain(chainId);
996
+ const response = await fetch(chain.rpcUrl, {
997
+ method: "POST",
998
+ headers: {
999
+ "Content-Type": "application/json"
1000
+ },
1001
+ body: JSON.stringify({
1002
+ jsonrpc: "2.0",
1003
+ id: 1,
1004
+ method: "eth_getBalance",
1005
+ params: [address, "latest"]
1006
+ })
1007
+ });
1008
+ if (!response.ok) {
1009
+ throw new Error("Failed to fetch balance");
1010
+ }
1011
+ const data = await response.json();
1012
+ return data.result;
1013
+ }
1014
+ async getERC20Balances(address, chainId) {
1015
+ const response = await fetch(`${this.baseUrl}/v1/chains/${chainId}/addresses/${address}/balances:listErc20`);
1016
+ if (!response.ok) {
1017
+ throw new Error("Failed to fetch ERC20 balances");
1018
+ }
1019
+ return response.json();
1020
+ }
1021
+ async getERC721Balances(address, chainId) {
1022
+ const response = await fetch(`${this.baseUrl}/v1/chains/${chainId}/addresses/${address}/balances:listErc721`);
1023
+ if (!response.ok) {
1024
+ throw new Error("Failed to fetch ERC721 balances");
1025
+ }
1026
+ return response.json();
1027
+ }
1028
+ async getERC1155Balances(address, chainId) {
1029
+ const response = await fetch(`${this.baseUrl}/v1/chains/${chainId}/addresses/${address}/balances:listErc1155`);
1030
+ if (!response.ok) {
1031
+ throw new Error("Failed to fetch ERC1155 balances");
1032
+ }
1033
+ return response.json();
1034
+ }
1035
+ };
1036
+ var glacierApi = new GlacierApiClient();
1037
+
1038
+ // src/hooks/useChainId.ts
1039
+ var import_react7 = require("react");
1040
+ var CHAIN_ID_STORAGE_KEY = "avalanche-chain-id";
1041
+ var DEFAULT_CHAIN_ID = 43113;
1042
+ function useChainId() {
1043
+ const [chainId, setChainIdState] = (0, import_react7.useState)(() => {
1044
+ const storedChainId = localStorage.getItem(CHAIN_ID_STORAGE_KEY);
1045
+ return storedChainId ? Number.parseInt(storedChainId, 10) : DEFAULT_CHAIN_ID;
1046
+ });
1047
+ const setChainId = (newChainId) => {
1048
+ localStorage.setItem(CHAIN_ID_STORAGE_KEY, newChainId.toString());
1049
+ setChainIdState(newChainId);
1050
+ };
1051
+ return { chainId, setChainId };
1052
+ }
1053
+
1054
+ // src/hooks/useGlacier.ts
1055
+ var glacierKeys = {
1056
+ all: ["glacier"],
1057
+ blockchains: () => [...glacierKeys.all, "blockchains"],
1058
+ blockchain: (chainId) => [...glacierKeys.blockchains(), chainId],
1059
+ validators: (subnetId) => [...glacierKeys.all, "validators", subnetId],
1060
+ subnets: () => [...glacierKeys.all, "subnets"],
1061
+ balance: (address, chainId) => [...glacierKeys.all, "balance", address, chainId],
1062
+ erc20Balances: (address, chainId) => [...glacierKeys.all, "erc20Balances", address, chainId],
1063
+ erc721Balances: (address, chainId) => [...glacierKeys.all, "erc721Balances", address, chainId],
1064
+ erc1155Balances: (address, chainId) => [...glacierKeys.all, "erc1155Balances", address, chainId]
1065
+ };
1066
+ function useGlacier() {
1067
+ var _a;
1068
+ const { wallet } = useAvaCloudWallet();
1069
+ const { chainId } = useChainId();
1070
+ const { data: blockchain } = useBlockchain(chainId.toString());
1071
+ const { data: balance, isLoading: isLoadingBalance } = (0, import_react_query.useQuery)({
1072
+ queryKey: glacierKeys.balance(wallet.address || "", chainId.toString()),
1073
+ queryFn: () => glacierApi.getBalance(wallet.address || "", chainId.toString()),
1074
+ enabled: !!wallet.address,
1075
+ refetchInterval: 3e3
1076
+ // Refetch every 3 seconds
1077
+ });
1078
+ return {
1079
+ balance: balance ? (Number.parseInt(balance, 16) / 1e18).toString() : "0",
1080
+ isLoadingBalance,
1081
+ currencySymbol: ((_a = blockchain == null ? void 0 : blockchain.networkToken) == null ? void 0 : _a.symbol) || "AVAX",
1082
+ blockchain
1083
+ };
1084
+ }
1085
+ function useBlockchain(chainId) {
1086
+ return (0, import_react_query.useQuery)({
1087
+ queryKey: glacierKeys.blockchain(chainId),
1088
+ queryFn: () => glacierApi.getBlockchain(chainId),
1089
+ enabled: !!chainId,
1090
+ staleTime: Number.POSITIVE_INFINITY
1091
+ });
1092
+ }
1093
+ function useERC20Balances(address, chainId) {
1094
+ return (0, import_react_query.useQuery)({
1095
+ queryKey: glacierKeys.erc20Balances(address || "", chainId || ""),
1096
+ queryFn: () => glacierApi.getERC20Balances(address || "", chainId || ""),
1097
+ enabled: !!address && !!chainId,
1098
+ refetchInterval: 3e3
1099
+ // Refetch every 3 seconds
1100
+ });
1101
+ }
1102
+ function useERC721Balances(address, chainId) {
1103
+ return (0, import_react_query.useQuery)({
1104
+ queryKey: glacierKeys.erc721Balances(address || "", chainId || ""),
1105
+ queryFn: () => glacierApi.getERC721Balances(address || "", chainId || ""),
1106
+ enabled: !!address && !!chainId,
1107
+ refetchInterval: 3e3
1108
+ // Refetch every 3 seconds
1109
+ });
1110
+ }
1111
+ function useERC1155Balances(address, chainId) {
1112
+ return (0, import_react_query.useQuery)({
1113
+ queryKey: glacierKeys.erc1155Balances(address || "", chainId || ""),
1114
+ queryFn: () => glacierApi.getERC1155Balances(address || "", chainId || ""),
1115
+ enabled: !!address && !!chainId,
1116
+ refetchInterval: 3e3
1117
+ // Refetch every 3 seconds
1118
+ });
1119
+ }
1120
+
1121
+ // src/providers/ThemeProvider.tsx
1122
+ var import_core_k2_components5 = require("@avalabs/core-k2-components");
1123
+ var import_react8 = require("react");
1124
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1125
+ var ThemeContext = (0, import_react8.createContext)({
1126
+ isDarkMode: false,
1127
+ toggleTheme: () => {
1128
+ }
1129
+ });
1130
+ var useThemeMode = () => (0, import_react8.useContext)(ThemeContext);
1131
+ var lightTheme = (0, import_core_k2_components5.createTheme)({
1132
+ typography: {
1133
+ fontFamily: "Inter, sans-serif"
1134
+ }
1135
+ });
1136
+ var darkTheme = (0, import_core_k2_components5.createTheme)({
1137
+ typography: {
1138
+ fontFamily: "Inter, sans-serif"
1139
+ },
1140
+ palette: {
1141
+ mode: "dark",
1142
+ background: {
1143
+ default: "#1A1A1A",
1144
+ paper: "#1A1A1A"
1145
+ },
1146
+ text: {
1147
+ primary: "#FFFFFF",
1148
+ secondary: "rgba(255, 255, 255, 0.7)"
1149
+ },
1150
+ primary: {
1151
+ main: "#4B9FFF",
1152
+ light: "#73B5FF",
1153
+ dark: "#3B7FCC",
1154
+ contrastText: "#FFFFFF"
1155
+ },
1156
+ divider: "rgba(255, 255, 255, 0.12)"
1157
+ },
1158
+ components: {
1159
+ MuiDialog: {
1160
+ styleOverrides: {
1161
+ paper: {
1162
+ backgroundColor: "#1A1A1A"
1163
+ }
1164
+ }
1165
+ }
1166
+ }
1167
+ });
1168
+ function ThemeProvider({ children, darkMode, onDarkModeChange }) {
1169
+ const [isDarkMode, setIsDarkMode] = (0, import_react8.useState)(darkMode != null ? darkMode : false);
1170
+ (0, import_react8.useEffect)(() => {
1171
+ if (darkMode !== void 0 && darkMode !== isDarkMode) {
1172
+ setIsDarkMode(darkMode);
1173
+ }
1174
+ }, [darkMode]);
1175
+ const toggleTheme = (0, import_react8.useCallback)(() => {
1176
+ const newDarkMode = !isDarkMode;
1177
+ setIsDarkMode(newDarkMode);
1178
+ onDarkModeChange == null ? void 0 : onDarkModeChange(newDarkMode);
1179
+ }, [isDarkMode, onDarkModeChange]);
1180
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ThemeContext.Provider, { value: { isDarkMode, toggleTheme }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_core_k2_components5.ThemeProvider, { theme: isDarkMode ? darkTheme : lightTheme, children }) });
1181
+ }
1182
+
1183
+ // src/AvaCloudWalletProvider.tsx
1184
+ var import_waas_common2 = require("@avacloud/waas-common");
1185
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1186
+ var AvaCloudWalletContext = (0, import_react9.createContext)(void 0);
1187
+ var queryClient = new import_react_query2.QueryClient({
1188
+ defaultOptions: {
1189
+ queries: {
1190
+ staleTime: 1e3 * 60 * 5,
1191
+ // 5 minutes
1192
+ retry: 2
1193
+ }
1194
+ }
1195
+ });
1196
+ var CUBIST_ENV = import_cubesigner_sdk.envs.gamma;
1197
+ function ViemProviderWrapper({ children, chainId }) {
1198
+ const { data: blockchain } = useBlockchain(chainId.toString());
1199
+ if (!(blockchain == null ? void 0 : blockchain.rpcUrl)) {
1200
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children });
1201
+ }
1202
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1203
+ ViemProvider,
1204
+ {
1205
+ chainId,
1206
+ rpcUrl: blockchain.rpcUrl,
1207
+ explorerUrl: blockchain.explorerUrl,
1208
+ children
1209
+ }
1210
+ );
1211
+ }
1212
+ function AvaCloudWalletProvider({
1213
+ children,
1214
+ authServiceUrl = "https://ac-auth-service.vercel.app/",
1215
+ orgId,
1216
+ chainId = 43113,
1217
+ darkMode = false,
1218
+ environment = "development",
1219
+ onAuthSuccess,
1220
+ onAuthError,
1221
+ onWalletUpdate
1222
+ }) {
1223
+ const [isAuthenticated, setIsAuthenticated] = (0, import_react9.useState)(false);
1224
+ const [isCubistLoading, setIsCubistLoading] = (0, import_react9.useState)(true);
1225
+ const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
1226
+ const [user, setUser] = (0, import_react9.useState)(null);
1227
+ const [wallet, setWallet] = (0, import_react9.useState)({ address: null });
1228
+ const [orgConfig, setOrgConfig] = (0, import_react9.useState)(null);
1229
+ const [iframe, setIframe] = (0, import_react9.useState)(null);
1230
+ const [isIframeReady, setIsIframeReady] = (0, import_react9.useState)(false);
1231
+ const [cubistClient, setCubistClient] = (0, import_react9.useState)(null);
1232
+ const [cubistError, setCubistError] = (0, import_react9.useState)(null);
1233
+ const [pendingOidcToken, setPendingOidcToken] = (0, import_react9.useState)(null);
1234
+ const iframeRef = (0, import_react9.useRef)(null);
1235
+ (0, import_react9.useEffect)(() => {
1236
+ setIsLoading(isCubistLoading || isAuthenticated && !wallet.address);
1237
+ }, [isCubistLoading, isAuthenticated, wallet.address]);
1238
+ const getWalletInfo = (0, import_react9.useCallback)(async (client, sessionId) => {
1239
+ try {
1240
+ const sessionKeys = await client.sessionKeys();
1241
+ if (!sessionKeys.length) {
1242
+ console.log("[getWalletInfo] No session keys found");
1243
+ return null;
1244
+ }
1245
+ const key = sessionKeys[0];
1246
+ const address = key.materialId;
1247
+ if (!(orgConfig == null ? void 0 : orgConfig.walletProviderOrgID)) {
1248
+ console.error("[getWalletInfo] Missing walletProviderOrgID in organization config");
1249
+ throw new Error("Missing required walletProviderOrgID in organization configuration");
1250
+ }
1251
+ console.log("[getWalletInfo] Returning wallet info with address:", address);
1252
+ return {
1253
+ address,
1254
+ sessionId,
1255
+ orgId: orgConfig.walletProviderOrgID
1256
+ };
1257
+ } catch (err) {
1258
+ console.error("[getWalletInfo] Error:", err);
1259
+ setCubistError(err instanceof Error ? err : new Error("Failed to get wallet info"));
1260
+ return null;
1261
+ }
1262
+ }, [orgConfig]);
1263
+ const loginWithCubist = (0, import_react9.useCallback)(async (oidcToken) => {
1264
+ console.log("[loginWithCubist] Starting...");
1265
+ console.log("[loginWithCubist] Current orgConfig:", orgConfig);
1266
+ if (!orgConfig || !orgConfig.walletProviderOrgID) {
1267
+ console.error("[loginWithCubist] PREVENTED: Missing walletProviderOrgID in organization config");
1268
+ const error = new Error("Missing required walletProviderOrgID in organization configuration");
1269
+ setCubistError(error);
1270
+ onAuthError == null ? void 0 : onAuthError(error);
1271
+ setIsCubistLoading(false);
1272
+ return;
1273
+ }
1274
+ try {
1275
+ setIsCubistLoading(true);
1276
+ setCubistError(null);
1277
+ if (!(orgConfig == null ? void 0 : orgConfig.walletProviderOrgID)) {
1278
+ console.error("[loginWithCubist] Missing walletProviderOrgID in organization config");
1279
+ throw new Error("Missing required walletProviderOrgID in organization configuration");
1280
+ }
1281
+ let accessToken;
1282
+ if (oidcToken) {
1283
+ console.log("[loginWithCubist] Using provided OIDC token.");
1284
+ accessToken = oidcToken;
1285
+ } else {
1286
+ console.log("[loginWithCubist] Attempting to get OIDC token from localStorage.");
1287
+ const tokens = localStorage.getItem(import_waas_common2.AUTH_TOKENS_KEY);
1288
+ if (!tokens) {
1289
+ throw new Error("No authentication tokens found in localStorage");
1290
+ }
1291
+ const parsed = JSON.parse(tokens);
1292
+ accessToken = parsed.access_token;
1293
+ }
1294
+ try {
1295
+ console.log(`[loginWithCubist] Attempting CubeSignerClient.createOidcSession for Org: ${orgConfig.walletProviderOrgID}`);
1296
+ const resp = await import_cubesigner_sdk2.CubeSignerClient.createOidcSession(
1297
+ CUBIST_ENV,
1298
+ orgConfig.walletProviderOrgID,
1299
+ accessToken,
1300
+ ["sign:*", "manage:*", "export:*"],
1301
+ {
1302
+ auth_lifetime: 5 * 60,
1303
+ // 5 minutes
1304
+ refresh_lifetime: 30 * 24 * 60 * 60,
1305
+ // 30 days
1306
+ session_lifetime: 90 * 24 * 60 * 60
1307
+ // 90 days
1308
+ }
1309
+ );
1310
+ console.log("[loginWithCubist] createOidcSession response received.");
1311
+ if (resp.requiresMfa()) {
1312
+ console.warn("[loginWithCubist] MFA required, aborting.");
1313
+ throw new Error("MFA required for Cubist login");
1314
+ }
1315
+ const sessionData = resp.data();
1316
+ console.log("[loginWithCubist] Session data obtained, attempting CubeSignerClient.create");
1317
+ const newClient = await import_cubesigner_sdk2.CubeSignerClient.create(sessionData);
1318
+ const sessionId = sessionData.session_info.session_id;
1319
+ console.log(`[loginWithCubist] CubeSignerClient created successfully. Session ID: ${sessionId}`);
1320
+ console.log("[loginWithCubist] Attempting getWalletInfo");
1321
+ const cubistWallet = await getWalletInfo(newClient, sessionId);
1322
+ console.log("[loginWithCubist] getWalletInfo result:", cubistWallet);
1323
+ console.log("[loginWithCubist] Setting cubistClient state.");
1324
+ setCubistClient(newClient);
1325
+ if (cubistWallet) {
1326
+ console.log("[loginWithCubist] Setting wallet state with cubistWallet.");
1327
+ setWallet((prev) => ({
1328
+ ...prev,
1329
+ address: cubistWallet.address,
1330
+ cubistWallet
1331
+ }));
1332
+ console.log("[loginWithCubist] Calling onWalletUpdate callback.");
1333
+ onWalletUpdate == null ? void 0 : onWalletUpdate({
1334
+ ...wallet,
1335
+ // Use current wallet state potentially
1336
+ cubistWallet
1337
+ });
1338
+ } else {
1339
+ console.warn("[loginWithCubist] cubistWallet is null, not updating wallet state further.");
1340
+ }
1341
+ } catch (error) {
1342
+ console.error("[loginWithCubist] Error during Cubist session creation/wallet info:", error);
1343
+ localStorage.removeItem(import_waas_common2.AUTH_TOKENS_KEY);
1344
+ localStorage.removeItem(import_waas_common2.AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
1345
+ setIsAuthenticated(false);
1346
+ setUser(null);
1347
+ setCubistClient(null);
1348
+ throw error;
1349
+ }
1350
+ } catch (error) {
1351
+ const err = error instanceof Error ? error : new Error("Failed to create Cubist session");
1352
+ console.error("[loginWithCubist] Final catch block error:", err);
1353
+ setCubistError(err);
1354
+ onAuthError == null ? void 0 : onAuthError(err);
1355
+ } finally {
1356
+ console.log("[loginWithCubist] Setting isCubistLoading to false.");
1357
+ setIsCubistLoading(false);
1358
+ }
1359
+ }, [wallet, onWalletUpdate, onAuthError, getWalletInfo, orgConfig]);
1360
+ const { sendMessage } = usePostMessage({
1361
+ authServiceUrl,
1362
+ orgId,
1363
+ environment,
1364
+ iframe,
1365
+ isIframeReady,
1366
+ onAuthSuccess: () => {
1367
+ console.log("[onAuthSuccess] Called");
1368
+ if (user) {
1369
+ if (wallet.address) {
1370
+ console.log("[onAuthSuccess] Calling onAuthSuccess callback with user");
1371
+ onAuthSuccess == null ? void 0 : onAuthSuccess(user);
1372
+ } else {
1373
+ console.log("[onAuthSuccess] Not calling callback yet, waiting for wallet");
1374
+ }
1375
+ } else {
1376
+ console.log("[onAuthSuccess] No user available");
1377
+ }
1378
+ },
1379
+ onAuthError: (error) => {
1380
+ console.log("[onAuthError] Called with error:", error);
1381
+ setIsCubistLoading(false);
1382
+ onAuthError == null ? void 0 : onAuthError(error);
1383
+ },
1384
+ onWalletUpdate: (newWallet) => {
1385
+ console.log("[onWalletUpdate] Called with wallet:", newWallet);
1386
+ setWallet(newWallet);
1387
+ if (user && isAuthenticated) {
1388
+ console.log("[onWalletUpdate] Calling onAuthSuccess callback");
1389
+ onAuthSuccess == null ? void 0 : onAuthSuccess(user);
1390
+ }
1391
+ queryClient.invalidateQueries({ queryKey: ["wallet"] });
1392
+ onWalletUpdate == null ? void 0 : onWalletUpdate(newWallet);
1393
+ },
1394
+ onOidcReceived: (token) => {
1395
+ console.log("[onOidcReceived] Received OIDC token - storing in state only");
1396
+ setIsCubistLoading(true);
1397
+ setPendingOidcToken(token);
1398
+ console.log("[onOidcReceived] Current orgConfig:", orgConfig);
1399
+ const originalLoginWithCubist = loginWithCubist;
1400
+ window.___tempSafeguard_loginWithCubist = (oidcToken) => {
1401
+ if (!(orgConfig == null ? void 0 : orgConfig.walletProviderOrgID)) {
1402
+ console.error("[SAFEGUARD] Prevented direct call to loginWithCubist without orgConfig");
1403
+ return Promise.reject(new Error("Missing required walletProviderOrgID in organization configuration"));
1404
+ }
1405
+ return originalLoginWithCubist(oidcToken);
1406
+ };
1407
+ },
1408
+ onOrgConfigUpdate: (config) => {
1409
+ console.log("[onOrgConfigUpdate] Received org config with walletProviderOrgID:", config == null ? void 0 : config.walletProviderOrgID);
1410
+ console.log("[onOrgConfigUpdate] Current pendingOidcToken:", !!pendingOidcToken);
1411
+ setOrgConfig(config);
1412
+ },
1413
+ setIsAuthenticated,
1414
+ setUser,
1415
+ setIsLoading: (isLoading2) => {
1416
+ console.log("[setIsLoading] Setting isLoading to:", isLoading2);
1417
+ setIsLoading(isLoading2);
1418
+ },
1419
+ setIsIframeReady,
1420
+ wallet,
1421
+ cubistClient
1422
+ });
1423
+ const login = (0, import_react9.useCallback)(() => {
1424
+ console.log("[login] Called");
1425
+ if (iframe == null ? void 0 : iframe.contentWindow) {
1426
+ setIsCubistLoading(true);
1427
+ sendMessage({ type: "LOGIN_REQUEST" });
1428
+ } else {
1429
+ console.error("[login] No iframe available for login");
1430
+ }
1431
+ }, [iframe, sendMessage]);
1432
+ const logout = (0, import_react9.useCallback)(() => {
1433
+ console.log("[logout] Called");
1434
+ sendMessage({ type: "LOGOUT_REQUEST" });
1435
+ setUser(null);
1436
+ setWallet({ address: null });
1437
+ setIsAuthenticated(false);
1438
+ localStorage.removeItem(import_waas_common2.AUTH_TOKENS_KEY);
1439
+ localStorage.removeItem(import_waas_common2.AUTH0_STORAGE_KEYS.IS_AUTHENTICATED);
1440
+ localStorage.removeItem(import_waas_common2.AUTH0_STORAGE_KEYS.ACCESS_TOKEN);
1441
+ localStorage.removeItem(import_waas_common2.AUTH0_STORAGE_KEYS.ID_TOKEN);
1442
+ localStorage.removeItem(import_waas_common2.AUTH0_STORAGE_KEYS.EXPIRES_AT);
1443
+ localStorage.removeItem(import_waas_common2.CUBIST_USER_ID_KEY);
1444
+ sessionStorage.removeItem(import_waas_common2.OIDC_TOKEN_KEY);
1445
+ setCubistClient(null);
1446
+ setCubistError(null);
1447
+ setPendingOidcToken(null);
1448
+ }, [sendMessage]);
1449
+ const addAccount = (0, import_react9.useCallback)(async (accountIndex) => {
1450
+ console.log("[addAccount] Called with accountIndex:", accountIndex);
1451
+ if (!isAuthenticated || !user || !wallet.mnemonicId) {
1452
+ throw new Error("User must be authenticated and have a wallet to add an account");
1453
+ }
1454
+ const path = getDerivationPath("EVM" /* EVM */, accountIndex);
1455
+ sendMessage({
1456
+ type: "ADD_ACCOUNT",
1457
+ payload: {
1458
+ accountIndex,
1459
+ mnemonicId: wallet.mnemonicId,
1460
+ derivationPath: path,
1461
+ identityProof: {
1462
+ email: user.email,
1463
+ displayName: user.displayName,
1464
+ sub: user.sub,
1465
+ configured_mfa: user.configured_mfa
1466
+ }
1467
+ }
1468
+ });
1469
+ }, [sendMessage, isAuthenticated, user, wallet.mnemonicId]);
1470
+ (0, import_react9.useEffect)(() => {
1471
+ console.log("[useEffect Auth] Running effect with dependencies...");
1472
+ console.log("[useEffect Auth] pendingOidcToken:", !!pendingOidcToken);
1473
+ console.log("[useEffect Auth] orgConfig?.walletProviderOrgID:", orgConfig == null ? void 0 : orgConfig.walletProviderOrgID);
1474
+ const hasOrgConfig = !!(orgConfig == null ? void 0 : orgConfig.walletProviderOrgID);
1475
+ const hasOidcToken = !!pendingOidcToken;
1476
+ console.log(`[useEffect Auth] Checking conditions - hasOrgConfig: ${hasOrgConfig}, hasOidcToken: ${hasOidcToken}`);
1477
+ if (hasOrgConfig && hasOidcToken && pendingOidcToken) {
1478
+ console.log("[useEffect Auth] Both orgConfig and oidcToken are available, calling loginWithCubist");
1479
+ const doLogin = async () => {
1480
+ try {
1481
+ await loginWithCubist(pendingOidcToken);
1482
+ } catch (error) {
1483
+ console.error("[useEffect Auth] Error in loginWithCubist:", error);
1484
+ onAuthError == null ? void 0 : onAuthError(error instanceof Error ? error : new Error("Failed to create Cubist session"));
1485
+ } finally {
1486
+ setIsCubistLoading(false);
1487
+ setPendingOidcToken(null);
1488
+ }
1489
+ };
1490
+ doLogin();
1491
+ }
1492
+ }, [orgConfig, pendingOidcToken, loginWithCubist, onAuthError]);
1493
+ (0, import_react9.useEffect)(() => {
1494
+ console.log("[useEffect Iframe] Setting up iframe...");
1495
+ if (typeof window === "undefined" || typeof document === "undefined") {
1496
+ return;
1497
+ }
1498
+ const frame = document.createElement("iframe");
1499
+ frame.style.position = "fixed";
1500
+ frame.style.bottom = "0";
1501
+ frame.style.right = "0";
1502
+ frame.style.width = "0";
1503
+ frame.style.height = "0";
1504
+ frame.style.border = "none";
1505
+ frame.style.visibility = "hidden";
1506
+ frame.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms allow-popups");
1507
+ frame.src = authServiceUrl;
1508
+ document.body.appendChild(frame);
1509
+ iframeRef.current = frame;
1510
+ setIframe(frame);
1511
+ console.log("[useEffect Iframe] Iframe created and added to DOM");
1512
+ const timeoutId = setTimeout(() => {
1513
+ console.log("[useEffect Iframe] Timeout reached, setting isCubistLoading to false");
1514
+ setIsCubistLoading(false);
1515
+ }, 5e3);
1516
+ return () => {
1517
+ clearTimeout(timeoutId);
1518
+ if (iframeRef.current) {
1519
+ iframeRef.current.remove();
1520
+ iframeRef.current = null;
1521
+ console.log("[useEffect Iframe] Iframe removed in cleanup");
1522
+ }
1523
+ };
1524
+ }, [authServiceUrl]);
1525
+ const contextValue = {
1526
+ isAuthenticated,
1527
+ isLoading,
1528
+ user,
1529
+ wallet,
1530
+ orgConfig,
1531
+ logout,
1532
+ loginWithCubist,
1533
+ cubistClient,
1534
+ cubistError,
1535
+ login,
1536
+ addAccount,
1537
+ queryClient,
1538
+ iframe,
1539
+ authServiceUrl,
1540
+ chainId,
1541
+ environment
1542
+ };
1543
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AvaCloudWalletContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_query2.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ThemeProvider, { darkMode, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthModalProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ViemProviderWrapper, { chainId, children }) }) }) }) });
1544
+ }
1545
+ function useAvaCloudWallet() {
1546
+ const context = (0, import_react9.useContext)(AvaCloudWalletContext);
1547
+ if (context === void 0) {
1548
+ throw new Error("useAvaCloudWallet must be used within an AvaCloudWalletProvider");
1549
+ }
1550
+ return context;
1551
+ }
1552
+
1553
+ // src/components/LoginButton.tsx
1554
+ var import_react10 = require("react");
1555
+ var import_core_k2_components6 = require("@avalabs/core-k2-components");
1556
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1557
+ function LoginButton({
1558
+ label = "Sign in",
1559
+ className = "",
1560
+ ...props
1561
+ }) {
1562
+ const { isLoading } = useAvaCloudWallet();
1563
+ const [isModalOpen, setIsModalOpen] = (0, import_react10.useState)(false);
1564
+ const handleOpen = () => setIsModalOpen(true);
1565
+ const handleClose = () => setIsModalOpen(false);
1566
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
1567
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1568
+ import_core_k2_components6.Button,
1569
+ {
1570
+ onClick: handleOpen,
1571
+ disabled: isLoading,
1572
+ variant: "contained",
1573
+ color: "primary",
1574
+ className,
1575
+ ...props,
1576
+ children: isLoading ? "Loading..." : label
1577
+ }
1578
+ ),
1579
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1580
+ import_core_k2_components6.Dialog,
1581
+ {
1582
+ open: isModalOpen,
1583
+ onClose: handleClose,
1584
+ maxWidth: "xs",
1585
+ children: [
1586
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core_k2_components6.DialogTitle, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: "", alt: "AvaCloud Connect", style: { height: "32px" } }) }),
1587
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core_k2_components6.DialogContent, { sx: { padding: 4 }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1588
+ LoginModal,
1589
+ {
1590
+ open: isModalOpen,
1591
+ onClose: handleClose
1592
+ }
1593
+ ) })
1594
+ ]
1595
+ }
1596
+ )
1597
+ ] });
1598
+ }
1599
+
1600
+ // src/components/WalletButton.tsx
1601
+ var import_react22 = require("react");
1602
+ var import_core_k2_components19 = require("@avalabs/core-k2-components");
1603
+
1604
+ // src/components/WalletCard.tsx
1605
+ var import_react21 = require("react");
1606
+ var import_core_k2_components18 = require("@avalabs/core-k2-components");
1607
+
1608
+ // src/components/SendView.tsx
1609
+ var import_react13 = require("react");
1610
+ var import_core_k2_components9 = require("@avalabs/core-k2-components");
1611
+ var import_react14 = require("@iconify/react");
1612
+
1613
+ // src/hooks/useTransferTokens.ts
1614
+ var import_react11 = require("react");
1615
+ var import_cubesigner_sdk3 = require("@cubist-labs/cubesigner-sdk");
1616
+ var import_react_query3 = require("@tanstack/react-query");
1617
+ var import_viem2 = require("viem");
1618
+ function useTransferTokens() {
1619
+ const [state, setState] = (0, import_react11.useState)({
1620
+ isLoading: false,
1621
+ error: null,
1622
+ txHash: null,
1623
+ viewState: "idle",
1624
+ actualBaseFee: null,
1625
+ actualPriorityFee: null,
1626
+ actualTotalFee: null
1627
+ });
1628
+ const { wallet, cubistClient } = useAvaCloudWallet();
1629
+ const { publicClient } = useViem();
1630
+ const queryClient2 = (0, import_react_query3.useQueryClient)();
1631
+ const reset = (0, import_react11.useCallback)(() => {
1632
+ setState({
1633
+ isLoading: false,
1634
+ error: null,
1635
+ txHash: null,
1636
+ viewState: "idle",
1637
+ actualBaseFee: null,
1638
+ actualPriorityFee: null,
1639
+ actualTotalFee: null
1640
+ });
1641
+ }, []);
1642
+ const transfer = (0, import_react11.useCallback)(async (toAddress, amount) => {
1643
+ var _a;
1644
+ if (!publicClient || !cubistClient || !(wallet == null ? void 0 : wallet.address)) {
1645
+ setState((prev) => ({
1646
+ ...prev,
1647
+ error: "Client not initialized",
1648
+ viewState: "failure"
1649
+ }));
1650
+ return;
1651
+ }
1652
+ if (!publicClient.chain) {
1653
+ setState((prev) => ({
1654
+ ...prev,
1655
+ error: "Chain not configured",
1656
+ viewState: "failure"
1657
+ }));
1658
+ return;
1659
+ }
1660
+ if (!(0, import_viem2.isAddress)(toAddress)) {
1661
+ setState((prev) => ({
1662
+ ...prev,
1663
+ error: "Invalid recipient address",
1664
+ viewState: "failure"
1665
+ }));
1666
+ return;
1667
+ }
1668
+ setState((prev) => ({
1669
+ ...prev,
1670
+ isLoading: true,
1671
+ error: null,
1672
+ viewState: "loading"
1673
+ }));
1674
+ try {
1675
+ const key = await cubistClient.org().getKeyByMaterialId(import_cubesigner_sdk3.Secp256k1.Evm, wallet.address);
1676
+ const tx = await publicClient.prepareTransactionRequest({
1677
+ account: wallet.address,
1678
+ to: toAddress,
1679
+ value: (0, import_viem2.parseEther)(amount),
1680
+ chain: publicClient.chain
1681
+ });
1682
+ const txReq = (0, import_viem2.formatTransactionRequest)(tx);
1683
+ const sig = await key.signEvm({
1684
+ chain_id: publicClient.chain.id,
1685
+ tx: txReq
1686
+ });
1687
+ const serializedTransaction = sig.data().rlp_signed_tx;
1688
+ const hash = await publicClient.sendRawTransaction({ serializedTransaction });
1689
+ setState((prev) => ({
1690
+ ...prev,
1691
+ txHash: hash
1692
+ }));
1693
+ const receipt = await publicClient.waitForTransactionReceipt({
1694
+ hash,
1695
+ confirmations: 1
1696
+ });
1697
+ const block = await publicClient.getBlock({
1698
+ blockHash: receipt.blockHash
1699
+ });
1700
+ const baseFeePerGas = block.baseFeePerGas || BigInt(0);
1701
+ const effectivePriorityFee = receipt.effectiveGasPrice - baseFeePerGas;
1702
+ const actualBaseFee = (0, import_viem2.formatEther)(baseFeePerGas * receipt.gasUsed);
1703
+ const actualPriorityFee = (0, import_viem2.formatEther)(effectivePriorityFee * receipt.gasUsed);
1704
+ const actualTotalFee = (0, import_viem2.formatEther)(receipt.effectiveGasPrice * receipt.gasUsed);
1705
+ console.log("Transaction confirmed:", receipt);
1706
+ if ((wallet == null ? void 0 : wallet.address) && ((_a = publicClient.chain) == null ? void 0 : _a.id)) {
1707
+ const chainId = publicClient.chain.id.toString();
1708
+ queryClient2.invalidateQueries({
1709
+ queryKey: glacierKeys.balance(wallet.address, chainId)
1710
+ });
1711
+ }
1712
+ setState((prev) => ({
1713
+ ...prev,
1714
+ viewState: "success",
1715
+ actualBaseFee: Number(actualBaseFee).toFixed(6),
1716
+ actualPriorityFee: Number(actualPriorityFee).toFixed(6),
1717
+ actualTotalFee: Number(actualTotalFee).toFixed(6)
1718
+ }));
1719
+ } catch (err) {
1720
+ console.error("Failed to send transaction:", err);
1721
+ setState((prev) => ({
1722
+ ...prev,
1723
+ error: err instanceof Error ? err.message : "Failed to send transaction",
1724
+ viewState: "failure"
1725
+ }));
1726
+ } finally {
1727
+ setState((prev) => ({ ...prev, isLoading: false }));
1728
+ }
1729
+ }, [publicClient, cubistClient, wallet == null ? void 0 : wallet.address, queryClient2]);
1730
+ const transferERC20 = (0, import_react11.useCallback)(async (tokenAddress, toAddress, amount, decimals) => {
1731
+ var _a;
1732
+ if (!publicClient || !cubistClient || !(wallet == null ? void 0 : wallet.address)) {
1733
+ setState((prev) => ({
1734
+ ...prev,
1735
+ error: "Client not initialized",
1736
+ viewState: "failure"
1737
+ }));
1738
+ return;
1739
+ }
1740
+ if (!publicClient.chain) {
1741
+ setState((prev) => ({
1742
+ ...prev,
1743
+ error: "Chain not configured",
1744
+ viewState: "failure"
1745
+ }));
1746
+ return;
1747
+ }
1748
+ if (!(0, import_viem2.isAddress)(toAddress)) {
1749
+ setState((prev) => ({
1750
+ ...prev,
1751
+ error: "Invalid recipient address",
1752
+ viewState: "failure"
1753
+ }));
1754
+ return;
1755
+ }
1756
+ setState((prev) => ({
1757
+ ...prev,
1758
+ isLoading: true,
1759
+ error: null,
1760
+ viewState: "loading"
1761
+ }));
1762
+ try {
1763
+ const key = await cubistClient.org().getKeyByMaterialId(import_cubesigner_sdk3.Secp256k1.Evm, wallet.address);
1764
+ const data = (0, import_viem2.encodeFunctionData)({
1765
+ abi: import_viem2.erc20Abi,
1766
+ functionName: "transfer",
1767
+ args: [toAddress, (0, import_viem2.parseUnits)(amount, decimals)]
1768
+ });
1769
+ const tx = await publicClient.prepareTransactionRequest({
1770
+ account: wallet.address,
1771
+ to: tokenAddress,
1772
+ data,
1773
+ chain: publicClient.chain
1774
+ });
1775
+ const txReq = (0, import_viem2.formatTransactionRequest)(tx);
1776
+ const sig = await key.signEvm({
1777
+ chain_id: publicClient.chain.id,
1778
+ tx: txReq
1779
+ });
1780
+ const serializedTransaction = sig.data().rlp_signed_tx;
1781
+ const hash = await publicClient.sendRawTransaction({ serializedTransaction });
1782
+ setState((prev) => ({
1783
+ ...prev,
1784
+ txHash: hash
1785
+ }));
1786
+ const receipt = await publicClient.waitForTransactionReceipt({
1787
+ hash,
1788
+ confirmations: 1
1789
+ });
1790
+ const block = await publicClient.getBlock({
1791
+ blockHash: receipt.blockHash
1792
+ });
1793
+ const baseFeePerGas = block.baseFeePerGas || BigInt(0);
1794
+ const effectivePriorityFee = receipt.effectiveGasPrice - baseFeePerGas;
1795
+ const actualBaseFee = (0, import_viem2.formatEther)(baseFeePerGas * receipt.gasUsed);
1796
+ const actualPriorityFee = (0, import_viem2.formatEther)(effectivePriorityFee * receipt.gasUsed);
1797
+ const actualTotalFee = (0, import_viem2.formatEther)(receipt.effectiveGasPrice * receipt.gasUsed);
1798
+ console.log("Transaction confirmed:", receipt);
1799
+ if ((wallet == null ? void 0 : wallet.address) && ((_a = publicClient.chain) == null ? void 0 : _a.id)) {
1800
+ const chainId = publicClient.chain.id.toString();
1801
+ queryClient2.invalidateQueries({
1802
+ queryKey: glacierKeys.erc20Balances(wallet.address, chainId)
1803
+ });
1804
+ queryClient2.invalidateQueries({
1805
+ queryKey: glacierKeys.balance(wallet.address, chainId)
1806
+ });
1807
+ }
1808
+ setState((prev) => ({
1809
+ ...prev,
1810
+ viewState: "success",
1811
+ actualBaseFee: Number(actualBaseFee).toFixed(6),
1812
+ actualPriorityFee: Number(actualPriorityFee).toFixed(6),
1813
+ actualTotalFee: Number(actualTotalFee).toFixed(6)
1814
+ }));
1815
+ } catch (err) {
1816
+ console.error("Failed to send transaction:", err);
1817
+ setState((prev) => ({
1818
+ ...prev,
1819
+ error: err instanceof Error ? err.message : "Failed to send transaction",
1820
+ viewState: "failure"
1821
+ }));
1822
+ } finally {
1823
+ setState((prev) => ({ ...prev, isLoading: false }));
1824
+ }
1825
+ }, [publicClient, cubistClient, wallet == null ? void 0 : wallet.address, queryClient2]);
1826
+ return {
1827
+ ...state,
1828
+ transfer,
1829
+ transferERC20,
1830
+ reset
1831
+ };
1832
+ }
1833
+
1834
+ // src/hooks/useGasEstimation.ts
1835
+ var import_react12 = require("react");
1836
+ var import_viem3 = require("viem");
1837
+ function useGasEstimation() {
1838
+ const [state, setState] = (0, import_react12.useState)({
1839
+ isLoading: false,
1840
+ error: null,
1841
+ baseFee: null,
1842
+ priorityFee: null,
1843
+ totalFee: null,
1844
+ totalWithAmount: null
1845
+ });
1846
+ const { publicClient } = useViem();
1847
+ const reset = (0, import_react12.useCallback)(() => {
1848
+ setState({
1849
+ isLoading: false,
1850
+ error: null,
1851
+ baseFee: null,
1852
+ priorityFee: null,
1853
+ totalFee: null,
1854
+ totalWithAmount: null
1855
+ });
1856
+ }, []);
1857
+ const updateTotal = (0, import_react12.useCallback)((amount) => {
1858
+ if (!state.totalFee) return;
1859
+ const amountValue = Number.parseFloat(amount);
1860
+ if (Number.isNaN(amountValue)) return;
1861
+ const newTotal = (Number(state.totalFee) + amountValue).toFixed(6);
1862
+ setState((prev) => ({
1863
+ ...prev,
1864
+ totalWithAmount: newTotal
1865
+ }));
1866
+ }, [state.totalFee]);
1867
+ const estimateGas = (0, import_react12.useCallback)(async (toAddress, amount) => {
1868
+ if (!publicClient) {
1869
+ setState((prev) => ({
1870
+ ...prev,
1871
+ error: "Client not initialized",
1872
+ isLoading: false
1873
+ }));
1874
+ return;
1875
+ }
1876
+ setState((prev) => ({
1877
+ ...prev,
1878
+ isLoading: true,
1879
+ error: null
1880
+ }));
1881
+ try {
1882
+ const block = await publicClient.getBlock();
1883
+ const gasEstimate = await publicClient.estimateGas({
1884
+ to: toAddress,
1885
+ value: (0, import_viem3.parseEther)(amount)
1886
+ });
1887
+ const feeHistory = await publicClient.getFeeHistory({
1888
+ blockCount: 10,
1889
+ rewardPercentiles: [50]
1890
+ });
1891
+ const baseFeePerGas = block.baseFeePerGas || BigInt(0);
1892
+ const priorityFeePerGas = feeHistory.reward && feeHistory.reward.length > 0 ? feeHistory.reward.reduce((acc, reward) => acc + reward[0], BigInt(0)) / BigInt(feeHistory.reward.length) : BigInt(0);
1893
+ const totalFeeWei = (baseFeePerGas + priorityFeePerGas) * gasEstimate;
1894
+ const baseFeeEth = Number((0, import_viem3.formatEther)(baseFeePerGas * gasEstimate)).toFixed(6);
1895
+ const priorityFeeEth = Number((0, import_viem3.formatEther)(priorityFeePerGas * gasEstimate)).toFixed(6);
1896
+ const totalFeeEth = Number((0, import_viem3.formatEther)(totalFeeWei)).toFixed(6);
1897
+ const totalWithAmount = (Number(totalFeeEth) + Number.parseFloat(amount)).toFixed(6);
1898
+ setState((prev) => ({
1899
+ ...prev,
1900
+ baseFee: baseFeeEth,
1901
+ priorityFee: priorityFeeEth,
1902
+ totalFee: totalFeeEth,
1903
+ totalWithAmount
1904
+ }));
1905
+ } catch (err) {
1906
+ console.error("Failed to estimate gas:", err);
1907
+ setState((prev) => ({
1908
+ ...prev,
1909
+ error: err instanceof Error ? err.message : "Failed to estimate gas",
1910
+ baseFee: null,
1911
+ priorityFee: null,
1912
+ totalFee: null,
1913
+ totalWithAmount: null
1914
+ }));
1915
+ } finally {
1916
+ setState((prev) => ({ ...prev, isLoading: false }));
1917
+ }
1918
+ }, [publicClient]);
1919
+ return {
1920
+ ...state,
1921
+ estimateGas,
1922
+ updateTotal,
1923
+ reset
1924
+ };
1925
+ }
1926
+
1927
+ // src/components/LoadingAnimation.tsx
1928
+ var import_lottie_react = require("lottie-react");
1929
+ var import_core_k2_components7 = require("@avalabs/core-k2-components");
1930
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1931
+ var loadingAnimation = {
1932
+ "v": "5.5.9",
1933
+ "fr": 32.498,
1934
+ "ip": 0,
1935
+ "op": 40,
1936
+ "w": 500,
1937
+ "h": 500,
1938
+ "nm": " ",
1939
+ "assets": [],
1940
+ "layers": [
1941
+ {
1942
+ "ind": 1,
1943
+ "ty": 4,
1944
+ "nm": "kanan stop",
1945
+ "sr": 0.63,
1946
+ "ks": {
1947
+ "o": { "a": 0, "k": 100, "ix": 11 },
1948
+ "r": { "a": 0, "k": 0, "ix": 10 },
1949
+ "p": {
1950
+ "a": 1,
1951
+ "k": [
1952
+ { "i": { "x": 0.667, "y": 1 }, "o": { "x": 0.333, "y": 0 }, "t": 0, "s": [380, 350, 0], "to": [0, -16.667, 0], "ti": [0, 33.333, 0] },
1953
+ { "i": { "x": 0.667, "y": 1 }, "o": { "x": 0.333, "y": 0 }, "t": 10, "s": [380, 250, 0], "to": [0, -33.333, 0], "ti": [0, 16.667, 0] },
1954
+ { "t": 20, "s": [380, 150, 0] }
1955
+ ],
1956
+ "ix": 2,
1957
+ "x": "var $bm_rt;\n$bm_rt = loopOut('pingpong');"
1958
+ },
1959
+ "a": { "a": 0, "k": [-29.557, -1.557, 0], "ix": 1 },
1960
+ "s": { "a": 0, "k": [200, 200, 100], "ix": 6 }
1961
+ },
1962
+ "ao": 0,
1963
+ "shapes": [
1964
+ {
1965
+ "ty": "gr",
1966
+ "it": [
1967
+ { "d": 1, "ty": "el", "s": { "a": 0, "k": [48.887, 48.887], "ix": 2 }, "p": { "a": 0, "k": [0, 0], "ix": 3 }, "nm": "Ellipse Path 1" },
1968
+ { "ty": "fl", "c": { "a": 0, "k": [0.851, 0.878, 0.902, 1], "ix": 4 }, "o": { "a": 0, "k": 100, "ix": 5 }, "r": 1, "nm": "Fill 1" },
1969
+ { "ty": "tr", "p": { "a": 0, "k": [-29.557, -1.557], "ix": 2 }, "a": { "a": 0, "k": [0, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100], "ix": 3 }, "r": { "a": 0, "k": 0, "ix": 6 }, "o": { "a": 0, "k": 100, "ix": 7 }, "sk": { "a": 0, "k": 0, "ix": 4 }, "sa": { "a": 0, "k": 0, "ix": 5 }, "nm": "Transform" }
1970
+ ],
1971
+ "nm": "Ellipse 1",
1972
+ "cix": 2,
1973
+ "ix": 1
1974
+ }
1975
+ ],
1976
+ "ip": 0,
1977
+ "op": 40,
1978
+ "st": 0
1979
+ },
1980
+ {
1981
+ "ind": 2,
1982
+ "ty": 4,
1983
+ "nm": "tengah stop",
1984
+ "sr": 0.63,
1985
+ "ks": {
1986
+ "o": { "a": 0, "k": 100, "ix": 11 },
1987
+ "r": { "a": 0, "k": 0, "ix": 10 },
1988
+ "p": { "a": 0, "k": [250, 250, 0], "ix": 2 },
1989
+ "a": { "a": 0, "k": [-29.557, -1.557, 0], "ix": 1 },
1990
+ "s": { "a": 0, "k": [200, 200, 100], "ix": 6 }
1991
+ },
1992
+ "ao": 0,
1993
+ "shapes": [
1994
+ {
1995
+ "ty": "gr",
1996
+ "it": [
1997
+ { "d": 1, "ty": "el", "s": { "a": 0, "k": [48.887, 48.887], "ix": 2 }, "p": { "a": 0, "k": [0, 0], "ix": 3 }, "nm": "Ellipse Path 1" },
1998
+ { "ty": "fl", "c": { "a": 0, "k": [0.851, 0.878, 0.902, 1], "ix": 4 }, "o": { "a": 0, "k": 100, "ix": 5 }, "r": 1, "nm": "Fill 1" },
1999
+ { "ty": "tr", "p": { "a": 0, "k": [-29.557, -1.557], "ix": 2 }, "a": { "a": 0, "k": [0, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100], "ix": 3 }, "r": { "a": 0, "k": 0, "ix": 6 }, "o": { "a": 0, "k": 100, "ix": 7 }, "sk": { "a": 0, "k": 0, "ix": 4 }, "sa": { "a": 0, "k": 0, "ix": 5 }, "nm": "Transform" }
2000
+ ],
2001
+ "nm": "Ellipse 1",
2002
+ "cix": 2,
2003
+ "ix": 1
2004
+ }
2005
+ ],
2006
+ "ip": 0,
2007
+ "op": 40,
2008
+ "st": 0
2009
+ },
2010
+ {
2011
+ "ind": 3,
2012
+ "ty": 4,
2013
+ "nm": "kiri stop",
2014
+ "sr": 0.63,
2015
+ "ks": {
2016
+ "o": { "a": 0, "k": 100, "ix": 11 },
2017
+ "r": { "a": 0, "k": 0, "ix": 10 },
2018
+ "p": {
2019
+ "a": 1,
2020
+ "k": [
2021
+ { "i": { "x": 0.667, "y": 1 }, "o": { "x": 0.333, "y": 0 }, "t": 0, "s": [120, 150, 0], "to": [0, 16.667, 0], "ti": [0, -33.333, 0] },
2022
+ { "i": { "x": 0.667, "y": 1 }, "o": { "x": 0.333, "y": 0 }, "t": 10, "s": [120, 250, 0], "to": [0, 33.333, 0], "ti": [0, -16.667, 0] },
2023
+ { "t": 20, "s": [120, 350, 0] }
2024
+ ],
2025
+ "ix": 2,
2026
+ "x": "var $bm_rt;\n$bm_rt = loopOut('pingpong');"
2027
+ },
2028
+ "a": { "a": 0, "k": [-29.557, -1.557, 0], "ix": 1 },
2029
+ "s": { "a": 0, "k": [200, 200, 100], "ix": 6 }
2030
+ },
2031
+ "ao": 0,
2032
+ "shapes": [
2033
+ {
2034
+ "ty": "gr",
2035
+ "it": [
2036
+ { "d": 1, "ty": "el", "s": { "a": 0, "k": [48.887, 48.887], "ix": 2 }, "p": { "a": 0, "k": [0, 0], "ix": 3 }, "nm": "Ellipse Path 1" },
2037
+ { "ty": "fl", "c": { "a": 0, "k": [0.851, 0.878, 0.902, 1], "ix": 4 }, "o": { "a": 0, "k": 100, "ix": 5 }, "r": 1, "nm": "Fill 1" },
2038
+ { "ty": "tr", "p": { "a": 0, "k": [-29.557, -1.557], "ix": 2 }, "a": { "a": 0, "k": [0, 0], "ix": 1 }, "s": { "a": 0, "k": [100, 100], "ix": 3 }, "r": { "a": 0, "k": 0, "ix": 6 }, "o": { "a": 0, "k": 100, "ix": 7 }, "sk": { "a": 0, "k": 0, "ix": 4 }, "sa": { "a": 0, "k": 0, "ix": 5 }, "nm": "Transform" }
2039
+ ],
2040
+ "nm": "Ellipse 1",
2041
+ "cix": 2,
2042
+ "ix": 1
2043
+ }
2044
+ ],
2045
+ "ip": 0,
2046
+ "op": 40,
2047
+ "st": 0
2048
+ }
2049
+ ],
2050
+ "markers": []
2051
+ };
2052
+ var LoadingAnimation = ({ size = 120, message }) => {
2053
+ const { View } = (0, import_lottie_react.useLottie)({
2054
+ animationData: loadingAnimation,
2055
+ loop: true
2056
+ });
2057
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_core_k2_components7.Box, { sx: {
2058
+ display: "flex",
2059
+ flexDirection: "column",
2060
+ alignItems: "center",
2061
+ justifyContent: "center",
2062
+ gap: 2
2063
+ }, children: [
2064
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core_k2_components7.Box, { sx: { width: size, height: size }, children: View }),
2065
+ message && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core_k2_components7.Typography, { variant: "body2", color: "text.secondary", children: message })
2066
+ ] });
2067
+ };
2068
+
2069
+ // src/components/SendView.tsx
2070
+ var import_viem4 = require("viem");
2071
+
2072
+ // src/components/TokenImage.tsx
2073
+ var import_core_k2_components8 = require("@avalabs/core-k2-components");
2074
+ var import_jsx_runtime10 = require("react/jsx-runtime");
2075
+ function TokenImage({ symbol, logoUri, size = 32 }) {
2076
+ if (logoUri) {
2077
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2078
+ "img",
2079
+ {
2080
+ src: logoUri,
2081
+ alt: symbol,
2082
+ style: {
2083
+ width: size,
2084
+ height: size,
2085
+ borderRadius: "50%",
2086
+ objectFit: "cover"
2087
+ }
2088
+ }
2089
+ );
2090
+ }
2091
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_core_k2_components8.Box, { sx: {
2092
+ width: size,
2093
+ height: size,
2094
+ borderRadius: "50%",
2095
+ bgcolor: "primary.light",
2096
+ display: "flex",
2097
+ alignItems: "center",
2098
+ justifyContent: "center",
2099
+ color: "white",
2100
+ fontSize: `${size * 0.4375}px`,
2101
+ fontWeight: 500
2102
+ }, children: symbol == null ? void 0 : symbol.slice(0, 2) });
2103
+ }
2104
+
2105
+ // src/components/SendView.tsx
2106
+ var import_jsx_runtime11 = require("react/jsx-runtime");
2107
+ var isValidAmount = (amount) => {
2108
+ if (!amount || amount === "." || amount === "0.") return false;
2109
+ const value = Number.parseFloat(amount);
2110
+ if (Number.isNaN(value) || value <= 0) return false;
2111
+ return true;
2112
+ };
2113
+ function LoadingView() {
2114
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: {
2115
+ display: "flex",
2116
+ alignItems: "center",
2117
+ justifyContent: "center",
2118
+ height: "100%",
2119
+ minHeight: "400px"
2120
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(LoadingAnimation, { message: "Processing transaction..." }) });
2121
+ }
2122
+ function SendFormView({
2123
+ recipient,
2124
+ amount,
2125
+ error,
2126
+ isLoading,
2127
+ selectedToken,
2128
+ chainId,
2129
+ onRecipientChange,
2130
+ onAmountChange,
2131
+ onTokenSelect,
2132
+ onSend
2133
+ }) {
2134
+ var _a, _b, _c, _d;
2135
+ const { wallet } = useAvaCloudWallet();
2136
+ const { data: blockchainInfo } = useBlockchain((chainId == null ? void 0 : chainId.toString()) || "");
2137
+ const { data: tokenBalancesResponse } = useERC20Balances((wallet == null ? void 0 : wallet.address) || void 0, chainId == null ? void 0 : chainId.toString());
2138
+ const tokenBalances = tokenBalancesResponse;
2139
+ const { baseFee, priorityFee, totalFee, totalWithAmount, estimateGas, updateTotal } = useGasEstimation();
2140
+ const [addressError, setAddressError] = (0, import_react13.useState)(null);
2141
+ const handleRecipientChange = (value) => {
2142
+ if (value && !(0, import_viem4.isAddress)(value)) {
2143
+ setAddressError("Invalid address format");
2144
+ } else {
2145
+ setAddressError(null);
2146
+ }
2147
+ onRecipientChange(value);
2148
+ };
2149
+ const handleAmountChange = (e) => {
2150
+ const value = e.target.value;
2151
+ if (/^\d*\.?\d{0,18}$/.test(value) || value === "") {
2152
+ onAmountChange(value);
2153
+ if (isValidAmount(value)) {
2154
+ updateTotal(value);
2155
+ }
2156
+ }
2157
+ };
2158
+ (0, import_react13.useEffect)(() => {
2159
+ if (!recipient || !(0, import_viem4.isAddress)(recipient)) {
2160
+ return;
2161
+ }
2162
+ if (!isValidAmount(amount)) {
2163
+ return;
2164
+ }
2165
+ estimateGas(recipient, amount).catch(console.error);
2166
+ }, [recipient, amount, estimateGas]);
2167
+ const isInsufficientBalance = () => {
2168
+ if (!selectedToken || !amount || !isValidAmount(amount)) return false;
2169
+ const amountValue = Number(amount);
2170
+ const tokenBalance = Number(selectedToken.balance) / 10 ** selectedToken.decimals;
2171
+ if ("address" in selectedToken) {
2172
+ return amountValue > tokenBalance;
2173
+ }
2174
+ return amountValue + Number(totalFee || "0") > tokenBalance;
2175
+ };
2176
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: {
2177
+ display: "flex",
2178
+ flexDirection: "column",
2179
+ height: "100%",
2180
+ gap: 3,
2181
+ p: 2,
2182
+ width: "100%",
2183
+ maxWidth: "600px",
2184
+ margin: "0 auto"
2185
+ }, children: [
2186
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2187
+ import_core_k2_components9.Typography,
2188
+ {
2189
+ variant: "h6",
2190
+ sx: {
2191
+ textAlign: "center",
2192
+ fontSize: "1.5rem",
2193
+ fontWeight: 500
2194
+ },
2195
+ children: "Send"
2196
+ }
2197
+ ),
2198
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2199
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 0.5, fontWeight: 500 }, children: "From" }),
2200
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2201
+ import_core_k2_components9.Paper,
2202
+ {
2203
+ elevation: 0,
2204
+ sx: {
2205
+ display: "flex",
2206
+ flexDirection: "column",
2207
+ p: 1.5,
2208
+ gap: 1.5,
2209
+ border: "1px solid",
2210
+ borderColor: "divider",
2211
+ borderRadius: 1
2212
+ },
2213
+ children: [
2214
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 1.5 }, children: [
2215
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2216
+ import_core_k2_components9.Box,
2217
+ {
2218
+ sx: {
2219
+ width: 40,
2220
+ height: 40,
2221
+ borderRadius: "50%",
2222
+ bgcolor: "#E84142",
2223
+ display: "flex",
2224
+ alignItems: "center",
2225
+ justifyContent: "center",
2226
+ overflow: "hidden"
2227
+ },
2228
+ children: (blockchainInfo == null ? void 0 : blockchainInfo.chainLogoUri) ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2229
+ "img",
2230
+ {
2231
+ src: blockchainInfo.chainLogoUri,
2232
+ alt: blockchainInfo.chainName || "Network",
2233
+ style: { width: "100%", height: "100%", objectFit: "cover" }
2234
+ }
2235
+ ) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react14.Icon, { icon: "cryptocurrency:avax", width: 24, height: 24, color: "white" })
2236
+ }
2237
+ ),
2238
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body1", sx: { fontWeight: 500 }, children: (blockchainInfo == null ? void 0 : blockchainInfo.chainName) || `Chain ${chainId}` }) })
2239
+ ] }),
2240
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2241
+ import_core_k2_components9.Select,
2242
+ {
2243
+ size: "small",
2244
+ value: selectedToken ? JSON.stringify({
2245
+ symbol: selectedToken.symbol,
2246
+ balance: selectedToken.balance,
2247
+ decimals: selectedToken.decimals,
2248
+ address: "address" in selectedToken ? selectedToken.address : void 0
2249
+ }) : "",
2250
+ onChange: (e) => {
2251
+ const value = e.target.value;
2252
+ if (!value) return;
2253
+ const tokenData = JSON.parse(value);
2254
+ const token = tokenData.address ? tokenBalances.erc20TokenBalances.find((t) => t.address === tokenData.address) : tokenBalances.nativeTokenBalance;
2255
+ if (token) {
2256
+ onTokenSelect(token);
2257
+ }
2258
+ },
2259
+ sx: {
2260
+ ".MuiSelect-select": {
2261
+ display: "flex",
2262
+ alignItems: "center",
2263
+ gap: 1
2264
+ }
2265
+ },
2266
+ children: [
2267
+ (tokenBalances == null ? void 0 : tokenBalances.nativeTokenBalance) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.MenuItem, { value: JSON.stringify({
2268
+ symbol: tokenBalances.nativeTokenBalance.symbol,
2269
+ balance: tokenBalances.nativeTokenBalance.balance,
2270
+ decimals: tokenBalances.nativeTokenBalance.decimals
2271
+ }), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 1, width: "100%" }, children: [
2272
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2273
+ TokenImage,
2274
+ {
2275
+ symbol: tokenBalances.nativeTokenBalance.symbol,
2276
+ logoUri: tokenBalances.nativeTokenBalance.logoUri,
2277
+ size: 24
2278
+ }
2279
+ ),
2280
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { flex: 1 }, children: [
2281
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { children: tokenBalances.nativeTokenBalance.symbol }),
2282
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: [
2283
+ "Balance: ",
2284
+ Number(tokenBalances.nativeTokenBalance.balance || 0) / 10 ** tokenBalances.nativeTokenBalance.decimals
2285
+ ] })
2286
+ ] })
2287
+ ] }) }),
2288
+ (_a = tokenBalances == null ? void 0 : tokenBalances.erc20TokenBalances) == null ? void 0 : _a.map((token) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2289
+ import_core_k2_components9.MenuItem,
2290
+ {
2291
+ value: JSON.stringify({
2292
+ symbol: token.symbol,
2293
+ balance: token.balance,
2294
+ decimals: token.decimals,
2295
+ address: token.address
2296
+ }),
2297
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 1, width: "100%" }, children: [
2298
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2299
+ TokenImage,
2300
+ {
2301
+ symbol: token.symbol,
2302
+ logoUri: token.logoUri,
2303
+ size: 24
2304
+ }
2305
+ ),
2306
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { flex: 1 }, children: [
2307
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { children: token.symbol }),
2308
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: [
2309
+ "Balance: ",
2310
+ Number(token.balance) / 10 ** token.decimals
2311
+ ] })
2312
+ ] })
2313
+ ] })
2314
+ },
2315
+ token.address
2316
+ ))
2317
+ ]
2318
+ }
2319
+ )
2320
+ ]
2321
+ }
2322
+ )
2323
+ ] }),
2324
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2325
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 0.5, fontWeight: 500 }, children: "Send to" }),
2326
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2327
+ import_core_k2_components9.TextField,
2328
+ {
2329
+ size: "small",
2330
+ fullWidth: true,
2331
+ placeholder: "Enter address",
2332
+ value: recipient,
2333
+ onChange: (e) => handleRecipientChange(e.target.value),
2334
+ error: !!error || !!addressError,
2335
+ helperText: addressError
2336
+ }
2337
+ )
2338
+ ] }),
2339
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2340
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 0.5, fontWeight: 500 }, children: "Amount" }),
2341
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2342
+ import_core_k2_components9.TextField,
2343
+ {
2344
+ size: "small",
2345
+ fullWidth: true,
2346
+ type: "text",
2347
+ inputProps: {
2348
+ inputMode: "decimal",
2349
+ pattern: "^[0-9]*[.]?[0-9]*$"
2350
+ },
2351
+ placeholder: "0.00",
2352
+ value: amount,
2353
+ onChange: handleAmountChange,
2354
+ error: !!error
2355
+ }
2356
+ )
2357
+ ] }),
2358
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2359
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", justifyContent: "space-between", mb: 1 }, children: [
2360
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: "Base fee" }),
2361
+ isValidAmount(amount) && recipient && (0, import_viem4.isAddress)(recipient) && !isInsufficientBalance() ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: { minWidth: 60, textAlign: "right" }, children: baseFee ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", children: [
2362
+ baseFee,
2363
+ " ",
2364
+ ((_b = tokenBalances == null ? void 0 : tokenBalances.nativeTokenBalance) == null ? void 0 : _b.symbol) || "AVAX"
2365
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.CircularProgress, { size: 16 }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", children: "--" })
2366
+ ] }),
2367
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", justifyContent: "space-between", mb: 1 }, children: [
2368
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: "Priority fee" }),
2369
+ isValidAmount(amount) && recipient && (0, import_viem4.isAddress)(recipient) && !isInsufficientBalance() ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: { minWidth: 60, textAlign: "right" }, children: priorityFee ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", children: [
2370
+ priorityFee,
2371
+ " ",
2372
+ ((_c = tokenBalances == null ? void 0 : tokenBalances.nativeTokenBalance) == null ? void 0 : _c.symbol) || "AVAX"
2373
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.CircularProgress, { size: 16 }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", children: "--" })
2374
+ ] }),
2375
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: {
2376
+ display: "flex",
2377
+ justifyContent: "space-between",
2378
+ borderTop: "1px solid",
2379
+ borderColor: "divider",
2380
+ pt: 1,
2381
+ mt: 1
2382
+ }, children: [
2383
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: "Total" }),
2384
+ isValidAmount(amount) && recipient && (0, import_viem4.isAddress)(recipient) && !isInsufficientBalance() ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: { minWidth: 60, textAlign: "right" }, children: totalWithAmount ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: selectedToken && "address" in selectedToken ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2385
+ amount,
2386
+ " ",
2387
+ selectedToken.symbol,
2388
+ " + ",
2389
+ totalFee,
2390
+ " ",
2391
+ ((_d = tokenBalances == null ? void 0 : tokenBalances.nativeTokenBalance) == null ? void 0 : _d.symbol) || "AVAX"
2392
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2393
+ totalWithAmount,
2394
+ " ",
2395
+ (selectedToken == null ? void 0 : selectedToken.symbol) || "AVAX"
2396
+ ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.CircularProgress, { size: 16 }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: "--" })
2397
+ ] })
2398
+ ] }),
2399
+ error && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Alert, { severity: "error", children: error }),
2400
+ isValidAmount(amount) && selectedToken && isInsufficientBalance() && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Alert, { severity: "error", children: selectedToken && "address" in selectedToken ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2401
+ "Insufficient token balance. Amount (",
2402
+ amount,
2403
+ " ",
2404
+ selectedToken.symbol,
2405
+ ") exceeds your balance (",
2406
+ (Number(selectedToken.balance) / 10 ** selectedToken.decimals).toFixed(4),
2407
+ " ",
2408
+ selectedToken.symbol,
2409
+ ")"
2410
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2411
+ "Insufficient balance. Total amount needed (",
2412
+ Number(amount) + Number(totalFee || "0"),
2413
+ " ",
2414
+ selectedToken.symbol,
2415
+ ") exceeds your balance (",
2416
+ (Number(selectedToken.balance) / 10 ** selectedToken.decimals).toFixed(4),
2417
+ " ",
2418
+ selectedToken.symbol,
2419
+ ")"
2420
+ ] }) }),
2421
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: { mt: "auto", display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2422
+ import_core_k2_components9.Button,
2423
+ {
2424
+ variant: "contained",
2425
+ size: "large",
2426
+ onClick: onSend,
2427
+ disabled: isLoading || !recipient || !!addressError || !isValidAmount(amount) || !selectedToken || isInsufficientBalance(),
2428
+ fullWidth: true,
2429
+ sx: {
2430
+ borderRadius: "9999px",
2431
+ height: "48px"
2432
+ },
2433
+ children: isLoading ? "Sending..." : "Send"
2434
+ }
2435
+ ) }),
2436
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PoweredByAvaCloud, {})
2437
+ ] });
2438
+ }
2439
+ function SuccessView({
2440
+ onDone,
2441
+ txHash,
2442
+ recipient,
2443
+ amount,
2444
+ currencySymbol,
2445
+ actualBaseFee,
2446
+ actualPriorityFee,
2447
+ actualTotalFee,
2448
+ nativeTokenSymbol
2449
+ }) {
2450
+ var _a, _b;
2451
+ const { blockchain } = useGlacier();
2452
+ const { wallet } = useAvaCloudWallet();
2453
+ const explorerUrl = (blockchain == null ? void 0 : blockchain.explorerUrl) ? `${blockchain.explorerUrl.replace(/\/$/, "")}/tx/${txHash}` : `https://subnets.avax.network/c-chain/tx/${txHash}`;
2454
+ const isERC20 = currencySymbol !== nativeTokenSymbol;
2455
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: {
2456
+ display: "flex",
2457
+ flexDirection: "column",
2458
+ height: "100%",
2459
+ p: 3,
2460
+ gap: 3,
2461
+ width: "100%",
2462
+ maxWidth: "600px",
2463
+ margin: "0 auto"
2464
+ }, children: [
2465
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 2 }, children: [
2466
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react14.Icon, { icon: "mdi:check-circle", color: "#4CAF50", width: 24, height: 24 }),
2467
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "h6", children: "Successfully sent" })
2468
+ ] }),
2469
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2470
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 1, fontWeight: 500 }, children: "From" }),
2471
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: {
2472
+ display: "flex",
2473
+ alignItems: "center",
2474
+ gap: 1.5
2475
+ }, children: [
2476
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2477
+ import_core_k2_components9.Box,
2478
+ {
2479
+ sx: {
2480
+ width: 40,
2481
+ height: 40,
2482
+ borderRadius: "50%",
2483
+ bgcolor: "#E84142",
2484
+ display: "flex",
2485
+ alignItems: "center",
2486
+ justifyContent: "center",
2487
+ overflow: "hidden"
2488
+ },
2489
+ children: (blockchain == null ? void 0 : blockchain.chainLogoUri) ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2490
+ "img",
2491
+ {
2492
+ src: blockchain.chainLogoUri,
2493
+ alt: blockchain.chainName || "Network",
2494
+ style: { width: "100%", height: "100%", objectFit: "cover" }
2495
+ }
2496
+ ) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react14.Icon, { icon: "cryptocurrency:avax", width: 24, height: 24, color: "white" })
2497
+ }
2498
+ ),
2499
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { flex: 1 }, children: [
2500
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body1", sx: { fontWeight: 500 }, children: (blockchain == null ? void 0 : blockchain.chainName) || "Avalanche C-Chain" }),
2501
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
2502
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", sx: { color: "text.secondary" }, children: [
2503
+ (_a = wallet.address) == null ? void 0 : _a.slice(0, 6),
2504
+ "...",
2505
+ (_b = wallet.address) == null ? void 0 : _b.slice(-4)
2506
+ ] }),
2507
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2508
+ import_core_k2_components9.IconButton,
2509
+ {
2510
+ size: "small",
2511
+ onClick: () => navigator.clipboard.writeText(wallet.address || ""),
2512
+ sx: { p: 0 },
2513
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react14.Icon, { icon: "mdi:content-copy", width: 16, height: 16 })
2514
+ }
2515
+ )
2516
+ ] })
2517
+ ] })
2518
+ ] })
2519
+ ] }),
2520
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2521
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 1, fontWeight: 500 }, children: "To" }),
2522
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
2523
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { sx: { wordBreak: "break-all" }, children: [
2524
+ recipient.slice(0, 6),
2525
+ "...",
2526
+ recipient.slice(-4)
2527
+ ] }),
2528
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2529
+ import_core_k2_components9.IconButton,
2530
+ {
2531
+ size: "small",
2532
+ onClick: () => navigator.clipboard.writeText(recipient),
2533
+ sx: { p: 0 },
2534
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react14.Icon, { icon: "mdi:content-copy", width: 16, height: 16 })
2535
+ }
2536
+ )
2537
+ ] })
2538
+ ] }),
2539
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2540
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 1, fontWeight: 500 }, children: "Amount" }),
2541
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { children: [
2542
+ amount,
2543
+ " ",
2544
+ currencySymbol
2545
+ ] })
2546
+ ] }),
2547
+ actualTotalFee && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2548
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 1, fontWeight: 500 }, children: "Transaction Fees" }),
2549
+ actualBaseFee && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", justifyContent: "space-between", mb: 0.5 }, children: [
2550
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: "Base fee" }),
2551
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", children: [
2552
+ actualBaseFee,
2553
+ " ",
2554
+ nativeTokenSymbol
2555
+ ] })
2556
+ ] }),
2557
+ actualPriorityFee && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { display: "flex", justifyContent: "space-between", mb: 0.5 }, children: [
2558
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: "Priority fee" }),
2559
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { variant: "body2", children: [
2560
+ actualPriorityFee,
2561
+ " ",
2562
+ nativeTokenSymbol
2563
+ ] })
2564
+ ] }),
2565
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: {
2566
+ display: "flex",
2567
+ justifyContent: "space-between",
2568
+ borderTop: "1px solid",
2569
+ borderColor: "divider",
2570
+ pt: 1,
2571
+ mt: 1
2572
+ }, children: [
2573
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: "Total" }),
2574
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { fontWeight: 500 }, children: isERC20 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2575
+ amount,
2576
+ " ",
2577
+ currencySymbol,
2578
+ " + ",
2579
+ actualTotalFee,
2580
+ " ",
2581
+ nativeTokenSymbol
2582
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
2583
+ (Number(amount) + Number(actualTotalFee)).toFixed(6),
2584
+ " ",
2585
+ currencySymbol
2586
+ ] }) })
2587
+ ] })
2588
+ ] }),
2589
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { children: [
2590
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", sx: { mb: 1, fontWeight: 500 }, children: "Transaction hash" }),
2591
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
2592
+ import_core_k2_components9.Box,
2593
+ {
2594
+ component: "a",
2595
+ href: explorerUrl,
2596
+ target: "_blank",
2597
+ rel: "noopener noreferrer",
2598
+ sx: {
2599
+ textDecoration: "none",
2600
+ color: "text.primary",
2601
+ wordBreak: "break-all",
2602
+ display: "flex",
2603
+ alignItems: "center",
2604
+ gap: 0.5,
2605
+ "&:hover": {
2606
+ textDecoration: "underline",
2607
+ color: "primary.main"
2608
+ }
2609
+ },
2610
+ children: [
2611
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { children: [
2612
+ txHash.slice(0, 6),
2613
+ "...",
2614
+ txHash.slice(-4)
2615
+ ] }),
2616
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react14.Icon, { icon: "mdi:open-in-new", width: 16, height: 16 })
2617
+ ]
2618
+ }
2619
+ ) })
2620
+ ] }),
2621
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2622
+ import_core_k2_components9.Button,
2623
+ {
2624
+ fullWidth: true,
2625
+ variant: "contained",
2626
+ onClick: onDone,
2627
+ sx: {
2628
+ borderRadius: "9999px",
2629
+ height: "48px",
2630
+ mt: "auto"
2631
+ },
2632
+ children: "Done"
2633
+ }
2634
+ )
2635
+ ] });
2636
+ }
2637
+ function FailureView({ recipient, amount, currencySymbol, error, onDone }) {
2638
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { p: 2 }, children: [
2639
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "h6", sx: { mb: 3 }, children: "Transaction Failed" }),
2640
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Box, { sx: { mb: 3 }, children: [
2641
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", children: "Amount" }),
2642
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_core_k2_components9.Typography, { children: [
2643
+ amount,
2644
+ " ",
2645
+ currencySymbol
2646
+ ] }),
2647
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { variant: "body2", color: "text.secondary", sx: { mt: 2 }, children: "Recipient" }),
2648
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Typography, { sx: { wordBreak: "break-all" }, children: recipient })
2649
+ ] }),
2650
+ error && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_core_k2_components9.Alert, { severity: "error", sx: { mb: 3 }, children: error }),
2651
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2652
+ import_core_k2_components9.Button,
2653
+ {
2654
+ fullWidth: true,
2655
+ variant: "contained",
2656
+ onClick: onDone,
2657
+ color: "error",
2658
+ children: "Try Again"
2659
+ }
2660
+ )
2661
+ ] });
2662
+ }
2663
+ function SendView({ onBack, onViewStateChange, selectedToken: initialToken }) {
2664
+ var _a;
2665
+ const { chainId } = useChainId();
2666
+ const [recipient, setRecipient] = (0, import_react13.useState)("");
2667
+ const [amount, setAmount] = (0, import_react13.useState)("");
2668
+ const [selectedToken, setSelectedToken] = (0, import_react13.useState)(initialToken);
2669
+ const { transfer, transferERC20, error, isLoading, txHash, viewState, reset, actualBaseFee, actualPriorityFee, actualTotalFee } = useTransferTokens();
2670
+ const { data: blockchainInfo } = useBlockchain((chainId == null ? void 0 : chainId.toString()) || "");
2671
+ (0, import_react13.useEffect)(() => {
2672
+ onViewStateChange == null ? void 0 : onViewStateChange(viewState);
2673
+ }, [viewState, onViewStateChange]);
2674
+ const handleSend = async () => {
2675
+ try {
2676
+ if (!recipient || !amount || !selectedToken) {
2677
+ throw new Error("Please fill in all fields");
2678
+ }
2679
+ if (!(0, import_viem4.isAddress)(recipient)) {
2680
+ throw new Error("Invalid recipient address");
2681
+ }
2682
+ if (!/^\d*\.?\d{0,18}$/.test(amount)) {
2683
+ throw new Error("Invalid amount format");
2684
+ }
2685
+ const amountValue = Number.parseFloat(amount);
2686
+ if (Number.isNaN(amountValue) || amountValue <= 0) {
2687
+ throw new Error("Please enter a valid amount");
2688
+ }
2689
+ const formattedAmount = amountValue.toLocaleString("fullwide", { useGrouping: false });
2690
+ if ("address" in selectedToken) {
2691
+ await transferERC20(selectedToken.address, recipient, formattedAmount, selectedToken.decimals);
2692
+ } else {
2693
+ await transfer(recipient, formattedAmount);
2694
+ }
2695
+ } catch (err) {
2696
+ console.error("Send failed:", err);
2697
+ }
2698
+ };
2699
+ const handleDone = () => {
2700
+ setRecipient("");
2701
+ setAmount("");
2702
+ setSelectedToken(void 0);
2703
+ reset();
2704
+ onBack();
2705
+ };
2706
+ if (viewState === "loading") {
2707
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(LoadingView, {});
2708
+ }
2709
+ if (viewState === "success" && txHash) {
2710
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2711
+ SuccessView,
2712
+ {
2713
+ onDone: handleDone,
2714
+ txHash,
2715
+ recipient,
2716
+ amount,
2717
+ currencySymbol: (selectedToken == null ? void 0 : selectedToken.symbol) || "AVAX",
2718
+ actualBaseFee,
2719
+ actualPriorityFee,
2720
+ actualTotalFee,
2721
+ nativeTokenSymbol: ((_a = blockchainInfo == null ? void 0 : blockchainInfo.networkToken) == null ? void 0 : _a.symbol) || "AVAX"
2722
+ }
2723
+ );
2724
+ }
2725
+ if (viewState === "failure") {
2726
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2727
+ FailureView,
2728
+ {
2729
+ recipient,
2730
+ amount,
2731
+ currencySymbol: (selectedToken == null ? void 0 : selectedToken.symbol) || "AVAX",
2732
+ error,
2733
+ onDone: handleDone
2734
+ }
2735
+ );
2736
+ }
2737
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2738
+ SendFormView,
2739
+ {
2740
+ recipient,
2741
+ amount,
2742
+ error,
2743
+ isLoading,
2744
+ selectedToken,
2745
+ chainId,
2746
+ onRecipientChange: setRecipient,
2747
+ onAmountChange: setAmount,
2748
+ onTokenSelect: setSelectedToken,
2749
+ onSend: handleSend,
2750
+ onBack
2751
+ }
2752
+ );
2753
+ }
2754
+
2755
+ // src/components/ReceiveView.tsx
2756
+ var import_react15 = require("react");
2757
+ var import_qrcode = require("qrcode.react");
2758
+ var import_core_k2_components10 = require("@avalabs/core-k2-components");
2759
+ var import_jsx_runtime12 = require("react/jsx-runtime");
2760
+ function ReceiveView(_props) {
2761
+ const { wallet } = useAvaCloudWallet();
2762
+ const { chainId } = useChainId();
2763
+ const [_copied, setCopied] = (0, import_react15.useState)(false);
2764
+ if (!wallet.address) {
2765
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_core_k2_components10.Box, { sx: { p: 2 }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_core_k2_components10.Typography, { color: "text.secondary", children: "No wallet address available" }) });
2766
+ }
2767
+ const handleCopy = () => {
2768
+ if (wallet.address) {
2769
+ navigator.clipboard.writeText(wallet.address);
2770
+ setCopied(true);
2771
+ setTimeout(() => setCopied(false), 2e3);
2772
+ }
2773
+ };
2774
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_core_k2_components10.Box, { sx: {
2775
+ display: "flex",
2776
+ flexDirection: "column",
2777
+ gap: 2,
2778
+ width: "100%",
2779
+ p: 2
2780
+ }, children: [
2781
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2782
+ import_core_k2_components10.Typography,
2783
+ {
2784
+ sx: {
2785
+ color: "#000",
2786
+ fontSize: "14px",
2787
+ fontWeight: 500,
2788
+ lineHeight: "20px"
2789
+ },
2790
+ children: "Address"
2791
+ }
2792
+ ),
2793
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_core_k2_components10.Box, { sx: {
2794
+ display: "flex",
2795
+ alignItems: "center",
2796
+ gap: 1,
2797
+ width: "100%"
2798
+ }, children: [
2799
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2800
+ import_core_k2_components10.Typography,
2801
+ {
2802
+ sx: {
2803
+ flex: 1,
2804
+ fontFamily: "monospace",
2805
+ fontSize: "14px",
2806
+ color: "#000",
2807
+ overflow: "hidden",
2808
+ textOverflow: "ellipsis"
2809
+ },
2810
+ children: wallet.address
2811
+ }
2812
+ ),
2813
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_core_k2_components10.IconButton, { onClick: handleCopy, size: "small", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_core_k2_components10.CopyIcon, {}) })
2814
+ ] }),
2815
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_core_k2_components10.Box, { sx: {
2816
+ display: "flex",
2817
+ justifyContent: "center",
2818
+ alignItems: "center",
2819
+ width: "100%",
2820
+ aspectRatio: "1",
2821
+ p: 2,
2822
+ background: "#FFF",
2823
+ borderRadius: "8px",
2824
+ border: "1px solid rgba(0, 0, 0, 0.12)"
2825
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2826
+ import_qrcode.QRCodeSVG,
2827
+ {
2828
+ value: wallet.address ? `ethereum:${wallet.address}@${chainId}` : "",
2829
+ level: "H",
2830
+ includeMargin: false,
2831
+ size: 200
2832
+ }
2833
+ ) }),
2834
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_core_k2_components10.Box, { sx: { mt: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(PoweredByAvaCloud, {}) })
2835
+ ] });
2836
+ }
2837
+
2838
+ // src/components/ExportView.tsx
2839
+ var import_react16 = require("react");
2840
+ var import_core_k2_components11 = require("@avalabs/core-k2-components");
2841
+ var import_jsx_runtime13 = require("react/jsx-runtime");
2842
+ function ExportView({ onBack }) {
2843
+ const { wallet, iframe } = useAvaCloudWallet();
2844
+ const [showKey, setShowKey] = (0, import_react16.useState)(false);
2845
+ const [copied, setCopied] = (0, import_react16.useState)(false);
2846
+ const [privateKey, setPrivateKey] = (0, import_react16.useState)(null);
2847
+ const [error, setError] = (0, import_react16.useState)(null);
2848
+ const handleExport = async () => {
2849
+ if (!(iframe == null ? void 0 : iframe.contentWindow)) return;
2850
+ try {
2851
+ iframe.contentWindow.postMessage({
2852
+ type: "EXPORT_PRIVATE_KEY",
2853
+ payload: {
2854
+ address: wallet.address
2855
+ }
2856
+ }, "*");
2857
+ const handleResponse = (event) => {
2858
+ if (event.data.type === "EXPORT_PRIVATE_KEY_RESPONSE") {
2859
+ setPrivateKey(event.data.payload.privateKey);
2860
+ setShowKey(true);
2861
+ window.removeEventListener("message", handleResponse);
2862
+ }
2863
+ };
2864
+ window.addEventListener("message", handleResponse);
2865
+ } catch (err) {
2866
+ console.error("Export failed:", err);
2867
+ setError("Failed to export private key. Please try again.");
2868
+ }
2869
+ };
2870
+ const handleCopy = () => {
2871
+ if (privateKey) {
2872
+ navigator.clipboard.writeText(privateKey);
2873
+ setCopied(true);
2874
+ setTimeout(() => setCopied(false), 2e3);
2875
+ }
2876
+ };
2877
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_core_k2_components11.Box, { sx: { p: 2 }, children: [
2878
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core_k2_components11.Typography, { variant: "h6", sx: { mb: 3 }, children: "Export Private Key" }),
2879
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_core_k2_components11.Alert, { severity: "warning", sx: { mb: 3 }, children: [
2880
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core_k2_components11.AlertTitle, { children: "Warning" }),
2881
+ "Never share your private key with anyone. Anyone with your private key can access your funds."
2882
+ ] }),
2883
+ !showKey ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2884
+ import_core_k2_components11.Button,
2885
+ {
2886
+ fullWidth: true,
2887
+ variant: "contained",
2888
+ color: "warning",
2889
+ onClick: handleExport,
2890
+ sx: { mb: 2 },
2891
+ children: "Show Private Key"
2892
+ }
2893
+ ) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core_k2_components11.Box, { sx: { mb: 3 }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_core_k2_components11.Box, { sx: {
2894
+ display: "flex",
2895
+ alignItems: "center",
2896
+ gap: 1,
2897
+ p: 2,
2898
+ bgcolor: "background.paper",
2899
+ borderRadius: 1,
2900
+ boxShadow: 1,
2901
+ mb: 2
2902
+ }, children: [
2903
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2904
+ import_core_k2_components11.Typography,
2905
+ {
2906
+ variant: "body2",
2907
+ sx: {
2908
+ fontFamily: "monospace",
2909
+ overflow: "hidden",
2910
+ textOverflow: "ellipsis",
2911
+ whiteSpace: "nowrap",
2912
+ flex: 1
2913
+ },
2914
+ children: privateKey
2915
+ }
2916
+ ),
2917
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2918
+ import_core_k2_components11.IconButton,
2919
+ {
2920
+ onClick: handleCopy,
2921
+ size: "small",
2922
+ color: copied ? "success" : "default",
2923
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core_k2_components11.CopyIcon, {})
2924
+ }
2925
+ )
2926
+ ] }) }),
2927
+ error && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core_k2_components11.Typography, { color: "error", sx: { mb: 2 }, children: error }),
2928
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2929
+ import_core_k2_components11.Button,
2930
+ {
2931
+ fullWidth: true,
2932
+ variant: "outlined",
2933
+ onClick: onBack,
2934
+ children: "Back"
2935
+ }
2936
+ )
2937
+ ] });
2938
+ }
2939
+
2940
+ // src/components/TokensView.tsx
2941
+ var import_react17 = require("react");
2942
+ var import_core_k2_components14 = require("@avalabs/core-k2-components");
2943
+
2944
+ // src/components/FungibleList.tsx
2945
+ var import_core_k2_components12 = require("@avalabs/core-k2-components");
2946
+ var import_jsx_runtime14 = require("react/jsx-runtime");
2947
+ function FungibleList({ onSend, onCopyAddress }) {
2948
+ var _a, _b, _c, _d;
2949
+ const { wallet } = useAvaCloudWallet();
2950
+ const { chainId } = useChainId();
2951
+ const { data: tokenBalances, isLoading: isLoadingERC20 } = useERC20Balances(
2952
+ (wallet == null ? void 0 : wallet.address) || void 0,
2953
+ chainId == null ? void 0 : chainId.toString()
2954
+ );
2955
+ if (isLoadingERC20) {
2956
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Box, { sx: {
2957
+ display: "flex",
2958
+ justifyContent: "center",
2959
+ alignItems: "center",
2960
+ height: "100%",
2961
+ minHeight: "200px"
2962
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(LoadingAnimation, { size: 80, message: "Loading tokens..." }) });
2963
+ }
2964
+ if (!(tokenBalances == null ? void 0 : tokenBalances.nativeTokenBalance) && !((_a = tokenBalances == null ? void 0 : tokenBalances.erc20TokenBalances) == null ? void 0 : _a.length)) {
2965
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Box, { sx: {
2966
+ p: 3,
2967
+ textAlign: "center",
2968
+ color: "text.secondary",
2969
+ bgcolor: "background.paper",
2970
+ borderRadius: "8px",
2971
+ border: "1px dashed rgba(0, 0, 0, 0.12)"
2972
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Typography, { children: "No tokens found" }) });
2973
+ }
2974
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_core_k2_components12.Box, { sx: {
2975
+ display: "flex",
2976
+ flexDirection: "column",
2977
+ height: "100%",
2978
+ overflow: "auto",
2979
+ py: 1,
2980
+ px: 1
2981
+ }, children: [
2982
+ (tokenBalances == null ? void 0 : tokenBalances.nativeTokenBalance) && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
2983
+ import_core_k2_components12.Box,
2984
+ {
2985
+ onClick: () => onSend == null ? void 0 : onSend(tokenBalances.nativeTokenBalance),
2986
+ sx: {
2987
+ display: "flex",
2988
+ alignItems: "center",
2989
+ py: 1.5,
2990
+ px: 1,
2991
+ cursor: onSend ? "pointer" : "default",
2992
+ "&:hover": onSend ? {
2993
+ bgcolor: "action.hover",
2994
+ borderRadius: 1
2995
+ } : {},
2996
+ borderRadius: 1,
2997
+ mb: 1
2998
+ },
2999
+ children: [
3000
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Box, { sx: { mr: 2 }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3001
+ TokenImage,
3002
+ {
3003
+ symbol: tokenBalances.nativeTokenBalance.symbol,
3004
+ logoUri: tokenBalances.nativeTokenBalance.logoUri,
3005
+ size: 32
3006
+ }
3007
+ ) }),
3008
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_core_k2_components12.Box, { sx: { flex: 1 }, children: [
3009
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Typography, { sx: { fontWeight: 500, fontSize: "14px" }, children: tokenBalances.nativeTokenBalance.symbol }),
3010
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_core_k2_components12.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
3011
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3012
+ import_core_k2_components12.Typography,
3013
+ {
3014
+ variant: "body2",
3015
+ sx: {
3016
+ color: "text.secondary",
3017
+ fontSize: "12px"
3018
+ },
3019
+ children: [
3020
+ (_b = wallet.address) == null ? void 0 : _b.slice(0, 6),
3021
+ "...",
3022
+ (_c = wallet.address) == null ? void 0 : _c.slice(-4)
3023
+ ]
3024
+ }
3025
+ ),
3026
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3027
+ import_core_k2_components12.IconButton,
3028
+ {
3029
+ size: "small",
3030
+ onClick: (e) => {
3031
+ e.stopPropagation();
3032
+ onCopyAddress(wallet.address || "");
3033
+ },
3034
+ sx: {
3035
+ padding: 0,
3036
+ color: "text.secondary",
3037
+ "&:hover": {
3038
+ color: "primary.main"
3039
+ }
3040
+ },
3041
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.CopyIcon, { fontSize: "small" })
3042
+ }
3043
+ )
3044
+ ] })
3045
+ ] }),
3046
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Box, { sx: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Typography, { sx: { fontWeight: 500 }, children: Number(Number(tokenBalances.nativeTokenBalance.balance) / 10 ** tokenBalances.nativeTokenBalance.decimals).toLocaleString(void 0, {
3047
+ minimumFractionDigits: 0,
3048
+ maximumFractionDigits: 6
3049
+ }) }) })
3050
+ ]
3051
+ }
3052
+ ),
3053
+ (_d = tokenBalances == null ? void 0 : tokenBalances.erc20TokenBalances) == null ? void 0 : _d.map((token) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3054
+ import_core_k2_components12.Box,
3055
+ {
3056
+ onClick: () => onSend == null ? void 0 : onSend(token),
3057
+ sx: {
3058
+ display: "flex",
3059
+ alignItems: "center",
3060
+ py: 1.5,
3061
+ px: 1,
3062
+ cursor: onSend ? "pointer" : "default",
3063
+ "&:hover": onSend ? {
3064
+ bgcolor: "action.hover",
3065
+ borderRadius: 1
3066
+ } : {},
3067
+ borderRadius: 1
3068
+ },
3069
+ children: [
3070
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Box, { sx: { mr: 2 }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3071
+ TokenImage,
3072
+ {
3073
+ symbol: token.symbol,
3074
+ logoUri: token.logoUri,
3075
+ size: 32
3076
+ }
3077
+ ) }),
3078
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_core_k2_components12.Box, { sx: { flex: 1 }, children: [
3079
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_core_k2_components12.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
3080
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Typography, { sx: { fontWeight: 500 }, children: token.symbol }),
3081
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3082
+ import_core_k2_components12.Typography,
3083
+ {
3084
+ variant: "body2",
3085
+ sx: {
3086
+ color: "text.secondary",
3087
+ fontSize: "12px"
3088
+ },
3089
+ children: token.name
3090
+ }
3091
+ )
3092
+ ] }),
3093
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_core_k2_components12.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
3094
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3095
+ import_core_k2_components12.Typography,
3096
+ {
3097
+ variant: "body2",
3098
+ sx: {
3099
+ color: "text.secondary",
3100
+ fontSize: "12px"
3101
+ },
3102
+ children: [
3103
+ token.address.slice(0, 6),
3104
+ "...",
3105
+ token.address.slice(-4)
3106
+ ]
3107
+ }
3108
+ ),
3109
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3110
+ import_core_k2_components12.IconButton,
3111
+ {
3112
+ size: "small",
3113
+ onClick: (e) => {
3114
+ e.stopPropagation();
3115
+ onCopyAddress(token.address);
3116
+ },
3117
+ sx: {
3118
+ padding: 0,
3119
+ color: "text.secondary",
3120
+ "&:hover": {
3121
+ color: "primary.main"
3122
+ }
3123
+ },
3124
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.CopyIcon, { fontSize: "small" })
3125
+ }
3126
+ )
3127
+ ] })
3128
+ ] }),
3129
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Box, { sx: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_core_k2_components12.Typography, { sx: { fontWeight: 500 }, children: Number(Number(token.balance) / 10 ** token.decimals).toLocaleString(void 0, {
3130
+ minimumFractionDigits: 0,
3131
+ maximumFractionDigits: 6
3132
+ }) }) })
3133
+ ]
3134
+ },
3135
+ token.address
3136
+ ))
3137
+ ] });
3138
+ }
3139
+
3140
+ // src/components/NonFungibleList.tsx
3141
+ var import_core_k2_components13 = require("@avalabs/core-k2-components");
3142
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3143
+ function convertIpfsUrl(url) {
3144
+ if (!url) return "/placeholder-nft.png";
3145
+ if (url.startsWith("ipfs://")) {
3146
+ const ipfsHash = url.replace("ipfs://", "");
3147
+ return `https://ipfs.io/ipfs/${ipfsHash}`;
3148
+ }
3149
+ return url;
3150
+ }
3151
+ function NonFungibleList() {
3152
+ const { wallet } = useAvaCloudWallet();
3153
+ const { chainId } = useChainId();
3154
+ const { data: blockchain } = useBlockchain(chainId == null ? void 0 : chainId.toString());
3155
+ const { data: erc721Response, isLoading: isLoadingERC721 } = useERC721Balances(
3156
+ (wallet == null ? void 0 : wallet.address) || void 0,
3157
+ chainId == null ? void 0 : chainId.toString()
3158
+ );
3159
+ const { data: erc1155Response, isLoading: isLoadingERC1155 } = useERC1155Balances(
3160
+ (wallet == null ? void 0 : wallet.address) || void 0,
3161
+ chainId == null ? void 0 : chainId.toString()
3162
+ );
3163
+ const isLoading = isLoadingERC721 || isLoadingERC1155;
3164
+ const getExplorerUrl = (contractAddress) => {
3165
+ if (!(blockchain == null ? void 0 : blockchain.explorerUrl)) return `https://subnets.avax.network/c-chain/address/${contractAddress}`;
3166
+ return `${blockchain.explorerUrl.replace(/\/$/, "")}/address/${contractAddress}`;
3167
+ };
3168
+ if (isLoading) {
3169
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Box, { sx: {
3170
+ display: "flex",
3171
+ justifyContent: "center",
3172
+ alignItems: "center",
3173
+ height: "100%",
3174
+ minHeight: "200px"
3175
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(LoadingAnimation, { size: 80, message: "Loading NFTs..." }) });
3176
+ }
3177
+ const erc721Tokens = (erc721Response == null ? void 0 : erc721Response.erc721TokenBalances) || [];
3178
+ const erc1155Tokens = (erc1155Response == null ? void 0 : erc1155Response.erc1155TokenBalances) || [];
3179
+ if (!erc721Tokens.length && !erc1155Tokens.length) {
3180
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Box, { sx: {
3181
+ p: 3,
3182
+ textAlign: "center",
3183
+ color: "text.secondary",
3184
+ bgcolor: "background.paper",
3185
+ borderRadius: "8px",
3186
+ border: "1px dashed rgba(0, 0, 0, 0.12)"
3187
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Typography, { children: "No NFTs found" }) });
3188
+ }
3189
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Box, { sx: {
3190
+ display: "flex",
3191
+ flexDirection: "column",
3192
+ height: "100%",
3193
+ overflow: "auto"
3194
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_core_k2_components13.Box, { sx: {
3195
+ display: "grid",
3196
+ gridTemplateColumns: "repeat(auto-fill, minmax(150px, 1fr))",
3197
+ gap: 2,
3198
+ p: 2
3199
+ }, children: [
3200
+ erc721Tokens.map((nft) => {
3201
+ var _a, _b, _c;
3202
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
3203
+ import_core_k2_components13.Box,
3204
+ {
3205
+ component: "a",
3206
+ href: getExplorerUrl(nft.address),
3207
+ target: "_blank",
3208
+ rel: "noopener noreferrer",
3209
+ sx: {
3210
+ bgcolor: "background.paper",
3211
+ borderRadius: 1,
3212
+ overflow: "hidden",
3213
+ boxShadow: 1,
3214
+ textDecoration: "none",
3215
+ color: "inherit",
3216
+ display: "block",
3217
+ transition: "transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out",
3218
+ "&:hover": {
3219
+ transform: "translateY(-2px)",
3220
+ boxShadow: 2
3221
+ }
3222
+ },
3223
+ children: [
3224
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Box, { sx: {
3225
+ position: "relative",
3226
+ paddingTop: "100%",
3227
+ bgcolor: "action.hover"
3228
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3229
+ import_core_k2_components13.Box,
3230
+ {
3231
+ component: "img",
3232
+ src: convertIpfsUrl((_a = nft.metadata) == null ? void 0 : _a.imageUri),
3233
+ alt: ((_b = nft.metadata) == null ? void 0 : _b.name) || nft.name,
3234
+ sx: {
3235
+ position: "absolute",
3236
+ top: 0,
3237
+ left: 0,
3238
+ width: "100%",
3239
+ height: "100%",
3240
+ objectFit: "cover"
3241
+ },
3242
+ onError: (e) => {
3243
+ const target = e.currentTarget;
3244
+ target.src = "/placeholder-nft.png";
3245
+ }
3246
+ }
3247
+ ) }),
3248
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_core_k2_components13.Box, { sx: { p: 1 }, children: [
3249
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Typography, { sx: { fontWeight: 500, fontSize: "14px" }, children: ((_c = nft.metadata) == null ? void 0 : _c.name) || nft.name }),
3250
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_core_k2_components13.Typography, { sx: { color: "text.secondary", fontSize: "12px" }, children: [
3251
+ "#",
3252
+ nft.tokenId
3253
+ ] })
3254
+ ] })
3255
+ ]
3256
+ },
3257
+ `${nft.address}-${nft.tokenId}`
3258
+ );
3259
+ }),
3260
+ erc1155Tokens.map((nft) => {
3261
+ var _a, _b, _c;
3262
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
3263
+ import_core_k2_components13.Box,
3264
+ {
3265
+ component: "a",
3266
+ href: getExplorerUrl(nft.address),
3267
+ target: "_blank",
3268
+ rel: "noopener noreferrer",
3269
+ sx: {
3270
+ bgcolor: "background.paper",
3271
+ borderRadius: 1,
3272
+ overflow: "hidden",
3273
+ boxShadow: 1,
3274
+ textDecoration: "none",
3275
+ color: "inherit",
3276
+ display: "block",
3277
+ transition: "transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out",
3278
+ "&:hover": {
3279
+ transform: "translateY(-2px)",
3280
+ boxShadow: 2
3281
+ }
3282
+ },
3283
+ children: [
3284
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Box, { sx: {
3285
+ position: "relative",
3286
+ paddingTop: "100%",
3287
+ bgcolor: "action.hover"
3288
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3289
+ import_core_k2_components13.Box,
3290
+ {
3291
+ component: "img",
3292
+ src: convertIpfsUrl((_a = nft.metadata) == null ? void 0 : _a.imageUri),
3293
+ alt: ((_b = nft.metadata) == null ? void 0 : _b.name) || nft.name,
3294
+ sx: {
3295
+ position: "absolute",
3296
+ top: 0,
3297
+ left: 0,
3298
+ width: "100%",
3299
+ height: "100%",
3300
+ objectFit: "cover"
3301
+ },
3302
+ onError: (e) => {
3303
+ const target = e.currentTarget;
3304
+ target.src = "/placeholder-nft.png";
3305
+ }
3306
+ }
3307
+ ) }),
3308
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_core_k2_components13.Box, { sx: { p: 1 }, children: [
3309
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core_k2_components13.Typography, { sx: { fontWeight: 500, fontSize: "14px" }, children: ((_c = nft.metadata) == null ? void 0 : _c.name) || nft.name }),
3310
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_core_k2_components13.Typography, { sx: { color: "text.secondary", fontSize: "12px" }, children: [
3311
+ "#",
3312
+ nft.tokenId,
3313
+ " ",
3314
+ nft.balance ? `\xD7 ${nft.balance}` : ""
3315
+ ] })
3316
+ ] })
3317
+ ]
3318
+ },
3319
+ `${nft.address}-${nft.tokenId}`
3320
+ );
3321
+ })
3322
+ ] }) });
3323
+ }
3324
+
3325
+ // src/components/TokensView.tsx
3326
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3327
+ function TokensView({ onSend }) {
3328
+ const [activeTab, setActiveTab] = (0, import_react17.useState)("tokens");
3329
+ const theme = (0, import_core_k2_components14.useTheme)();
3330
+ const handleCopyAddress = (address) => {
3331
+ navigator.clipboard.writeText(address);
3332
+ };
3333
+ const handleTabChange = (_, value) => {
3334
+ setActiveTab(value);
3335
+ };
3336
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_core_k2_components14.Box, { sx: {
3337
+ display: "flex",
3338
+ flexDirection: "column",
3339
+ width: "100%",
3340
+ height: "100%",
3341
+ overflow: "hidden"
3342
+ }, children: [
3343
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_core_k2_components14.Box, { sx: { mb: 2, display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
3344
+ import_core_k2_components14.Tabs,
3345
+ {
3346
+ value: activeTab,
3347
+ onChange: handleTabChange,
3348
+ isContained: true,
3349
+ centered: true,
3350
+ sx: {
3351
+ minHeight: 40,
3352
+ background: theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.05)" : "#F5F5F5",
3353
+ borderRadius: 999,
3354
+ padding: "4px",
3355
+ "& .MuiTabs-indicator": {
3356
+ backgroundColor: theme.palette.mode === "dark" ? "#000000" : "#000000",
3357
+ borderRadius: 999,
3358
+ height: "100%",
3359
+ zIndex: 1
3360
+ },
3361
+ "& .MuiTab-root": {
3362
+ minHeight: 32,
3363
+ borderRadius: 999,
3364
+ color: theme.palette.mode === "dark" ? "rgba(255, 255, 255, 0.5)" : "#666666",
3365
+ zIndex: 2,
3366
+ "&.Mui-selected": {
3367
+ color: "#FFFFFF"
3368
+ }
3369
+ }
3370
+ },
3371
+ children: [
3372
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3373
+ import_core_k2_components14.Tab,
3374
+ {
3375
+ value: "tokens",
3376
+ label: "Tokens"
3377
+ }
3378
+ ),
3379
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3380
+ import_core_k2_components14.Tab,
3381
+ {
3382
+ value: "nfts",
3383
+ label: "NFTs"
3384
+ }
3385
+ )
3386
+ ]
3387
+ }
3388
+ ) }),
3389
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_core_k2_components14.Box, { sx: {
3390
+ flex: 1,
3391
+ minHeight: 0,
3392
+ position: "relative",
3393
+ maxHeight: "500px",
3394
+ overflow: "auto",
3395
+ "&::-webkit-scrollbar": {
3396
+ width: "8px"
3397
+ },
3398
+ "&::-webkit-scrollbar-track": {
3399
+ background: "transparent"
3400
+ }
3401
+ }, children: activeTab === "tokens" ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3402
+ FungibleList,
3403
+ {
3404
+ onSend,
3405
+ onCopyAddress: handleCopyAddress
3406
+ }
3407
+ ) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(NonFungibleList, {}) })
3408
+ ] });
3409
+ }
3410
+
3411
+ // src/components/WalletHeader.tsx
3412
+ var import_core_k2_components15 = require("@avalabs/core-k2-components");
3413
+ var import_react18 = require("@iconify/react");
3414
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3415
+ function WalletHeader({ onClose }) {
3416
+ const { user, logout } = useAvaCloudWallet();
3417
+ if (!user) return null;
3418
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_core_k2_components15.Box, { sx: {
3419
+ display: "grid",
3420
+ gridTemplateColumns: "repeat(3, 1fr)",
3421
+ alignItems: "center",
3422
+ width: "100%",
3423
+ mb: 1
3424
+ }, children: [
3425
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_core_k2_components15.Box, { sx: {
3426
+ justifySelf: "start",
3427
+ display: "flex",
3428
+ alignItems: "center",
3429
+ gap: 1
3430
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3431
+ import_core_k2_components15.IconButton,
3432
+ {
3433
+ onClick: logout,
3434
+ size: "small",
3435
+ sx: {
3436
+ color: "text.secondary",
3437
+ "&:hover": {
3438
+ color: "text.primary"
3439
+ }
3440
+ },
3441
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_core_k2_components15.LogOutIcon, {})
3442
+ }
3443
+ ) }),
3444
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_core_k2_components15.Box, { sx: { justifySelf: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3445
+ import_core_k2_components15.Typography,
3446
+ {
3447
+ variant: "body2",
3448
+ sx: {
3449
+ color: "text.secondary",
3450
+ overflow: "hidden",
3451
+ textOverflow: "ellipsis",
3452
+ whiteSpace: "nowrap"
3453
+ },
3454
+ children: user.displayName
3455
+ }
3456
+ ) }),
3457
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_core_k2_components15.Box, { sx: { justifySelf: "end" }, children: onClose && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3458
+ import_core_k2_components15.IconButton,
3459
+ {
3460
+ onClick: onClose,
3461
+ sx: { color: "text.secondary" },
3462
+ children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react18.Icon, { icon: "ph:x-bold", width: 20, height: 20 })
3463
+ }
3464
+ ) })
3465
+ ] });
3466
+ }
3467
+
3468
+ // src/components/Buttons/SendButton.tsx
3469
+ var import_react19 = require("react");
3470
+ var import_core_k2_components16 = require("@avalabs/core-k2-components");
3471
+ var import_jsx_runtime18 = require("react/jsx-runtime");
3472
+ function SendButtonComponent({
3473
+ label = "Send",
3474
+ variant = "text",
3475
+ color = "primary",
3476
+ ...props
3477
+ }) {
3478
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(
3479
+ import_core_k2_components16.Button,
3480
+ {
3481
+ variant,
3482
+ color,
3483
+ ...props,
3484
+ sx: {
3485
+ display: "flex",
3486
+ width: "128px",
3487
+ height: "96px",
3488
+ flexDirection: "column",
3489
+ justifyContent: "center",
3490
+ alignItems: "center",
3491
+ gap: "8px",
3492
+ flexShrink: 0,
3493
+ borderRadius: "16px",
3494
+ background: "rgba(0, 0, 0, 0.02)",
3495
+ boxShadow: "2px 1px 4px 0px rgba(0, 0, 0, 0.25)",
3496
+ "& .MuiButton-startIcon": {
3497
+ margin: 0
3498
+ },
3499
+ ...props.sx
3500
+ },
3501
+ children: [
3502
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_core_k2_components16.ArrowUpIcon, {}),
3503
+ label
3504
+ ]
3505
+ }
3506
+ );
3507
+ }
3508
+ var SendButton = (0, import_react19.memo)(SendButtonComponent);
3509
+
3510
+ // src/components/Buttons/ReceiveButton.tsx
3511
+ var import_react20 = require("react");
3512
+ var import_core_k2_components17 = require("@avalabs/core-k2-components");
3513
+ var import_jsx_runtime19 = require("react/jsx-runtime");
3514
+ function ReceiveButtonComponent({
3515
+ label = "Receive",
3516
+ variant = "text",
3517
+ color = "primary",
3518
+ ...props
3519
+ }) {
3520
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(
3521
+ import_core_k2_components17.Button,
3522
+ {
3523
+ variant,
3524
+ color,
3525
+ ...props,
3526
+ sx: {
3527
+ display: "flex",
3528
+ width: "128px",
3529
+ height: "96px",
3530
+ flexDirection: "column",
3531
+ justifyContent: "center",
3532
+ alignItems: "center",
3533
+ gap: "8px",
3534
+ flexShrink: 0,
3535
+ borderRadius: "16px",
3536
+ background: "rgba(0, 0, 0, 0.02)",
3537
+ boxShadow: "2px 1px 4px 0px rgba(0, 0, 0, 0.25)",
3538
+ "& .MuiButton-startIcon": {
3539
+ margin: 0
3540
+ },
3541
+ ...props.sx
3542
+ },
3543
+ children: [
3544
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core_k2_components17.ArrowDownIcon, {}),
3545
+ label
3546
+ ]
3547
+ }
3548
+ );
3549
+ }
3550
+ var ReceiveButton = (0, import_react20.memo)(ReceiveButtonComponent);
3551
+
3552
+ // src/components/WalletCard.tsx
3553
+ var import_jsx_runtime20 = require("react/jsx-runtime");
3554
+ function WalletCard({ onClose }) {
3555
+ const { user, wallet, isAuthenticated } = useAvaCloudWallet();
3556
+ const { balance, isLoadingBalance, currencySymbol, blockchain } = useGlacier();
3557
+ const [currentView, setCurrentView] = (0, import_react21.useState)("main");
3558
+ const [selectedToken, setSelectedToken] = (0, import_react21.useState)();
3559
+ const theme = (0, import_core_k2_components18.useTheme)();
3560
+ if (!isAuthenticated || !user) return null;
3561
+ const handleCopy = (e) => {
3562
+ e.stopPropagation();
3563
+ if (wallet.address) {
3564
+ navigator.clipboard.writeText(wallet.address);
3565
+ }
3566
+ };
3567
+ const handleTokenSend = (token) => {
3568
+ setSelectedToken(token);
3569
+ setCurrentView("send");
3570
+ };
3571
+ const renderMainView = () => {
3572
+ var _a;
3573
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
3574
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core_k2_components18.Box, { sx: { textAlign: "center", mb: 3 }, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core_k2_components18.AvaCloudIcon, { width: 64, height: 64, foregroundFill: theme.palette.primary.main }) }),
3575
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_core_k2_components18.Box, { sx: { textAlign: "center", mb: 4, width: "100%" }, children: [
3576
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3577
+ import_core_k2_components18.Typography,
3578
+ {
3579
+ variant: "h4",
3580
+ sx: {
3581
+ mb: 2,
3582
+ fontWeight: 700,
3583
+ fontSize: "34px",
3584
+ lineHeight: "44px"
3585
+ },
3586
+ children: isLoadingBalance ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core_k2_components18.CircularProgress, { size: 24, sx: { mx: 1 } }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
3587
+ Number(balance || 0).toLocaleString(void 0, {
3588
+ minimumFractionDigits: 0,
3589
+ maximumFractionDigits: 4
3590
+ }),
3591
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3592
+ import_core_k2_components18.Box,
3593
+ {
3594
+ component: "span",
3595
+ sx: {
3596
+ display: "inline-flex",
3597
+ alignItems: "center",
3598
+ ml: 1,
3599
+ verticalAlign: "middle",
3600
+ "& img": {
3601
+ boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.1)",
3602
+ border: "1px solid rgba(0, 0, 0, 0.05)",
3603
+ transition: "transform 0.2s ease-in-out",
3604
+ "&:hover": {
3605
+ transform: "scale(1.05)"
3606
+ }
3607
+ }
3608
+ },
3609
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3610
+ TokenImage,
3611
+ {
3612
+ symbol: currencySymbol,
3613
+ logoUri: (_a = blockchain == null ? void 0 : blockchain.networkToken) == null ? void 0 : _a.logoUri,
3614
+ size: 28
3615
+ }
3616
+ )
3617
+ }
3618
+ )
3619
+ ] })
3620
+ }
3621
+ ),
3622
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_core_k2_components18.Box, { sx: {
3623
+ display: "flex",
3624
+ alignItems: "center",
3625
+ justifyContent: "center",
3626
+ gap: 1
3627
+ }, children: [
3628
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3629
+ import_core_k2_components18.Typography,
3630
+ {
3631
+ variant: "body2",
3632
+ sx: {
3633
+ overflow: "hidden",
3634
+ textOverflow: "ellipsis",
3635
+ whiteSpace: "nowrap"
3636
+ },
3637
+ children: wallet.address ? `${wallet.address.slice(0, 6)}...${wallet.address.slice(-4)}` : ""
3638
+ }
3639
+ ),
3640
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3641
+ import_core_k2_components18.IconButton,
3642
+ {
3643
+ size: "small",
3644
+ onClick: handleCopy,
3645
+ sx: { color: "text.secondary" },
3646
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core_k2_components18.CopyIcon, {})
3647
+ }
3648
+ )
3649
+ ] })
3650
+ ] }),
3651
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_core_k2_components18.Box, { sx: { display: "flex", gap: 2, width: "100%", mb: 3, justifyContent: "center" }, children: [
3652
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SendButton, { onClick: () => setCurrentView("send") }),
3653
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ReceiveButton, { onClick: () => setCurrentView("receive") })
3654
+ ] }),
3655
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3656
+ import_core_k2_components18.Button,
3657
+ {
3658
+ variant: "text",
3659
+ onClick: () => setCurrentView("tokens"),
3660
+ sx: {
3661
+ width: "100%",
3662
+ mb: 3,
3663
+ color: "text.secondary",
3664
+ "&:hover": {
3665
+ color: "primary.main",
3666
+ background: "transparent"
3667
+ }
3668
+ },
3669
+ children: "View All Assets \u2192"
3670
+ }
3671
+ ),
3672
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core_k2_components18.Box, { sx: { width: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(PoweredByAvaCloud, {}) })
3673
+ ] });
3674
+ };
3675
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3676
+ import_core_k2_components18.Dialog,
3677
+ {
3678
+ open: true,
3679
+ PaperProps: {
3680
+ sx: {
3681
+ width: "439px",
3682
+ maxWidth: "90vw",
3683
+ minHeight: "500px",
3684
+ maxHeight: "85vh",
3685
+ borderRadius: "16px",
3686
+ background: theme.palette.mode === "dark" ? theme.palette.background.paper : "#FCFCFC",
3687
+ boxShadow: theme.palette.mode === "dark" ? "0px 4px 6px 0px rgba(0, 0, 0, 0.3), 0px 4px 15px 0px rgba(0, 0, 0, 0.25)" : "0px 4px 6px 0px rgba(0, 0, 0, 0.16), 0px 4px 15px 0px rgba(0, 0, 0, 0.15)",
3688
+ backdropFilter: "blur(50px)",
3689
+ fontFamily: "Inter",
3690
+ display: "flex",
3691
+ flexDirection: "column"
3692
+ }
3693
+ },
3694
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
3695
+ import_core_k2_components18.DialogContent,
3696
+ {
3697
+ sx: {
3698
+ display: "flex",
3699
+ flexDirection: "column",
3700
+ alignItems: "center",
3701
+ gap: "24px",
3702
+ padding: "24px 32px 12px 32px",
3703
+ overflow: "hidden",
3704
+ "&.MuiDialogContent-root": {
3705
+ padding: "24px 32px 12px 32px",
3706
+ fontFamily: "Inter"
3707
+ }
3708
+ },
3709
+ children: [
3710
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(WalletHeader, { onClose }),
3711
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3712
+ import_core_k2_components18.Box,
3713
+ {
3714
+ sx: {
3715
+ flex: 1,
3716
+ width: "100%",
3717
+ minHeight: 0,
3718
+ overflowY: currentView === "tokens" ? "hidden" : "auto"
3719
+ },
3720
+ children: currentView === "main" ? renderMainView() : currentView === "receive" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ReceiveView, { onBack: () => setCurrentView("main") }) : currentView === "send" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3721
+ SendView,
3722
+ {
3723
+ onBack: () => setCurrentView("main"),
3724
+ selectedToken
3725
+ }
3726
+ ) : currentView === "tokens" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3727
+ TokensView,
3728
+ {
3729
+ onBack: () => setCurrentView("main"),
3730
+ onSend: handleTokenSend
3731
+ }
3732
+ ) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(ExportView, { onBack: () => setCurrentView("main") })
3733
+ }
3734
+ )
3735
+ ]
3736
+ }
3737
+ )
3738
+ }
3739
+ );
3740
+ }
3741
+
3742
+ // src/components/WalletButton.tsx
3743
+ var import_jsx_runtime21 = require("react/jsx-runtime");
3744
+ function WalletButton({
3745
+ label = "Connect Wallet",
3746
+ className = "",
3747
+ ...props
3748
+ }) {
3749
+ const { isLoading, isAuthenticated, wallet } = useAvaCloudWallet();
3750
+ const [isModalOpen, setIsModalOpen] = (0, import_react22.useState)(false);
3751
+ const theme = (0, import_core_k2_components19.useTheme)();
3752
+ const { isDarkMode } = useThemeMode();
3753
+ const handleOpen = () => setIsModalOpen(true);
3754
+ const handleClose = () => setIsModalOpen(false);
3755
+ const handleCopy = (e) => {
3756
+ e.stopPropagation();
3757
+ if (wallet.address) {
3758
+ navigator.clipboard.writeText(wallet.address);
3759
+ }
3760
+ };
3761
+ if (!isAuthenticated) {
3762
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
3763
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3764
+ import_core_k2_components19.Button,
3765
+ {
3766
+ onClick: handleOpen,
3767
+ disabled: isLoading,
3768
+ variant: "contained",
3769
+ color: "primary",
3770
+ className,
3771
+ sx: {
3772
+ fontFamily: "Inter"
3773
+ },
3774
+ ...props,
3775
+ children: isLoading ? "Loading..." : label
3776
+ }
3777
+ ),
3778
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3779
+ LoginModal,
3780
+ {
3781
+ open: isModalOpen,
3782
+ onClose: handleClose
3783
+ }
3784
+ )
3785
+ ] });
3786
+ }
3787
+ const displayAddress = wallet.address ? `${wallet.address.slice(0, 6)}...${wallet.address.slice(-4)}` : "";
3788
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
3789
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
3790
+ import_core_k2_components19.Button,
3791
+ {
3792
+ onClick: handleOpen,
3793
+ variant: "outlined",
3794
+ sx: {
3795
+ display: "inline-flex",
3796
+ padding: "12px 16px",
3797
+ alignItems: "center",
3798
+ gap: "16px",
3799
+ borderRadius: "16px",
3800
+ background: isDarkMode ? theme.palette.background.paper : "#FCFCFC",
3801
+ boxShadow: isDarkMode ? "0px 4px 6px 0px rgba(0, 0, 0, 0.3), 0px 4px 15px 0px rgba(0, 0, 0, 0.25)" : "0px 4px 6px 0px rgba(0, 0, 0, 0.16), 0px 4px 15px 0px rgba(0, 0, 0, 0.15)",
3802
+ backdropFilter: "blur(50px)",
3803
+ fontFamily: "Inter",
3804
+ border: `1px solid ${isDarkMode ? "rgba(255, 255, 255, 0.12)" : "rgba(0, 0, 0, 0.12)"}`,
3805
+ transition: "all 0.2s ease-in-out",
3806
+ "&:hover": {
3807
+ background: isDarkMode ? theme.palette.background.paper : "#FCFCFC",
3808
+ borderColor: theme.palette.primary.main,
3809
+ transform: "translateY(-1px)",
3810
+ boxShadow: isDarkMode ? "0px 6px 8px 0px rgba(0, 0, 0, 0.35), 0px 6px 20px 0px rgba(0, 0, 0, 0.3)" : "0px 6px 8px 0px rgba(0, 0, 0, 0.18), 0px 6px 20px 0px rgba(0, 0, 0, 0.17)"
3811
+ },
3812
+ "&:active": {
3813
+ transform: "translateY(0px)",
3814
+ background: isDarkMode ? theme.palette.background.paper : "#FCFCFC",
3815
+ boxShadow: isDarkMode ? "0px 2px 4px 0px rgba(0, 0, 0, 0.3), 0px 2px 10px 0px rgba(0, 0, 0, 0.25)" : "0px 2px 4px 0px rgba(0, 0, 0, 0.14), 0px 2px 10px 0px rgba(0, 0, 0, 0.13)"
3816
+ }
3817
+ },
3818
+ className,
3819
+ ...props,
3820
+ children: [
3821
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_core_k2_components19.AvaCloudIcon, { width: 24, height: 24, foregroundFill: theme.palette.primary.main }),
3822
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_core_k2_components19.Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
3823
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3824
+ import_core_k2_components19.Typography,
3825
+ {
3826
+ variant: "body2",
3827
+ sx: {
3828
+ fontFamily: "Inter",
3829
+ fontWeight: 500,
3830
+ color: theme.palette.text.primary
3831
+ },
3832
+ children: displayAddress
3833
+ }
3834
+ ),
3835
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3836
+ import_core_k2_components19.IconButton,
3837
+ {
3838
+ size: "small",
3839
+ onClick: handleCopy,
3840
+ sx: { color: "text.secondary" },
3841
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_core_k2_components19.CopyIcon, {})
3842
+ }
3843
+ )
3844
+ ] })
3845
+ ]
3846
+ }
3847
+ ),
3848
+ isModalOpen && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(WalletCard, { onClose: handleClose })
3849
+ ] });
3850
+ }
3851
+
3852
+ // src/components/WalletDisplay.tsx
3853
+ var import_react23 = require("react");
3854
+ var import_jsx_runtime22 = require("react/jsx-runtime");
3855
+ function WalletDisplay({
3856
+ className = "",
3857
+ truncateAddress = true,
3858
+ showAddAccount = true
3859
+ }) {
3860
+ const { wallet, addAccount, isAuthenticated } = useAvaCloudWallet();
3861
+ const [isAdding, setIsAdding] = (0, import_react23.useState)(false);
3862
+ const [accountIndex, setAccountIndex] = (0, import_react23.useState)(0);
3863
+ if (!isAuthenticated || !wallet.address) {
3864
+ return null;
3865
+ }
3866
+ const displayAddress = truncateAddress ? `${wallet.address.slice(0, 6)}...${wallet.address.slice(-4)}` : wallet.address;
3867
+ const handleAddAccount = async () => {
3868
+ try {
3869
+ setIsAdding(true);
3870
+ await addAccount(accountIndex);
3871
+ setAccountIndex((prev) => prev + 1);
3872
+ } catch (error) {
3873
+ console.error("Failed to add account:", error);
3874
+ } finally {
3875
+ setIsAdding(false);
3876
+ }
3877
+ };
3878
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: `space-y-4 ${className}`, children: [
3879
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: "bg-gray-50 rounded-lg p-4", children: [
3880
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "text-sm text-gray-500", children: "Wallet Address" }),
3881
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "mt-1 font-mono text-sm break-all", children: displayAddress })
3882
+ ] }),
3883
+ showAddAccount && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
3884
+ "button",
3885
+ {
3886
+ type: "button",
3887
+ onClick: handleAddAccount,
3888
+ disabled: isAdding,
3889
+ className: "w-full inline-flex items-center justify-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed",
3890
+ children: isAdding ? "Adding Account..." : "Add Account"
3891
+ }
3892
+ )
3893
+ ] });
3894
+ }
3895
+
3896
+ // src/components/UserProfile.tsx
3897
+ var import_jsx_runtime23 = require("react/jsx-runtime");
3898
+ function UserProfile({
3899
+ className = "",
3900
+ showLogout = true
3901
+ }) {
3902
+ const { user, logout, isAuthenticated } = useAvaCloudWallet();
3903
+ if (!isAuthenticated || !user) {
3904
+ return null;
3905
+ }
3906
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: `space-y-4 ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "bg-white shadow rounded-lg p-6", children: [
3907
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "px-4 py-5 sm:px-6", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("h3", { className: "text-lg font-medium leading-6 text-gray-900", children: "User Profile" }) }),
3908
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "border-t border-gray-200", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("dl", { children: [
3909
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6", children: [
3910
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("dt", { className: "text-sm font-medium text-gray-500", children: "Display Name" }),
3911
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("dd", { className: "mt-1 text-sm text-gray-900 sm:col-span-2", children: user.displayName })
3912
+ ] }),
3913
+ user.email && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: "bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6", children: [
3914
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("dt", { className: "text-sm font-medium text-gray-500", children: "Email address" }),
3915
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("dd", { className: "mt-1 text-sm text-gray-900 sm:col-span-2", children: user.email })
3916
+ ] }),
3917
+ user.configured_mfa && user.configured_mfa.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { children: [
3918
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "text-sm font-medium text-gray-500", children: "MFA Methods" }),
3919
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "mt-1 space-y-1", children: user.configured_mfa.map((method) => {
3920
+ const mfaMethod = typeof method === "string" ? { type: method } : method;
3921
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3922
+ "div",
3923
+ {
3924
+ className: "text-sm text-gray-900",
3925
+ children: mfaMethod.type === "totp" ? "Authenticator App" : mfaMethod.name
3926
+ },
3927
+ mfaMethod.type === "fido" ? mfaMethod.id : `totp-${mfaMethod.type}`
3928
+ );
3929
+ }) })
3930
+ ] })
3931
+ ] }) }),
3932
+ showLogout && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: "mt-6", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3933
+ "button",
3934
+ {
3935
+ type: "button",
3936
+ onClick: logout,
3937
+ className: "w-full inline-flex items-center justify-center px-4 py-2 border border-transparent text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500",
3938
+ children: "Sign Out"
3939
+ }
3940
+ ) })
3941
+ ] }) });
3942
+ }
3943
+
3944
+ // src/hooks/useSignMessage.ts
3945
+ var import_react24 = require("react");
3946
+ var import_cubesigner_sdk4 = require("@cubist-labs/cubesigner-sdk");
3947
+ function useSignMessage() {
3948
+ const [state, setState] = (0, import_react24.useState)({
3949
+ isLoading: false,
3950
+ error: null,
3951
+ signature: null
3952
+ });
3953
+ const { wallet, cubistClient } = useAvaCloudWallet();
3954
+ const reset = (0, import_react24.useCallback)(() => {
3955
+ setState({
3956
+ isLoading: false,
3957
+ error: null,
3958
+ signature: null
3959
+ });
3960
+ }, []);
3961
+ const signMessage = (0, import_react24.useCallback)(async (message) => {
3962
+ if (!cubistClient || !wallet.address) {
3963
+ setState((prev) => ({
3964
+ ...prev,
3965
+ error: "Client not initialized"
3966
+ }));
3967
+ return;
3968
+ }
3969
+ setState((prev) => ({
3970
+ ...prev,
3971
+ isLoading: true,
3972
+ error: null
3973
+ }));
3974
+ try {
3975
+ const key = await cubistClient.org().getKeyByMaterialId(import_cubesigner_sdk4.Secp256k1.Evm, wallet.address);
3976
+ const sig = await key.signBlob({
3977
+ message_base64: btoa(message)
3978
+ });
3979
+ const signature = `0x${sig.data().signature}`;
3980
+ setState((prev) => ({ ...prev, signature }));
3981
+ } catch (err) {
3982
+ setState((prev) => ({
3983
+ ...prev,
3984
+ error: err instanceof Error ? err.message : "Failed to sign message"
3985
+ }));
3986
+ } finally {
3987
+ setState((prev) => ({ ...prev, isLoading: false }));
3988
+ }
3989
+ }, [cubistClient, wallet.address]);
3990
+ return {
3991
+ ...state,
3992
+ signMessage,
3993
+ reset
3994
+ };
3995
+ }
3996
+
3997
+ // src/hooks/useSignTransaction.ts
3998
+ var import_react25 = require("react");
3999
+ var import_cubesigner_sdk5 = require("@cubist-labs/cubesigner-sdk");
4000
+ function useSignTransaction() {
4001
+ const [state, setState] = (0, import_react25.useState)({
4002
+ isLoading: false,
4003
+ error: null,
4004
+ signature: null,
4005
+ signedTransaction: null
4006
+ });
4007
+ const { wallet, cubistClient } = useAvaCloudWallet();
4008
+ const { publicClient } = useViem();
4009
+ const reset = (0, import_react25.useCallback)(() => {
4010
+ setState({
4011
+ isLoading: false,
4012
+ error: null,
4013
+ signature: null,
4014
+ signedTransaction: null
4015
+ });
4016
+ }, []);
4017
+ const signTransaction = (0, import_react25.useCallback)(async (transaction) => {
4018
+ var _a, _b, _c, _d;
4019
+ console.log("Signing transaction with:", {
4020
+ wallet: wallet == null ? void 0 : wallet.address,
4021
+ hasClient: !!cubistClient,
4022
+ hasPublicClient: !!publicClient,
4023
+ chain: publicClient == null ? void 0 : publicClient.chain
4024
+ });
4025
+ if (!(wallet == null ? void 0 : wallet.address)) {
4026
+ setState((prev) => ({
4027
+ ...prev,
4028
+ error: "Wallet not connected"
4029
+ }));
4030
+ return;
4031
+ }
4032
+ if (!cubistClient) {
4033
+ setState((prev) => ({
4034
+ ...prev,
4035
+ error: "Cubist client not initialized"
4036
+ }));
4037
+ return;
4038
+ }
4039
+ if (!(publicClient == null ? void 0 : publicClient.chain)) {
4040
+ setState((prev) => ({
4041
+ ...prev,
4042
+ error: "Public client or chain not initialized"
4043
+ }));
4044
+ return;
4045
+ }
4046
+ setState((prev) => ({
4047
+ ...prev,
4048
+ isLoading: true,
4049
+ error: null
4050
+ }));
4051
+ try {
4052
+ const key = await cubistClient.org().getKeyByMaterialId(import_cubesigner_sdk5.Secp256k1.Evm, wallet.address);
4053
+ if (!key) {
4054
+ throw new Error("No signing key available");
4055
+ }
4056
+ const signReq = {
4057
+ chain_id: publicClient.chain.id,
4058
+ tx: {
4059
+ to: transaction.to || void 0,
4060
+ value: (_a = transaction.value) == null ? void 0 : _a.toString(),
4061
+ data: transaction.data || "0x",
4062
+ nonce: (_b = transaction.nonce) == null ? void 0 : _b.toString(),
4063
+ type: "0x2",
4064
+ // EIP-1559
4065
+ maxFeePerGas: (_c = transaction.maxFeePerGas) == null ? void 0 : _c.toString(),
4066
+ maxPriorityFeePerGas: (_d = transaction.maxPriorityFeePerGas) == null ? void 0 : _d.toString()
4067
+ }
4068
+ };
4069
+ console.log("Signing request:", signReq);
4070
+ const sig = await key.signEvm(signReq);
4071
+ const signedTx = sig.data().rlp_signed_tx;
4072
+ setState((prev) => ({
4073
+ ...prev,
4074
+ signedTransaction: signedTx
4075
+ }));
4076
+ } catch (err) {
4077
+ console.error("Error signing transaction:", err);
4078
+ setState((prev) => ({
4079
+ ...prev,
4080
+ error: err instanceof Error ? err.message : "Failed to sign transaction"
4081
+ }));
4082
+ } finally {
4083
+ setState((prev) => ({ ...prev, isLoading: false }));
4084
+ }
4085
+ }, [wallet == null ? void 0 : wallet.address, publicClient, cubistClient]);
4086
+ return {
4087
+ ...state,
4088
+ signTransaction,
4089
+ reset
4090
+ };
4091
+ }
4092
+
4093
+ // src/hooks/useUserWallets.ts
4094
+ var import_react26 = require("react");
4095
+ function useUserWallets() {
4096
+ const [error, setError] = (0, import_react26.useState)(null);
4097
+ const [isLoading, setIsLoading] = (0, import_react26.useState)(false);
4098
+ const getWallets = (0, import_react26.useCallback)(async (client) => {
4099
+ setIsLoading(true);
4100
+ setError(null);
4101
+ try {
4102
+ const mnemonics = await client.org().keys();
4103
+ if (mnemonics.length === 0) {
4104
+ return [];
4105
+ }
4106
+ const wallets = mnemonics.map((key) => ({
4107
+ address: key.materialId,
4108
+ mnemonicId: key.id
4109
+ }));
4110
+ return wallets;
4111
+ } catch (err) {
4112
+ const error2 = err instanceof Error ? err : new Error("Failed to get user wallets");
4113
+ setError(error2);
4114
+ throw error2;
4115
+ } finally {
4116
+ setIsLoading(false);
4117
+ }
4118
+ }, []);
4119
+ return {
4120
+ getWallets,
4121
+ error,
4122
+ isLoading
4123
+ };
4124
+ }
4125
+ // Annotate the CommonJS export names for ESM import in node:
4126
+ 0 && (module.exports = {
4127
+ AvaCloudWalletProvider,
4128
+ ExportView,
4129
+ LoginButton,
4130
+ ReceiveView,
4131
+ SendView,
4132
+ ThemeProvider,
4133
+ TokensView,
4134
+ UserProfile,
4135
+ VM,
4136
+ WalletButton,
4137
+ WalletCard,
4138
+ WalletDisplay,
4139
+ useAuth,
4140
+ useAvaCloudWallet,
4141
+ useChainId,
4142
+ usePostMessage,
4143
+ useSignMessage,
4144
+ useSignTransaction,
4145
+ useThemeMode,
4146
+ useTransferTokens,
4147
+ useUserWallets
4148
+ });