@taskon/widget-react 0.0.1-beta.6 → 0.0.1-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +48 -43
  2. package/dist/EligibilityInfo.css +2 -33
  3. package/dist/TaskOnProvider.css +287 -0
  4. package/dist/ThemeProvider.css +227 -0
  5. package/dist/UserCenterWidget2.css +32 -290
  6. package/dist/WidgetShell.css +0 -227
  7. package/dist/chunks/{CommunityTaskList-Hde2OKHH.js → CommunityTaskList-D0uVD8wD.js} +37 -58
  8. package/dist/chunks/{EligibilityInfo-BV0Z2TgY.js → EligibilityInfo-Cf6hx9-a.js} +17 -209
  9. package/dist/chunks/{LeaderboardWidget-BNGRD5Bu.js → LeaderboardWidget-DyoiiNS6.js} +10 -9
  10. package/dist/chunks/{PageBuilder-C5DSHiW9.js → PageBuilder-DoAFPm6-.js} +5 -5
  11. package/dist/chunks/{Quest-DG9zfXJo.js → Quest-ySZlYd4u.js} +6 -11
  12. package/dist/chunks/TaskOnProvider-CxtFIs3n.js +2072 -0
  13. package/dist/chunks/{WidgetShell-D7yC894Y.js → ThemeProvider-CulHkqqY.js} +1354 -617
  14. package/dist/chunks/UserCenterWidget-BJsc_GSZ.js +3246 -0
  15. package/dist/chunks/{UserCenterWidget-D5ttw4hO.js → UserCenterWidget-STq8kpV4.js} +162 -365
  16. package/dist/chunks/WidgetShell-8xn-Jivw.js +659 -0
  17. package/dist/chunks/useIsMobile-D6Ybur-6.js +30 -0
  18. package/dist/chunks/useToast-BGJhd3BX.js +93 -0
  19. package/dist/community-task.js +1 -1
  20. package/dist/core.d.ts +9 -15
  21. package/dist/core.js +3 -3
  22. package/dist/index.d.ts +64 -15
  23. package/dist/index.js +15 -10
  24. package/dist/leaderboard.js +1 -1
  25. package/dist/page-builder.js +1 -1
  26. package/dist/quest.js +1 -1
  27. package/dist/user-center.js +1 -1
  28. package/package.json +1 -1
  29. package/dist/chunks/TaskOnProvider-BhamHIyY.js +0 -1260
  30. package/dist/chunks/ThemeProvider-mXLdLSkq.js +0 -1397
  31. package/dist/chunks/UserCenterWidget-jDO5zTN1.js +0 -3297
  32. package/dist/chunks/useToast-CaRkylKe.js +0 -304
