@taskon/widget-react 0.0.1-beta.5 → 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.
- package/README.md +61 -47
- package/dist/CommunityTaskList.css +9 -1
- package/dist/EligibilityInfo.css +48 -75
- package/dist/LeaderboardWidget.css +73 -71
- package/dist/PageBuilder.css +5 -0
- package/dist/Quest.css +18 -14
- package/dist/TaskOnProvider.css +289 -0
- package/dist/ThemeProvider.css +227 -0
- package/dist/UserCenterWidget.css +6 -6
- package/dist/UserCenterWidget2.css +1388 -1621
- package/dist/{dynamic-import-helper.css → WidgetShell.css} +0 -227
- package/dist/chunks/{CommunityTaskList-CrMvOB8w.js → CommunityTaskList-D0uVD8wD.js} +393 -208
- package/dist/chunks/{EligibilityInfo-Beww12QX.js → EligibilityInfo-Cf6hx9-a.js} +459 -679
- package/dist/chunks/{LeaderboardWidget-DwuSpVl0.js → LeaderboardWidget-DyoiiNS6.js} +274 -252
- package/dist/chunks/{PageBuilder-DsX6Tv0N.js → PageBuilder-DoAFPm6-.js} +5 -5
- package/dist/chunks/{Quest-CuD2LElS.js → Quest-ySZlYd4u.js} +74 -57
- package/dist/chunks/TaskOnProvider-CxtFIs3n.js +2072 -0
- package/dist/chunks/{dynamic-import-helper-WmIF58Sb.js → ThemeProvider-CulHkqqY.js} +1282 -555
- package/dist/chunks/UserCenterWidget-BJsc_GSZ.js +3246 -0
- package/dist/chunks/{UserCenterWidget-CvU6K4AC.js → UserCenterWidget-STq8kpV4.js} +1174 -1386
- package/dist/chunks/WidgetShell-8xn-Jivw.js +659 -0
- package/dist/chunks/communitytask-es-CBNnS4o2.js +521 -0
- package/dist/chunks/communitytask-ja-GRf9cbdx.js +521 -0
- package/dist/chunks/communitytask-ko-Bf24PQKI.js +521 -0
- package/dist/chunks/{communitytask-ru-DhySaZL8.js → communitytask-ru-CZm2CPoV.js} +211 -1
- package/dist/chunks/leaderboardwidget-es-vKjrjQaz.js +146 -0
- package/dist/chunks/leaderboardwidget-ja-Q6u0HxKG.js +146 -0
- package/dist/chunks/leaderboardwidget-ko-CG6SWgxf.js +146 -0
- package/dist/chunks/leaderboardwidget-ru-DCcHcJGz.js +146 -0
- package/dist/chunks/{quest-es-D-b5xcme.js → quest-es-Dyyy0zaw.js} +8 -93
- package/dist/chunks/{quest-ja-Dxd2vqBF.js → quest-ja-Depog33y.js} +8 -93
- package/dist/chunks/{quest-ko-CSmRWgK_.js → quest-ko-BMu3uRQJ.js} +8 -93
- package/dist/chunks/{quest-ru-CkEKv1_F.js → quest-ru-xne814Rw.js} +8 -93
- package/dist/chunks/useIsMobile-D6Ybur-6.js +30 -0
- package/dist/chunks/useToast-BGJhd3BX.js +93 -0
- package/dist/chunks/usercenter-es-Dz3Wp2vV.js +512 -0
- package/dist/chunks/usercenter-ja-CKE4DJC6.js +512 -0
- package/dist/chunks/usercenter-ko-Dtpkn2qb.js +512 -0
- package/dist/chunks/usercenter-ru-DnBGee45.js +512 -0
- package/dist/community-task.d.ts +0 -390
- package/dist/community-task.js +2 -7
- package/dist/core.d.ts +38 -20
- package/dist/core.js +9 -10
- package/dist/index.d.ts +86 -709
- package/dist/index.js +22 -28
- package/dist/leaderboard.d.ts +0 -498
- package/dist/leaderboard.js +2 -16
- package/dist/page-builder.js +1 -1
- package/dist/quest.d.ts +0 -971
- package/dist/quest.js +2 -7
- package/dist/user-center.d.ts +0 -1610
- package/dist/user-center.js +2 -494
- package/package.json +2 -2
- package/dist/chunks/TaskOnProvider-xUeP2Nro.js +0 -1243
- package/dist/chunks/ThemeProvider-Bt4UZ33y.js +0 -1334
- package/dist/chunks/UserCenterWidget-CB0hnj-L.js +0 -3230
- package/dist/chunks/communitytask-es-1zawvXEX.js +0 -311
- package/dist/chunks/communitytask-ja-CmW6nP-L.js +0 -311
- package/dist/chunks/communitytask-ko-BD0hzQSi.js +0 -311
- package/dist/chunks/createLocaleLoader-BameiEhU.js +0 -65
- package/dist/chunks/leaderboardwidget-ja-Bj6gz6y1.js +0 -119
- package/dist/chunks/leaderboardwidget-ko-f1cLO9ic.js +0 -119
- package/dist/chunks/useToast-CaRkylKe.js +0 -304
- package/dist/chunks/usercenter-ja-B2465c1O.js +0 -326
- package/dist/chunks/usercenter-ko-xAEYxqLg.js +0 -326
|
@@ -1,1243 +0,0 @@
|
|
|
1
|
-
import { p as preloadWidgetLocale, b as useWidgetLocale, e as createContextScope, f as useComposedRefs, g as createSlot, P as Primitive, B as Branch, h as useControllableState, j as Presence, k as composeEventHandlers, l as useCallbackRef, R as Root, m as Portal, n as dispatchDiscreteCustomEvent, o as useLayoutEffect2, q as TaskOnContext } from "./ThemeProvider-Bt4UZ33y.js";
|
|
2
|
-
import { c as createLocaleLoader } from "./createLocaleLoader-BameiEhU.js";
|
|
3
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import React__default, { useState, useRef, useEffect, useMemo, useCallback } from "react";
|
|
6
|
-
import { createTaskOnClient, createUserApi, createChainApi, createCommunityTaskApi } from "@taskon/core";
|
|
7
|
-
import { c as createEthereumAdapter, W as WalletContext, b as useToastState, T as ToastContext } from "./useToast-CaRkylKe.js";
|
|
8
|
-
import * as ReactDOM from "react-dom";
|
|
9
|
-
import '../TaskOnProvider.css';const TOKEN_STORAGE_KEY = "taskon_user_token";
|
|
10
|
-
function isBrowser() {
|
|
11
|
-
return typeof window !== "undefined";
|
|
12
|
-
}
|
|
13
|
-
function getStoredToken() {
|
|
14
|
-
if (!isBrowser()) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
return localStorage.getItem(TOKEN_STORAGE_KEY);
|
|
19
|
-
} catch {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function setStoredToken(token) {
|
|
24
|
-
if (!isBrowser()) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
localStorage.setItem(TOKEN_STORAGE_KEY, token);
|
|
29
|
-
} catch {
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function removeStoredToken() {
|
|
33
|
-
if (!isBrowser()) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
localStorage.removeItem(TOKEN_STORAGE_KEY);
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function useClientInit({
|
|
42
|
-
apiKey,
|
|
43
|
-
baseURL,
|
|
44
|
-
setUserInfo,
|
|
45
|
-
setUserToken
|
|
46
|
-
}) {
|
|
47
|
-
const [client, setClient] = useState(null);
|
|
48
|
-
const userApiRef = useRef(null);
|
|
49
|
-
const [isInitializing, setIsInitializing] = useState(true);
|
|
50
|
-
const isInitializedRef = useRef(false);
|
|
51
|
-
const configRef = useRef({ apiKey, baseURL });
|
|
52
|
-
configRef.current = { apiKey, baseURL };
|
|
53
|
-
const settersRef = useRef({ setUserInfo, setUserToken });
|
|
54
|
-
settersRef.current = { setUserInfo, setUserToken };
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (isInitializedRef.current) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
isInitializedRef.current = true;
|
|
60
|
-
const init = async () => {
|
|
61
|
-
try {
|
|
62
|
-
const { apiKey: apiKey2, baseURL: baseURL2 } = configRef.current;
|
|
63
|
-
const { setUserInfo: setUserInfo2, setUserToken: setUserToken2 } = settersRef.current;
|
|
64
|
-
const taskOnClient = createTaskOnClient({
|
|
65
|
-
apiKey: apiKey2,
|
|
66
|
-
baseURL: baseURL2,
|
|
67
|
-
// Unified auth error handler - called when any API returns auth error
|
|
68
|
-
onAuthError: () => {
|
|
69
|
-
taskOnClient.setUserToken(null);
|
|
70
|
-
settersRef.current.setUserInfo(null);
|
|
71
|
-
settersRef.current.setUserToken(null);
|
|
72
|
-
removeStoredToken();
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
const userApi = createUserApi(taskOnClient);
|
|
76
|
-
setClient(taskOnClient);
|
|
77
|
-
userApiRef.current = userApi;
|
|
78
|
-
const storedToken = getStoredToken();
|
|
79
|
-
if (storedToken) {
|
|
80
|
-
try {
|
|
81
|
-
taskOnClient.setUserToken(storedToken);
|
|
82
|
-
const info = await userApi.getInfo();
|
|
83
|
-
setUserInfo2(info);
|
|
84
|
-
setUserToken2(storedToken);
|
|
85
|
-
} catch {
|
|
86
|
-
taskOnClient.setUserToken(null);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} finally {
|
|
90
|
-
setIsInitializing(false);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
init();
|
|
94
|
-
}, []);
|
|
95
|
-
return {
|
|
96
|
-
client,
|
|
97
|
-
userApiRef,
|
|
98
|
-
isInitializing
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
const registry = /* @__PURE__ */ new Map();
|
|
102
|
-
const builtInLocaleImports = {
|
|
103
|
-
CommunityTask: {
|
|
104
|
-
ko: () => import("./communitytask-ko-BD0hzQSi.js").then((module) => ({
|
|
105
|
-
default: module.default
|
|
106
|
-
})),
|
|
107
|
-
ja: () => import("./communitytask-ja-CmW6nP-L.js").then((module) => ({
|
|
108
|
-
default: module.default
|
|
109
|
-
})),
|
|
110
|
-
ru: () => import("./communitytask-ru-DhySaZL8.js").then((module) => ({
|
|
111
|
-
default: module.default
|
|
112
|
-
})),
|
|
113
|
-
es: () => import("./communitytask-es-1zawvXEX.js").then((module) => ({
|
|
114
|
-
default: module.default
|
|
115
|
-
}))
|
|
116
|
-
},
|
|
117
|
-
Quest: {
|
|
118
|
-
ko: () => import("./quest-ko-CSmRWgK_.js").then((module) => ({
|
|
119
|
-
default: module.default
|
|
120
|
-
})),
|
|
121
|
-
ja: () => import("./quest-ja-Dxd2vqBF.js").then((module) => ({
|
|
122
|
-
default: module.default
|
|
123
|
-
})),
|
|
124
|
-
ru: () => import("./quest-ru-CkEKv1_F.js").then((module) => ({
|
|
125
|
-
default: module.default
|
|
126
|
-
})),
|
|
127
|
-
es: () => import("./quest-es-D-b5xcme.js").then((module) => ({
|
|
128
|
-
default: module.default
|
|
129
|
-
}))
|
|
130
|
-
},
|
|
131
|
-
TaskWidget: {
|
|
132
|
-
ko: () => import("./taskwidget-ko-EHgXFV4B.js").then((module) => ({
|
|
133
|
-
default: module.default
|
|
134
|
-
})),
|
|
135
|
-
ja: () => import("./taskwidget-ja-CqSu-yWA.js").then((module) => ({
|
|
136
|
-
default: module.default
|
|
137
|
-
})),
|
|
138
|
-
ru: () => import("./taskwidget-ru-CMbLQDK4.js").then((module) => ({
|
|
139
|
-
default: module.default
|
|
140
|
-
})),
|
|
141
|
-
es: () => import("./taskwidget-es-Do9b3Mqw.js").then((module) => ({
|
|
142
|
-
default: module.default
|
|
143
|
-
}))
|
|
144
|
-
},
|
|
145
|
-
LeaderboardWidget: {
|
|
146
|
-
ko: () => import("./leaderboardwidget-ko-f1cLO9ic.js").then((module) => ({
|
|
147
|
-
default: module.default
|
|
148
|
-
})),
|
|
149
|
-
ja: () => import("./leaderboardwidget-ja-Bj6gz6y1.js").then((module) => ({
|
|
150
|
-
default: module.default
|
|
151
|
-
}))
|
|
152
|
-
},
|
|
153
|
-
UserCenterWidget: {
|
|
154
|
-
ko: () => import("./usercenter-ko-xAEYxqLg.js").then((module) => ({
|
|
155
|
-
default: module.default
|
|
156
|
-
})),
|
|
157
|
-
ja: () => import("./usercenter-ja-B2465c1O.js").then((module) => ({
|
|
158
|
-
default: module.default
|
|
159
|
-
}))
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
async function preloadBuiltInWidgetLocale(widget, locale) {
|
|
163
|
-
if (locale === "en") return;
|
|
164
|
-
const localeLoader = builtInLocaleImports[widget][locale];
|
|
165
|
-
if (!localeLoader) return;
|
|
166
|
-
await preloadWidgetLocale(widget, locale, () => localeLoader());
|
|
167
|
-
}
|
|
168
|
-
const builtInPreloaders = {
|
|
169
|
-
CommunityTask: (locale) => preloadBuiltInWidgetLocale("CommunityTask", locale),
|
|
170
|
-
Quest: (locale) => preloadBuiltInWidgetLocale("Quest", locale),
|
|
171
|
-
TaskWidget: (locale) => preloadBuiltInWidgetLocale("TaskWidget", locale),
|
|
172
|
-
LeaderboardWidget: (locale) => preloadBuiltInWidgetLocale("LeaderboardWidget", locale),
|
|
173
|
-
UserCenterWidget: (locale) => preloadBuiltInWidgetLocale("UserCenterWidget", locale)
|
|
174
|
-
};
|
|
175
|
-
async function preloadWidgets(widgets, locale) {
|
|
176
|
-
const preloadPromises = widgets.map((name) => {
|
|
177
|
-
const preloadFn = registry.get(name) ?? builtInPreloaders[name];
|
|
178
|
-
if (!preloadFn) {
|
|
179
|
-
if (process.env.NODE_ENV !== "production") {
|
|
180
|
-
console.warn(
|
|
181
|
-
`[widget-react] Widget "${name}" not found in registry. Make sure this widget has a preload loader configured.`
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
return preloadFn(locale);
|
|
187
|
-
}).filter(Boolean);
|
|
188
|
-
await Promise.all(preloadPromises);
|
|
189
|
-
}
|
|
190
|
-
const loading = "Loading...";
|
|
191
|
-
const error = "Something went wrong";
|
|
192
|
-
const retry = "Retry";
|
|
193
|
-
const success = "Success";
|
|
194
|
-
const cancel = "Cancel";
|
|
195
|
-
const confirm = "Confirm";
|
|
196
|
-
const enMessages = {
|
|
197
|
-
loading,
|
|
198
|
-
error,
|
|
199
|
-
retry,
|
|
200
|
-
success,
|
|
201
|
-
cancel,
|
|
202
|
-
confirm
|
|
203
|
-
};
|
|
204
|
-
const loadMessages = createLocaleLoader(enMessages, {
|
|
205
|
-
ko: () => import("./common-ko-80ezXsMG.js").then((m) => ({ default: m.default })),
|
|
206
|
-
ja: () => import("./common-ja-DWhTaFHb.js").then((m) => ({ default: m.default }))
|
|
207
|
-
});
|
|
208
|
-
function useCommonLocale() {
|
|
209
|
-
return useWidgetLocale({
|
|
210
|
-
widgetId: "Common",
|
|
211
|
-
defaultMessages: enMessages,
|
|
212
|
-
loadMessages
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
const SUPPORTED_LOCALES = ["en", "ko", "ja", "ru", "es"];
|
|
216
|
-
const DEFAULT_LOCALE = "en";
|
|
217
|
-
function detectLocale() {
|
|
218
|
-
if (typeof window === "undefined") {
|
|
219
|
-
return DEFAULT_LOCALE;
|
|
220
|
-
}
|
|
221
|
-
const browserLang = navigator.language.split("-")[0];
|
|
222
|
-
if (SUPPORTED_LOCALES.includes(browserLang)) {
|
|
223
|
-
return browserLang;
|
|
224
|
-
}
|
|
225
|
-
return DEFAULT_LOCALE;
|
|
226
|
-
}
|
|
227
|
-
function useLocaleManager({
|
|
228
|
-
configLocale,
|
|
229
|
-
preloadLocales
|
|
230
|
-
}) {
|
|
231
|
-
const [isPreloading, setIsPreloading] = useState(
|
|
232
|
-
() => preloadLocales !== void 0 && preloadLocales.length > 0
|
|
233
|
-
);
|
|
234
|
-
const preloadLocalesRef = useRef(preloadLocales);
|
|
235
|
-
preloadLocalesRef.current = preloadLocales;
|
|
236
|
-
const locale = useMemo(() => {
|
|
237
|
-
return configLocale ?? detectLocale();
|
|
238
|
-
}, [configLocale]);
|
|
239
|
-
useEffect(() => {
|
|
240
|
-
const widgets = preloadLocalesRef.current;
|
|
241
|
-
if (!widgets || widgets.length === 0) {
|
|
242
|
-
setIsPreloading(false);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
if (locale === "en") {
|
|
246
|
-
setIsPreloading(false);
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
let isMounted = true;
|
|
250
|
-
preloadWidgets(widgets, locale).finally(() => {
|
|
251
|
-
if (isMounted) {
|
|
252
|
-
setIsPreloading(false);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
return () => {
|
|
256
|
-
isMounted = false;
|
|
257
|
-
};
|
|
258
|
-
}, [locale]);
|
|
259
|
-
return {
|
|
260
|
-
locale,
|
|
261
|
-
isPreloading
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
const LOGIN_METHOD_MAP = {
|
|
265
|
-
evm_wallet: {
|
|
266
|
-
apiMethod: "loginWithEvm",
|
|
267
|
-
buildParams: (value, sign, timestamp) => ({ address: value, sign, timestamp })
|
|
268
|
-
},
|
|
269
|
-
email: {
|
|
270
|
-
apiMethod: "loginWithEmail",
|
|
271
|
-
buildParams: (value, sign, timestamp) => ({ email: value, sign, timestamp })
|
|
272
|
-
},
|
|
273
|
-
discord: {
|
|
274
|
-
apiMethod: "loginWithSns",
|
|
275
|
-
buildParams: (value, sign, timestamp) => ({ type: "Discord", token: value, sign, timestamp })
|
|
276
|
-
},
|
|
277
|
-
twitter: {
|
|
278
|
-
apiMethod: "loginWithSns",
|
|
279
|
-
buildParams: (value, sign, timestamp) => ({ type: "Twitter", token: value, sign, timestamp })
|
|
280
|
-
},
|
|
281
|
-
telegram: {
|
|
282
|
-
apiMethod: "loginWithSns",
|
|
283
|
-
buildParams: (value, sign, timestamp) => ({ type: "Telegram", token: value, sign, timestamp })
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
function useAuth({
|
|
287
|
-
client,
|
|
288
|
-
userApiRef,
|
|
289
|
-
setUserInfo,
|
|
290
|
-
setUserToken
|
|
291
|
-
}) {
|
|
292
|
-
const setToken = useCallback(
|
|
293
|
-
(token) => {
|
|
294
|
-
if (!client) {
|
|
295
|
-
throw new Error("TaskOn client not initialized");
|
|
296
|
-
}
|
|
297
|
-
client.setUserToken(token);
|
|
298
|
-
setUserToken(token);
|
|
299
|
-
setStoredToken(token);
|
|
300
|
-
},
|
|
301
|
-
[client, setUserToken]
|
|
302
|
-
);
|
|
303
|
-
const login = useCallback(
|
|
304
|
-
async (params) => {
|
|
305
|
-
const userApi = userApiRef.current;
|
|
306
|
-
if (!userApi) {
|
|
307
|
-
throw new Error("TaskOn client not initialized");
|
|
308
|
-
}
|
|
309
|
-
const { method, value, sign, timestamp } = params;
|
|
310
|
-
const methodConfig = LOGIN_METHOD_MAP[method];
|
|
311
|
-
if (!methodConfig) {
|
|
312
|
-
throw new Error(`Unsupported login method: ${method}`);
|
|
313
|
-
}
|
|
314
|
-
const apiParams = methodConfig.buildParams(value, sign, timestamp);
|
|
315
|
-
const result = await userApi[methodConfig.apiMethod](apiParams);
|
|
316
|
-
setToken(result.token);
|
|
317
|
-
try {
|
|
318
|
-
const info = await userApi.getInfo();
|
|
319
|
-
setUserInfo(info);
|
|
320
|
-
} catch {
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
[userApiRef, setToken, setUserInfo]
|
|
324
|
-
);
|
|
325
|
-
const logout = useCallback(() => {
|
|
326
|
-
if (client) {
|
|
327
|
-
client.setUserToken(null);
|
|
328
|
-
}
|
|
329
|
-
setUserInfo(null);
|
|
330
|
-
setUserToken(null);
|
|
331
|
-
removeStoredToken();
|
|
332
|
-
}, [client, setUserInfo, setUserToken]);
|
|
333
|
-
return { login, logout };
|
|
334
|
-
}
|
|
335
|
-
function WalletProvider({
|
|
336
|
-
children,
|
|
337
|
-
config
|
|
338
|
-
}) {
|
|
339
|
-
const [state, setState] = useState({
|
|
340
|
-
adapter: (config == null ? void 0 : config.evmAdapter) ?? null,
|
|
341
|
-
address: null,
|
|
342
|
-
chainId: null
|
|
343
|
-
});
|
|
344
|
-
useEffect(() => {
|
|
345
|
-
if ((config == null ? void 0 : config.evmAdapter) || (config == null ? void 0 : config.disableAutoDetect)) return;
|
|
346
|
-
const ethereumAdapter = createEthereumAdapter();
|
|
347
|
-
if (ethereumAdapter) {
|
|
348
|
-
setState((prev) => ({
|
|
349
|
-
...prev,
|
|
350
|
-
adapter: ethereumAdapter
|
|
351
|
-
}));
|
|
352
|
-
}
|
|
353
|
-
}, [config == null ? void 0 : config.evmAdapter, config == null ? void 0 : config.disableAutoDetect]);
|
|
354
|
-
const contextValue = useMemo(
|
|
355
|
-
() => ({
|
|
356
|
-
evmAdapter: state.adapter,
|
|
357
|
-
evmAddress: state.address,
|
|
358
|
-
evmChainId: state.chainId,
|
|
359
|
-
isEvmConnected: state.address !== null,
|
|
360
|
-
isDetecting: false,
|
|
361
|
-
// Actions - delegate to adapter
|
|
362
|
-
connectEvm: async () => {
|
|
363
|
-
if (!state.adapter) return null;
|
|
364
|
-
try {
|
|
365
|
-
const address = await state.adapter.connect();
|
|
366
|
-
setState((prev) => {
|
|
367
|
-
var _a, _b;
|
|
368
|
-
return {
|
|
369
|
-
...prev,
|
|
370
|
-
address,
|
|
371
|
-
chainId: ((_b = (_a = state.adapter) == null ? void 0 : _a.getChainId) == null ? void 0 : _b.call(_a)) ?? null
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
return address;
|
|
375
|
-
} catch {
|
|
376
|
-
return null;
|
|
377
|
-
}
|
|
378
|
-
},
|
|
379
|
-
disconnectEvm: async () => {
|
|
380
|
-
var _a;
|
|
381
|
-
await ((_a = state.adapter) == null ? void 0 : _a.disconnect());
|
|
382
|
-
setState((prev) => ({
|
|
383
|
-
...prev,
|
|
384
|
-
address: null
|
|
385
|
-
}));
|
|
386
|
-
},
|
|
387
|
-
signEvmMessage: async (message) => {
|
|
388
|
-
if (!state.adapter) return null;
|
|
389
|
-
try {
|
|
390
|
-
return await state.adapter.signMessage(message);
|
|
391
|
-
} catch {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}),
|
|
396
|
-
[state]
|
|
397
|
-
);
|
|
398
|
-
return /* @__PURE__ */ jsx(WalletContext.Provider, { value: contextValue, children });
|
|
399
|
-
}
|
|
400
|
-
function createCollection(name) {
|
|
401
|
-
const PROVIDER_NAME2 = name + "CollectionProvider";
|
|
402
|
-
const [createCollectionContext, createCollectionScope2] = createContextScope(PROVIDER_NAME2);
|
|
403
|
-
const [CollectionProviderImpl, useCollectionContext] = createCollectionContext(
|
|
404
|
-
PROVIDER_NAME2,
|
|
405
|
-
{ collectionRef: { current: null }, itemMap: /* @__PURE__ */ new Map() }
|
|
406
|
-
);
|
|
407
|
-
const CollectionProvider = (props) => {
|
|
408
|
-
const { scope, children } = props;
|
|
409
|
-
const ref = React__default.useRef(null);
|
|
410
|
-
const itemMap = React__default.useRef(/* @__PURE__ */ new Map()).current;
|
|
411
|
-
return /* @__PURE__ */ jsx(CollectionProviderImpl, { scope, itemMap, collectionRef: ref, children });
|
|
412
|
-
};
|
|
413
|
-
CollectionProvider.displayName = PROVIDER_NAME2;
|
|
414
|
-
const COLLECTION_SLOT_NAME = name + "CollectionSlot";
|
|
415
|
-
const CollectionSlotImpl = createSlot(COLLECTION_SLOT_NAME);
|
|
416
|
-
const CollectionSlot = React__default.forwardRef(
|
|
417
|
-
(props, forwardedRef) => {
|
|
418
|
-
const { scope, children } = props;
|
|
419
|
-
const context = useCollectionContext(COLLECTION_SLOT_NAME, scope);
|
|
420
|
-
const composedRefs = useComposedRefs(forwardedRef, context.collectionRef);
|
|
421
|
-
return /* @__PURE__ */ jsx(CollectionSlotImpl, { ref: composedRefs, children });
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
CollectionSlot.displayName = COLLECTION_SLOT_NAME;
|
|
425
|
-
const ITEM_SLOT_NAME = name + "CollectionItemSlot";
|
|
426
|
-
const ITEM_DATA_ATTR = "data-radix-collection-item";
|
|
427
|
-
const CollectionItemSlotImpl = createSlot(ITEM_SLOT_NAME);
|
|
428
|
-
const CollectionItemSlot = React__default.forwardRef(
|
|
429
|
-
(props, forwardedRef) => {
|
|
430
|
-
const { scope, children, ...itemData } = props;
|
|
431
|
-
const ref = React__default.useRef(null);
|
|
432
|
-
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
433
|
-
const context = useCollectionContext(ITEM_SLOT_NAME, scope);
|
|
434
|
-
React__default.useEffect(() => {
|
|
435
|
-
context.itemMap.set(ref, { ref, ...itemData });
|
|
436
|
-
return () => void context.itemMap.delete(ref);
|
|
437
|
-
});
|
|
438
|
-
return /* @__PURE__ */ jsx(CollectionItemSlotImpl, { ...{ [ITEM_DATA_ATTR]: "" }, ref: composedRefs, children });
|
|
439
|
-
}
|
|
440
|
-
);
|
|
441
|
-
CollectionItemSlot.displayName = ITEM_SLOT_NAME;
|
|
442
|
-
function useCollection2(scope) {
|
|
443
|
-
const context = useCollectionContext(name + "CollectionConsumer", scope);
|
|
444
|
-
const getItems = React__default.useCallback(() => {
|
|
445
|
-
const collectionNode = context.collectionRef.current;
|
|
446
|
-
if (!collectionNode) return [];
|
|
447
|
-
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${ITEM_DATA_ATTR}]`));
|
|
448
|
-
const items = Array.from(context.itemMap.values());
|
|
449
|
-
const orderedItems = items.sort(
|
|
450
|
-
(a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current)
|
|
451
|
-
);
|
|
452
|
-
return orderedItems;
|
|
453
|
-
}, [context.collectionRef, context.itemMap]);
|
|
454
|
-
return getItems;
|
|
455
|
-
}
|
|
456
|
-
return [
|
|
457
|
-
{ Provider: CollectionProvider, Slot: CollectionSlot, ItemSlot: CollectionItemSlot },
|
|
458
|
-
useCollection2,
|
|
459
|
-
createCollectionScope2
|
|
460
|
-
];
|
|
461
|
-
}
|
|
462
|
-
var VISUALLY_HIDDEN_STYLES = Object.freeze({
|
|
463
|
-
// See: https://github.com/twbs/bootstrap/blob/main/scss/mixins/_visually-hidden.scss
|
|
464
|
-
position: "absolute",
|
|
465
|
-
border: 0,
|
|
466
|
-
width: 1,
|
|
467
|
-
height: 1,
|
|
468
|
-
padding: 0,
|
|
469
|
-
margin: -1,
|
|
470
|
-
overflow: "hidden",
|
|
471
|
-
clip: "rect(0, 0, 0, 0)",
|
|
472
|
-
whiteSpace: "nowrap",
|
|
473
|
-
wordWrap: "normal"
|
|
474
|
-
});
|
|
475
|
-
var NAME = "VisuallyHidden";
|
|
476
|
-
var VisuallyHidden = React.forwardRef(
|
|
477
|
-
(props, forwardedRef) => {
|
|
478
|
-
return /* @__PURE__ */ jsx(
|
|
479
|
-
Primitive.span,
|
|
480
|
-
{
|
|
481
|
-
...props,
|
|
482
|
-
ref: forwardedRef,
|
|
483
|
-
style: { ...VISUALLY_HIDDEN_STYLES, ...props.style }
|
|
484
|
-
}
|
|
485
|
-
);
|
|
486
|
-
}
|
|
487
|
-
);
|
|
488
|
-
VisuallyHidden.displayName = NAME;
|
|
489
|
-
var PROVIDER_NAME = "ToastProvider";
|
|
490
|
-
var [Collection, useCollection, createCollectionScope] = createCollection("Toast");
|
|
491
|
-
var [createToastContext] = createContextScope("Toast", [createCollectionScope]);
|
|
492
|
-
var [ToastProviderProvider, useToastProviderContext] = createToastContext(PROVIDER_NAME);
|
|
493
|
-
var ToastProvider$1 = (props) => {
|
|
494
|
-
const {
|
|
495
|
-
__scopeToast,
|
|
496
|
-
label = "Notification",
|
|
497
|
-
duration = 5e3,
|
|
498
|
-
swipeDirection = "right",
|
|
499
|
-
swipeThreshold = 50,
|
|
500
|
-
children
|
|
501
|
-
} = props;
|
|
502
|
-
const [viewport, setViewport] = React.useState(null);
|
|
503
|
-
const [toastCount, setToastCount] = React.useState(0);
|
|
504
|
-
const isFocusedToastEscapeKeyDownRef = React.useRef(false);
|
|
505
|
-
const isClosePausedRef = React.useRef(false);
|
|
506
|
-
if (!label.trim()) {
|
|
507
|
-
console.error(
|
|
508
|
-
`Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
return /* @__PURE__ */ jsx(Collection.Provider, { scope: __scopeToast, children: /* @__PURE__ */ jsx(
|
|
512
|
-
ToastProviderProvider,
|
|
513
|
-
{
|
|
514
|
-
scope: __scopeToast,
|
|
515
|
-
label,
|
|
516
|
-
duration,
|
|
517
|
-
swipeDirection,
|
|
518
|
-
swipeThreshold,
|
|
519
|
-
toastCount,
|
|
520
|
-
viewport,
|
|
521
|
-
onViewportChange: setViewport,
|
|
522
|
-
onToastAdd: React.useCallback(() => setToastCount((prevCount) => prevCount + 1), []),
|
|
523
|
-
onToastRemove: React.useCallback(() => setToastCount((prevCount) => prevCount - 1), []),
|
|
524
|
-
isFocusedToastEscapeKeyDownRef,
|
|
525
|
-
isClosePausedRef,
|
|
526
|
-
children
|
|
527
|
-
}
|
|
528
|
-
) });
|
|
529
|
-
};
|
|
530
|
-
ToastProvider$1.displayName = PROVIDER_NAME;
|
|
531
|
-
var VIEWPORT_NAME = "ToastViewport";
|
|
532
|
-
var VIEWPORT_DEFAULT_HOTKEY = ["F8"];
|
|
533
|
-
var VIEWPORT_PAUSE = "toast.viewportPause";
|
|
534
|
-
var VIEWPORT_RESUME = "toast.viewportResume";
|
|
535
|
-
var ToastViewport$1 = React.forwardRef(
|
|
536
|
-
(props, forwardedRef) => {
|
|
537
|
-
const {
|
|
538
|
-
__scopeToast,
|
|
539
|
-
hotkey = VIEWPORT_DEFAULT_HOTKEY,
|
|
540
|
-
label = "Notifications ({hotkey})",
|
|
541
|
-
...viewportProps
|
|
542
|
-
} = props;
|
|
543
|
-
const context = useToastProviderContext(VIEWPORT_NAME, __scopeToast);
|
|
544
|
-
const getItems = useCollection(__scopeToast);
|
|
545
|
-
const wrapperRef = React.useRef(null);
|
|
546
|
-
const headFocusProxyRef = React.useRef(null);
|
|
547
|
-
const tailFocusProxyRef = React.useRef(null);
|
|
548
|
-
const ref = React.useRef(null);
|
|
549
|
-
const composedRefs = useComposedRefs(forwardedRef, ref, context.onViewportChange);
|
|
550
|
-
const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
|
|
551
|
-
const hasToasts = context.toastCount > 0;
|
|
552
|
-
React.useEffect(() => {
|
|
553
|
-
const handleKeyDown = (event) => {
|
|
554
|
-
var _a;
|
|
555
|
-
const isHotkeyPressed = hotkey.length !== 0 && hotkey.every((key) => event[key] || event.code === key);
|
|
556
|
-
if (isHotkeyPressed) (_a = ref.current) == null ? void 0 : _a.focus();
|
|
557
|
-
};
|
|
558
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
559
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
560
|
-
}, [hotkey]);
|
|
561
|
-
React.useEffect(() => {
|
|
562
|
-
const wrapper = wrapperRef.current;
|
|
563
|
-
const viewport = ref.current;
|
|
564
|
-
if (hasToasts && wrapper && viewport) {
|
|
565
|
-
const handlePause = () => {
|
|
566
|
-
if (!context.isClosePausedRef.current) {
|
|
567
|
-
const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
|
|
568
|
-
viewport.dispatchEvent(pauseEvent);
|
|
569
|
-
context.isClosePausedRef.current = true;
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
const handleResume = () => {
|
|
573
|
-
if (context.isClosePausedRef.current) {
|
|
574
|
-
const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
|
|
575
|
-
viewport.dispatchEvent(resumeEvent);
|
|
576
|
-
context.isClosePausedRef.current = false;
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
const handleFocusOutResume = (event) => {
|
|
580
|
-
const isFocusMovingOutside = !wrapper.contains(event.relatedTarget);
|
|
581
|
-
if (isFocusMovingOutside) handleResume();
|
|
582
|
-
};
|
|
583
|
-
const handlePointerLeaveResume = () => {
|
|
584
|
-
const isFocusInside = wrapper.contains(document.activeElement);
|
|
585
|
-
if (!isFocusInside) handleResume();
|
|
586
|
-
};
|
|
587
|
-
wrapper.addEventListener("focusin", handlePause);
|
|
588
|
-
wrapper.addEventListener("focusout", handleFocusOutResume);
|
|
589
|
-
wrapper.addEventListener("pointermove", handlePause);
|
|
590
|
-
wrapper.addEventListener("pointerleave", handlePointerLeaveResume);
|
|
591
|
-
window.addEventListener("blur", handlePause);
|
|
592
|
-
window.addEventListener("focus", handleResume);
|
|
593
|
-
return () => {
|
|
594
|
-
wrapper.removeEventListener("focusin", handlePause);
|
|
595
|
-
wrapper.removeEventListener("focusout", handleFocusOutResume);
|
|
596
|
-
wrapper.removeEventListener("pointermove", handlePause);
|
|
597
|
-
wrapper.removeEventListener("pointerleave", handlePointerLeaveResume);
|
|
598
|
-
window.removeEventListener("blur", handlePause);
|
|
599
|
-
window.removeEventListener("focus", handleResume);
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
}, [hasToasts, context.isClosePausedRef]);
|
|
603
|
-
const getSortedTabbableCandidates = React.useCallback(
|
|
604
|
-
({ tabbingDirection }) => {
|
|
605
|
-
const toastItems = getItems();
|
|
606
|
-
const tabbableCandidates = toastItems.map((toastItem) => {
|
|
607
|
-
const toastNode = toastItem.ref.current;
|
|
608
|
-
const toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)];
|
|
609
|
-
return tabbingDirection === "forwards" ? toastTabbableCandidates : toastTabbableCandidates.reverse();
|
|
610
|
-
});
|
|
611
|
-
return (tabbingDirection === "forwards" ? tabbableCandidates.reverse() : tabbableCandidates).flat();
|
|
612
|
-
},
|
|
613
|
-
[getItems]
|
|
614
|
-
);
|
|
615
|
-
React.useEffect(() => {
|
|
616
|
-
const viewport = ref.current;
|
|
617
|
-
if (viewport) {
|
|
618
|
-
const handleKeyDown = (event) => {
|
|
619
|
-
var _a, _b, _c;
|
|
620
|
-
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
621
|
-
const isTabKey = event.key === "Tab" && !isMetaKey;
|
|
622
|
-
if (isTabKey) {
|
|
623
|
-
const focusedElement = document.activeElement;
|
|
624
|
-
const isTabbingBackwards = event.shiftKey;
|
|
625
|
-
const targetIsViewport = event.target === viewport;
|
|
626
|
-
if (targetIsViewport && isTabbingBackwards) {
|
|
627
|
-
(_a = headFocusProxyRef.current) == null ? void 0 : _a.focus();
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
|
|
631
|
-
const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection });
|
|
632
|
-
const index = sortedCandidates.findIndex((candidate) => candidate === focusedElement);
|
|
633
|
-
if (focusFirst(sortedCandidates.slice(index + 1))) {
|
|
634
|
-
event.preventDefault();
|
|
635
|
-
} else {
|
|
636
|
-
isTabbingBackwards ? (_b = headFocusProxyRef.current) == null ? void 0 : _b.focus() : (_c = tailFocusProxyRef.current) == null ? void 0 : _c.focus();
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
viewport.addEventListener("keydown", handleKeyDown);
|
|
641
|
-
return () => viewport.removeEventListener("keydown", handleKeyDown);
|
|
642
|
-
}
|
|
643
|
-
}, [getItems, getSortedTabbableCandidates]);
|
|
644
|
-
return /* @__PURE__ */ jsxs(
|
|
645
|
-
Branch,
|
|
646
|
-
{
|
|
647
|
-
ref: wrapperRef,
|
|
648
|
-
role: "region",
|
|
649
|
-
"aria-label": label.replace("{hotkey}", hotkeyLabel),
|
|
650
|
-
tabIndex: -1,
|
|
651
|
-
style: { pointerEvents: hasToasts ? void 0 : "none" },
|
|
652
|
-
children: [
|
|
653
|
-
hasToasts && /* @__PURE__ */ jsx(
|
|
654
|
-
FocusProxy,
|
|
655
|
-
{
|
|
656
|
-
ref: headFocusProxyRef,
|
|
657
|
-
onFocusFromOutsideViewport: () => {
|
|
658
|
-
const tabbableCandidates = getSortedTabbableCandidates({
|
|
659
|
-
tabbingDirection: "forwards"
|
|
660
|
-
});
|
|
661
|
-
focusFirst(tabbableCandidates);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
),
|
|
665
|
-
/* @__PURE__ */ jsx(Collection.Slot, { scope: __scopeToast, children: /* @__PURE__ */ jsx(Primitive.ol, { tabIndex: -1, ...viewportProps, ref: composedRefs }) }),
|
|
666
|
-
hasToasts && /* @__PURE__ */ jsx(
|
|
667
|
-
FocusProxy,
|
|
668
|
-
{
|
|
669
|
-
ref: tailFocusProxyRef,
|
|
670
|
-
onFocusFromOutsideViewport: () => {
|
|
671
|
-
const tabbableCandidates = getSortedTabbableCandidates({
|
|
672
|
-
tabbingDirection: "backwards"
|
|
673
|
-
});
|
|
674
|
-
focusFirst(tabbableCandidates);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
)
|
|
678
|
-
]
|
|
679
|
-
}
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
);
|
|
683
|
-
ToastViewport$1.displayName = VIEWPORT_NAME;
|
|
684
|
-
var FOCUS_PROXY_NAME = "ToastFocusProxy";
|
|
685
|
-
var FocusProxy = React.forwardRef(
|
|
686
|
-
(props, forwardedRef) => {
|
|
687
|
-
const { __scopeToast, onFocusFromOutsideViewport, ...proxyProps } = props;
|
|
688
|
-
const context = useToastProviderContext(FOCUS_PROXY_NAME, __scopeToast);
|
|
689
|
-
return /* @__PURE__ */ jsx(
|
|
690
|
-
VisuallyHidden,
|
|
691
|
-
{
|
|
692
|
-
tabIndex: 0,
|
|
693
|
-
...proxyProps,
|
|
694
|
-
ref: forwardedRef,
|
|
695
|
-
style: { position: "fixed" },
|
|
696
|
-
onFocus: (event) => {
|
|
697
|
-
var _a;
|
|
698
|
-
const prevFocusedElement = event.relatedTarget;
|
|
699
|
-
const isFocusFromOutsideViewport = !((_a = context.viewport) == null ? void 0 : _a.contains(prevFocusedElement));
|
|
700
|
-
if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
);
|
|
704
|
-
}
|
|
705
|
-
);
|
|
706
|
-
FocusProxy.displayName = FOCUS_PROXY_NAME;
|
|
707
|
-
var TOAST_NAME = "Toast";
|
|
708
|
-
var TOAST_SWIPE_START = "toast.swipeStart";
|
|
709
|
-
var TOAST_SWIPE_MOVE = "toast.swipeMove";
|
|
710
|
-
var TOAST_SWIPE_CANCEL = "toast.swipeCancel";
|
|
711
|
-
var TOAST_SWIPE_END = "toast.swipeEnd";
|
|
712
|
-
var Toast = React.forwardRef(
|
|
713
|
-
(props, forwardedRef) => {
|
|
714
|
-
const { forceMount, open: openProp, defaultOpen, onOpenChange, ...toastProps } = props;
|
|
715
|
-
const [open, setOpen] = useControllableState({
|
|
716
|
-
prop: openProp,
|
|
717
|
-
defaultProp: defaultOpen ?? true,
|
|
718
|
-
onChange: onOpenChange,
|
|
719
|
-
caller: TOAST_NAME
|
|
720
|
-
});
|
|
721
|
-
return /* @__PURE__ */ jsx(Presence, { present: forceMount || open, children: /* @__PURE__ */ jsx(
|
|
722
|
-
ToastImpl,
|
|
723
|
-
{
|
|
724
|
-
open,
|
|
725
|
-
...toastProps,
|
|
726
|
-
ref: forwardedRef,
|
|
727
|
-
onClose: () => setOpen(false),
|
|
728
|
-
onPause: useCallbackRef(props.onPause),
|
|
729
|
-
onResume: useCallbackRef(props.onResume),
|
|
730
|
-
onSwipeStart: composeEventHandlers(props.onSwipeStart, (event) => {
|
|
731
|
-
event.currentTarget.setAttribute("data-swipe", "start");
|
|
732
|
-
}),
|
|
733
|
-
onSwipeMove: composeEventHandlers(props.onSwipeMove, (event) => {
|
|
734
|
-
const { x, y } = event.detail.delta;
|
|
735
|
-
event.currentTarget.setAttribute("data-swipe", "move");
|
|
736
|
-
event.currentTarget.style.setProperty("--radix-toast-swipe-move-x", `${x}px`);
|
|
737
|
-
event.currentTarget.style.setProperty("--radix-toast-swipe-move-y", `${y}px`);
|
|
738
|
-
}),
|
|
739
|
-
onSwipeCancel: composeEventHandlers(props.onSwipeCancel, (event) => {
|
|
740
|
-
event.currentTarget.setAttribute("data-swipe", "cancel");
|
|
741
|
-
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-x");
|
|
742
|
-
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-y");
|
|
743
|
-
event.currentTarget.style.removeProperty("--radix-toast-swipe-end-x");
|
|
744
|
-
event.currentTarget.style.removeProperty("--radix-toast-swipe-end-y");
|
|
745
|
-
}),
|
|
746
|
-
onSwipeEnd: composeEventHandlers(props.onSwipeEnd, (event) => {
|
|
747
|
-
const { x, y } = event.detail.delta;
|
|
748
|
-
event.currentTarget.setAttribute("data-swipe", "end");
|
|
749
|
-
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-x");
|
|
750
|
-
event.currentTarget.style.removeProperty("--radix-toast-swipe-move-y");
|
|
751
|
-
event.currentTarget.style.setProperty("--radix-toast-swipe-end-x", `${x}px`);
|
|
752
|
-
event.currentTarget.style.setProperty("--radix-toast-swipe-end-y", `${y}px`);
|
|
753
|
-
setOpen(false);
|
|
754
|
-
})
|
|
755
|
-
}
|
|
756
|
-
) });
|
|
757
|
-
}
|
|
758
|
-
);
|
|
759
|
-
Toast.displayName = TOAST_NAME;
|
|
760
|
-
var [ToastInteractiveProvider, useToastInteractiveContext] = createToastContext(TOAST_NAME, {
|
|
761
|
-
onClose() {
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
var ToastImpl = React.forwardRef(
|
|
765
|
-
(props, forwardedRef) => {
|
|
766
|
-
const {
|
|
767
|
-
__scopeToast,
|
|
768
|
-
type = "foreground",
|
|
769
|
-
duration: durationProp,
|
|
770
|
-
open,
|
|
771
|
-
onClose,
|
|
772
|
-
onEscapeKeyDown,
|
|
773
|
-
onPause,
|
|
774
|
-
onResume,
|
|
775
|
-
onSwipeStart,
|
|
776
|
-
onSwipeMove,
|
|
777
|
-
onSwipeCancel,
|
|
778
|
-
onSwipeEnd,
|
|
779
|
-
...toastProps
|
|
780
|
-
} = props;
|
|
781
|
-
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
782
|
-
const [node, setNode] = React.useState(null);
|
|
783
|
-
const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
|
|
784
|
-
const pointerStartRef = React.useRef(null);
|
|
785
|
-
const swipeDeltaRef = React.useRef(null);
|
|
786
|
-
const duration = durationProp || context.duration;
|
|
787
|
-
const closeTimerStartTimeRef = React.useRef(0);
|
|
788
|
-
const closeTimerRemainingTimeRef = React.useRef(duration);
|
|
789
|
-
const closeTimerRef = React.useRef(0);
|
|
790
|
-
const { onToastAdd, onToastRemove } = context;
|
|
791
|
-
const handleClose = useCallbackRef(() => {
|
|
792
|
-
var _a;
|
|
793
|
-
const isFocusInToast = node == null ? void 0 : node.contains(document.activeElement);
|
|
794
|
-
if (isFocusInToast) (_a = context.viewport) == null ? void 0 : _a.focus();
|
|
795
|
-
onClose();
|
|
796
|
-
});
|
|
797
|
-
const startTimer = React.useCallback(
|
|
798
|
-
(duration2) => {
|
|
799
|
-
if (!duration2 || duration2 === Infinity) return;
|
|
800
|
-
window.clearTimeout(closeTimerRef.current);
|
|
801
|
-
closeTimerStartTimeRef.current = (/* @__PURE__ */ new Date()).getTime();
|
|
802
|
-
closeTimerRef.current = window.setTimeout(handleClose, duration2);
|
|
803
|
-
},
|
|
804
|
-
[handleClose]
|
|
805
|
-
);
|
|
806
|
-
React.useEffect(() => {
|
|
807
|
-
const viewport = context.viewport;
|
|
808
|
-
if (viewport) {
|
|
809
|
-
const handleResume = () => {
|
|
810
|
-
startTimer(closeTimerRemainingTimeRef.current);
|
|
811
|
-
onResume == null ? void 0 : onResume();
|
|
812
|
-
};
|
|
813
|
-
const handlePause = () => {
|
|
814
|
-
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - closeTimerStartTimeRef.current;
|
|
815
|
-
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
816
|
-
window.clearTimeout(closeTimerRef.current);
|
|
817
|
-
onPause == null ? void 0 : onPause();
|
|
818
|
-
};
|
|
819
|
-
viewport.addEventListener(VIEWPORT_PAUSE, handlePause);
|
|
820
|
-
viewport.addEventListener(VIEWPORT_RESUME, handleResume);
|
|
821
|
-
return () => {
|
|
822
|
-
viewport.removeEventListener(VIEWPORT_PAUSE, handlePause);
|
|
823
|
-
viewport.removeEventListener(VIEWPORT_RESUME, handleResume);
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
}, [context.viewport, duration, onPause, onResume, startTimer]);
|
|
827
|
-
React.useEffect(() => {
|
|
828
|
-
if (open && !context.isClosePausedRef.current) startTimer(duration);
|
|
829
|
-
}, [open, duration, context.isClosePausedRef, startTimer]);
|
|
830
|
-
React.useEffect(() => {
|
|
831
|
-
onToastAdd();
|
|
832
|
-
return () => onToastRemove();
|
|
833
|
-
}, [onToastAdd, onToastRemove]);
|
|
834
|
-
const announceTextContent = React.useMemo(() => {
|
|
835
|
-
return node ? getAnnounceTextContent(node) : null;
|
|
836
|
-
}, [node]);
|
|
837
|
-
if (!context.viewport) return null;
|
|
838
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
839
|
-
announceTextContent && /* @__PURE__ */ jsx(
|
|
840
|
-
ToastAnnounce,
|
|
841
|
-
{
|
|
842
|
-
__scopeToast,
|
|
843
|
-
role: "status",
|
|
844
|
-
"aria-live": type === "foreground" ? "assertive" : "polite",
|
|
845
|
-
children: announceTextContent
|
|
846
|
-
}
|
|
847
|
-
),
|
|
848
|
-
/* @__PURE__ */ jsx(ToastInteractiveProvider, { scope: __scopeToast, onClose: handleClose, children: ReactDOM.createPortal(
|
|
849
|
-
/* @__PURE__ */ jsx(Collection.ItemSlot, { scope: __scopeToast, children: /* @__PURE__ */ jsx(
|
|
850
|
-
Root,
|
|
851
|
-
{
|
|
852
|
-
asChild: true,
|
|
853
|
-
onEscapeKeyDown: composeEventHandlers(onEscapeKeyDown, () => {
|
|
854
|
-
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
|
|
855
|
-
context.isFocusedToastEscapeKeyDownRef.current = false;
|
|
856
|
-
}),
|
|
857
|
-
children: /* @__PURE__ */ jsx(
|
|
858
|
-
Primitive.li,
|
|
859
|
-
{
|
|
860
|
-
tabIndex: 0,
|
|
861
|
-
"data-state": open ? "open" : "closed",
|
|
862
|
-
"data-swipe-direction": context.swipeDirection,
|
|
863
|
-
...toastProps,
|
|
864
|
-
ref: composedRefs,
|
|
865
|
-
style: { userSelect: "none", touchAction: "none", ...props.style },
|
|
866
|
-
onKeyDown: composeEventHandlers(props.onKeyDown, (event) => {
|
|
867
|
-
if (event.key !== "Escape") return;
|
|
868
|
-
onEscapeKeyDown == null ? void 0 : onEscapeKeyDown(event.nativeEvent);
|
|
869
|
-
if (!event.nativeEvent.defaultPrevented) {
|
|
870
|
-
context.isFocusedToastEscapeKeyDownRef.current = true;
|
|
871
|
-
handleClose();
|
|
872
|
-
}
|
|
873
|
-
}),
|
|
874
|
-
onPointerDown: composeEventHandlers(props.onPointerDown, (event) => {
|
|
875
|
-
if (event.button !== 0) return;
|
|
876
|
-
pointerStartRef.current = { x: event.clientX, y: event.clientY };
|
|
877
|
-
}),
|
|
878
|
-
onPointerMove: composeEventHandlers(props.onPointerMove, (event) => {
|
|
879
|
-
if (!pointerStartRef.current) return;
|
|
880
|
-
const x = event.clientX - pointerStartRef.current.x;
|
|
881
|
-
const y = event.clientY - pointerStartRef.current.y;
|
|
882
|
-
const hasSwipeMoveStarted = Boolean(swipeDeltaRef.current);
|
|
883
|
-
const isHorizontalSwipe = ["left", "right"].includes(context.swipeDirection);
|
|
884
|
-
const clamp = ["left", "up"].includes(context.swipeDirection) ? Math.min : Math.max;
|
|
885
|
-
const clampedX = isHorizontalSwipe ? clamp(0, x) : 0;
|
|
886
|
-
const clampedY = !isHorizontalSwipe ? clamp(0, y) : 0;
|
|
887
|
-
const moveStartBuffer = event.pointerType === "touch" ? 10 : 2;
|
|
888
|
-
const delta = { x: clampedX, y: clampedY };
|
|
889
|
-
const eventDetail = { originalEvent: event, delta };
|
|
890
|
-
if (hasSwipeMoveStarted) {
|
|
891
|
-
swipeDeltaRef.current = delta;
|
|
892
|
-
handleAndDispatchCustomEvent(TOAST_SWIPE_MOVE, onSwipeMove, eventDetail, {
|
|
893
|
-
discrete: false
|
|
894
|
-
});
|
|
895
|
-
} else if (isDeltaInDirection(delta, context.swipeDirection, moveStartBuffer)) {
|
|
896
|
-
swipeDeltaRef.current = delta;
|
|
897
|
-
handleAndDispatchCustomEvent(TOAST_SWIPE_START, onSwipeStart, eventDetail, {
|
|
898
|
-
discrete: false
|
|
899
|
-
});
|
|
900
|
-
event.target.setPointerCapture(event.pointerId);
|
|
901
|
-
} else if (Math.abs(x) > moveStartBuffer || Math.abs(y) > moveStartBuffer) {
|
|
902
|
-
pointerStartRef.current = null;
|
|
903
|
-
}
|
|
904
|
-
}),
|
|
905
|
-
onPointerUp: composeEventHandlers(props.onPointerUp, (event) => {
|
|
906
|
-
const delta = swipeDeltaRef.current;
|
|
907
|
-
const target = event.target;
|
|
908
|
-
if (target.hasPointerCapture(event.pointerId)) {
|
|
909
|
-
target.releasePointerCapture(event.pointerId);
|
|
910
|
-
}
|
|
911
|
-
swipeDeltaRef.current = null;
|
|
912
|
-
pointerStartRef.current = null;
|
|
913
|
-
if (delta) {
|
|
914
|
-
const toast = event.currentTarget;
|
|
915
|
-
const eventDetail = { originalEvent: event, delta };
|
|
916
|
-
if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) {
|
|
917
|
-
handleAndDispatchCustomEvent(TOAST_SWIPE_END, onSwipeEnd, eventDetail, {
|
|
918
|
-
discrete: true
|
|
919
|
-
});
|
|
920
|
-
} else {
|
|
921
|
-
handleAndDispatchCustomEvent(
|
|
922
|
-
TOAST_SWIPE_CANCEL,
|
|
923
|
-
onSwipeCancel,
|
|
924
|
-
eventDetail,
|
|
925
|
-
{
|
|
926
|
-
discrete: true
|
|
927
|
-
}
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
toast.addEventListener("click", (event2) => event2.preventDefault(), {
|
|
931
|
-
once: true
|
|
932
|
-
});
|
|
933
|
-
}
|
|
934
|
-
})
|
|
935
|
-
}
|
|
936
|
-
)
|
|
937
|
-
}
|
|
938
|
-
) }),
|
|
939
|
-
context.viewport
|
|
940
|
-
) })
|
|
941
|
-
] });
|
|
942
|
-
}
|
|
943
|
-
);
|
|
944
|
-
var ToastAnnounce = (props) => {
|
|
945
|
-
const { __scopeToast, children, ...announceProps } = props;
|
|
946
|
-
const context = useToastProviderContext(TOAST_NAME, __scopeToast);
|
|
947
|
-
const [renderAnnounceText, setRenderAnnounceText] = React.useState(false);
|
|
948
|
-
const [isAnnounced, setIsAnnounced] = React.useState(false);
|
|
949
|
-
useNextFrame(() => setRenderAnnounceText(true));
|
|
950
|
-
React.useEffect(() => {
|
|
951
|
-
const timer = window.setTimeout(() => setIsAnnounced(true), 1e3);
|
|
952
|
-
return () => window.clearTimeout(timer);
|
|
953
|
-
}, []);
|
|
954
|
-
return isAnnounced ? null : /* @__PURE__ */ jsx(Portal, { asChild: true, children: /* @__PURE__ */ jsx(VisuallyHidden, { ...announceProps, children: renderAnnounceText && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
955
|
-
context.label,
|
|
956
|
-
" ",
|
|
957
|
-
children
|
|
958
|
-
] }) }) });
|
|
959
|
-
};
|
|
960
|
-
var TITLE_NAME = "ToastTitle";
|
|
961
|
-
var ToastTitle = React.forwardRef(
|
|
962
|
-
(props, forwardedRef) => {
|
|
963
|
-
const { __scopeToast, ...titleProps } = props;
|
|
964
|
-
return /* @__PURE__ */ jsx(Primitive.div, { ...titleProps, ref: forwardedRef });
|
|
965
|
-
}
|
|
966
|
-
);
|
|
967
|
-
ToastTitle.displayName = TITLE_NAME;
|
|
968
|
-
var DESCRIPTION_NAME = "ToastDescription";
|
|
969
|
-
var ToastDescription = React.forwardRef(
|
|
970
|
-
(props, forwardedRef) => {
|
|
971
|
-
const { __scopeToast, ...descriptionProps } = props;
|
|
972
|
-
return /* @__PURE__ */ jsx(Primitive.div, { ...descriptionProps, ref: forwardedRef });
|
|
973
|
-
}
|
|
974
|
-
);
|
|
975
|
-
ToastDescription.displayName = DESCRIPTION_NAME;
|
|
976
|
-
var ACTION_NAME = "ToastAction";
|
|
977
|
-
var ToastAction = React.forwardRef(
|
|
978
|
-
(props, forwardedRef) => {
|
|
979
|
-
const { altText, ...actionProps } = props;
|
|
980
|
-
if (!altText.trim()) {
|
|
981
|
-
console.error(
|
|
982
|
-
`Invalid prop \`altText\` supplied to \`${ACTION_NAME}\`. Expected non-empty \`string\`.`
|
|
983
|
-
);
|
|
984
|
-
return null;
|
|
985
|
-
}
|
|
986
|
-
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { altText, asChild: true, children: /* @__PURE__ */ jsx(ToastClose, { ...actionProps, ref: forwardedRef }) });
|
|
987
|
-
}
|
|
988
|
-
);
|
|
989
|
-
ToastAction.displayName = ACTION_NAME;
|
|
990
|
-
var CLOSE_NAME = "ToastClose";
|
|
991
|
-
var ToastClose = React.forwardRef(
|
|
992
|
-
(props, forwardedRef) => {
|
|
993
|
-
const { __scopeToast, ...closeProps } = props;
|
|
994
|
-
const interactiveContext = useToastInteractiveContext(CLOSE_NAME, __scopeToast);
|
|
995
|
-
return /* @__PURE__ */ jsx(ToastAnnounceExclude, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
996
|
-
Primitive.button,
|
|
997
|
-
{
|
|
998
|
-
type: "button",
|
|
999
|
-
...closeProps,
|
|
1000
|
-
ref: forwardedRef,
|
|
1001
|
-
onClick: composeEventHandlers(props.onClick, interactiveContext.onClose)
|
|
1002
|
-
}
|
|
1003
|
-
) });
|
|
1004
|
-
}
|
|
1005
|
-
);
|
|
1006
|
-
ToastClose.displayName = CLOSE_NAME;
|
|
1007
|
-
var ToastAnnounceExclude = React.forwardRef((props, forwardedRef) => {
|
|
1008
|
-
const { __scopeToast, altText, ...announceExcludeProps } = props;
|
|
1009
|
-
return /* @__PURE__ */ jsx(
|
|
1010
|
-
Primitive.div,
|
|
1011
|
-
{
|
|
1012
|
-
"data-radix-toast-announce-exclude": "",
|
|
1013
|
-
"data-radix-toast-announce-alt": altText || void 0,
|
|
1014
|
-
...announceExcludeProps,
|
|
1015
|
-
ref: forwardedRef
|
|
1016
|
-
}
|
|
1017
|
-
);
|
|
1018
|
-
});
|
|
1019
|
-
function getAnnounceTextContent(container) {
|
|
1020
|
-
const textContent = [];
|
|
1021
|
-
const childNodes = Array.from(container.childNodes);
|
|
1022
|
-
childNodes.forEach((node) => {
|
|
1023
|
-
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
|
|
1024
|
-
if (isHTMLElement(node)) {
|
|
1025
|
-
const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
|
|
1026
|
-
const isExcluded = node.dataset.radixToastAnnounceExclude === "";
|
|
1027
|
-
if (!isHidden) {
|
|
1028
|
-
if (isExcluded) {
|
|
1029
|
-
const altText = node.dataset.radixToastAnnounceAlt;
|
|
1030
|
-
if (altText) textContent.push(altText);
|
|
1031
|
-
} else {
|
|
1032
|
-
textContent.push(...getAnnounceTextContent(node));
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1037
|
-
return textContent;
|
|
1038
|
-
}
|
|
1039
|
-
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
1040
|
-
const currentTarget = detail.originalEvent.currentTarget;
|
|
1041
|
-
const event = new CustomEvent(name, { bubbles: true, cancelable: true, detail });
|
|
1042
|
-
if (handler) currentTarget.addEventListener(name, handler, { once: true });
|
|
1043
|
-
if (discrete) {
|
|
1044
|
-
dispatchDiscreteCustomEvent(currentTarget, event);
|
|
1045
|
-
} else {
|
|
1046
|
-
currentTarget.dispatchEvent(event);
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
var isDeltaInDirection = (delta, direction, threshold = 0) => {
|
|
1050
|
-
const deltaX = Math.abs(delta.x);
|
|
1051
|
-
const deltaY = Math.abs(delta.y);
|
|
1052
|
-
const isDeltaX = deltaX > deltaY;
|
|
1053
|
-
if (direction === "left" || direction === "right") {
|
|
1054
|
-
return isDeltaX && deltaX > threshold;
|
|
1055
|
-
} else {
|
|
1056
|
-
return !isDeltaX && deltaY > threshold;
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
function useNextFrame(callback = () => {
|
|
1060
|
-
}) {
|
|
1061
|
-
const fn = useCallbackRef(callback);
|
|
1062
|
-
useLayoutEffect2(() => {
|
|
1063
|
-
let raf1 = 0;
|
|
1064
|
-
let raf2 = 0;
|
|
1065
|
-
raf1 = window.requestAnimationFrame(() => raf2 = window.requestAnimationFrame(fn));
|
|
1066
|
-
return () => {
|
|
1067
|
-
window.cancelAnimationFrame(raf1);
|
|
1068
|
-
window.cancelAnimationFrame(raf2);
|
|
1069
|
-
};
|
|
1070
|
-
}, [fn]);
|
|
1071
|
-
}
|
|
1072
|
-
function isHTMLElement(node) {
|
|
1073
|
-
return node.nodeType === node.ELEMENT_NODE;
|
|
1074
|
-
}
|
|
1075
|
-
function getTabbableCandidates(container) {
|
|
1076
|
-
const nodes = [];
|
|
1077
|
-
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
1078
|
-
acceptNode: (node) => {
|
|
1079
|
-
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
1080
|
-
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
|
|
1081
|
-
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
while (walker.nextNode()) nodes.push(walker.currentNode);
|
|
1085
|
-
return nodes;
|
|
1086
|
-
}
|
|
1087
|
-
function focusFirst(candidates) {
|
|
1088
|
-
const previouslyFocusedElement = document.activeElement;
|
|
1089
|
-
return candidates.some((candidate) => {
|
|
1090
|
-
if (candidate === previouslyFocusedElement) return true;
|
|
1091
|
-
candidate.focus();
|
|
1092
|
-
return document.activeElement !== previouslyFocusedElement;
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
var Provider = ToastProvider$1;
|
|
1096
|
-
var Viewport = ToastViewport$1;
|
|
1097
|
-
var Root2 = Toast;
|
|
1098
|
-
var Description = ToastDescription;
|
|
1099
|
-
function getToastIcon(type) {
|
|
1100
|
-
switch (type) {
|
|
1101
|
-
case "success":
|
|
1102
|
-
return "✓";
|
|
1103
|
-
case "error":
|
|
1104
|
-
return "✕";
|
|
1105
|
-
case "warning":
|
|
1106
|
-
return "⚠";
|
|
1107
|
-
case "info":
|
|
1108
|
-
default:
|
|
1109
|
-
return "ℹ";
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
function ToastItem({ toast, onOpenChange }) {
|
|
1113
|
-
return /* @__PURE__ */ jsxs(
|
|
1114
|
-
Root2,
|
|
1115
|
-
{
|
|
1116
|
-
className: `taskon-toast taskon-toast--${toast.type}`,
|
|
1117
|
-
duration: toast.duration ?? 3e3,
|
|
1118
|
-
onOpenChange,
|
|
1119
|
-
children: [
|
|
1120
|
-
/* @__PURE__ */ jsx("div", { className: "taskon-toast-icon", children: getToastIcon(toast.type) }),
|
|
1121
|
-
/* @__PURE__ */ jsx(Description, { className: "taskon-toast-message", children: toast.message })
|
|
1122
|
-
]
|
|
1123
|
-
}
|
|
1124
|
-
);
|
|
1125
|
-
}
|
|
1126
|
-
function ToastViewport({
|
|
1127
|
-
toasts,
|
|
1128
|
-
onRemove
|
|
1129
|
-
}) {
|
|
1130
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1131
|
-
toasts.map((toast) => /* @__PURE__ */ jsx(
|
|
1132
|
-
ToastItem,
|
|
1133
|
-
{
|
|
1134
|
-
toast,
|
|
1135
|
-
onOpenChange: (open) => {
|
|
1136
|
-
if (!open) {
|
|
1137
|
-
onRemove(toast.id);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
},
|
|
1141
|
-
toast.id
|
|
1142
|
-
)),
|
|
1143
|
-
/* @__PURE__ */ jsx(Viewport, { className: "taskon-toast-viewport" })
|
|
1144
|
-
] });
|
|
1145
|
-
}
|
|
1146
|
-
const ToastProvider = Provider;
|
|
1147
|
-
function TaskOnProvider({
|
|
1148
|
-
config,
|
|
1149
|
-
children,
|
|
1150
|
-
preloadLocales
|
|
1151
|
-
}) {
|
|
1152
|
-
const [userInfo, setUserInfo] = useState(null);
|
|
1153
|
-
const [userToken, setUserToken] = useState(null);
|
|
1154
|
-
const [chains, setChains] = useState([]);
|
|
1155
|
-
const [communityInfo, setCommunityInfo] = useState(null);
|
|
1156
|
-
const toastState = useToastState();
|
|
1157
|
-
const { locale } = useLocaleManager({
|
|
1158
|
-
configLocale: config.locale,
|
|
1159
|
-
preloadLocales
|
|
1160
|
-
});
|
|
1161
|
-
const { client, userApiRef, isInitializing } = useClientInit({
|
|
1162
|
-
apiKey: config.apiKey,
|
|
1163
|
-
baseURL: config.baseURL,
|
|
1164
|
-
setUserInfo,
|
|
1165
|
-
setUserToken
|
|
1166
|
-
});
|
|
1167
|
-
const { login, logout } = useAuth({
|
|
1168
|
-
client,
|
|
1169
|
-
userApiRef,
|
|
1170
|
-
setUserInfo,
|
|
1171
|
-
setUserToken
|
|
1172
|
-
});
|
|
1173
|
-
const requestLogin = useCallback(() => {
|
|
1174
|
-
var _a;
|
|
1175
|
-
(_a = config.onRequestLogin) == null ? void 0 : _a.call(config);
|
|
1176
|
-
}, [config]);
|
|
1177
|
-
const refreshUserInfo = useCallback(async () => {
|
|
1178
|
-
const userApi = userApiRef.current;
|
|
1179
|
-
if (!userApi) return;
|
|
1180
|
-
try {
|
|
1181
|
-
const info = await userApi.getInfo();
|
|
1182
|
-
setUserInfo(info);
|
|
1183
|
-
} catch {
|
|
1184
|
-
}
|
|
1185
|
-
}, [userApiRef]);
|
|
1186
|
-
useEffect(() => {
|
|
1187
|
-
if (!client) return;
|
|
1188
|
-
const loadChains = async () => {
|
|
1189
|
-
try {
|
|
1190
|
-
const chainApi = createChainApi(client);
|
|
1191
|
-
const chainList = await chainApi.getChainInfo();
|
|
1192
|
-
setChains(chainList);
|
|
1193
|
-
} catch {
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
loadChains();
|
|
1197
|
-
}, [client]);
|
|
1198
|
-
useEffect(() => {
|
|
1199
|
-
if (!client) return;
|
|
1200
|
-
const loadCommunityInfo = async () => {
|
|
1201
|
-
try {
|
|
1202
|
-
const communityTaskApi = createCommunityTaskApi(client);
|
|
1203
|
-
const info = await communityTaskApi.getCommunityInfo();
|
|
1204
|
-
setCommunityInfo(info);
|
|
1205
|
-
} catch {
|
|
1206
|
-
}
|
|
1207
|
-
};
|
|
1208
|
-
loadCommunityInfo();
|
|
1209
|
-
}, [client]);
|
|
1210
|
-
const contextValue = useMemo(
|
|
1211
|
-
() => ({
|
|
1212
|
-
config,
|
|
1213
|
-
client,
|
|
1214
|
-
isInitializing,
|
|
1215
|
-
locale,
|
|
1216
|
-
userId: (userInfo == null ? void 0 : userInfo.id) ?? null,
|
|
1217
|
-
userInfo,
|
|
1218
|
-
userToken,
|
|
1219
|
-
isLoggedIn: userInfo !== null && userToken !== null,
|
|
1220
|
-
login,
|
|
1221
|
-
logout,
|
|
1222
|
-
requestLogin,
|
|
1223
|
-
refreshUserInfo,
|
|
1224
|
-
chains,
|
|
1225
|
-
communityInfo
|
|
1226
|
-
}),
|
|
1227
|
-
[config, client, isInitializing, locale, userInfo, userToken, login, logout, requestLogin, refreshUserInfo, chains, communityInfo]
|
|
1228
|
-
);
|
|
1229
|
-
return /* @__PURE__ */ jsx(TaskOnContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(ToastContext.Provider, { value: toastState, children: /* @__PURE__ */ jsxs(ToastProvider, { children: [
|
|
1230
|
-
/* @__PURE__ */ jsx(WalletProvider, { config: config.walletConfig, children }),
|
|
1231
|
-
/* @__PURE__ */ jsx(
|
|
1232
|
-
ToastViewport,
|
|
1233
|
-
{
|
|
1234
|
-
toasts: toastState.toasts,
|
|
1235
|
-
onRemove: toastState.removeToast
|
|
1236
|
-
}
|
|
1237
|
-
)
|
|
1238
|
-
] }) }) });
|
|
1239
|
-
}
|
|
1240
|
-
export {
|
|
1241
|
-
TaskOnProvider as T,
|
|
1242
|
-
useCommonLocale as u
|
|
1243
|
-
};
|