@@ -1,3297 +0,0 @@
1
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import { useState, useRef, useCallback, useLayoutEffect, useMemo, useEffect } from "react";
3
- import { UserCenterRewardCardType, USER_CENTER_PAGE_SIZE, createUserCenterApi, SnsType, createUserApi, VerifyCodeType, getChainName, truncateAddress, filterEnabledAccounts, filterEnabledWallets, USER_CENTER_REWARD_CARD_TYPES, RewardType, toWei, LockedType, filterEnabledTabs, UserCenterTabType } from "@taskon/core";
4
- import { h as useTaskOnContext } from "./ThemeProvider-mXLdLSkq.js";
5
- import { u as useUserCenterLocale, L as LoadingState, E as EmptyState, P as Pagination, f as formatDateTime, A as AssetImage, b as buildRewardCards, a as useBindSocialAccount, I as Input, c as useTokenAssets, d as useRewardDetails, e as usePointsHistory, W as WithdrawForm, g as PointsList, N as NftRewardContent, T as TokenRewardContent } from "./UserCenterWidget-D5ttw4hO.js";
6
- import { T as Table, a as usePagination, D as Dialog, B as Button, u as useResolvedWidgetConfig, W as WidgetShell } from "./WidgetShell-D7yC894Y.js";
7
- import { u as useWallet, d as useToast } from "./useToast-CaRkylKe.js";
8
- import '../UserCenterWidget.css';function Tabs({
9
- items,
10
- activeKey,
11
- defaultActiveKey,
12
- onChange,
13
- className = "",
14
- style,
15
- gap = 40
16
- }) {
17
- var _a;
18
- const [internalActiveKey, setInternalActiveKey] = useState(
19
- defaultActiveKey ?? ((_a = items[0]) == null ? void 0 : _a.key) ?? ""
20
- );
21
- const currentActiveKey = activeKey ?? internalActiveKey;
22
- const tabsRef = useRef(null);
23
- const [indicatorStyle, setIndicatorStyle] = useState({});
24
- const updateIndicator = useCallback(() => {
25
- if (!tabsRef.current) return;
26
- const activeTab = tabsRef.current.querySelector(
27
- `.taskon-tabs__tab--active`
28
- );
29
- if (activeTab) {
30
- setIndicatorStyle({
31
- width: activeTab.offsetWidth,
32
- transform: `translateX(${activeTab.offsetLeft}px)`
33
- });
34
- }
35
- }, []);
36
- useLayoutEffect(() => {
37
- updateIndicator();
38
- }, [currentActiveKey, updateIndicator]);
39
- useLayoutEffect(() => {
40
- window.addEventListener("resize", updateIndicator);
41
- return () => window.removeEventListener("resize", updateIndicator);
42
- }, [updateIndicator]);
43
- const handleTabClick = (item) => {
44
- if (item.disabled) return;
45
- if (activeKey === void 0) {
46
- setInternalActiveKey(item.key);
47
- }
48
- onChange == null ? void 0 : onChange(item.key);
49
- };
50
- return /* @__PURE__ */ jsxs(
51
- "div",
52
- {
53
- ref: tabsRef,
54
- className: `taskon-tabs ${className}`,
55
- style: { ...style, "--taskon-tabs-gap": `${gap}px` },
56
- children: [
57
- /* @__PURE__ */ jsx("div", { className: "taskon-tabs__list", children: items.map((item) => /* @__PURE__ */ jsx(
58
- "button",
59
- {
60
- type: "button",
61
- className: `taskon-tabs__tab ${currentActiveKey === item.key ? "taskon-tabs__tab--active" : ""} ${item.disabled ? "taskon-tabs__tab--disabled" : ""}`,
62
- onClick: () => handleTabClick(item),
63
- disabled: item.disabled,
64
- "aria-selected": currentActiveKey === item.key,
65
- role: "tab",
66
- children: item.label
67
- },
68
- item.key
69
- )) }),
70
- /* @__PURE__ */ jsx("div", { className: "taskon-tabs__indicator", style: indicatorStyle })
71
- ]
72
- }
73
- );
74
- }
75
- function formatTimeRange(startTime, endTime) {
76
- const formatDate = (timestamp) => {
77
- const date = new Date(timestamp);
78
- const year = date.getFullYear();
79
- const month = String(date.getMonth() + 1).padStart(2, "0");
80
- const day = String(date.getDate()).padStart(2, "0");
81
- const hours = String(date.getHours()).padStart(2, "0");
82
- const minutes = String(date.getMinutes()).padStart(2, "0");
83
- const seconds = String(date.getSeconds()).padStart(2, "0");
84
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
85
- };
86
- return `${formatDate(startTime)} - ${formatDate(endTime)}`;
87
- }
88
- function ActivityHistoryList({
89
- data,
90
- loading,
91
- error,
92
- pagination,
93
- mode = "pagination",
94
- onItemClick,
95
- onRetry
96
- }) {
97
- const { messages } = useUserCenterLocale();
98
- const columns = useMemo(
99
- () => [
100
- {
101
- key: "campaign_name",
102
- title: messages.activity_name,
103
- cellClassName: "taskon-activity-history__cell--name",
104
- render: (_value, row) => /* @__PURE__ */ jsxs("div", { className: "taskon-activity-history__name-cell", children: [
105
- /* @__PURE__ */ jsx("span", { className: "taskon-activity-history__campaign-name", children: row.campaign_name }),
106
- /* @__PURE__ */ jsx("span", { className: "taskon-activity-history__campaign-type", children: row.campaign_type })
107
- ] })
108
- },
109
- {
110
- key: "time",
111
- title: messages.activity_time,
112
- width: "380px",
113
- align: "right",
114
- cellClassName: "taskon-activity-history__cell--time",
115
- render: (_value, row) => formatTimeRange(row.start_time, row.end_time)
116
- }
117
- ],
118
- [messages.activity_name, messages.activity_time]
119
- );
120
- const rowConfig = useMemo(
121
- () => ({
122
- getRowKey: (row) => `${row.campaign_type}-${row.campaign_id}`,
123
- onRowClick: onItemClick
124
- }),
125
- [onItemClick]
126
- );
127
- if (loading && data.length === 0) {
128
- return /* @__PURE__ */ jsx(LoadingState, { message: messages.loading });
129
- }
130
- if (error && data.length === 0) {
131
- return /* @__PURE__ */ jsxs("div", { className: "taskon-user-center-error", children: [
132
- /* @__PURE__ */ jsx("p", { className: "taskon-user-center-error__message", children: error.message }),
133
- onRetry && /* @__PURE__ */ jsx(
134
- "button",
135
- {
136
- type: "button",
137
- className: "taskon-user-center-error__retry",
138
- onClick: onRetry,
139
- children: messages.retry
140
- }
141
- )
142
- ] });
143
- }
144
- if (!loading && data.length === 0) {
145
- return /* @__PURE__ */ jsx(EmptyState, { message: messages.empty_activity_history });
146
- }
147
- return /* @__PURE__ */ jsxs("div", { className: "taskon-activity-history", children: [
148
- /* @__PURE__ */ jsx(
149
- Table,
150
- {
151
- columns,
152
- data,
153
- rowConfig,
154
- className: "taskon-activity-history__table",
155
- compact: true,
156
- loading,
157
- loadingText: messages.loading
158
- }
159
- ),
160
- mode === "pagination" ? /* @__PURE__ */ jsx(
161
- Pagination,
162
- {
163
- page: pagination.page,
164
- totalPages: pagination.totalPages,
165
- onPrevious: pagination.goToPrevious,
166
- onNext: pagination.goToNext,
167
- hasPrevious: pagination.hasPrevious,
168
- hasNext: pagination.hasNext
169
- }
170
- ) : pagination.hasMore && /* @__PURE__ */ jsx("div", { className: "taskon-activity-history__load-more", children: /* @__PURE__ */ jsx(
171
- "button",
172
- {
173
- type: "button",
174
- className: "taskon-activity-history__load-more-btn",
175
- onClick: pagination.loadMore,
176
- disabled: loading,
177
- children: loading ? messages.loading : messages.load_more
178
- }
179
- ) })
180
- ] });
181
- }
182
- function getCardTitle(type, messages, pointsData, xpLevelData) {
183
- var _a;
184
- switch (type) {
185
- case UserCenterRewardCardType.Token:
186
- return messages.reward_token;
187
- case UserCenterRewardCardType.Nft:
188
- return messages.reward_nft;
189
- case UserCenterRewardCardType.Whitelist:
190
- return messages.reward_whitelist;
191
- case UserCenterRewardCardType.DiscordRole:
192
- return messages.reward_discord_role;
193
- case UserCenterRewardCardType.Points:
194
- return (pointsData == null ? void 0 : pointsData.points_name) ?? messages.reward_points;
195
- case UserCenterRewardCardType.XpLevel: {
196
- const xpPointsName = (_a = xpLevelData == null ? void 0 : xpLevelData.xpPointsName) == null ? void 0 : _a.trim();
197
- if (xpPointsName) {
198
- return `${xpPointsName} & ${messages.level}`;
199
- }
200
- return messages.reward_xp_level;
201
- }
202
- default:
203
- return type;
204
- }
205
- }
206
- function getCardIconUrl(type, pointsData) {
207
- if (type === UserCenterRewardCardType.Points && (pointsData == null ? void 0 : pointsData.points_icon)) {
208
- return pointsData.points_icon;
209
- }
210
- return null;
211
- }
212
- function TokenIcon() {
213
- return /* @__PURE__ */ jsxs("svg", { width: "25", height: "28", viewBox: "0 0 25 28", fill: "none", children: [
214
- /* @__PURE__ */ jsx("path", { d: "M12.5 2L3 10H22L12.5 2Z", fill: "url(#token-gem-top)" }),
215
- /* @__PURE__ */ jsx("path", { d: "M3 10L12.5 26L12.5 10H3Z", fill: "url(#token-gem-left)" }),
216
- /* @__PURE__ */ jsx("path", { d: "M22 10L12.5 26L12.5 10H22Z", fill: "url(#token-gem-right)" }),
217
- /* @__PURE__ */ jsx(
218
- "path",
219
- {
220
- d: "M12.5 2L8 10H17L12.5 2Z",
221
- fill: "url(#token-gem-highlight)",
222
- fillOpacity: "0.6"
223
- }
224
- ),
225
- /* @__PURE__ */ jsxs("defs", { children: [
226
- /* @__PURE__ */ jsxs(
227
- "linearGradient",
228
- {
229
- id: "token-gem-top",
230
- x1: "12.5",
231
- y1: "2",
232
- x2: "12.5",
233
- y2: "10",
234
- gradientUnits: "userSpaceOnUse",
235
- children: [
236
- /* @__PURE__ */ jsx("stop", { stopColor: "#81D4FA" }),
237
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#4FC3F7" })
238
- ]
239
- }
240
- ),
241
- /* @__PURE__ */ jsxs(
242
- "linearGradient",
243
- {
244
- id: "token-gem-left",
245
- x1: "3",
246
- y1: "10",
247
- x2: "12.5",
248
- y2: "26",
249
- gradientUnits: "userSpaceOnUse",
250
- children: [
251
- /* @__PURE__ */ jsx("stop", { stopColor: "#4FC3F7" }),
252
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#0288D1" })
253
- ]
254
- }
255
- ),
256
- /* @__PURE__ */ jsxs(
257
- "linearGradient",
258
- {
259
- id: "token-gem-right",
260
- x1: "22",
261
- y1: "10",
262
- x2: "12.5",
263
- y2: "26",
264
- gradientUnits: "userSpaceOnUse",
265
- children: [
266
- /* @__PURE__ */ jsx("stop", { stopColor: "#29B6F6" }),
267
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#0277BD" })
268
- ]
269
- }
270
- ),
271
- /* @__PURE__ */ jsxs(
272
- "linearGradient",
273
- {
274
- id: "token-gem-highlight",
275
- x1: "12.5",
276
- y1: "2",
277
- x2: "12.5",
278
- y2: "10",
279
- gradientUnits: "userSpaceOnUse",
280
- children: [
281
- /* @__PURE__ */ jsx("stop", { stopColor: "#E1F5FE" }),
282
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#81D4FA" })
283
- ]
284
- }
285
- )
286
- ] })
287
- ] });
288
- }
289
- function NftIcon() {
290
- return /* @__PURE__ */ jsx("span", { className: "taskon-asset-card__icon-nft", children: "NFT" });
291
- }
292
- function WhitelistIcon() {
293
- return /* @__PURE__ */ jsx("span", { className: "taskon-asset-card__icon-wl", children: "WL" });
294
- }
295
- function DiscordRoleIcon() {
296
- return /* @__PURE__ */ jsx("svg", { width: "28", height: "22", viewBox: "0 0 28 22", fill: "none", children: /* @__PURE__ */ jsx(
297
- "path",
298
- {
299
- d: "M23.7 1.84A23.15 23.15 0 0018 0a.09.09 0 00-.09.04c-.25.44-.52 1.01-.71 1.46a21.37 21.37 0 00-6.4 0 14.77 14.77 0 00-.72-1.46.09.09 0 00-.1-.04 23.08 23.08 0 00-5.7 1.84.08.08 0 00-.04.03C.62 7.86-.37 13.68.12 19.41a.1.1 0 00.04.07 23.26 23.26 0 007 3.54.1.1 0 00.1-.04c.54-.74.97-1.52 1.33-2.33a.09.09 0 00-.05-.13 15.32 15.32 0 01-2.19-1.04.1.1 0 01-.01-.15c.15-.11.3-.22.43-.34a.09.09 0 01.09-.01c4.6 2.1 9.57 2.1 14.12 0a.09.09 0 01.1.01c.14.12.28.23.43.34a.1.1 0 01-.01.15c-.7.41-1.42.75-2.19 1.04a.09.09 0 00-.05.13c.38.81.8 1.59 1.32 2.33a.1.1 0 00.1.04 23.17 23.17 0 007.01-3.54.1.1 0 00.04-.07c.58-6.07-.97-11.84-4.13-16.84a.08.08 0 00-.04-.03zM9.36 15.91c-1.39 0-2.52-1.27-2.52-2.83s1.11-2.83 2.52-2.83c1.42 0 2.55 1.29 2.52 2.83 0 1.56-1.11 2.83-2.52 2.83zm9.32 0c-1.39 0-2.52-1.27-2.52-2.83s1.11-2.83 2.52-2.83c1.42 0 2.55 1.29 2.52 2.83 0 1.56-1.1 2.83-2.52 2.83z",
300
- fill: "#ffffff"
301
- }
302
- ) });
303
- }
304
- function XpLevelIcon() {
305
- return /* @__PURE__ */ jsxs("svg", { width: "26", height: "26", viewBox: "0 0 26 26", fill: "none", children: [
306
- /* @__PURE__ */ jsx(
307
- "path",
308
- {
309
- d: "M13 2L15.9 8.9L23 9.5L17.5 14.4L19.1 21.5L13 17.8L6.9 21.5L8.5 14.4L3 9.5L10.1 8.9L13 2Z",
310
- fill: "url(#xp-gradient)",
311
- stroke: "#F59E0B",
312
- strokeWidth: "1.5",
313
- strokeLinejoin: "round"
314
- }
315
- ),
316
- /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
317
- "linearGradient",
318
- {
319
- id: "xp-gradient",
320
- x1: "13",
321
- y1: "2",
322
- x2: "13",
323
- y2: "21.5",
324
- gradientUnits: "userSpaceOnUse",
325
- children: [
326
- /* @__PURE__ */ jsx("stop", { stopColor: "#FDE68A" }),
327
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#F59E0B" })
328
- ]
329
- }
330
- ) })
331
- ] });
332
- }
333
- function PointsIcon() {
334
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", children: [
335
- /* @__PURE__ */ jsx(
336
- "path",
337
- {
338
- d: "M12 2L14.4 8.6L21.5 9.2L16.2 13.8L17.8 20.8L12 17.1L6.2 20.8L7.8 13.8L2.5 9.2L9.6 8.6L12 2Z",
339
- fill: "url(#points-gradient)"
340
- }
341
- ),
342
- /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs(
343
- "linearGradient",
344
- {
345
- id: "points-gradient",
346
- x1: "12",
347
- y1: "2",
348
- x2: "12",
349
- y2: "20.8",
350
- gradientUnits: "userSpaceOnUse",
351
- children: [
352
- /* @__PURE__ */ jsx("stop", { stopColor: "#A78BFA" }),
353
- /* @__PURE__ */ jsx("stop", { offset: "1", stopColor: "#7C3AED" })
354
- ]
355
- }
356
- ) })
357
- ] });
358
- }
359
- function DefaultIcon({
360
- type
361
- }) {
362
- switch (type) {
363
- case UserCenterRewardCardType.Token:
364
- return /* @__PURE__ */ jsx(TokenIcon, {});
365
- case UserCenterRewardCardType.Nft:
366
- return /* @__PURE__ */ jsx(NftIcon, {});
367
- case UserCenterRewardCardType.Whitelist:
368
- return /* @__PURE__ */ jsx(WhitelistIcon, {});
369
- case UserCenterRewardCardType.DiscordRole:
370
- return /* @__PURE__ */ jsx(DiscordRoleIcon, {});
371
- case UserCenterRewardCardType.Points:
372
- return /* @__PURE__ */ jsx(PointsIcon, {});
373
- case UserCenterRewardCardType.XpLevel:
374
- return /* @__PURE__ */ jsx(XpLevelIcon, {});
375
- default:
376
- return /* @__PURE__ */ jsx(PointsIcon, {});
377
- }
378
- }
379
- function needsLightBackground(type) {
380
- return type === UserCenterRewardCardType.Whitelist;
381
- }
382
- function AssetCard({
383
- type,
384
- value,
385
- selected = false,
386
- onClick,
387
- pointsData,
388
- xpLevelData
389
- }) {
390
- const { messages } = useUserCenterLocale();
391
- const title = getCardTitle(type, messages, pointsData, xpLevelData);
392
- const iconUrl = getCardIconUrl(type, pointsData);
393
- const iconClassName = `taskon-asset-card__icon${needsLightBackground(type) ? " taskon-asset-card__icon--light" : ""}`;
394
- return /* @__PURE__ */ jsxs(
395
- "button",
396
- {
397
- type: "button",
398
- className: `taskon-asset-card ${selected ? "taskon-asset-card--selected" : ""}`,
399
- onClick,
400
- "aria-pressed": selected,
401
- children: [
402
- /* @__PURE__ */ jsx("div", { className: iconClassName, children: iconUrl ? /* @__PURE__ */ jsx(
403
- "img",
404
- {
405
- src: iconUrl,
406
- alt: title,
407
- className: "taskon-asset-card__icon-img"
408
- }
409
- ) : /* @__PURE__ */ jsx(DefaultIcon, { type }) }),
410
- /* @__PURE__ */ jsxs("div", { className: "taskon-asset-card__content", children: [
411
- /* @__PURE__ */ jsx("span", { className: "taskon-asset-card__title", children: title }),
412
- /* @__PURE__ */ jsx("span", { className: "taskon-asset-card__value", children: value })
413
- ] })
414
- ]
415
- }
416
- );
417
- }
418
- function AssetCarousel({
419
- cards,
420
- selectedCard,
421
- selectedPointsId,
422
- onSelectCard
423
- }) {
424
- const { messages } = useUserCenterLocale();
425
- const containerRef = useRef(null);
426
- const [showLeftArrow, setShowLeftArrow] = useState(false);
427
- const [showRightArrow, setShowRightArrow] = useState(false);
428
- const visibleCards = cards.filter((card) => card.visible);
429
- const checkScrollArrows = useCallback(() => {
430
- const container = containerRef.current;
431
- if (!container) return;
432
- const { scrollLeft, scrollWidth, clientWidth } = container;
433
- setShowLeftArrow(scrollLeft > 0);
434
- setShowRightArrow(scrollLeft + clientWidth < scrollWidth - 1);
435
- }, []);
436
- useCallback((direction) => {
437
- const container = containerRef.current;
438
- if (!container) return;
439
- const scrollAmount = 200;
440
- const newScrollLeft = direction === "left" ? container.scrollLeft - scrollAmount : container.scrollLeft + scrollAmount;
441
- container.scrollTo({
442
- left: newScrollLeft,
443
- behavior: "smooth"
444
- });
445
- }, []);
446
- const isCardSelected = useCallback(
447
- (card) => {
448
- if (selectedCard !== card.type) return false;
449
- if (card.type === "Points" && card.pointsData) {
450
- return selectedPointsId === card.pointsData.points_id;
451
- }
452
- return true;
453
- },
454
- [selectedCard, selectedPointsId]
455
- );
456
- useEffect(() => {
457
- const container = containerRef.current;
458
- if (!container) return;
459
- checkScrollArrows();
460
- container.addEventListener("scroll", checkScrollArrows);
461
- window.addEventListener("resize", checkScrollArrows);
462
- return () => {
463
- container.removeEventListener("scroll", checkScrollArrows);
464
- window.removeEventListener("resize", checkScrollArrows);
465
- };
466
- }, [checkScrollArrows, visibleCards]);
467
- if (visibleCards.length === 0) {
468
- return /* @__PURE__ */ jsx("div", { className: "taskon-asset-carousel--empty" });
469
- }
470
- return /* @__PURE__ */ jsxs("div", { className: "taskon-asset-carousel", children: [
471
- /* @__PURE__ */ jsx("h3", { className: "taskon-asset-carousel__title", children: messages.section_you_have_earned }),
472
- /* @__PURE__ */ jsx("div", { ref: containerRef, className: "taskon-asset-carousel__container", children: visibleCards.map((card, index) => {
473
- var _a;
474
- return /* @__PURE__ */ jsx(
475
- AssetCard,
476
- {
477
- type: card.type,
478
- value: card.value,
479
- selected: isCardSelected(card),
480
- onClick: () => {
481
- var _a2;
482
- return onSelectCard(card.type, (_a2 = card.pointsData) == null ? void 0 : _a2.points_id);
483
- },
484
- pointsData: card.pointsData,
485
- xpLevelData: card.xpLevelData
486
- },
487
- `${card.type}-${((_a = card.pointsData) == null ? void 0 : _a.points_id) ?? index}`
488
- );
489
- }) })
490
- ] });
491
- }
492
- function ProgressBar({
493
- value,
494
- max,
495
- showPercent = false,
496
- showValues = false,
497
- height = 8,
498
- className = "",
499
- color,
500
- backgroundColor
501
- }) {
502
- const percent = max > 0 ? Math.min(100, Math.max(0, value / max * 100)) : 0;
503
- const formatValue = (val) => {
504
- if (val >= 1e6) {
505
- return `${(val / 1e6).toFixed(1)}M`;
506
- }
507
- if (val >= 1e3) {
508
- return `${(val / 1e3).toFixed(1)}K`;
509
- }
510
- return val.toLocaleString();
511
- };
512
- const containerStyle = {
513
- height: `${height}px`,
514
- ...backgroundColor && { backgroundColor }
515
- };
516
- const fillStyle = {
517
- width: `${percent}%`,
518
- ...color && { backgroundColor: color }
519
- };
520
- return /* @__PURE__ */ jsxs("div", { className: `taskon-progress-bar ${className}`, children: [
521
- /* @__PURE__ */ jsx("div", { className: "taskon-progress-bar__container", style: containerStyle, children: /* @__PURE__ */ jsx("div", { className: "taskon-progress-bar__fill", style: fillStyle }) }),
522
- (showPercent || showValues) && /* @__PURE__ */ jsxs("div", { className: "taskon-progress-bar__info", children: [
523
- showValues && /* @__PURE__ */ jsxs("span", { className: "taskon-progress-bar__values", children: [
524
- formatValue(value),
525
- " / ",
526
- formatValue(max)
527
- ] }),
528
- showPercent && /* @__PURE__ */ jsxs("span", { className: "taskon-progress-bar__percent", children: [
529
- percent.toFixed(0),
530
- "%"
531
- ] })
532
- ] })
533
- ] });
534
- }
535
- function formatNumber(val) {
536
- if (Math.abs(val) >= 1e6) {
537
- return `${(val / 1e6).toFixed(1)}M`;
538
- }
539
- if (Math.abs(val) >= 1e3) {
540
- return `${(val / 1e3).toFixed(1)}K`;
541
- }
542
- return val.toLocaleString();
543
- }
544
- function XpLevelCard({
545
- xpData,
546
- historyData,
547
- historyLoading,
548
- historyError,
549
- pagination,
550
- className = ""
551
- }) {
552
- var _a;
553
- const { messages } = useUserCenterLocale();
554
- const { level, currentXp, nextLevelXp, totalXp } = xpData;
555
- const pointsName = ((_a = xpData.pointsName) == null ? void 0 : _a.trim()) || messages.default_xp_points_name;
556
- const xpToNext = Math.max(0, nextLevelXp - currentXp);
557
- const columns = [
558
- {
559
- key: "detail",
560
- title: messages.column_detail,
561
- render: (_, row) => /* @__PURE__ */ jsx("span", { className: "taskon-points-list__name", children: row.name })
562
- },
563
- {
564
- key: "time",
565
- title: messages.column_time,
566
- width: 160,
567
- render: (_, row) => /* @__PURE__ */ jsx("span", { className: "taskon-points-list__time", children: formatDateTime(row.receive_time) })
568
- },
569
- {
570
- key: "amount",
571
- title: `${messages.column_amount} (${pointsName})`,
572
- width: 160,
573
- align: "right",
574
- render: (_, row) => {
575
- const isPositive = row.points.amount >= 0;
576
- return /* @__PURE__ */ jsxs("div", { className: "taskon-points-list__amount-cell", children: [
577
- row.points.points_icon && /* @__PURE__ */ jsx(
578
- "img",
579
- {
580
- src: row.points.points_icon,
581
- alt: "",
582
- className: "taskon-points-list__amount-icon"
583
- }
584
- ),
585
- /* @__PURE__ */ jsxs(
586
- "span",
587
- {
588
- className: `taskon-points-list__amount-value ${isPositive ? "taskon-points-list__amount-value--positive" : "taskon-points-list__amount-value--negative"}`,
589
- children: [
590
- isPositive ? "+" : "",
591
- formatNumber(row.points.amount)
592
- ]
593
- }
594
- )
595
- ] });
596
- }
597
- }
598
- ];
599
- return /* @__PURE__ */ jsxs("div", { className: `taskon-xp-level-card ${className}`, children: [
600
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__header", children: [
601
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__level", children: [
602
- /* @__PURE__ */ jsx("div", { className: "taskon-xp-level-card__level-badge", children: level }),
603
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__level-info", children: [
604
- /* @__PURE__ */ jsx("span", { className: "taskon-xp-level-card__level-label", children: messages.level }),
605
- /* @__PURE__ */ jsxs("span", { className: "taskon-xp-level-card__level-value", children: [
606
- messages.level,
607
- " ",
608
- level
609
- ] })
610
- ] })
611
- ] }),
612
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__xp", children: [
613
- /* @__PURE__ */ jsx("span", { className: "taskon-xp-level-card__xp-label", children: messages.total_xp }),
614
- /* @__PURE__ */ jsxs("span", { className: "taskon-xp-level-card__xp-value", children: [
615
- formatNumber(totalXp),
616
- " ",
617
- pointsName
618
- ] })
619
- ] })
620
- ] }),
621
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__progress", children: [
622
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__progress-label", children: [
623
- /* @__PURE__ */ jsxs("span", { children: [
624
- formatNumber(currentXp),
625
- " / ",
626
- formatNumber(nextLevelXp),
627
- " ",
628
- pointsName
629
- ] }),
630
- /* @__PURE__ */ jsxs("span", { children: [
631
- messages.xp_to_next_level,
632
- ": ",
633
- formatNumber(xpToNext),
634
- " ",
635
- pointsName
636
- ] })
637
- ] }),
638
- /* @__PURE__ */ jsx(ProgressBar, { value: currentXp, max: nextLevelXp, height: 10 })
639
- ] }),
640
- /* @__PURE__ */ jsxs("div", { className: "taskon-xp-level-card__history", children: [
641
- /* @__PURE__ */ jsx("h4", { className: "taskon-xp-level-card__history-title", children: messages.xp_history }),
642
- historyLoading && historyData.length === 0 && /* @__PURE__ */ jsx(LoadingState, { message: messages.loading }),
643
- historyError && historyData.length === 0 && /* @__PURE__ */ jsx("div", { className: "taskon-user-center-error", children: /* @__PURE__ */ jsx("p", { className: "taskon-user-center-error__message", children: historyError.message }) }),
644
- !historyLoading && !historyError && historyData.length === 0 && /* @__PURE__ */ jsx(EmptyState, { message: messages.no_data }),
645
- historyData.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
646
- /* @__PURE__ */ jsx("div", { className: "taskon-xp-level-card__table-wrap", children: /* @__PURE__ */ jsx(
647
- Table,
648
- {
649
- columns,
650
- data: historyData,
651
- rowConfig: {
652
- getRowKey: (row, index) => `${row.campaign_id ?? row.task_id ?? "item"}-${row.receive_time}-${index}`
653
- },
654
- loading: historyLoading && historyData.length > 0,
655
- loadingText: messages.loading,
656
- empty: {
657
- title: messages.no_data
658
- }
659
- }
660
- ) }),
661
- pagination.totalPages > 1 && /* @__PURE__ */ jsx(
662
- Pagination,
663
- {
664
- page: pagination.page,
665
- totalPages: pagination.totalPages,
666
- onPrevious: pagination.goToPrevious,
667
- onNext: pagination.goToNext,
668
- hasPrevious: pagination.hasPrevious,
669
- hasNext: pagination.hasNext
670
- }
671
- )
672
- ] })
673
- ] })
674
- ] });
675
- }
676
- function WhitelistTable({
677
- data,
678
- loading,
679
- error,
680
- pagination
681
- }) {
682
- const { messages } = useUserCenterLocale();
683
- if (loading && data.length === 0) {
684
- return /* @__PURE__ */ jsx(LoadingState, { message: messages.loading });
685
- }
686
- if (error && data.length === 0) {
687
- return /* @__PURE__ */ jsx("div", { className: "taskon-user-center-error", children: /* @__PURE__ */ jsx("p", { className: "taskon-user-center-error__message", children: error.message }) });
688
- }
689
- if (!loading && data.length === 0) {
690
- return /* @__PURE__ */ jsx(EmptyState, { message: messages.no_data });
691
- }
692
- const columns = [
693
- {
694
- key: "whitelist",
695
- title: messages.column_whitelist,
696
- width: 100,
697
- render: (_, row) => {
698
- const wlValue = row.reward_value;
699
- return /* @__PURE__ */ jsx(
700
- AssetImage,
701
- {
702
- src: wlValue.nft_image,
703
- chain: wlValue.chain,
704
- alt: "Whitelist",
705
- size: 60,
706
- useWhitelistDefault: !wlValue.nft_image
707
- }
708
- );
709
- }
710
- },
711
- {
712
- key: "detail",
713
- title: messages.column_detail,
714
- render: (_, row) => /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__campaign-name", children: row.campaign_name })
715
- },
716
- {
717
- key: "time",
718
- title: messages.column_time,
719
- width: 160,
720
- render: (_, row) => /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__time", children: formatDateTime(row.reward_time) })
721
- },
722
- {
723
- key: "status",
724
- title: messages.column_status,
725
- width: 120,
726
- align: "right",
727
- render: () => /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__manual-drop", children: messages.manual_drop })
728
- }
729
- ];
730
- return /* @__PURE__ */ jsxs("div", { className: "taskon-reward-table", children: [
731
- /* @__PURE__ */ jsx(
732
- Table,
733
- {
734
- columns,
735
- data,
736
- rowConfig: {
737
- getRowKey: (row, index) => `${row.campaign_id}-${row.reward_time}-${index}`
738
- },
739
- loading: loading && data.length > 0,
740
- loadingText: messages.loading,
741
- empty: {
742
- title: messages.no_data
743
- }
744
- }
745
- ),
746
- pagination.totalPages > 1 && /* @__PURE__ */ jsx(
747
- Pagination,
748
- {
749
- page: pagination.page,
750
- totalPages: pagination.totalPages,
751
- onPrevious: pagination.goToPrevious,
752
- onNext: pagination.goToNext,
753
- hasPrevious: pagination.hasPrevious,
754
- hasNext: pagination.hasNext
755
- }
756
- )
757
- ] });
758
- }
759
- function DiscordRoleTable({
760
- data,
761
- loading,
762
- error,
763
- pagination
764
- }) {
765
- const { messages } = useUserCenterLocale();
766
- if (loading && data.length === 0) {
767
- return /* @__PURE__ */ jsx(LoadingState, { message: messages.loading });
768
- }
769
- if (error && data.length === 0) {
770
- return /* @__PURE__ */ jsx("div", { className: "taskon-user-center-error", children: /* @__PURE__ */ jsx("p", { className: "taskon-user-center-error__message", children: error.message }) });
771
- }
772
- if (!loading && data.length === 0) {
773
- return /* @__PURE__ */ jsx(EmptyState, { message: messages.no_data });
774
- }
775
- const columns = [
776
- {
777
- key: "discordRole",
778
- title: messages.column_discord_role,
779
- width: 160,
780
- render: (_, row) => {
781
- const dcValue = row.reward_value;
782
- return /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__role-name", children: dcValue.role_name });
783
- }
784
- },
785
- {
786
- key: "detail",
787
- title: messages.column_detail,
788
- render: (_, row) => /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__campaign-name", children: row.milestone_name || row.campaign_name })
789
- },
790
- {
791
- key: "time",
792
- title: messages.column_time,
793
- width: 160,
794
- render: (_, row) => /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__time", children: formatDateTime(row.reward_time) })
795
- },
796
- {
797
- key: "status",
798
- title: messages.column_status,
799
- width: 120,
800
- align: "right",
801
- render: () => /* @__PURE__ */ jsx("span", { className: "taskon-reward-table__manual-drop", children: messages.manual_drop })
802
- }
803
- ];
804
- return /* @__PURE__ */ jsxs("div", { className: "taskon-reward-table", children: [
805
- /* @__PURE__ */ jsx(
806
- Table,
807
- {
808
- columns,
809
- data,
810
- rowConfig: {
811
- getRowKey: (row, index) => `${row.campaign_id}-${row.reward_time}-${index}`
812
- },
813
- loading: loading && data.length > 0,
814
- loadingText: messages.loading,
815
- empty: {
816
- title: messages.no_data
817
- }
818
- }
819
- ),
820
- pagination.totalPages > 1 && /* @__PURE__ */ jsx(
821
- Pagination,
822
- {
823
- page: pagination.page,
824
- totalPages: pagination.totalPages,
825
- onPrevious: pagination.goToPrevious,
826
- onNext: pagination.goToNext,
827
- hasPrevious: pagination.hasPrevious,
828
- hasNext: pagination.hasNext
829
- }
830
- )
831
- ] });
832
- }
833
- function useActivityHistory(options = {}) {
834
- const {
835
- pageSize = USER_CENTER_PAGE_SIZE,
836
- mode = "pagination",
837
- autoLoad = true
838
- } = options;
839
- const { client } = useTaskOnContext();
840
- const [data, setData] = useState([]);
841
- const [total, setTotal] = useState(0);
842
- const [loading, setLoading] = useState(false);
843
- const [error, setError] = useState(null);
844
- const isInitialLoad = useRef(true);
845
- const lastFetchedPage = useRef(null);
846
- const api = useMemo(() => {
847
- if (!client) return null;
848
- return createUserCenterApi(client);
849
- }, [client]);
850
- const pagination = usePagination({
851
- total,
852
- pageSize,
853
- initialPage: 0,
854
- // 使用 0-based 索引
855
- mode
856
- });
857
- const fetchData = useCallback(
858
- async (pageNo, append = false) => {
859
- if (!api) {
860
- setError(new Error("TaskOn client not initialized"));
861
- return;
862
- }
863
- if (lastFetchedPage.current === pageNo && !append) {
864
- return;
865
- }
866
- setLoading(true);
867
- setError(null);
868
- lastFetchedPage.current = pageNo;
869
- try {
870
- const response = await api.getMyCampaignHistory({
871
- page: {
872
- page_no: pageNo,
873
- // API 使用 0-based 索引
874
- size: pageSize
875
- }
876
- });
877
- if (append) {
878
- setData((prev) => [...prev, ...response.data]);
879
- } else {
880
- setData(response.data);
881
- }
882
- setTotal(response.total);
883
- } catch (err) {
884
- setError(
885
- err instanceof Error ? err : new Error("Failed to fetch activity history")
886
- );
887
- } finally {
888
- setLoading(false);
889
- }
890
- },
891
- [api, pageSize]
892
- );
893
- const refresh = useCallback(async () => {
894
- pagination.goToPage(0);
895
- setData([]);
896
- lastFetchedPage.current = null;
897
- await fetchData(0, false);
898
- }, [fetchData, pagination]);
899
- useEffect(() => {
900
- if (autoLoad && isInitialLoad.current) {
901
- isInitialLoad.current = false;
902
- fetchData(0, false);
903
- }
904
- }, [autoLoad, fetchData]);
905
- useEffect(() => {
906
- if (isInitialLoad.current) {
907
- return;
908
- }
909
- if (mode === "pagination") {
910
- fetchData(pagination.page, false);
911
- }
912
- }, [mode, pagination.page, fetchData]);
913
- useEffect(() => {
914
- if (mode === "infinite" && pagination.loadedCount > pageSize) {
915
- const nextPage = Math.ceil(pagination.loadedCount / pageSize) - 1;
916
- fetchData(nextPage, true);
917
- }
918
- }, [mode, pagination.loadedCount, pageSize, fetchData]);
919
- return {
920
- data,
921
- loading,
922
- error,
923
- total,
924
- pagination,
925
- refresh
926
- };
927
- }
928
- function useUserRewards(options = {}) {
929
- const { autoLoad = true } = options;
930
- const { client } = useTaskOnContext();
931
- const [rewards, setRewards] = useState(null);
932
- const [userInfo, setUserInfo] = useState(null);
933
- const [selectedCard, setSelectedCard] = useState(null);
934
- const [loading, setLoading] = useState(false);
935
- const [error, setError] = useState(null);
936
- const api = useMemo(() => {
937
- if (!client) return null;
938
- return createUserCenterApi(client);
939
- }, [client]);
940
- const cards = useMemo(() => {
941
- if (!rewards) return [];
942
- return buildRewardCards(rewards, userInfo);
943
- }, [rewards, userInfo]);
944
- const fetchData = useCallback(async () => {
945
- if (!api) {
946
- setError(new Error("TaskOn client not initialized"));
947
- return;
948
- }
949
- setLoading(true);
950
- setError(null);
951
- try {
952
- const [rewardsResponse, userInfoResponse] = await Promise.all([
953
- api.getMyCommunityRewards({}),
954
- api.getCUserInfo({})
955
- ]);
956
- setRewards(rewardsResponse);
957
- setUserInfo(userInfoResponse);
958
- const builtCards = buildRewardCards(rewardsResponse, userInfoResponse);
959
- const firstVisibleCard = builtCards.find((c) => c.visible);
960
- if (firstVisibleCard && !selectedCard) {
961
- setSelectedCard(firstVisibleCard.type);
962
- }
963
- } catch (err) {
964
- setError(
965
- err instanceof Error ? err : new Error("Failed to fetch rewards")
966
- );
967
- } finally {
968
- setLoading(false);
969
- }
970
- }, [api, selectedCard]);
971
- const selectCard = useCallback((type) => {
972
- setSelectedCard(type);
973
- }, []);
974
- const refresh = useCallback(async () => {
975
- await fetchData();
976
- }, [fetchData]);
977
- useEffect(() => {
978
- if (autoLoad) {
979
- fetchData();
980
- }
981
- }, [autoLoad, fetchData]);
982
- return {
983
- rewards,
984
- userInfo,
985
- cards,
986
- selectedCard,
987
- selectCard,
988
- loading,
989
- error,
990
- refresh
991
- };
992
- }
993
- function useFrozenAssets(options) {
994
- const { tokenId, pageSize = USER_CENTER_PAGE_SIZE, autoLoad = true } = options;
995
- const { client } = useTaskOnContext();
996
- const [data, setData] = useState([]);
997
- const [total, setTotal] = useState(0);
998
- const [loading, setLoading] = useState(false);
999
- const [error, setError] = useState(null);
1000
- const api = useMemo(() => {
1001
- if (!client) return null;
1002
- return createUserCenterApi(client);
1003
- }, [client]);
1004
- const pagination = usePagination({
1005
- total,
1006
- pageSize,
1007
- initialPage: 0,
1008
- mode: "pagination"
1009
- });
1010
- const skipNextPageEffectRef = useRef(false);
1011
- const fetchData = useCallback(
1012
- async (pageNo) => {
1013
- if (!api) {
1014
- setError(new Error("TaskOn client not initialized"));
1015
- return;
1016
- }
1017
- if (!tokenId) {
1018
- setError(new Error("Token ID is required"));
1019
- return;
1020
- }
1021
- setLoading(true);
1022
- setError(null);
1023
- try {
1024
- const response = await api.getLockedTokenList({
1025
- token_id: tokenId,
1026
- page: {
1027
- page_no: pageNo,
1028
- // API 使用 0-based 索引
1029
- size: pageSize
1030
- }
1031
- });
1032
- setData(response.data);
1033
- setTotal(response.total);
1034
- } catch (err) {
1035
- setError(
1036
- err instanceof Error ? err : new Error("Failed to fetch frozen assets")
1037
- );
1038
- } finally {
1039
- setLoading(false);
1040
- }
1041
- },
1042
- [api, tokenId, pageSize]
1043
- );
1044
- const refresh = useCallback(async () => {
1045
- if (autoLoad && pagination.page !== 0) {
1046
- skipNextPageEffectRef.current = true;
1047
- }
1048
- pagination.goToPage(0);
1049
- await fetchData(0);
1050
- }, [autoLoad, fetchData, pagination]);
1051
- const canResend = useCallback((item) => {
1052
- return item.type === "Withdraw" && Boolean(item.nonce) && Boolean(item.receiver_address);
1053
- }, []);
1054
- useEffect(() => {
1055
- if (!autoLoad || !tokenId) {
1056
- return;
1057
- }
1058
- if (skipNextPageEffectRef.current) {
1059
- skipNextPageEffectRef.current = false;
1060
- return;
1061
- }
1062
- fetchData(pagination.page);
1063
- }, [autoLoad, tokenId, pagination.page, fetchData]);
1064
- return {
1065
- data,
1066
- loading,
1067
- error,
1068
- total,
1069
- pagination,
1070
- refresh,
1071
- canResend
1072
- };
1073
- }
1074
- const SNS_TYPE_MAP = {
1075
- Twitter: "Twitter",
1076
- Discord: "Discord",
1077
- Telegram: "Telegram",
1078
- Email: "Email",
1079
- Reddit: "Reddit"
1080
- };
1081
- const CHAIN_TYPE_MAP = {
1082
- evm: "evm",
1083
- solana: "solana",
1084
- sui: "sui",
1085
- aptos: "aptos",
1086
- btc: "btc",
1087
- starknet: "starknet",
1088
- tron: "tron",
1089
- ton: "ton",
1090
- nibiru: "nibiru",
1091
- kaspa: "kaspa"
1092
- };
1093
- const ALL_SOCIAL_TYPES = [
1094
- SnsType.Twitter,
1095
- SnsType.Discord,
1096
- SnsType.Telegram,
1097
- SnsType.Email,
1098
- SnsType.Reddit
1099
- ];
1100
- const ALL_CHAIN_TYPES = [
1101
- "evm",
1102
- "solana",
1103
- "sui",
1104
- "aptos",
1105
- "btc",
1106
- "starknet",
1107
- "tron",
1108
- "ton",
1109
- "nibiru",
1110
- "kaspa"
1111
- ];
1112
- function getSocialProfileUrl(snsType, username) {
1113
- switch (snsType) {
1114
- case SnsType.Twitter:
1115
- return `https://twitter.com/${username}`;
1116
- case SnsType.Discord:
1117
- return null;
1118
- case SnsType.Telegram:
1119
- return `https://t.me/${username}`;
1120
- case SnsType.Reddit:
1121
- return `https://reddit.com/user/${username}`;
1122
- case SnsType.Email:
1123
- return null;
1124
- default:
1125
- return null;
1126
- }
1127
- }
1128
- function useIdentityData() {
1129
- const { userInfo } = useTaskOnContext();
1130
- const rawSns = (userInfo == null ? void 0 : userInfo.sns) ?? [];
1131
- const rawAddresses = (userInfo == null ? void 0 : userInfo.address) ?? [];
1132
- const isLoaded = userInfo !== null;
1133
- const socialAccounts = useMemo(() => {
1134
- return ALL_SOCIAL_TYPES.map((snsType) => {
1135
- const boundAccount = rawSns.find((s) => s.sns_type === snsType);
1136
- const accountType = SNS_TYPE_MAP[snsType];
1137
- return {
1138
- accountType: accountType ?? snsType,
1139
- snsType,
1140
- isBound: !!boundAccount,
1141
- account: boundAccount ?? null,
1142
- profileUrl: boundAccount ? getSocialProfileUrl(snsType, boundAccount.sns_user_name) : null
1143
- };
1144
- });
1145
- }, [rawSns]);
1146
- const walletAddresses = useMemo(() => {
1147
- return ALL_CHAIN_TYPES.map((chainType) => {
1148
- const boundAddress = rawAddresses.find((a) => a.chain_type === chainType);
1149
- const widgetChainType = CHAIN_TYPE_MAP[chainType];
1150
- return {
1151
- chainType: widgetChainType ?? chainType,
1152
- coreChainType: chainType,
1153
- isBound: !!boundAddress,
1154
- address: boundAddress ?? null,
1155
- isPrimary: (boundAddress == null ? void 0 : boundAddress.is_primary) ?? false,
1156
- // 暂时没有 KYC 信息,后续可扩展
1157
- isKycVerified: void 0
1158
- };
1159
- });
1160
- }, [rawAddresses]);
1161
- const totalBoundCount = useMemo(() => {
1162
- const boundSocialCount = socialAccounts.filter((a) => a.isBound).length;
1163
- const boundWalletCount = walletAddresses.filter((a) => a.isBound).length;
1164
- return boundSocialCount + boundWalletCount;
1165
- }, [socialAccounts, walletAddresses]);
1166
- return {
1167
- socialAccounts,
1168
- walletAddresses,
1169
- rawSns,
1170
- rawAddresses,
1171
- isLoaded,
1172
- totalBoundCount
1173
- };
1174
- }
1175
- function useUnbindSocial(options = {}) {
1176
- const { onUnbindSuccess, onUnbindError } = options;
1177
- const { client, refreshUserInfo } = useTaskOnContext();
1178
- const [unbindStatus, setUnbindStatus] = useState("idle");
1179
- const [error, setError] = useState(null);
1180
- const [processingType, setProcessingType] = useState(null);
1181
- const api = useMemo(() => {
1182
- if (!client) return null;
1183
- return createUserApi(client);
1184
- }, [client]);
1185
- const unbind = useCallback(
1186
- async (snsId, type) => {
1187
- if (!api) {
1188
- const err = new Error("TaskOn client not initialized");
1189
- setError(err);
1190
- onUnbindError == null ? void 0 : onUnbindError(err);
1191
- return false;
1192
- }
1193
- setProcessingType(type);
1194
- setUnbindStatus("loading");
1195
- setError(null);
1196
- try {
1197
- const result = await api.unbindSNS({
1198
- sns_id: snsId,
1199
- sns_type: type
1200
- });
1201
- if (result) {
1202
- await refreshUserInfo();
1203
- setUnbindStatus("success");
1204
- onUnbindSuccess == null ? void 0 : onUnbindSuccess();
1205
- return true;
1206
- } else {
1207
- const err = new Error("Unbind failed");
1208
- setUnbindStatus("error");
1209
- setError(err);
1210
- onUnbindError == null ? void 0 : onUnbindError(err);
1211
- return false;
1212
- }
1213
- } catch (err) {
1214
- const error2 = err instanceof Error ? err : new Error("Unbind failed");
1215
- setUnbindStatus("error");
1216
- setError(error2);
1217
- onUnbindError == null ? void 0 : onUnbindError(error2);
1218
- return false;
1219
- } finally {
1220
- setProcessingType(null);
1221
- }
1222
- },
1223
- [api, refreshUserInfo, onUnbindSuccess, onUnbindError]
1224
- );
1225
- const reset = useCallback(() => {
1226
- setUnbindStatus("idle");
1227
- setError(null);
1228
- setProcessingType(null);
1229
- }, []);
1230
- return {
1231
- unbindStatus,
1232
- error,
1233
- processingType,
1234
- unbind,
1235
- reset
1236
- };
1237
- }
1238
- const COUNTDOWN_SECONDS = 60;
1239
- const EMAIL_REGEX$1 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1240
- const SNS_BIND_DUPLICATE_ERROR = 10016;
1241
- const INVALID_EMAIL_VERIFY_CODE = 10017;
1242
- function useBindEmail(options = {}) {
1243
- const { onSendCodeSuccess, onSendCodeError, onBindSuccess, onBindError } = options;
1244
- const { client, refreshUserInfo } = useTaskOnContext();
1245
- const [status, setStatus] = useState("idle");
1246
- const [countdown, setCountdown] = useState(0);
1247
- const [error, setError] = useState(null);
1248
- const [isEmailDuplicate, setIsEmailDuplicate] = useState(false);
1249
- const [isCodeInvalid, setIsCodeInvalid] = useState(false);
1250
- const [email, setEmail] = useState("");
1251
- const countdownTimerRef = useRef(null);
1252
- const api = useMemo(() => {
1253
- if (!client) return null;
1254
- return createUserApi(client);
1255
- }, [client]);
1256
- const startCountdown = useCallback(() => {
1257
- setCountdown(COUNTDOWN_SECONDS);
1258
- countdownTimerRef.current = setInterval(() => {
1259
- setCountdown((prev) => {
1260
- if (prev <= 1) {
1261
- if (countdownTimerRef.current) {
1262
- clearInterval(countdownTimerRef.current);
1263
- countdownTimerRef.current = null;
1264
- }
1265
- return 0;
1266
- }
1267
- return prev - 1;
1268
- });
1269
- }, 1e3);
1270
- }, []);
1271
- const stopCountdown = useCallback(() => {
1272
- if (countdownTimerRef.current) {
1273
- clearInterval(countdownTimerRef.current);
1274
- countdownTimerRef.current = null;
1275
- }
1276
- setCountdown(0);
1277
- }, []);
1278
- useEffect(() => {
1279
- return () => {
1280
- if (countdownTimerRef.current) {
1281
- clearInterval(countdownTimerRef.current);
1282
- }
1283
- };
1284
- }, []);
1285
- const open = useCallback(() => {
1286
- setStatus("inputEmail");
1287
- setError(null);
1288
- setIsEmailDuplicate(false);
1289
- setIsCodeInvalid(false);
1290
- }, []);
1291
- const close = useCallback(() => {
1292
- setStatus("idle");
1293
- setError(null);
1294
- setIsEmailDuplicate(false);
1295
- setIsCodeInvalid(false);
1296
- setEmail("");
1297
- stopCountdown();
1298
- }, [stopCountdown]);
1299
- const clearError = useCallback(() => {
1300
- setError(null);
1301
- setIsEmailDuplicate(false);
1302
- setIsCodeInvalid(false);
1303
- }, []);
1304
- const sendCode = useCallback(
1305
- async (emailAddress) => {
1306
- if (!api) {
1307
- const err = new Error("TaskOn client not initialized");
1308
- setError(err);
1309
- onSendCodeError == null ? void 0 : onSendCodeError(err);
1310
- return false;
1311
- }
1312
- if (!EMAIL_REGEX$1.test(emailAddress)) {
1313
- const err = new Error("Invalid email format");
1314
- setError(err);
1315
- onSendCodeError == null ? void 0 : onSendCodeError(err);
1316
- return false;
1317
- }
1318
- setStatus("sendingCode");
1319
- setError(null);
1320
- setIsEmailDuplicate(false);
1321
- try {
1322
- const result = await api.requestEmailVerifyCode({
1323
- email: emailAddress,
1324
- type: VerifyCodeType.Bind
1325
- });
1326
- if (result) {
1327
- setStatus("inputCode");
1328
- setEmail(emailAddress);
1329
- startCountdown();
1330
- onSendCodeSuccess == null ? void 0 : onSendCodeSuccess();
1331
- return true;
1332
- } else {
1333
- const err = new Error("Failed to send verification code");
1334
- setStatus("inputEmail");
1335
- setError(err);
1336
- onSendCodeError == null ? void 0 : onSendCodeError(err);
1337
- return false;
1338
- }
1339
- } catch (err) {
1340
- const error2 = err;
1341
- if (error2.code === SNS_BIND_DUPLICATE_ERROR) {
1342
- setIsEmailDuplicate(true);
1343
- }
1344
- setStatus("inputEmail");
1345
- setError(error2);
1346
- onSendCodeError == null ? void 0 : onSendCodeError(error2);
1347
- return false;
1348
- }
1349
- },
1350
- [api, onSendCodeSuccess, onSendCodeError, startCountdown]
1351
- );
1352
- const bind = useCallback(
1353
- async (emailAddress, code) => {
1354
- if (!api) {
1355
- const err = new Error("TaskOn client not initialized");
1356
- setError(err);
1357
- onBindError == null ? void 0 : onBindError(err);
1358
- return null;
1359
- }
1360
- setStatus("submitting");
1361
- setError(null);
1362
- setIsCodeInvalid(false);
1363
- try {
1364
- const result = await api.bindSNS({
1365
- sns_type: SnsType.Email,
1366
- token: code,
1367
- sns_user_name: emailAddress
1368
- });
1369
- if (result.result) {
1370
- await refreshUserInfo();
1371
- setStatus("success");
1372
- onBindSuccess == null ? void 0 : onBindSuccess(result);
1373
- return result;
1374
- } else {
1375
- const err = new Error("Email is already linked to another account");
1376
- setStatus("inputCode");
1377
- setError(err);
1378
- onBindError == null ? void 0 : onBindError(err);
1379
- return null;
1380
- }
1381
- } catch (err) {
1382
- const error2 = err;
1383
- if (error2.code === INVALID_EMAIL_VERIFY_CODE) {
1384
- setIsCodeInvalid(true);
1385
- }
1386
- setStatus("inputCode");
1387
- setError(error2);
1388
- onBindError == null ? void 0 : onBindError(error2);
1389
- return null;
1390
- }
1391
- },
1392
- [api, refreshUserInfo, onBindSuccess, onBindError]
1393
- );
1394
- const reset = useCallback(() => {
1395
- setStatus("idle");
1396
- setError(null);
1397
- setIsEmailDuplicate(false);
1398
- setIsCodeInvalid(false);
1399
- setEmail("");
1400
- stopCountdown();
1401
- }, [stopCountdown]);
1402
- return {
1403
- status,
1404
- countdown,
1405
- error,
1406
- isEmailDuplicate,
1407
- isCodeInvalid,
1408
- email,
1409
- open,
1410
- close,
1411
- setEmail,
1412
- sendCode,
1413
- bind,
1414
- reset,
1415
- clearError
1416
- };
1417
- }
1418
- function generateSignMessage(action, address, nonce) {
1419
- return `TaskOn ${action} wallet
1420
- Address: ${address}
1421
- Nonce: ${nonce}`;
1422
- }
1423
- function generateNonce() {
1424
- return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
1425
- }
1426
- function useBindWallet(options = {}) {
1427
- const {
1428
- onBindSuccess,
1429
- onBindError,
1430
- onUnbindSuccess,
1431
- onUnbindError
1432
- } = options;
1433
- const { client, refreshUserInfo } = useTaskOnContext();
1434
- const {
1435
- connectEvm,
1436
- signEvmMessage,
1437
- evmAddress: connectedAddress,
1438
- isEvmConnected: isConnected
1439
- } = useWallet();
1440
- const [bindStatus, setBindStatus] = useState("idle");
1441
- const [unbindStatus, setUnbindStatus] = useState("idle");
1442
- const [error, setError] = useState(null);
1443
- const [processingChain, setProcessingChain] = useState(null);
1444
- const api = useMemo(() => {
1445
- if (!client) return null;
1446
- return createUserApi(client);
1447
- }, [client]);
1448
- const bind = useCallback(
1449
- async (chainType) => {
1450
- if (!api) {
1451
- const err = new Error("TaskOn client not initialized");
1452
- setError(err);
1453
- onBindError == null ? void 0 : onBindError(err);
1454
- return false;
1455
- }
1456
- setProcessingChain(chainType);
1457
- setBindStatus("connecting");
1458
- setError(null);
1459
- try {
1460
- let walletAddress = connectedAddress;
1461
- if (!isConnected || !walletAddress) {
1462
- setBindStatus("connecting");
1463
- const connectResult = await connectEvm();
1464
- if (!connectResult) {
1465
- throw new Error("Failed to connect wallet");
1466
- }
1467
- walletAddress = connectResult;
1468
- }
1469
- if (!walletAddress) {
1470
- throw new Error("No wallet address available");
1471
- }
1472
- const nonce = generateNonce();
1473
- const message = generateSignMessage("bind", walletAddress, nonce);
1474
- setBindStatus("signing");
1475
- const signature = await signEvmMessage(message);
1476
- if (!signature) {
1477
- throw new Error("Failed to sign message");
1478
- }
1479
- setBindStatus("submitting");
1480
- const result = await api.bindAddress({
1481
- chain_type: chainType,
1482
- address: walletAddress,
1483
- nonce,
1484
- sig: signature
1485
- });
1486
- if (result) {
1487
- await refreshUserInfo();
1488
- setBindStatus("success");
1489
- onBindSuccess == null ? void 0 : onBindSuccess();
1490
- return true;
1491
- } else {
1492
- throw new Error("Bind wallet failed");
1493
- }
1494
- } catch (err) {
1495
- const error2 = err instanceof Error ? err : new Error("Bind wallet failed");
1496
- setBindStatus("error");
1497
- setError(error2);
1498
- onBindError == null ? void 0 : onBindError(error2);
1499
- return false;
1500
- } finally {
1501
- setProcessingChain(null);
1502
- }
1503
- },
1504
- [
1505
- api,
1506
- refreshUserInfo,
1507
- connectEvm,
1508
- signEvmMessage,
1509
- connectedAddress,
1510
- isConnected,
1511
- onBindSuccess,
1512
- onBindError
1513
- ]
1514
- );
1515
- const unbind = useCallback(
1516
- async (chainType, address) => {
1517
- if (!api) {
1518
- const err = new Error("TaskOn client not initialized");
1519
- setError(err);
1520
- onUnbindError == null ? void 0 : onUnbindError(err);
1521
- return false;
1522
- }
1523
- setProcessingChain(chainType);
1524
- setUnbindStatus("connecting");
1525
- setError(null);
1526
- try {
1527
- let walletAddress = connectedAddress;
1528
- if (!isConnected || !walletAddress) {
1529
- setUnbindStatus("connecting");
1530
- const connectResult = await connectEvm();
1531
- if (!connectResult) {
1532
- throw new Error("Failed to connect wallet");
1533
- }
1534
- walletAddress = connectResult;
1535
- }
1536
- if ((walletAddress == null ? void 0 : walletAddress.toLowerCase()) !== address.toLowerCase()) {
1537
- throw new Error(
1538
- "Connected wallet address does not match the address to unbind. Please connect the correct wallet."
1539
- );
1540
- }
1541
- const nonce = generateNonce();
1542
- const message = generateSignMessage("unbind", address, nonce);
1543
- setUnbindStatus("signing");
1544
- const signature = await signEvmMessage(message);
1545
- if (!signature) {
1546
- throw new Error("Failed to sign message");
1547
- }
1548
- setUnbindStatus("submitting");
1549
- const result = await api.unbindAddress({
1550
- chain_type: chainType,
1551
- address,
1552
- nonce,
1553
- sig: signature
1554
- });
1555
- if (result) {
1556
- await refreshUserInfo();
1557
- setUnbindStatus("success");
1558
- onUnbindSuccess == null ? void 0 : onUnbindSuccess();
1559
- return true;
1560
- } else {
1561
- throw new Error("Unbind wallet failed");
1562
- }
1563
- } catch (err) {
1564
- const error2 = err instanceof Error ? err : new Error("Unbind wallet failed");
1565
- setUnbindStatus("error");
1566
- setError(error2);
1567
- onUnbindError == null ? void 0 : onUnbindError(error2);
1568
- return false;
1569
- } finally {
1570
- setProcessingChain(null);
1571
- }
1572
- },
1573
- [
1574
- api,
1575
- refreshUserInfo,
1576
- connectEvm,
1577
- signEvmMessage,
1578
- connectedAddress,
1579
- isConnected,
1580
- onUnbindSuccess,
1581
- onUnbindError
1582
- ]
1583
- );
1584
- const reset = useCallback(() => {
1585
- setBindStatus("idle");
1586
- setUnbindStatus("idle");
1587
- setError(null);
1588
- setProcessingChain(null);
1589
- }, []);
1590
- return {
1591
- bindStatus,
1592
- unbindStatus,
1593
- error,
1594
- processingChain,
1595
- bind,
1596
- unbind,
1597
- reset
1598
- };
1599
- }
1600
- const OAUTH_SNS_TYPES = ["Twitter", "Discord", "Telegram"];
1601
- function useOAuthBindings(options = {}) {
1602
- const { onSuccess, onFailed } = options;
1603
- const {
1604
- bindIfNeed: bindTwitter,
1605
- isWaitingAuth: isTwitterBinding
1606
- } = useBindSocialAccount({
1607
- snsType: "Twitter",
1608
- onSuccess,
1609
- onFailed
1610
- });
1611
- const {
1612
- bindIfNeed: bindDiscord,
1613
- isWaitingAuth: isDiscordBinding
1614
- } = useBindSocialAccount({
1615
- snsType: "Discord",
1616
- onSuccess,
1617
- onFailed
1618
- });
1619
- const {
1620
- bindIfNeed: bindTelegram,
1621
- isWaitingAuth: isTelegramBinding
1622
- } = useBindSocialAccount({
1623
- snsType: "Telegram",
1624
- onSuccess,
1625
- onFailed
1626
- });
1627
- const bind = useCallback(
1628
- (snsType) => {
1629
- switch (snsType) {
1630
- case "Twitter":
1631
- bindTwitter();
1632
- break;
1633
- case "Discord":
1634
- bindDiscord();
1635
- break;
1636
- case "Telegram":
1637
- bindTelegram();
1638
- break;
1639
- default:
1640
- console.warn(`[useOAuthBindings] Unsupported snsType: ${snsType}`);
1641
- }
1642
- },
1643
- [bindTwitter, bindDiscord, bindTelegram]
1644
- );
1645
- const isBinding = useCallback(
1646
- (snsType) => {
1647
- switch (snsType.toLowerCase()) {
1648
- case "twitter":
1649
- return isTwitterBinding;
1650
- case "discord":
1651
- return isDiscordBinding;
1652
- case "telegram":
1653
- return isTelegramBinding;
1654
- default:
1655
- return false;
1656
- }
1657
- },
1658
- [isTwitterBinding, isDiscordBinding, isTelegramBinding]
1659
- );
1660
- const isOAuthSupported = useCallback((snsType) => {
1661
- return OAUTH_SNS_TYPES.includes(snsType);
1662
- }, []);
1663
- return {
1664
- bind,
1665
- isBinding,
1666
- isOAuthSupported
1667
- };
1668
- }
1669
- const UNBIND_COOLDOWN_MS = 24 * 60 * 60 * 1e3;
1670
- const MIN_LOGIN_METHODS = 1;
1671
- function isInCooldown(bindTime) {
1672
- const now = Date.now();
1673
- return now - bindTime < UNBIND_COOLDOWN_MS;
1674
- }
1675
- function getCooldownRemaining(bindTime) {
1676
- const now = Date.now();
1677
- const elapsed = now - bindTime;
1678
- const remaining = UNBIND_COOLDOWN_MS - elapsed;
1679
- return Math.max(0, remaining);
1680
- }
1681
- function formatCooldownTime(ms) {
1682
- const hours = Math.ceil(ms / (60 * 60 * 1e3));
1683
- if (hours <= 1) {
1684
- return "less than 1 hour";
1685
- }
1686
- return `${hours} hours`;
1687
- }
1688
- function useDisableUnlink() {
1689
- const { totalBoundCount } = useIdentityData();
1690
- const isLastLoginMethod = totalBoundCount <= MIN_LOGIN_METHODS;
1691
- const checkSocialUnlink = useMemo(() => {
1692
- return (account) => {
1693
- if (isLastLoginMethod) {
1694
- return {
1695
- disabled: true,
1696
- reason: "lastLoginMethod",
1697
- message: "Cannot unbind the last login method. You must keep at least one login method.",
1698
- cooldownRemaining: null,
1699
- needsKycWarning: false
1700
- };
1701
- }
1702
- const bindTimeMs = account.bind_time;
1703
- if (isInCooldown(bindTimeMs)) {
1704
- const remaining = getCooldownRemaining(bindTimeMs);
1705
- return {
1706
- disabled: true,
1707
- reason: "cooldown",
1708
- message: `Cannot unbind within 24 hours of binding. Please wait ${formatCooldownTime(remaining)}.`,
1709
- cooldownRemaining: remaining,
1710
- needsKycWarning: false
1711
- };
1712
- }
1713
- return {
1714
- disabled: false,
1715
- reason: null,
1716
- message: null,
1717
- cooldownRemaining: null,
1718
- needsKycWarning: false
1719
- };
1720
- };
1721
- }, [isLastLoginMethod]);
1722
- const checkWalletUnlink = useMemo(() => {
1723
- return (address, isKycVerified = false) => {
1724
- if (isLastLoginMethod) {
1725
- return {
1726
- disabled: true,
1727
- reason: "lastLoginMethod",
1728
- message: "Cannot unbind the last login method. You must keep at least one login method.",
1729
- cooldownRemaining: null,
1730
- needsKycWarning: false
1731
- };
1732
- }
1733
- const bindTimeMs = address.bind_time;
1734
- if (isInCooldown(bindTimeMs)) {
1735
- const remaining = getCooldownRemaining(bindTimeMs);
1736
- return {
1737
- disabled: true,
1738
- reason: "cooldown",
1739
- message: `Cannot unbind within 24 hours of binding. Please wait ${formatCooldownTime(remaining)}.`,
1740
- cooldownRemaining: remaining,
1741
- needsKycWarning: isKycVerified
1742
- };
1743
- }
1744
- if (isKycVerified) {
1745
- return {
1746
- disabled: false,
1747
- reason: "kycVerified",
1748
- message: "This address has been KYC verified. Unbinding will clear your KYC verification status.",
1749
- cooldownRemaining: null,
1750
- needsKycWarning: true
1751
- };
1752
- }
1753
- return {
1754
- disabled: false,
1755
- reason: null,
1756
- message: null,
1757
- cooldownRemaining: null,
1758
- needsKycWarning: false
1759
- };
1760
- };
1761
- }, [isLastLoginMethod]);
1762
- return {
1763
- checkSocialUnlink,
1764
- checkWalletUnlink,
1765
- totalBoundCount,
1766
- isLastLoginMethod
1767
- };
1768
- }
1769
- const twitterIcon = new URL("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAH3SURBVHgBzZeNkYIwEIXjVYAdcB1QAtcBVqBWcFoBdgBWgB1YAtcBJUAHlrCXxxEnEzaQIMi9mR0zIT+fSd4GhDBERLGMTEZN86uSUcgIhU3yYdABvEuYK+AgKnq/KgXz0bGkMiLxfkXd3GJDf/tVi3X1hRVJzdrz+Sw2mw0b2+1WNE0jXHU8Htt+u91uqFkiiDkbj8eDoigi2YCCIKAwDNtAGXVxHDsdgMvl0rZHX4w5oFrYnlRV9ZwYZQWIQVGX5zkNCc8VRF3XNCYx9DDLst4/0gHLsmT7oV6tpgvEKAiEbcCgp9NpEFAJEyvQ+/1OrhoFsQ3MAaKt2ro0TclHoyAQAMylNgH18+ML4QwC4Z+bjtEBkyRpy/idImcQm2MUoKNNXweBdDdwlkbemCovEEg5BglPt7QJuDgI5GvpxUDUFplJjQNcDEQ/E+YK6Ja2Zd3ZQHSb7vf7nmWLopi0RV4g5m1qszQHOBuIDqFfZNwF53NLe4FwKV6XSmqw9BDgSyCut6l6kdIdwwFOAvG5TW2O4QC9QKbcplxSc7W0FWTqbaqSGveuO2RpgNRmpcdLb09orybm4nA4cN0qfNfkssG3WFc3gMSyUIp19fkhP35+ZOEq1tNVMjRtif7BR/hTHYxbPp5HeQ/CAApl3GiZFao7gNic9xdG16HkLDPmwQAAAABJRU5ErkJggg==", import.meta.url).href;
1770
- const discordIcon = new URL("data:image/svg+xml,%3csvg%20width='24'%20height='25'%20viewBox='0%200%2024%2025'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20y='0.187012'%20width='24'%20height='24.2243'%20rx='8'%20fill='%237870FF'/%3e%3cpath%20d='M18.7627%206.96988C16.7288%205.45184%2014.7966%205.34341%2014.4915%205.34341L14.2881%205.56027C16.6271%206.21086%2017.9492%207.4036%2018.0508%207.51203C14.3898%205.56027%2010.322%205.45184%206.66102%206.96988C6.15254%207.18674%205.84746%207.4036%205.74576%207.4036C5.94915%207.29517%207.16949%206.10243%209.71186%205.45184L9.50847%205.23498C9.50847%205.23498%207.47458%205.12655%205.23729%206.86145C5.23729%206.86145%203%2010.8734%203%2015.9697C3%2015.9697%204.32203%2018.2467%207.67797%2018.3551C7.67797%2018.3551%208.18644%2017.7046%208.69492%2017.054C6.9661%2016.5118%206.15254%2015.3191%206.05085%2015.2106L6.66102%2015.5359C8.49153%2016.2949%2010.4237%2017.3793%2013.9831%2016.7287C14.6949%2016.6202%2015.5085%2016.4034%2016.2203%2016.0781C16.7288%2015.7528%2017.339%2015.5359%2017.9492%2015.1022C17.8475%2015.2106%2017.0339%2016.4034%2015.2034%2016.9455C15.6102%2017.5961%2016.2203%2018.2467%2016.2203%2018.2467C19.678%2018.1383%2021%2015.8612%2021%2016.0781C21%2011.0903%2018.7627%206.96988%2018.7627%206.96988ZM9.20339%2014.3432C8.38983%2014.3432%207.67797%2013.5842%207.67797%2012.6083C7.67797%2011.6324%208.38983%2010.8734%209.20339%2010.8734C10.0169%2010.8734%2010.7288%2011.7408%2010.7288%2012.6083C10.7288%2013.5842%2010.0169%2014.3432%209.20339%2014.3432ZM14.7966%2014.3432C13.9831%2014.3432%2013.2712%2013.5842%2013.2712%2012.6083C13.2712%2011.6324%2013.9831%2010.8734%2014.7966%2010.8734C15.7119%2010.8734%2016.4237%2011.7408%2016.4237%2012.6083C16.4237%2013.5842%2015.7119%2014.3432%2014.7966%2014.3432Z'%20fill='white'/%3e%3c/svg%3e", import.meta.url).href;
1771
- const telegramIcon = new URL("data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%3e%3crect%20y='0.000396729'%20width='24'%20height='24'%20rx='8'%20fill='%2354AEFF'/%3e%3cpath%20d='M18.9513%206.24633L16.5438%2017.617C16.377%2018.424%2015.8902%2018.6174%2015.21%2018.2439L11.542%2015.5296L9.76804%2017.2435C9.56797%2017.4436%209.40125%2017.617%209.03445%2017.617C8.55428%2017.617%208.63431%2017.4369%208.47425%2016.9835L7.20714%2012.8553L3.57252%2011.7216C2.78558%2011.4882%202.77891%2010.948%203.74592%2010.5545L17.9243%205.08592C18.5711%204.79915%2019.1914%205.24598%2018.9446%206.23966L18.9513%206.24633Z'%20fill='white'/%3e%3c/svg%3e", import.meta.url).href;
1772
- const redditIcon = new URL("data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cg%20id='Group%2048098228'%3e%3crect%20id='Rectangle%206202'%20y='0.000488281'%20width='24'%20height='24'%20rx='8'%20fill='%23FF4500'/%3e%3cpath%20id='Vector'%20d='M20.0319%2012.242C20.0319%2011.2761%2019.2031%2010.4913%2018.185%2010.4913C17.7441%2010.4913%2017.3313%2010.6436%2016.9987%2010.9114L16.9658%2010.9306C15.7642%2010.2012%2014.1714%209.73623%2012.4103%209.67371L13.4612%206.83847L16.0864%207.43325C16.0881%208.22042%2016.763%208.86009%2017.5934%208.86009C18.4255%208.86009%2019.102%208.21882%2019.102%207.43005C19.102%206.64128%2018.4255%206%2017.5951%206C16.9626%206%2016.4231%206.37034%2016.1995%206.89298L13.0893%206.18837L11.7987%209.6673C9.96066%209.69936%208.29575%2010.1707%207.05007%2010.9242C6.71195%2010.6442%206.28667%2010.4911%205.84768%2010.4913C4.82725%2010.4905%204%2011.2761%204%2012.2412C4%2012.8384%204.32465%2013.3899%204.8521%2013.7113C4.82003%2013.8853%204.79919%2014.0616%204.79919%2014.2412C4.79919%2016.7694%208.03042%2018.8255%2012.0015%2018.8255C15.9734%2018.8255%2019.2055%2016.7694%2019.2055%2014.242C19.2055%2014.0681%2019.187%2013.8965%2019.1566%2013.7274C19.6968%2013.4083%2020.0319%2012.8488%2020.0319%2012.242ZM14.4512%2014.5089C13.8243%2014.5089%2013.3169%2014.028%2013.3169%2013.4332C13.3169%2012.8392%2013.8243%2012.3575%2014.4512%2012.3575C15.078%2012.3575%2015.5863%2012.8384%2015.5863%2013.4332C15.5863%2014.028%2015.0772%2014.5089%2014.4512%2014.5089ZM14.6764%2016.3438C14.6428%2016.3758%2013.8292%2017.1614%2011.9887%2017.1614C10.1386%2017.1614%209.39954%2016.3662%209.36748%2016.3318C9.3428%2016.3048%209.32396%2016.273%209.31214%2016.2384C9.30032%2016.2039%209.29577%2016.1672%209.29878%2016.1308C9.30179%2016.0943%209.3123%2016.0589%209.32964%2016.0268C9.34697%2015.9946%209.37078%2015.9663%209.39954%2015.9438C9.45882%2015.8964%209.53372%2015.873%209.60941%2015.8782C9.68511%2015.8834%209.7561%2015.9168%209.80836%2015.9718C9.82439%2015.9895%2010.4416%2016.6131%2011.9887%2016.6131C13.5622%2016.6131%2014.2524%2015.9678%2014.2596%2015.9614C14.3147%2015.9094%2014.3873%2015.88%2014.4631%2015.8791C14.5388%2015.8782%2014.6122%2015.9059%2014.6684%2015.9566C14.6955%2015.9808%2014.7174%2016.0103%2014.7325%2016.0433C14.7477%2016.0763%2014.756%2016.1121%2014.7567%2016.1485C14.7575%2016.1848%2014.7507%2016.2209%2014.7369%2016.2545C14.7231%2016.2881%2014.7025%2016.3185%2014.6764%2016.3438ZM8.57871%2013.4332C8.57871%2012.8392%209.08612%2012.3575%209.71457%2012.3575C10.3398%2012.3575%2010.8488%2012.8384%2010.8488%2013.4332C10.8488%2014.028%2010.3398%2014.5089%209.71457%2014.5089C9.08692%2014.5089%208.57871%2014.028%208.57871%2013.4332Z'%20fill='white'/%3e%3c/g%3e%3c/svg%3e", import.meta.url).href;
1773
- const emailIcon = new URL("data:image/svg+xml,%3csvg%20width='24'%20height='25'%20viewBox='0%200%2024%2025'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3crect%20width='24'%20height='24.2243'%20rx='8'%20fill='%23DD9F00'/%3e%3cpath%20d='M5.14286%2015.2063L9.41607%2012L4%207.93687V16.0612L4.89286%2015.3919L5.14286%2015.2063ZM12%2012.4631L18.8571%207.32L19.8393%206.585C19.6393%206.23437%2019.275%206%2018.8571%206H5.14286C4.75893%206%204.41964%206.19875%204.2125%206.5025L5.14286%207.32L12%2012.4631ZM13.6%2012.7369L12%2013.9369L10.4%2012.7369L5.14286%2016.68L4.89286%2016.8956L4.20536%2017.4862C4.41071%2017.7975%204.75536%2018%205.14286%2018H18.8571C19.2768%2018%2019.6429%2017.7638%2019.8411%2017.4113L18.8571%2016.68L13.6%2012.7369ZM14.5821%2012L20%2016.0631V7.93687L14.5821%2012Z'%20fill='white'/%3e%3c/svg%3e", import.meta.url).href;
1774
- const SOCIAL_ICONS = {
1775
- [SnsType.Twitter]: twitterIcon,
1776
- [SnsType.Discord]: discordIcon,
1777
- [SnsType.Telegram]: telegramIcon,
1778
- [SnsType.Reddit]: redditIcon,
1779
- [SnsType.Email]: emailIcon
1780
- };
1781
- function SocialIcon({
1782
- type,
1783
- size = 24,
1784
- className = ""
1785
- }) {
1786
- const iconSrc = SOCIAL_ICONS[type];
1787
- if (iconSrc) {
1788
- return /* @__PURE__ */ jsx(
1789
- "img",
1790
- {
1791
- src: iconSrc,
1792
- alt: type,
1793
- width: size,
1794
- height: size,
1795
- className: `taskon-social-icon ${className}`,
1796
- style: { objectFit: "contain" }
1797
- }
1798
- );
1799
- }
1800
- return /* @__PURE__ */ jsx(
1801
- "svg",
1802
- {
1803
- width: size,
1804
- height: size,
1805
- viewBox: "0 0 24 24",
1806
- fill: "none",
1807
- xmlns: "http://www.w3.org/2000/svg",
1808
- className,
1809
- style: { color: "var(--taskon-color-text-secondary)" },
1810
- children: /* @__PURE__ */ jsx(
1811
- "path",
1812
- {
1813
- d: "M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1ZM8 13h8v-2H8v2Zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5Z",
1814
- fill: "currentColor"
1815
- }
1816
- )
1817
- }
1818
- );
1819
- }
1820
- function ChainIcon({ chain }) {
1821
- if (chain === "evm") {
1822
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1823
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "white" }),
1824
- /* @__PURE__ */ jsx("path", { d: "M12 4L6 12L12 9.5V4Z", fill: "#343434" }),
1825
- /* @__PURE__ */ jsx("path", { d: "M12 4L18 12L12 9.5V4Z", fill: "#8C8C8C" }),
1826
- /* @__PURE__ */ jsx("path", { d: "M12 16.5L6 12L12 14.5V16.5Z", fill: "#3C3C3B" }),
1827
- /* @__PURE__ */ jsx("path", { d: "M12 16.5L18 12L12 14.5V16.5Z", fill: "#8C8C8C" }),
1828
- /* @__PURE__ */ jsx("path", { d: "M12 17.5L6 13L12 20V17.5Z", fill: "#141414" }),
1829
- /* @__PURE__ */ jsx("path", { d: "M12 17.5L18 13L12 20V17.5Z", fill: "#393939" })
1830
- ] });
1831
- }
1832
- if (chain === "sui") {
1833
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1834
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#4DA2FF" }),
1835
- /* @__PURE__ */ jsx("path", { d: "M16.5 8.5C15.5 7.5 14 7 12.5 7.5C11 8 10 9 9.5 10.5C9 12 9 13.5 9.5 15C10 16.5 11 17.5 12.5 18C14 18.5 15.5 18 16.5 17", stroke: "white", strokeWidth: "2", strokeLinecap: "round" }),
1836
- /* @__PURE__ */ jsx("circle", { cx: "15", cy: "10", r: "1.5", fill: "white" })
1837
- ] });
1838
- }
1839
- if (chain === "solana") {
1840
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1841
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "black" }),
1842
- /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", { id: "solana-grad", x1: "4", y1: "20", x2: "20", y2: "4", children: [
1843
- /* @__PURE__ */ jsx("stop", { offset: "0%", stopColor: "#9945FF" }),
1844
- /* @__PURE__ */ jsx("stop", { offset: "50%", stopColor: "#14F195" }),
1845
- /* @__PURE__ */ jsx("stop", { offset: "100%", stopColor: "#00D1FF" })
1846
- ] }) }),
1847
- /* @__PURE__ */ jsx("path", { d: "M6 15.5L8.5 13H18L15.5 15.5H6Z", fill: "url(#solana-grad)" }),
1848
- /* @__PURE__ */ jsx("path", { d: "M6 8.5L8.5 11H18L15.5 8.5H6Z", fill: "url(#solana-grad)" }),
1849
- /* @__PURE__ */ jsx("path", { d: "M6 12L8.5 9.5H18L15.5 12H6Z", fill: "url(#solana-grad)" })
1850
- ] });
1851
- }
1852
- if (chain === "starknet") {
1853
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1854
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#EC796B" }),
1855
- /* @__PURE__ */ jsx("path", { d: "M12 6L8 10L12 8L16 10L12 6Z", fill: "white" }),
1856
- /* @__PURE__ */ jsx("path", { d: "M8 10L12 14L8 12V10Z", fill: "white", fillOpacity: "0.6" }),
1857
- /* @__PURE__ */ jsx("path", { d: "M16 10L12 14L16 12V10Z", fill: "white", fillOpacity: "0.8" }),
1858
- /* @__PURE__ */ jsx("path", { d: "M12 14L8 12L12 18L16 12L12 14Z", fill: "white" })
1859
- ] });
1860
- }
1861
- if (chain === "aptos") {
1862
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1863
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "white" }),
1864
- /* @__PURE__ */ jsx("path", { d: "M16 8H14L12 12L10 8H8L11 14H9V16H15V14H13L16 8Z", fill: "black" })
1865
- ] });
1866
- }
1867
- if (chain === "btc") {
1868
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1869
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#F7931A" }),
1870
- /* @__PURE__ */ jsx("path", { d: "M15.5 10.5C15.5 8.5 14 8 12 8V6H11V8H10V6H9V8H7V10H8.5V14H7V16H9V18H10V16H11V18H12V16C14.5 16 16 15 16 13C16 11.5 15 11 15.5 10.5ZM10 10H12C13 10 13.5 10.5 13.5 11C13.5 11.5 13 12 12 12H10V10ZM12.5 14H10V12H12.5C13.5 12 14 12.5 14 13C14 13.5 13.5 14 12.5 14Z", fill: "white" })
1871
- ] });
1872
- }
1873
- if (chain === "tron") {
1874
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1875
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#FF0013" }),
1876
- /* @__PURE__ */ jsx("path", { d: "M7 7L12 19L17 7H7Z", fill: "white" }),
1877
- /* @__PURE__ */ jsx("path", { d: "M9 9L12 16L15 9H9Z", fill: "#FF0013" })
1878
- ] });
1879
- }
1880
- if (chain === "ton") {
1881
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1882
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#0088CC" }),
1883
- /* @__PURE__ */ jsx("path", { d: "M12 6L6 18H10L12 14L14 18H18L12 6Z", fill: "white" })
1884
- ] });
1885
- }
1886
- if (chain === "nibiru") {
1887
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1888
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#1E1E2F" }),
1889
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "5", stroke: "#7B68EE", strokeWidth: "2" }),
1890
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "2", fill: "#7B68EE" })
1891
- ] });
1892
- }
1893
- if (chain === "kaspa") {
1894
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1895
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#49EACB" }),
1896
- /* @__PURE__ */ jsx("path", { d: "M8 8L12 12L8 16M12 12L16 8M12 12L16 16", stroke: "white", strokeWidth: "2", strokeLinecap: "round" })
1897
- ] });
1898
- }
1899
- return /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1900
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#4B5563" }),
1901
- /* @__PURE__ */ jsx("path", { d: "M12 6C8.69 6 6 8.69 6 12s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm0 10c-2.21 0-4-1.79-4-4s1.79-4 4-4 4 1.79 4 4-1.79 4-4 4z", fill: "white" })
1902
- ] });
1903
- }
1904
- function EvmChainIcons() {
1905
- return /* @__PURE__ */ jsxs("div", { className: "taskon-network-chain-icons", children: [
1906
- /* @__PURE__ */ jsx(ChainIcon, { chain: "evm" }),
1907
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1908
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#213147" }),
1909
- /* @__PURE__ */ jsx("path", { d: "M12 6L16.5 12L12 18L7.5 12L12 6Z", fill: "#28A0F0" }),
1910
- /* @__PURE__ */ jsx("path", { d: "M12 6L7.5 12L12 14.5V6Z", fill: "white" })
1911
- ] }),
1912
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1913
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#8247E5" }),
1914
- /* @__PURE__ */ jsx("path", { d: "M15.5 9L12 7L8.5 9V13L12 15L15.5 13V9Z", stroke: "white", strokeWidth: "1.5" }),
1915
- /* @__PURE__ */ jsx("path", { d: "M12 11L15.5 9M12 11L8.5 9M12 11V15", stroke: "white", strokeWidth: "1.5" })
1916
- ] }),
1917
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1918
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#F3BA2F" }),
1919
- /* @__PURE__ */ jsx("path", { d: "M12 7L9.5 9.5L10.5 10.5L12 9L13.5 10.5L14.5 9.5L12 7Z", fill: "white" }),
1920
- /* @__PURE__ */ jsx("path", { d: "M7 12L8 11L9 12L8 13L7 12Z", fill: "white" }),
1921
- /* @__PURE__ */ jsx("path", { d: "M17 12L16 11L15 12L16 13L17 12Z", fill: "white" }),
1922
- /* @__PURE__ */ jsx("path", { d: "M12 17L14.5 14.5L13.5 13.5L12 15L10.5 13.5L9.5 14.5L12 17Z", fill: "white" }),
1923
- /* @__PURE__ */ jsx("path", { d: "M12 11L11 12L12 13L13 12L12 11Z", fill: "white" })
1924
- ] }),
1925
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1926
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#FF0420" }),
1927
- /* @__PURE__ */ jsx("circle", { cx: "10", cy: "12", r: "3", fill: "white" }),
1928
- /* @__PURE__ */ jsx("path", { d: "M14 9H17V10.5H15V11.5H17V13H15V15H14V9Z", fill: "white" })
1929
- ] }),
1930
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1931
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#E84142" }),
1932
- /* @__PURE__ */ jsx("path", { d: "M8 16L12 8L16 16H13L12 14L11 16H8Z", fill: "white" })
1933
- ] }),
1934
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1935
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#0052FF" }),
1936
- /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "5", stroke: "white", strokeWidth: "2" }),
1937
- /* @__PURE__ */ jsx("path", { d: "M12 9V12H15", stroke: "white", strokeWidth: "2", strokeLinecap: "round" })
1938
- ] }),
1939
- /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1940
- /* @__PURE__ */ jsx("rect", { width: "24", height: "24", rx: "8", fill: "#121212" }),
1941
- /* @__PURE__ */ jsx("path", { d: "M7 17V7H9V15H17V17H7Z", fill: "white" })
1942
- ] }),
1943
- /* @__PURE__ */ jsx("div", { className: "taskon-network-chain-icons__more", children: /* @__PURE__ */ jsxs("svg", { width: "12", height: "3", viewBox: "0 0 12 3", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1944
- /* @__PURE__ */ jsx("circle", { cx: "1.5", cy: "1.5", r: "1.5", fill: "#666" }),
1945
- /* @__PURE__ */ jsx("circle", { cx: "6", cy: "1.5", r: "1.5", fill: "#666" }),
1946
- /* @__PURE__ */ jsx("circle", { cx: "10.5", cy: "1.5", r: "1.5", fill: "#666" })
1947
- ] }) })
1948
- ] });
1949
- }
1950
- function ArrowButton({
1951
- onClick,
1952
- disabled,
1953
- isLoading,
1954
- title
1955
- }) {
1956
- return /* @__PURE__ */ jsx(
1957
- "button",
1958
- {
1959
- className: "taskon-identity-social-btn",
1960
- onClick,
1961
- disabled: disabled || isLoading,
1962
- title,
1963
- children: isLoading ? /* @__PURE__ */ jsx("span", { className: "taskon-identity-social-btn__spinner" }) : /* @__PURE__ */ jsxs("svg", { width: "18", height: "18", viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1964
- /* @__PURE__ */ jsx("path", { d: "M10.8225 4.44751L15.375 9.00001L10.8225 13.5525", stroke: "currentColor", strokeWidth: "1.5", strokeMiterlimit: "10", strokeLinecap: "round", strokeLinejoin: "round" }),
1965
- /* @__PURE__ */ jsx("path", { d: "M2.625 9H15.2475", stroke: "currentColor", strokeWidth: "1.5", strokeMiterlimit: "10", strokeLinecap: "round", strokeLinejoin: "round" })
1966
- ] })
1967
- }
1968
- );
1969
- }
1970
- function CopyButton({
1971
- text,
1972
- copyLabel,
1973
- copiedLabel
1974
- }) {
1975
- const [copied, setCopied] = useState(false);
1976
- const handleCopy = useCallback(() => {
1977
- navigator.clipboard.writeText(text).then(() => {
1978
- setCopied(true);
1979
- setTimeout(() => setCopied(false), 2e3);
1980
- });
1981
- }, [text]);
1982
- return /* @__PURE__ */ jsx(
1983
- "button",
1984
- {
1985
- className: "taskon-network-copy-btn",
1986
- onClick: handleCopy,
1987
- title: copied ? copiedLabel : copyLabel,
1988
- "aria-label": copied ? copiedLabel : copyLabel,
1989
- children: copied ? (
1990
- // 复制成功图标(勾选)
1991
- /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M3 7L6 10L11 4", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
1992
- ) : (
1993
- // 复制图标
1994
- /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
1995
- /* @__PURE__ */ jsx("rect", { x: "4", y: "4", width: "8", height: "8", rx: "1.5", stroke: "currentColor", strokeWidth: "1.5" }),
1996
- /* @__PURE__ */ jsx("path", { d: "M2 10V3C2 2.44772 2.44772 2 3 2H10", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
1997
- ] })
1998
- )
1999
- }
2000
- );
2001
- }
2002
- function SocialAccountItem({
2003
- data,
2004
- onBind,
2005
- onUnbind,
2006
- isLoading,
2007
- disabled,
2008
- disabledReason,
2009
- messages
2010
- }) {
2011
- const displayText = data.isBound && data.account ? data.account.sns_user_name : messages.link_platform_account.replace("{platform}", data.snsType);
2012
- return /* @__PURE__ */ jsxs(
2013
- "div",
2014
- {
2015
- className: `taskon-identity-social-item ${data.isBound ? "taskon-identity-social-item--bound" : ""} ${data.isBound && disabled ? "taskon-identity-social-item--unlink-disabled" : ""}`,
2016
- children: [
2017
- /* @__PURE__ */ jsxs("div", { className: "taskon-identity-social-item__content", children: [
2018
- /* @__PURE__ */ jsx("div", { className: "taskon-identity-social-item__icon", children: /* @__PURE__ */ jsx(SocialIcon, { type: data.snsType }) }),
2019
- /* @__PURE__ */ jsx("div", { className: "taskon-identity-social-item__text", children: data.isBound && data.profileUrl ? /* @__PURE__ */ jsx(
2020
- "a",
2021
- {
2022
- href: data.profileUrl,
2023
- target: "_blank",
2024
- rel: "noopener noreferrer",
2025
- className: "taskon-identity-social-item__link",
2026
- children: displayText
2027
- }
2028
- ) : /* @__PURE__ */ jsx("span", { className: "taskon-identity-social-item__name", children: displayText }) })
2029
- ] }),
2030
- data.isBound ? /* @__PURE__ */ jsxs(Fragment, { children: [
2031
- /* @__PURE__ */ jsx("span", { className: "taskon-identity-social-item__linked", children: messages.linked }),
2032
- !disabled && /* @__PURE__ */ jsx(
2033
- "button",
2034
- {
2035
- className: "taskon-identity-social-item__unlink-btn",
2036
- onClick: onUnbind,
2037
- disabled: isLoading,
2038
- "aria-label": messages.unbind,
2039
- children: isLoading ? /* @__PURE__ */ jsx("span", { className: "taskon-identity-social-btn__spinner" }) : /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M11 3L3 11M3 3L11 11", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })
2040
- }
2041
- )
2042
- ] }) : (
2043
- /* 未绑定状态:显示箭头按钮 */
2044
- /* @__PURE__ */ jsx(
2045
- ArrowButton,
2046
- {
2047
- onClick: onBind,
2048
- disabled: false,
2049
- isLoading
2050
- }
2051
- )
2052
- )
2053
- ]
2054
- }
2055
- );
2056
- }
2057
- function WalletItem({
2058
- data,
2059
- addresses,
2060
- onBind,
2061
- onUnbind,
2062
- isLoading,
2063
- disabled,
2064
- disabledReason,
2065
- messages
2066
- }) {
2067
- const name = getChainName(data.coreChainType);
2068
- const isEvm = data.coreChainType === "evm";
2069
- if (isEvm && addresses && addresses.length > 0) {
2070
- return /* @__PURE__ */ jsxs("div", { className: "taskon-network-card taskon-network-card--multi", children: [
2071
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__header", children: /* @__PURE__ */ jsx("span", { className: "taskon-network-card__label", children: messages.evm_chain }) }),
2072
- /* @__PURE__ */ jsx(EvmChainIcons, {}),
2073
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__addresses", children: addresses.map((addr, index) => {
2074
- var _a, _b, _c;
2075
- return /* @__PURE__ */ jsxs("div", { className: "taskon-network-address-row", children: [
2076
- /* @__PURE__ */ jsxs("div", { className: "taskon-network-address-row__left", children: [
2077
- /* @__PURE__ */ jsx("span", { className: `taskon-network-address-row__addr ${!addr.isPrimary ? "taskon-network-address-row__addr--secondary" : ""}`, children: truncateAddress(((_a = addr.address) == null ? void 0 : _a.address) ?? "") }),
2078
- /* @__PURE__ */ jsx(
2079
- CopyButton,
2080
- {
2081
- text: ((_b = addr.address) == null ? void 0 : _b.address) ?? "",
2082
- copyLabel: messages.copy,
2083
- copiedLabel: messages.copied
2084
- }
2085
- )
2086
- ] }),
2087
- /* @__PURE__ */ jsx("div", { className: "taskon-network-address-row__divider" }),
2088
- /* @__PURE__ */ jsxs("div", { className: "taskon-network-address-row__right", children: [
2089
- /* @__PURE__ */ jsx("span", { className: `taskon-network-address-row__type ${addr.isPrimary ? "taskon-network-address-row__type--primary" : "taskon-network-address-row__type--secondary"}`, children: addr.isPrimary ? messages.primary_address : messages.secondary_address }),
2090
- /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "taskon-network-address-row__edit", children: [
2091
- /* @__PURE__ */ jsx("path", { d: "M2 12H4L10.5 5.5L8.5 3.5L2 10V12Z", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round" }),
2092
- /* @__PURE__ */ jsx("path", { d: "M8.5 3.5L10.5 5.5", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round" })
2093
- ] })
2094
- ] }),
2095
- /* @__PURE__ */ jsx(
2096
- "button",
2097
- {
2098
- className: "taskon-network-unbind-badge",
2099
- onClick: () => {
2100
- var _a2;
2101
- return onUnbind((_a2 = addr.address) == null ? void 0 : _a2.address);
2102
- },
2103
- disabled: isLoading || disabled,
2104
- title: disabledReason,
2105
- children: messages.unbind
2106
- }
2107
- )
2108
- ] }, ((_c = addr.address) == null ? void 0 : _c.address) ?? index);
2109
- }) })
2110
- ] });
2111
- }
2112
- if (isEvm && !data.isBound) {
2113
- return /* @__PURE__ */ jsxs("div", { className: "taskon-network-card taskon-network-card--multi", children: [
2114
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__header", children: /* @__PURE__ */ jsx("span", { className: "taskon-network-card__label", children: messages.evm_chain }) }),
2115
- /* @__PURE__ */ jsx(EvmChainIcons, {}),
2116
- /* @__PURE__ */ jsx(
2117
- "button",
2118
- {
2119
- className: "taskon-network-connect-btn",
2120
- onClick: onBind,
2121
- disabled: isLoading,
2122
- children: isLoading ? messages.loading : messages.connect_wallet
2123
- }
2124
- )
2125
- ] });
2126
- }
2127
- if (data.isBound && data.address) {
2128
- return /* @__PURE__ */ jsxs("div", { className: "taskon-network-card taskon-network-card--single", children: [
2129
- /* @__PURE__ */ jsx(
2130
- "button",
2131
- {
2132
- className: "taskon-network-unbind-badge taskon-network-unbind-badge--corner",
2133
- onClick: () => onUnbind(),
2134
- disabled: isLoading || disabled,
2135
- title: disabledReason,
2136
- children: messages.unbind
2137
- }
2138
- ),
2139
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__header", children: /* @__PURE__ */ jsx("span", { className: "taskon-network-card__label", children: name }) }),
2140
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__chain-icon", children: /* @__PURE__ */ jsx(ChainIcon, { chain: data.coreChainType }) }),
2141
- /* @__PURE__ */ jsxs("div", { className: "taskon-network-address-input", children: [
2142
- /* @__PURE__ */ jsx("span", { className: "taskon-network-address-input__text", children: truncateAddress(data.address.address) }),
2143
- /* @__PURE__ */ jsx(
2144
- CopyButton,
2145
- {
2146
- text: data.address.address,
2147
- copyLabel: messages.copy,
2148
- copiedLabel: messages.copied
2149
- }
2150
- )
2151
- ] })
2152
- ] });
2153
- }
2154
- return /* @__PURE__ */ jsxs("div", { className: "taskon-network-card taskon-network-card--single", children: [
2155
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__header", children: /* @__PURE__ */ jsx("span", { className: "taskon-network-card__label", children: name }) }),
2156
- /* @__PURE__ */ jsx("div", { className: "taskon-network-card__chain-icon", children: /* @__PURE__ */ jsx(ChainIcon, { chain: data.coreChainType }) }),
2157
- /* @__PURE__ */ jsx(
2158
- "button",
2159
- {
2160
- className: "taskon-network-connect-btn",
2161
- onClick: onBind,
2162
- disabled: isLoading,
2163
- children: isLoading ? messages.loading : messages.connect_wallet
2164
- }
2165
- )
2166
- ] });
2167
- }
2168
- function WarningIcon() {
2169
- return /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx(
2170
- "path",
2171
- {
2172
- d: "M12 9V13M12 17H12.01M10.29 3.86L1.82 18C1.64 18.3 1.55 18.65 1.55 19C1.56 19.35 1.65 19.69 1.82 20C2 20.3 2.25 20.56 2.55 20.73C2.85 20.91 3.19 21 3.54 21H20.46C20.81 21 21.15 20.91 21.45 20.73C21.75 20.56 22 20.3 22.18 20C22.35 19.69 22.44 19.35 22.45 19C22.45 18.65 22.36 18.3 22.18 18L13.71 3.86C13.53 3.56 13.28 3.32 12.98 3.15C12.68 2.98 12.34 2.89 12 2.89C11.66 2.89 11.32 2.98 11.02 3.15C10.72 3.32 10.47 3.56 10.29 3.86Z",
2173
- stroke: "currentColor",
2174
- strokeWidth: "2",
2175
- strokeLinecap: "round",
2176
- strokeLinejoin: "round"
2177
- }
2178
- ) });
2179
- }
2180
- function ConfirmUnlinkDialog({
2181
- open,
2182
- onOpenChange,
2183
- onConfirm,
2184
- onCancel,
2185
- loading = false,
2186
- messages
2187
- }) {
2188
- return /* @__PURE__ */ jsx(
2189
- Dialog,
2190
- {
2191
- open,
2192
- onOpenChange,
2193
- title: messages.confirm_unbind,
2194
- showCloseButton: false,
2195
- maxWidth: 400,
2196
- children: /* @__PURE__ */ jsxs("div", { className: "taskon-confirm-unlink", children: [
2197
- /* @__PURE__ */ jsx("div", { className: "taskon-confirm-unlink__icon", children: /* @__PURE__ */ jsx(WarningIcon, {}) }),
2198
- /* @__PURE__ */ jsxs("div", { className: "taskon-confirm-unlink__text", children: [
2199
- /* @__PURE__ */ jsx("h4", { className: "taskon-confirm-unlink__title", children: messages.confirm_unbind }),
2200
- /* @__PURE__ */ jsx("p", { className: "taskon-confirm-unlink__description", children: messages.unbind_warning })
2201
- ] }),
2202
- /* @__PURE__ */ jsxs("div", { className: "taskon-confirm-unlink__actions", children: [
2203
- /* @__PURE__ */ jsx(
2204
- "button",
2205
- {
2206
- className: "taskon-confirm-unlink__btn taskon-confirm-unlink__btn--cancel",
2207
- onClick: onCancel,
2208
- disabled: loading,
2209
- children: messages.cancel
2210
- }
2211
- ),
2212
- /* @__PURE__ */ jsx(
2213
- "button",
2214
- {
2215
- className: "taskon-confirm-unlink__btn taskon-confirm-unlink__btn--confirm",
2216
- onClick: onConfirm,
2217
- disabled: loading,
2218
- children: loading ? messages.unbinding : messages.confirm
2219
- }
2220
- )
2221
- ] })
2222
- ] })
2223
- }
2224
- );
2225
- }
2226
- function SocialAccountsSection({
2227
- accounts,
2228
- onBind,
2229
- onUnbind,
2230
- isProcessing,
2231
- checkUnlink,
2232
- onShowWarning
2233
- }) {
2234
- const { messages } = useUserCenterLocale();
2235
- if (accounts.length === 0) {
2236
- return null;
2237
- }
2238
- const [confirmTarget, setConfirmTarget] = useState(
2239
- null
2240
- );
2241
- const showConfirm = confirmTarget !== null;
2242
- const handleBind = useCallback(
2243
- (account) => {
2244
- onBind(account.snsType);
2245
- },
2246
- [onBind]
2247
- );
2248
- const handleUnbind = useCallback(
2249
- (account) => {
2250
- if (!account.account) return;
2251
- const check = checkUnlink(account.account);
2252
- if (check.disabled) {
2253
- onShowWarning(check.message ?? messages.unbind_failed);
2254
- return;
2255
- }
2256
- setConfirmTarget(account);
2257
- },
2258
- [checkUnlink, onShowWarning, messages]
2259
- );
2260
- const handleConfirmUnbind = useCallback(() => {
2261
- if (!(confirmTarget == null ? void 0 : confirmTarget.account)) return;
2262
- onUnbind(confirmTarget.account.sns_id, confirmTarget.snsType);
2263
- setConfirmTarget(null);
2264
- }, [confirmTarget, onUnbind]);
2265
- return /* @__PURE__ */ jsxs("section", { className: "taskon-identity-social-section", children: [
2266
- /* @__PURE__ */ jsx("h3", { className: "taskon-identity-social-section__title", children: messages.social_accounts }),
2267
- /* @__PURE__ */ jsx("div", { className: "taskon-identity-social-grid", children: accounts.map((account) => {
2268
- const check = account.account ? checkUnlink(account.account) : { disabled: false, message: null };
2269
- return /* @__PURE__ */ jsx(
2270
- SocialAccountItem,
2271
- {
2272
- data: account,
2273
- onBind: () => handleBind(account),
2274
- onUnbind: () => handleUnbind(account),
2275
- isLoading: isProcessing(account.snsType),
2276
- disabled: check.disabled,
2277
- disabledReason: check.message ?? void 0,
2278
- messages
2279
- },
2280
- account.snsType
2281
- );
2282
- }) }),
2283
- /* @__PURE__ */ jsx(
2284
- ConfirmUnlinkDialog,
2285
- {
2286
- open: showConfirm,
2287
- onOpenChange: (open) => {
2288
- if (!open) setConfirmTarget(null);
2289
- },
2290
- onConfirm: handleConfirmUnbind,
2291
- onCancel: () => setConfirmTarget(null),
2292
- loading: confirmTarget ? isProcessing(confirmTarget.snsType) : false,
2293
- messages
2294
- }
2295
- )
2296
- ] });
2297
- }
2298
- function WalletsSection({
2299
- wallets,
2300
- rawAddresses,
2301
- onBind,
2302
- onUnbind,
2303
- isProcessing,
2304
- checkUnlink,
2305
- onShowWarning,
2306
- onShowInfo
2307
- }) {
2308
- const { messages } = useUserCenterLocale();
2309
- if (wallets.length === 0) {
2310
- return null;
2311
- }
2312
- const evmAddresses = useMemo(() => {
2313
- return rawAddresses.filter((addr) => addr.chain_type === "evm").map((addr) => ({
2314
- chainType: "EVM",
2315
- // UserCenterChainType.EVM
2316
- coreChainType: "evm",
2317
- isBound: true,
2318
- address: addr,
2319
- isPrimary: addr.is_primary ?? false,
2320
- isKycVerified: void 0
2321
- }));
2322
- }, [rawAddresses]);
2323
- const [confirmTarget, setConfirmTarget] = useState(null);
2324
- const showConfirm = confirmTarget !== null;
2325
- const handleBind = useCallback(
2326
- (wallet) => {
2327
- onBind(wallet.coreChainType);
2328
- },
2329
- [onBind]
2330
- );
2331
- const handleUnbind = useCallback(
2332
- (wallet, specificAddress) => {
2333
- var _a;
2334
- const addressToUnbind = specificAddress ?? ((_a = wallet.address) == null ? void 0 : _a.address);
2335
- if (!addressToUnbind || !wallet.address) return;
2336
- const check = checkUnlink(wallet.address, wallet.isKycVerified);
2337
- if (check.disabled) {
2338
- onShowWarning(check.message ?? messages.unbind_failed);
2339
- return;
2340
- }
2341
- if (check.needsKycWarning) {
2342
- onShowInfo(messages.kyc_warning);
2343
- }
2344
- setConfirmTarget({ wallet, address: addressToUnbind });
2345
- },
2346
- [checkUnlink, onShowWarning, onShowInfo, messages]
2347
- );
2348
- const handleConfirmUnbind = useCallback(() => {
2349
- if (!confirmTarget) return;
2350
- onUnbind(confirmTarget.wallet.coreChainType, confirmTarget.address);
2351
- setConfirmTarget(null);
2352
- }, [confirmTarget, onUnbind]);
2353
- return /* @__PURE__ */ jsxs("section", { className: "taskon-network-section", children: [
2354
- /* @__PURE__ */ jsx("h3", { className: "taskon-network-section__title", children: messages.wallet_addresses }),
2355
- /* @__PURE__ */ jsx("div", { className: "taskon-network-grid", children: wallets.map((wallet) => {
2356
- const check = wallet.address ? checkUnlink(wallet.address, wallet.isKycVerified) : { disabled: false, message: null };
2357
- const isEvm = wallet.coreChainType === "evm";
2358
- return /* @__PURE__ */ jsx(
2359
- WalletItem,
2360
- {
2361
- data: wallet,
2362
- addresses: isEvm && evmAddresses.length > 0 ? evmAddresses : void 0,
2363
- onBind: () => handleBind(wallet),
2364
- onUnbind: (addr) => handleUnbind(wallet, addr),
2365
- isLoading: isProcessing(wallet.chainType),
2366
- disabled: check.disabled,
2367
- disabledReason: check.message ?? void 0,
2368
- messages
2369
- },
2370
- wallet.coreChainType
2371
- );
2372
- }) }),
2373
- /* @__PURE__ */ jsx(
2374
- ConfirmUnlinkDialog,
2375
- {
2376
- open: showConfirm,
2377
- onOpenChange: (open) => {
2378
- if (!open) setConfirmTarget(null);
2379
- },
2380
- onConfirm: handleConfirmUnbind,
2381
- onCancel: () => setConfirmTarget(null),
2382
- loading: confirmTarget ? isProcessing(confirmTarget.wallet.chainType) : false,
2383
- messages
2384
- }
2385
- )
2386
- ] });
2387
- }
2388
- const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
2389
- function EmailBindDialog({
2390
- visible,
2391
- status,
2392
- countdown,
2393
- isEmailDuplicate,
2394
- isCodeInvalid,
2395
- messages,
2396
- onClose,
2397
- onSendCode,
2398
- onBind,
2399
- onClearError
2400
- }) {
2401
- const [email, setEmail] = useState("");
2402
- const [code, setCode] = useState("");
2403
- const isEmailValid = useMemo(() => EMAIL_REGEX.test(email), [email]);
2404
- const isCodeValid = useMemo(() => code.length >= 4, [code]);
2405
- const isSending = status === "sendingCode";
2406
- const isSubmitting = status === "submitting";
2407
- const showCodeInput = status === "inputCode" || status === "submitting" || status === "success";
2408
- const emailError = useMemo(() => {
2409
- if (isEmailDuplicate) {
2410
- return messages.email_already_linked;
2411
- }
2412
- if (email && !isEmailValid) {
2413
- return messages.please_enter_valid_email;
2414
- }
2415
- return void 0;
2416
- }, [isEmailDuplicate, email, isEmailValid, messages]);
2417
- const codeError = useMemo(() => {
2418
- if (isCodeInvalid) {
2419
- return messages.please_enter_valid_code;
2420
- }
2421
- return void 0;
2422
- }, [isCodeInvalid, messages]);
2423
- const handleEmailChange = useCallback(
2424
- (value) => {
2425
- setEmail(value);
2426
- onClearError();
2427
- },
2428
- [onClearError]
2429
- );
2430
- const handleCodeChange = useCallback(
2431
- (value) => {
2432
- const numericValue = value.replace(/[^0-9]/g, "").slice(0, 6);
2433
- setCode(numericValue);
2434
- onClearError();
2435
- },
2436
- [onClearError]
2437
- );
2438
- const handleSendCode = useCallback(async () => {
2439
- if (!isEmailValid || isSending) return;
2440
- await onSendCode(email);
2441
- }, [email, isEmailValid, isSending, onSendCode]);
2442
- const handleBind = useCallback(async () => {
2443
- if (!isEmailValid || !isCodeValid || isSubmitting) return;
2444
- const result = await onBind(email, code);
2445
- if (result == null ? void 0 : result.result) {
2446
- setEmail("");
2447
- setCode("");
2448
- onClose();
2449
- }
2450
- }, [email, code, isEmailValid, isCodeValid, isSubmitting, onBind, onClose]);
2451
- const handleClose = useCallback(() => {
2452
- setEmail("");
2453
- setCode("");
2454
- onClose();
2455
- }, [onClose]);
2456
- return /* @__PURE__ */ jsx(
2457
- Dialog,
2458
- {
2459
- open: visible,
2460
- onOpenChange: (open) => {
2461
- if (!open) handleClose();
2462
- },
2463
- title: messages.link_email_account,
2464
- showCloseButton: true,
2465
- maxWidth: 400,
2466
- children: /* @__PURE__ */ jsxs("div", { className: "taskon-email-bind-dialog", children: [
2467
- /* @__PURE__ */ jsx("h2", { className: "taskon-email-bind-dialog__title", children: messages.link_email_account }),
2468
- /* @__PURE__ */ jsxs("div", { className: "taskon-email-bind-dialog__field", children: [
2469
- /* @__PURE__ */ jsx("label", { className: "taskon-email-bind-dialog__label", children: messages.email_address }),
2470
- /* @__PURE__ */ jsx(
2471
- Input,
2472
- {
2473
- type: "email",
2474
- value: email,
2475
- onChange: handleEmailChange,
2476
- placeholder: messages.please_enter_email,
2477
- maxLength: 64,
2478
- disabled: showCodeInput,
2479
- error: emailError,
2480
- onBlur: () => setEmail(email.trim())
2481
- }
2482
- )
2483
- ] }),
2484
- showCodeInput && /* @__PURE__ */ jsxs("div", { className: "taskon-email-bind-dialog__field", children: [
2485
- /* @__PURE__ */ jsx("label", { className: "taskon-email-bind-dialog__label", children: messages.verification_code }),
2486
- /* @__PURE__ */ jsx(
2487
- Input,
2488
- {
2489
- type: "text",
2490
- inputMode: "numeric",
2491
- value: code,
2492
- onChange: handleCodeChange,
2493
- placeholder: messages.please_enter_code,
2494
- maxLength: 6,
2495
- disabled: isSubmitting,
2496
- error: codeError,
2497
- rightSlot: /* @__PURE__ */ jsx(
2498
- Button,
2499
- {
2500
- variant: "ghost",
2501
- size: "small",
2502
- disabled: countdown > 0 || isSending,
2503
- loading: isSending,
2504
- onClick: handleSendCode,
2505
- children: countdown > 0 ? `${messages.resend_code} (${countdown}s)` : messages.resend_code
2506
- }
2507
- )
2508
- }
2509
- )
2510
- ] }),
2511
- /* @__PURE__ */ jsx("div", { className: "taskon-email-bind-dialog__actions", children: !showCodeInput ? (
2512
- /* 发送验证码按钮 */
2513
- /* @__PURE__ */ jsx(
2514
- Button,
2515
- {
2516
- variant: "primary",
2517
- size: "large",
2518
- disabled: !isEmailValid || isSending,
2519
- loading: isSending,
2520
- onClick: handleSendCode,
2521
- style: { width: "100%" },
2522
- children: messages.send_verification_code
2523
- }
2524
- )
2525
- ) : (
2526
- /* 确认绑定按钮 */
2527
- /* @__PURE__ */ jsx(
2528
- Button,
2529
- {
2530
- variant: "primary",
2531
- size: "large",
2532
- disabled: !isEmailValid || !isCodeValid || isSubmitting,
2533
- loading: isSubmitting,
2534
- onClick: handleBind,
2535
- style: { width: "100%" },
2536
- children: messages.confirm
2537
- }
2538
- )
2539
- ) })
2540
- ] })
2541
- }
2542
- );
2543
- }
2544
- function EmailSection({
2545
- emailAccount,
2546
- onUnbind,
2547
- isUnbinding,
2548
- checkUnlink,
2549
- onShowSuccess,
2550
- onShowError,
2551
- onShowWarning
2552
- }) {
2553
- const { messages } = useUserCenterLocale();
2554
- const [dialogVisible, setDialogVisible] = useState(false);
2555
- const {
2556
- status: emailBindStatus,
2557
- countdown: emailCountdown,
2558
- isEmailDuplicate,
2559
- isCodeInvalid,
2560
- sendCode: sendEmailCode,
2561
- bind: bindEmail,
2562
- reset: resetEmailBind,
2563
- clearError: clearEmailError
2564
- } = useBindEmail({
2565
- onSendCodeSuccess: () => {
2566
- onShowSuccess(messages.send_code_success);
2567
- },
2568
- onSendCodeError: (error) => {
2569
- if (!error.message.includes("duplicate")) {
2570
- onShowError(messages.send_code_failed);
2571
- }
2572
- },
2573
- onBindSuccess: () => {
2574
- onShowSuccess(messages.bind_success);
2575
- setDialogVisible(false);
2576
- },
2577
- onBindError: () => {
2578
- onShowError(messages.bind_failed);
2579
- }
2580
- });
2581
- const handleBind = useCallback(() => {
2582
- setDialogVisible(true);
2583
- }, []);
2584
- const handleUnbind = useCallback(() => {
2585
- if (!emailAccount.account) return;
2586
- const check2 = checkUnlink(emailAccount.account);
2587
- if (check2.disabled) {
2588
- onShowWarning(check2.message ?? messages.unbind_failed);
2589
- return;
2590
- }
2591
- onUnbind(emailAccount.account.sns_id, "Email");
2592
- }, [emailAccount, checkUnlink, onUnbind, onShowWarning, messages]);
2593
- const handleDialogClose = useCallback(() => {
2594
- setDialogVisible(false);
2595
- resetEmailBind();
2596
- }, [resetEmailBind]);
2597
- const check = emailAccount.account ? checkUnlink(emailAccount.account) : { disabled: false, message: null };
2598
- return /* @__PURE__ */ jsxs(Fragment, { children: [
2599
- /* @__PURE__ */ jsxs("section", { className: "taskon-identity-email-section", children: [
2600
- /* @__PURE__ */ jsx("h3", { className: "taskon-identity-email-section__title", children: messages.email_address }),
2601
- /* @__PURE__ */ jsx("div", { className: "taskon-identity-email-card", children: /* @__PURE__ */ jsx(
2602
- SocialAccountItem,
2603
- {
2604
- data: emailAccount,
2605
- onBind: handleBind,
2606
- onUnbind: handleUnbind,
2607
- isLoading: isUnbinding,
2608
- disabled: check.disabled,
2609
- disabledReason: check.message ?? void 0,
2610
- messages
2611
- }
2612
- ) })
2613
- ] }),
2614
- /* @__PURE__ */ jsx(
2615
- EmailBindDialog,
2616
- {
2617
- visible: dialogVisible,
2618
- status: emailBindStatus,
2619
- countdown: emailCountdown,
2620
- isEmailDuplicate,
2621
- isCodeInvalid,
2622
- messages,
2623
- onClose: handleDialogClose,
2624
- onSendCode: sendEmailCode,
2625
- onBind: bindEmail,
2626
- onClearError: clearEmailError
2627
- }
2628
- )
2629
- ] });
2630
- }
2631
- const USER_CENTER_WALLET_ACCOUNT_TYPE = String(SnsType.All).toLowerCase();
2632
- const isWalletAccountType = (accountType) => accountType.toLowerCase() === USER_CENTER_WALLET_ACCOUNT_TYPE;
2633
- function IdentityContent({
2634
- config
2635
- }) {
2636
- var _a, _b, _c, _d;
2637
- const { t } = useUserCenterLocale();
2638
- const identityTab = config.find(
2639
- (t2) => t2.tab === "Identity"
2640
- );
2641
- const enabledAccounts = identityTab ? filterEnabledAccounts(identityTab) : [];
2642
- const enabledWallets = identityTab ? filterEnabledWallets(identityTab) : [];
2643
- const identityParams = identityTab && !Array.isArray(identityTab.params) ? identityTab.params : void 0;
2644
- const walletAccountOption = (_a = identityParams == null ? void 0 : identityParams.accountOptions) == null ? void 0 : _a.find(
2645
- (account) => isWalletAccountType(String(account.account))
2646
- );
2647
- const isWalletAccountEnabled = walletAccountOption ? walletAccountOption.enabled !== false : true;
2648
- const hasExplicitAccountConfig = (((_b = identityParams == null ? void 0 : identityParams.accountOptions) == null ? void 0 : _b.length) ?? 0) > 0;
2649
- const hasExplicitWalletConfig = (((_c = walletAccountOption == null ? void 0 : walletAccountOption.walletOptions) == null ? void 0 : _c.length) ?? 0) > 0 || (((_d = identityParams == null ? void 0 : identityParams.walletOptions) == null ? void 0 : _d.length) ?? 0) > 0;
2650
- const { socialAccounts, walletAddresses, rawAddresses, isLoaded } = useIdentityData();
2651
- const { checkSocialUnlink, checkWalletUnlink } = useDisableUnlink();
2652
- const { toast } = useToast();
2653
- const {
2654
- unbind: unbindSocial,
2655
- unbindStatus: socialUnbindStatus,
2656
- processingType: socialProcessingType
2657
- } = useUnbindSocial({
2658
- onUnbindSuccess: () => {
2659
- toast.success(t("unbind_success"));
2660
- },
2661
- onUnbindError: () => {
2662
- toast.error(t("unbind_failed"));
2663
- }
2664
- });
2665
- const {
2666
- bind: bindOAuth,
2667
- isBinding: isOAuthBinding,
2668
- isOAuthSupported
2669
- } = useOAuthBindings({
2670
- onSuccess: () => {
2671
- toast.success(t("bind_success"));
2672
- },
2673
- onFailed: (error) => {
2674
- toast.error(error || t("bind_failed"));
2675
- }
2676
- });
2677
- const {
2678
- bind: bindWallet,
2679
- unbind: unbindWallet,
2680
- bindStatus: walletBindStatus,
2681
- unbindStatus: walletUnbindStatus,
2682
- processingChain: walletProcessingChain
2683
- } = useBindWallet({
2684
- onBindSuccess: () => {
2685
- toast.success(t("bind_success"));
2686
- },
2687
- onUnbindSuccess: () => {
2688
- toast.success(t("unbind_success"));
2689
- },
2690
- onBindError: () => {
2691
- toast.error(t("bind_failed"));
2692
- },
2693
- onUnbindError: () => {
2694
- toast.error(t("unbind_failed"));
2695
- }
2696
- });
2697
- const enabledSocialAccountTypes = useMemo(() => {
2698
- return new Set(
2699
- enabledAccounts.filter((account) => !isWalletAccountType(String(account.account))).map((account) => String(account.account).toLowerCase())
2700
- );
2701
- }, [enabledAccounts]);
2702
- const enabledWalletChainTypes = useMemo(() => {
2703
- return new Set(
2704
- enabledWallets.map((wallet) => String(wallet.chain).toLowerCase())
2705
- );
2706
- }, [enabledWallets]);
2707
- const filteredSocialAccounts = useMemo(() => {
2708
- return socialAccounts.filter((account) => {
2709
- if (isWalletAccountType(String(account.snsType))) {
2710
- return false;
2711
- }
2712
- if (!hasExplicitAccountConfig) {
2713
- return true;
2714
- }
2715
- return enabledSocialAccountTypes.has(account.snsType.toLowerCase());
2716
- });
2717
- }, [socialAccounts, hasExplicitAccountConfig, enabledSocialAccountTypes]);
2718
- const filteredWalletAddresses = useMemo(() => {
2719
- if (!isWalletAccountEnabled) {
2720
- return [];
2721
- }
2722
- if (!hasExplicitWalletConfig) {
2723
- return walletAddresses;
2724
- }
2725
- return walletAddresses.filter((wallet) => {
2726
- return enabledWalletChainTypes.has(wallet.coreChainType.toLowerCase());
2727
- });
2728
- }, [
2729
- walletAddresses,
2730
- hasExplicitWalletConfig,
2731
- enabledWalletChainTypes,
2732
- isWalletAccountEnabled
2733
- ]);
2734
- const emailAccount = useMemo(() => {
2735
- return filteredSocialAccounts.find((a) => a.snsType === SnsType.Email);
2736
- }, [filteredSocialAccounts]);
2737
- const socialAccountsWithoutEmail = useMemo(() => {
2738
- return filteredSocialAccounts.filter((a) => a.snsType !== SnsType.Email);
2739
- }, [filteredSocialAccounts]);
2740
- const handleSocialBind = useCallback(
2741
- (snsType) => {
2742
- if (isOAuthSupported(snsType)) {
2743
- bindOAuth(snsType);
2744
- return;
2745
- }
2746
- toast.info(t("bind_social_todo"));
2747
- },
2748
- [bindOAuth, isOAuthSupported, toast, t]
2749
- );
2750
- const isSocialProcessing = useCallback(
2751
- (snsType) => {
2752
- if (isOAuthBinding(snsType)) return true;
2753
- return String(socialProcessingType).toLowerCase() === snsType.toLowerCase() && socialUnbindStatus === "loading";
2754
- },
2755
- [isOAuthBinding, socialProcessingType, socialUnbindStatus]
2756
- );
2757
- const handleWalletBind = useCallback(
2758
- (chainType) => {
2759
- bindWallet(chainType);
2760
- },
2761
- [bindWallet]
2762
- );
2763
- const handleWalletUnbind = useCallback(
2764
- (chainType, address) => {
2765
- unbindWallet(chainType, address);
2766
- },
2767
- [unbindWallet]
2768
- );
2769
- const isWalletProcessing = useCallback(
2770
- (chainType) => {
2771
- return String(walletProcessingChain) === String(chainType) && (walletBindStatus !== "idle" || walletUnbindStatus !== "idle");
2772
- },
2773
- [walletProcessingChain, walletBindStatus, walletUnbindStatus]
2774
- );
2775
- const isEmailUnbinding = useMemo(() => {
2776
- return socialProcessingType === SnsType.Email && socialUnbindStatus === "loading";
2777
- }, [socialProcessingType, socialUnbindStatus]);
2778
- if (!isLoaded) {
2779
- return /* @__PURE__ */ jsx("div", { className: "taskon-identity", children: /* @__PURE__ */ jsx("div", { className: "taskon-identity-loading", children: t("loading") }) });
2780
- }
2781
- const isEmpty = socialAccountsWithoutEmail.length === 0 && !emailAccount && filteredWalletAddresses.length === 0;
2782
- return /* @__PURE__ */ jsxs("div", { className: "taskon-identity", children: [
2783
- /* @__PURE__ */ jsx(
2784
- SocialAccountsSection,
2785
- {
2786
- accounts: socialAccountsWithoutEmail,
2787
- onBind: handleSocialBind,
2788
- onUnbind: unbindSocial,
2789
- isProcessing: isSocialProcessing,
2790
- checkUnlink: checkSocialUnlink,
2791
- onShowWarning: toast.warning
2792
- }
2793
- ),
2794
- /* @__PURE__ */ jsx(
2795
- WalletsSection,
2796
- {
2797
- wallets: filteredWalletAddresses,
2798
- rawAddresses,
2799
- onBind: handleWalletBind,
2800
- onUnbind: handleWalletUnbind,
2801
- isProcessing: isWalletProcessing,
2802
- checkUnlink: checkWalletUnlink,
2803
- onShowWarning: toast.warning,
2804
- onShowInfo: toast.info
2805
- }
2806
- ),
2807
- emailAccount && /* @__PURE__ */ jsx(
2808
- EmailSection,
2809
- {
2810
- emailAccount,
2811
- onUnbind: unbindSocial,
2812
- isUnbinding: isEmailUnbinding,
2813
- checkUnlink: checkSocialUnlink,
2814
- onShowSuccess: toast.success,
2815
- onShowError: toast.error,
2816
- onShowWarning: toast.warning
2817
- }
2818
- ),
2819
- isEmpty && /* @__PURE__ */ jsx("div", { className: "taskon-identity-empty", children: t("empty_identity") })
2820
- ] });
2821
- }
2822
- function MyRewardsContent({
2823
- defaultRewardCard,
2824
- defaultPointId
2825
- }) {
2826
- const { toast } = useToast();
2827
- const { t } = useUserCenterLocale();
2828
- const { client } = useTaskOnContext();
2829
- const [selectedPointsId, setSelectedPointsId] = useState(null);
2830
- const hasUserSelectedRef = useRef(false);
2831
- const appliedDefaultKeyRef = useRef(null);
2832
- const [showWithdrawForm, setShowWithdrawForm] = useState(false);
2833
- const [selectedTokenForWithdraw, setSelectedTokenForWithdraw] = useState(null);
2834
- const [viewingFrozenToken, setViewingFrozenToken] = useState(null);
2835
- const [resendParams, setResendParams] = useState(void 0);
2836
- const {
2837
- cards,
2838
- selectedCard,
2839
- selectCard,
2840
- loading: rewardsLoading,
2841
- error: rewardsError
2842
- } = useUserRewards({});
2843
- const selectedPointsData = useMemo(() => {
2844
- if (selectedCard !== USER_CENTER_REWARD_CARD_TYPES.Points) return null;
2845
- const selectedCardData = cards.find(
2846
- (c) => {
2847
- var _a;
2848
- return c.type === selectedCard && ((_a = c.pointsData) == null ? void 0 : _a.points_id) === selectedPointsId;
2849
- }
2850
- );
2851
- return (selectedCardData == null ? void 0 : selectedCardData.pointsData) ?? null;
2852
- }, [selectedCard, cards, selectedPointsId]);
2853
- const selectedXpLevelData = useMemo(() => {
2854
- if (selectedCard !== USER_CENTER_REWARD_CARD_TYPES.XpLevel) return null;
2855
- const xpLevelCard = cards.find(
2856
- (c) => c.type === USER_CENTER_REWARD_CARD_TYPES.XpLevel
2857
- );
2858
- return (xpLevelCard == null ? void 0 : xpLevelCard.xpLevelData) ?? null;
2859
- }, [selectedCard, cards]);
2860
- const {
2861
- data: tokenAssets,
2862
- loading: tokenAssetsLoading,
2863
- error: tokenAssetsError,
2864
- pendingWithdrawals,
2865
- refresh: refreshTokenAssets
2866
- } = useTokenAssets({
2867
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.Token
2868
- });
2869
- const {
2870
- data: tokenHistory,
2871
- loading: tokenHistoryLoading,
2872
- error: tokenHistoryError,
2873
- pagination: tokenHistoryPagination
2874
- } = useRewardDetails({
2875
- rewardType: RewardType.Token,
2876
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.Token
2877
- });
2878
- const {
2879
- data: frozenAssets,
2880
- loading: frozenAssetsLoading,
2881
- error: frozenAssetsError,
2882
- pagination: frozenAssetsPagination,
2883
- canResend
2884
- } = useFrozenAssets({
2885
- tokenId: (viewingFrozenToken == null ? void 0 : viewingFrozenToken.token_id) ?? 0,
2886
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.Token && !!(viewingFrozenToken == null ? void 0 : viewingFrozenToken.token_id)
2887
- });
2888
- const userCenterApi = useMemo(() => {
2889
- if (!client) return null;
2890
- return createUserCenterApi(client);
2891
- }, [client]);
2892
- const {
2893
- data: nftList,
2894
- loading: nftLoading,
2895
- error: nftError,
2896
- pagination: nftPagination,
2897
- refresh: refreshNftList
2898
- } = useRewardDetails({
2899
- rewardType: RewardType.Nft,
2900
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.Nft
2901
- });
2902
- const {
2903
- data: whitelistList,
2904
- loading: whitelistLoading,
2905
- error: whitelistError,
2906
- pagination: whitelistPagination
2907
- } = useRewardDetails({
2908
- rewardType: RewardType.Whitelist,
2909
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.Whitelist
2910
- });
2911
- const {
2912
- data: discordRoleList,
2913
- loading: discordRoleLoading,
2914
- error: discordRoleError,
2915
- pagination: discordRolePagination
2916
- } = useRewardDetails({
2917
- rewardType: RewardType.DiscordRole,
2918
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.DiscordRole
2919
- });
2920
- const {
2921
- data: pointsHistory,
2922
- loading: pointsLoading,
2923
- error: pointsError,
2924
- pagination: pointsPagination
2925
- } = usePointsHistory({
2926
- pointsId: (selectedPointsData == null ? void 0 : selectedPointsData.points_id) ?? 0,
2927
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.Points && !!selectedPointsData
2928
- });
2929
- const {
2930
- data: xpLevelHistory,
2931
- loading: xpLevelHistoryLoading,
2932
- error: xpLevelHistoryError,
2933
- pagination: xpLevelHistoryPagination
2934
- } = usePointsHistory({
2935
- pointsId: (selectedXpLevelData == null ? void 0 : selectedXpLevelData.xpPointsId) ?? 0,
2936
- autoLoad: selectedCard === USER_CENTER_REWARD_CARD_TYPES.XpLevel && !!selectedXpLevelData
2937
- });
2938
- const handleWithdraw = (token) => {
2939
- setResendParams(void 0);
2940
- setSelectedTokenForWithdraw(token);
2941
- setShowWithdrawForm(true);
2942
- };
2943
- const handleBatchWithdraw = () => {
2944
- setResendParams(void 0);
2945
- setSelectedTokenForWithdraw(null);
2946
- setShowWithdrawForm(true);
2947
- };
2948
- const handleViewFrozen = (token) => {
2949
- setViewingFrozenToken(token);
2950
- };
2951
- const handleCloseFrozenAssets = () => {
2952
- setViewingFrozenToken(null);
2953
- };
2954
- const handleResendFrozenAsset = async (item) => {
2955
- if (!viewingFrozenToken || !userCenterApi) {
2956
- return;
2957
- }
2958
- if (item.type !== LockedType.Withdraw) {
2959
- return;
2960
- }
2961
- if (!item.nonce || !item.receiver_address) {
2962
- toast.error(t("missing_resend_payload"));
2963
- return;
2964
- }
2965
- try {
2966
- const requests = await userCenterApi.getTokenWithdrawByNonce({
2967
- chain: viewingFrozenToken.chain,
2968
- nonce: item.nonce
2969
- });
2970
- const withdrawableRequests = requests.filter(
2971
- (request) => request.can_withdraw
2972
- );
2973
- if (withdrawableRequests.length === 0) {
2974
- toast.error(t("no_tokens_for_resend"));
2975
- return;
2976
- }
2977
- setResendParams({
2978
- nonce: item.nonce,
2979
- receiverAddress: item.receiver_address,
2980
- tokens: withdrawableRequests
2981
- });
2982
- setSelectedTokenForWithdraw(viewingFrozenToken);
2983
- setShowWithdrawForm(true);
2984
- } catch (error) {
2985
- toast.error(
2986
- error instanceof Error ? error.message : t("failed_load_resend_details")
2987
- );
2988
- }
2989
- };
2990
- const handleSelectCard = (type, pointsId) => {
2991
- hasUserSelectedRef.current = true;
2992
- selectCard(type);
2993
- setSelectedPointsId(pointsId ?? null);
2994
- };
2995
- useEffect(() => {
2996
- var _a, _b;
2997
- if (!defaultRewardCard) return;
2998
- if (hasUserSelectedRef.current) return;
2999
- if (cards.length === 0) return;
3000
- const applyKey = `${defaultRewardCard}:${defaultPointId ?? ""}`;
3001
- if (appliedDefaultKeyRef.current === applyKey) return;
3002
- const visibleDefaultCard = cards.find(
3003
- (card) => card.visible && card.type === defaultRewardCard
3004
- );
3005
- if (!visibleDefaultCard) {
3006
- appliedDefaultKeyRef.current = applyKey;
3007
- return;
3008
- }
3009
- selectCard(defaultRewardCard);
3010
- if (defaultRewardCard === USER_CENTER_REWARD_CARD_TYPES.Points) {
3011
- const matchedPointsCard = cards.find(
3012
- (card) => {
3013
- var _a2;
3014
- return card.type === USER_CENTER_REWARD_CARD_TYPES.Points && ((_a2 = card.pointsData) == null ? void 0 : _a2.points_id) === defaultPointId;
3015
- }
3016
- );
3017
- if (((_a = matchedPointsCard == null ? void 0 : matchedPointsCard.pointsData) == null ? void 0 : _a.points_id) != null) {
3018
- setSelectedPointsId(matchedPointsCard.pointsData.points_id);
3019
- } else if (((_b = visibleDefaultCard.pointsData) == null ? void 0 : _b.points_id) != null) {
3020
- setSelectedPointsId(visibleDefaultCard.pointsData.points_id);
3021
- }
3022
- } else {
3023
- setSelectedPointsId(null);
3024
- }
3025
- appliedDefaultKeyRef.current = applyKey;
3026
- }, [cards, defaultPointId, defaultRewardCard, selectCard]);
3027
- useEffect(() => {
3028
- if (selectedCard !== USER_CENTER_REWARD_CARD_TYPES.Token) {
3029
- setViewingFrozenToken(null);
3030
- }
3031
- }, [selectedCard]);
3032
- if (rewardsLoading && cards.length === 0) {
3033
- return /* @__PURE__ */ jsx(LoadingState, { message: t("loading") });
3034
- }
3035
- if (rewardsError && cards.length === 0) {
3036
- return /* @__PURE__ */ jsx("div", { className: "taskon-user-center-error", children: /* @__PURE__ */ jsx("p", { className: "taskon-user-center-error__message", children: rewardsError.message }) });
3037
- }
3038
- const hasVisibleCards = cards.some((c) => c.visible);
3039
- if (!rewardsLoading && !hasVisibleCards) {
3040
- return /* @__PURE__ */ jsx(EmptyState, { message: t("empty_rewards") });
3041
- }
3042
- const renderSelectedContent = () => {
3043
- switch (selectedCard) {
3044
- case USER_CENTER_REWARD_CARD_TYPES.Token:
3045
- return /* @__PURE__ */ jsx(
3046
- TokenRewardContent,
3047
- {
3048
- tokenAssets,
3049
- tokenAssetsLoading,
3050
- tokenAssetsError,
3051
- pendingWithdrawals,
3052
- tokenHistory,
3053
- tokenHistoryLoading,
3054
- tokenHistoryError,
3055
- tokenHistoryPagination,
3056
- onWithdraw: handleWithdraw,
3057
- onBatchWithdraw: handleBatchWithdraw,
3058
- onViewFrozen: handleViewFrozen,
3059
- showFrozenAssets: !!viewingFrozenToken,
3060
- frozenAssets,
3061
- frozenAssetsLoading,
3062
- frozenAssetsError,
3063
- frozenAssetsPagination,
3064
- canResendFrozenAsset: canResend,
3065
- onResendFrozenAsset: handleResendFrozenAsset,
3066
- onCloseFrozenAssets: handleCloseFrozenAssets
3067
- }
3068
- );
3069
- case USER_CENTER_REWARD_CARD_TYPES.XpLevel:
3070
- if (!selectedXpLevelData) {
3071
- return /* @__PURE__ */ jsx(EmptyState, { message: t("no_data") });
3072
- }
3073
- return /* @__PURE__ */ jsx(
3074
- XpLevelCard,
3075
- {
3076
- xpData: {
3077
- level: selectedXpLevelData.level,
3078
- currentXp: selectedXpLevelData.currentXp,
3079
- nextLevelXp: selectedXpLevelData.nextLevelXp,
3080
- totalXp: selectedXpLevelData.currentXp,
3081
- pointsName: selectedXpLevelData.xpPointsName
3082
- },
3083
- historyData: xpLevelHistory,
3084
- historyLoading: xpLevelHistoryLoading,
3085
- historyError: xpLevelHistoryError,
3086
- pagination: xpLevelHistoryPagination
3087
- }
3088
- );
3089
- case USER_CENTER_REWARD_CARD_TYPES.Nft:
3090
- return /* @__PURE__ */ jsx(
3091
- NftRewardContent,
3092
- {
3093
- nftList,
3094
- loading: nftLoading,
3095
- error: nftError,
3096
- pagination: nftPagination,
3097
- onClaimSuccess: () => {
3098
- refreshNftList();
3099
- }
3100
- }
3101
- );
3102
- case USER_CENTER_REWARD_CARD_TYPES.Whitelist:
3103
- return /* @__PURE__ */ jsx(
3104
- WhitelistTable,
3105
- {
3106
- data: whitelistList,
3107
- loading: whitelistLoading,
3108
- error: whitelistError,
3109
- pagination: whitelistPagination
3110
- }
3111
- );
3112
- case USER_CENTER_REWARD_CARD_TYPES.DiscordRole:
3113
- return /* @__PURE__ */ jsx(
3114
- DiscordRoleTable,
3115
- {
3116
- data: discordRoleList,
3117
- loading: discordRoleLoading,
3118
- error: discordRoleError,
3119
- pagination: discordRolePagination
3120
- }
3121
- );
3122
- case USER_CENTER_REWARD_CARD_TYPES.Points:
3123
- if (!selectedPointsData) {
3124
- return /* @__PURE__ */ jsx(EmptyState, { message: t("empty_points") });
3125
- }
3126
- return /* @__PURE__ */ jsx(
3127
- PointsList,
3128
- {
3129
- pointsInfo: selectedPointsData,
3130
- data: pointsHistory,
3131
- loading: pointsLoading,
3132
- error: pointsError,
3133
- pagination: pointsPagination
3134
- }
3135
- );
3136
- default:
3137
- return null;
3138
- }
3139
- };
3140
- return /* @__PURE__ */ jsxs("div", { className: "taskon-my-rewards", children: [
3141
- /* @__PURE__ */ jsx(
3142
- AssetCarousel,
3143
- {
3144
- cards,
3145
- selectedCard,
3146
- selectedPointsId,
3147
- onSelectCard: handleSelectCard
3148
- }
3149
- ),
3150
- renderSelectedContent(),
3151
- /* @__PURE__ */ jsx(
3152
- WithdrawForm,
3153
- {
3154
- open: showWithdrawForm,
3155
- tokenAssets,
3156
- tokenAssetsLoading,
3157
- initialTokenId: selectedTokenForWithdraw == null ? void 0 : selectedTokenForWithdraw.token_id,
3158
- initialChain: selectedTokenForWithdraw == null ? void 0 : selectedTokenForWithdraw.chain,
3159
- resend: resendParams ? {
3160
- nonce: resendParams.nonce,
3161
- receiverAddress: resendParams.receiverAddress
3162
- } : void 0,
3163
- resendTokenItems: resendParams ? resendParams.tokens.map((request) => {
3164
- const matchedToken = tokenAssets.find(
3165
- (token) => token.token_id === request.token_id && token.chain.toLowerCase() === request.chain.toLowerCase()
3166
- );
3167
- return {
3168
- tokenId: request.token_id,
3169
- tokenSymbol: request.token_symbol,
3170
- tokenIcon: (matchedToken == null ? void 0 : matchedToken.token_icon) ?? "",
3171
- tokenAddress: request.token_address,
3172
- tokenDecimals: request.token_decimals,
3173
- chain: request.chain,
3174
- chainLabel: (matchedToken == null ? void 0 : matchedToken.chain_label) ?? request.chain,
3175
- amount: request.token_amount,
3176
- amountInWei: toWei(
3177
- request.token_amount,
3178
- request.token_decimals
3179
- )
3180
- };
3181
- }) : void 0,
3182
- onClose: () => {
3183
- setResendParams(void 0);
3184
- setShowWithdrawForm(false);
3185
- },
3186
- onSuccess: () => {
3187
- refreshTokenAssets();
3188
- setResendParams(void 0);
3189
- setShowWithdrawForm(false);
3190
- }
3191
- }
3192
- )
3193
- ] });
3194
- }
3195
- function ActivityHistoryContent() {
3196
- const { data, loading, error, pagination, refresh } = useActivityHistory({
3197
- mode: "pagination"
3198
- });
3199
- return /* @__PURE__ */ jsx(
3200
- ActivityHistoryList,
3201
- {
3202
- data,
3203
- loading,
3204
- error,
3205
- pagination,
3206
- mode: "pagination",
3207
- onRetry: refresh
3208
- }
3209
- );
3210
- }
3211
- function mergeUserCenterConfig(props, cloud) {
3212
- const resolved = props.config ?? cloud ?? null;
3213
- const normalized = Array.isArray(resolved) && resolved.length > 0 ? resolved : null;
3214
- return {
3215
- config: normalized
3216
- };
3217
- }
3218
- const TAB_LABEL_KEYS = {
3219
- [UserCenterTabType.MyRewards]: "tab_my_rewards",
3220
- [UserCenterTabType.Identity]: "tab_identity",
3221
- [UserCenterTabType.ActivityHistory]: "tab_activity_history"
3222
- };
3223
- function UserCenterWidget(props) {
3224
- const { widgetId, themeMode } = props;
3225
- const { t } = useUserCenterLocale();
3226
- const { functionConfig, cloudTheme, isConfigLoading, configError } = useResolvedWidgetConfig(widgetId);
3227
- const mergedConfig = useMemo(() => {
3228
- return mergeUserCenterConfig(
3229
- props,
3230
- functionConfig ?? null
3231
- );
3232
- }, [props.config, functionConfig]);
3233
- const resolvedConfig = mergedConfig.config;
3234
- const isConfigured = Array.isArray(resolvedConfig) && resolvedConfig.length > 0;
3235
- return /* @__PURE__ */ jsx(
3236
- WidgetShell,
3237
- {
3238
- widgetId,
3239
- isConfigLoading,
3240
- cloudTheme,
3241
- themeMode,
3242
- className: "taskon-user-center",
3243
- errorMessage: configError ?? (!isConfigured ? t("not_configured") : void 0),
3244
- children: Array.isArray(resolvedConfig) && resolvedConfig.length > 0 ? /* @__PURE__ */ jsx(UserCenterWidgetInner, { ...props, config: resolvedConfig }) : null
3245
- }
3246
- );
3247
- }
3248
- function UserCenterWidgetInner({
3249
- config,
3250
- defaultTab,
3251
- defaultRewardCard,
3252
- defaultPointId,
3253
- onTabChange,
3254
- className = "",
3255
- style
3256
- }) {
3257
- var _a;
3258
- const { isInitializing } = useTaskOnContext();
3259
- const { t, isLoading: isLocaleLoading } = useUserCenterLocale();
3260
- const enabledTabs = useMemo(() => filterEnabledTabs(config), [config]);
3261
- const tabItems = useMemo(() => {
3262
- return enabledTabs.map((tabConfig) => ({
3263
- key: tabConfig.tab,
3264
- label: t(TAB_LABEL_KEYS[tabConfig.tab])
3265
- }));
3266
- }, [enabledTabs, t]);
3267
- const initialTab = defaultTab && enabledTabs.some((t2) => t2.tab === defaultTab) ? defaultTab : ((_a = enabledTabs[0]) == null ? void 0 : _a.tab) ?? UserCenterTabType.MyRewards;
3268
- const [activeTab, setActiveTab] = useState(initialTab);
3269
- const handleTabChange = (tab) => {
3270
- setActiveTab(tab);
3271
- onTabChange == null ? void 0 : onTabChange(tab);
3272
- };
3273
- if (isInitializing || isLocaleLoading) {
3274
- return /* @__PURE__ */ jsx("div", { className: `taskon-user-center ${className}`, style, children: /* @__PURE__ */ jsx(LoadingState, { message: t("loading") }) });
3275
- }
3276
- if (enabledTabs.length === 0) {
3277
- return /* @__PURE__ */ jsx("div", { className: `taskon-user-center ${className}`, style, children: /* @__PURE__ */ jsx("div", { className: "taskon-user-center-empty", children: t("no_data") }) });
3278
- }
3279
- return /* @__PURE__ */ jsxs("div", { className: `taskon-user-center ${className}`, style, children: [
3280
- /* @__PURE__ */ jsx(Tabs, { items: tabItems, activeKey: activeTab, onChange: handleTabChange }),
3281
- /* @__PURE__ */ jsxs("div", { className: "taskon-user-center-content", children: [
3282
- activeTab === UserCenterTabType.MyRewards && /* @__PURE__ */ jsx(
3283
- MyRewardsContent,
3284
- {
3285
- config,
3286
- defaultRewardCard,
3287
- defaultPointId
3288
- }
3289
- ),
3290
- activeTab === UserCenterTabType.Identity && /* @__PURE__ */ jsx(IdentityContent, { config }),
3291
- activeTab === UserCenterTabType.ActivityHistory && /* @__PURE__ */ jsx(ActivityHistoryContent, {})
3292
- ] })
3293
- ] });
3294
- }
3295
- export {
3296
- UserCenterWidget as U
3297
- };