@taskon/widget-react 0.0.1
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 +1064 -0
- package/dist/CommunityTaskList.css +5010 -0
- package/dist/EligibilityInfo.css +1966 -0
- package/dist/LeaderboardWidget.css +815 -0
- package/dist/Quest.css +4584 -0
- package/dist/Table.css +389 -0
- package/dist/TaskOnProvider.css +163 -0
- package/dist/WidgetShell.css +182 -0
- package/dist/chunks/CommunityTaskList-CrH6r4Av.js +6886 -0
- package/dist/chunks/EligibilityInfo-DesW9-k9.js +24900 -0
- package/dist/chunks/LeaderboardWidget-BSGpHKTk.js +1156 -0
- package/dist/chunks/Quest-uSIVq78I.js +8581 -0
- package/dist/chunks/Table-CWGf2FKV.js +449 -0
- package/dist/chunks/TaskOnProvider-QMwxGL44.js +1435 -0
- package/dist/chunks/ThemeProvider-Cs8IUVQj.js +1118 -0
- package/dist/chunks/WidgetShell-NlOgn1x5.js +1517 -0
- package/dist/chunks/common-ja-DWhTaFHb.js +23 -0
- package/dist/chunks/common-ko-80ezXsMG.js +23 -0
- package/dist/chunks/index-CwMvO_wZ.js +777 -0
- package/dist/chunks/leaderboardwidget-ja-Bj6gz6y1.js +119 -0
- package/dist/chunks/leaderboardwidget-ko-f1cLO9ic.js +119 -0
- package/dist/chunks/useToast-BGJhd3BX.js +93 -0
- package/dist/chunks/useWidgetLocale-BVcopbZS.js +74 -0
- package/dist/chunks/usercenter-ja-DBj_dtuz.js +329 -0
- package/dist/chunks/usercenter-ko-DYTkHAld.js +329 -0
- package/dist/community-task.d.ts +451 -0
- package/dist/community-task.js +9 -0
- package/dist/core.d.ts +803 -0
- package/dist/core.js +22 -0
- package/dist/index.css +3662 -0
- package/dist/index.d.ts +1627 -0
- package/dist/index.js +7372 -0
- package/dist/leaderboard.d.ts +547 -0
- package/dist/leaderboard.js +17 -0
- package/dist/quest.d.ts +389 -0
- package/dist/quest.js +8 -0
- package/package.json +97 -0
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
import { ChainInfo } from '@taskon/core';
|
|
2
|
+
import { CommunityInfo } from '@taskon/core';
|
|
3
|
+
import { LoginResult } from '@taskon/core';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import { RewardType } from '@taskon/core';
|
|
6
|
+
import { TaskOnClient } from '@taskon/core';
|
|
7
|
+
import { UserInfo } from '@taskon/core';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Clear the locale cache
|
|
11
|
+
* Useful for testing or when you need to force reload locales
|
|
12
|
+
*/
|
|
13
|
+
export declare function clearLocaleCache(): void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Common messages type definition
|
|
17
|
+
*
|
|
18
|
+
* These are shared messages used across multiple widgets.
|
|
19
|
+
* All language files must implement this interface.
|
|
20
|
+
*/
|
|
21
|
+
export declare interface CommonMessages {
|
|
22
|
+
/** Loading state text */
|
|
23
|
+
loading: string;
|
|
24
|
+
/** Generic error message */
|
|
25
|
+
error: string;
|
|
26
|
+
/** Retry action text */
|
|
27
|
+
retry: string;
|
|
28
|
+
/** Success message */
|
|
29
|
+
success: string;
|
|
30
|
+
/** Cancel action text */
|
|
31
|
+
cancel: string;
|
|
32
|
+
/** Confirm action text */
|
|
33
|
+
confirm: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Create a locale loader function for a widget
|
|
38
|
+
*
|
|
39
|
+
* @template T - The shape of the messages object
|
|
40
|
+
* @param defaultMessages - English messages (used as fallback)
|
|
41
|
+
* @param imports - Map of locale codes to dynamic import functions
|
|
42
|
+
* @returns A function that loads messages for a given locale
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import enMessages from './locales/en';
|
|
47
|
+
*
|
|
48
|
+
* const loadMessages = createLocaleLoader(enMessages, {
|
|
49
|
+
* ko: () => import('./locales/ko'),
|
|
50
|
+
* ja: () => import('./locales/ja'),
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function createLocaleLoader<T>(defaultMessages: T, imports: LocaleImportMap<T>): (locale: Locale) => Promise<{
|
|
55
|
+
default: T;
|
|
56
|
+
}>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create a translation function from a messages object
|
|
60
|
+
*
|
|
61
|
+
* @param messages - Object containing translation strings
|
|
62
|
+
* @returns A function that retrieves and interpolates translations
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const messages = {
|
|
67
|
+
* greeting: 'Hello, {name}!',
|
|
68
|
+
* points: 'You have {count} points',
|
|
69
|
+
* };
|
|
70
|
+
*
|
|
71
|
+
* const t = createT(messages);
|
|
72
|
+
*
|
|
73
|
+
* t('greeting', { name: 'John' }) // => 'Hello, John!'
|
|
74
|
+
* t('points', { count: 100 }) // => 'You have 100 points'
|
|
75
|
+
* t('greeting') // => 'Hello, {name}!' (no params)
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function createT<T extends Record<string, string>>(messages: T): <K extends keyof T>(key: K, params?: InterpolationParams) => string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Interpolate a string with parameters
|
|
82
|
+
*
|
|
83
|
+
* @param template - String template with {key} placeholders
|
|
84
|
+
* @param params - Object containing values to replace placeholders
|
|
85
|
+
* @returns Interpolated string
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* interpolate('Hello, {name}!', { name: 'John' })
|
|
90
|
+
* // => 'Hello, John!'
|
|
91
|
+
*
|
|
92
|
+
* interpolate('You have {count} points', { count: 100 })
|
|
93
|
+
* // => 'You have 100 points'
|
|
94
|
+
*
|
|
95
|
+
* interpolate('{a} + {b} = {result}', { a: 1, b: 2, result: 3 })
|
|
96
|
+
* // => '1 + 2 = 3'
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function interpolate(template: string, params?: InterpolationParams): string;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* interpolate - Simple string interpolation utility
|
|
103
|
+
*
|
|
104
|
+
* Replaces placeholders in the format {key} with values from the params object.
|
|
105
|
+
* This is a lightweight alternative to full i18n libraries when only simple
|
|
106
|
+
* variable replacement is needed.
|
|
107
|
+
*/
|
|
108
|
+
/**
|
|
109
|
+
* Params object type for interpolation
|
|
110
|
+
*/
|
|
111
|
+
export declare type InterpolationParams = Record<string, string | number | undefined>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Parameters for contract invocation
|
|
115
|
+
*/
|
|
116
|
+
declare interface InvokeContractParams {
|
|
117
|
+
/** Contract address */
|
|
118
|
+
contract: string;
|
|
119
|
+
/** Contract ABI (Application Binary Interface) */
|
|
120
|
+
abi: unknown[];
|
|
121
|
+
/** Method name to call */
|
|
122
|
+
method: string;
|
|
123
|
+
/** Method parameters */
|
|
124
|
+
params: unknown[];
|
|
125
|
+
/** Target chain ID (optional, will switch network if needed) */
|
|
126
|
+
chainId?: number;
|
|
127
|
+
/** Transaction value in wei (for payable methods) */
|
|
128
|
+
value?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Check if a locale has full translation support
|
|
133
|
+
*/
|
|
134
|
+
export declare function isSupportedLocale(locale: Locale): locale is SupportedLocale;
|
|
135
|
+
|
|
136
|
+
export declare type Locale = "en" | "ko" | "ja" | "ru" | "es";
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Locale import map type
|
|
140
|
+
* Maps supported locales to their dynamic import functions
|
|
141
|
+
*/
|
|
142
|
+
export declare type LocaleImportMap<T> = {
|
|
143
|
+
[K in Exclude<SupportedLocale, "en">]?: () => Promise<{
|
|
144
|
+
default: T;
|
|
145
|
+
}>;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Supported login methods
|
|
150
|
+
*/
|
|
151
|
+
export declare type LoginMethod = "evm_wallet" | "email" | "discord" | "twitter" | "telegram";
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Unified login parameters
|
|
155
|
+
*/
|
|
156
|
+
export declare interface LoginParams {
|
|
157
|
+
/** Login method */
|
|
158
|
+
method: LoginMethod;
|
|
159
|
+
/** Value: wallet address / email / OAuth token */
|
|
160
|
+
value: string;
|
|
161
|
+
/** Signature from backend */
|
|
162
|
+
sign: string;
|
|
163
|
+
/** Timestamp used for signing (seconds) */
|
|
164
|
+
timestamp: number;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { LoginResult }
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Map Token - Can override derived values
|
|
171
|
+
*/
|
|
172
|
+
export declare interface MapToken {
|
|
173
|
+
colorPrimary?: string;
|
|
174
|
+
colorPrimaryHover?: string;
|
|
175
|
+
colorPrimaryActive?: string;
|
|
176
|
+
colorPrimaryBg?: string;
|
|
177
|
+
colorSecondary?: string;
|
|
178
|
+
colorSuccess?: string;
|
|
179
|
+
colorWarning?: string;
|
|
180
|
+
colorError?: string;
|
|
181
|
+
colorBg?: string;
|
|
182
|
+
colorBgElevated?: string;
|
|
183
|
+
colorBgSpotlight?: string;
|
|
184
|
+
colorText?: string;
|
|
185
|
+
colorTextSecondary?: string;
|
|
186
|
+
colorTextTertiary?: string;
|
|
187
|
+
colorTextDisabled?: string;
|
|
188
|
+
colorBorder?: string;
|
|
189
|
+
colorBorderSecondary?: string;
|
|
190
|
+
borderRadius?: number;
|
|
191
|
+
borderRadiusSm?: number;
|
|
192
|
+
borderRadiusLg?: number;
|
|
193
|
+
fontSize?: number;
|
|
194
|
+
fontSizeSm?: number;
|
|
195
|
+
fontSizeLg?: number;
|
|
196
|
+
spacing?: number;
|
|
197
|
+
spacingXs?: number;
|
|
198
|
+
spacingSm?: number;
|
|
199
|
+
spacingMd?: number;
|
|
200
|
+
spacingLg?: number;
|
|
201
|
+
spacingXl?: number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Mode-specific configuration
|
|
206
|
+
*/
|
|
207
|
+
declare interface ModeThemeConfig {
|
|
208
|
+
seed?: SeedToken;
|
|
209
|
+
map?: MapToken;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { RewardType }
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Seed Token - Input values that auto-derive other tokens
|
|
216
|
+
*/
|
|
217
|
+
export declare interface SeedToken {
|
|
218
|
+
/** Primary color */
|
|
219
|
+
colorPrimary?: string;
|
|
220
|
+
/** Secondary color */
|
|
221
|
+
colorSecondary?: string;
|
|
222
|
+
/** Success color */
|
|
223
|
+
colorSuccess?: string;
|
|
224
|
+
/** Warning color */
|
|
225
|
+
colorWarning?: string;
|
|
226
|
+
/** Error color */
|
|
227
|
+
colorError?: string;
|
|
228
|
+
/** Base border radius */
|
|
229
|
+
borderRadius?: number;
|
|
230
|
+
/** Base font size */
|
|
231
|
+
fontSize?: number;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Locales that have full translation support in all widgets
|
|
236
|
+
* Other locales in the Locale type will fallback to English
|
|
237
|
+
*/
|
|
238
|
+
export declare type SupportedLocale = "en" | "ko" | "ja";
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* TaskOn Context value
|
|
242
|
+
*/
|
|
243
|
+
export declare interface TaskOnContextValue {
|
|
244
|
+
/**
|
|
245
|
+
* Provider configuration
|
|
246
|
+
*/
|
|
247
|
+
config: TaskOnProviderConfig;
|
|
248
|
+
/**
|
|
249
|
+
* TaskOn client instance from @taskon/core
|
|
250
|
+
*/
|
|
251
|
+
client: TaskOnClient | null;
|
|
252
|
+
/**
|
|
253
|
+
* Whether the provider is initializing
|
|
254
|
+
*/
|
|
255
|
+
isInitializing: boolean;
|
|
256
|
+
/**
|
|
257
|
+
* Resolved locale
|
|
258
|
+
*/
|
|
259
|
+
locale: Locale;
|
|
260
|
+
/**
|
|
261
|
+
* TaskOn user ID, null if not logged in
|
|
262
|
+
*/
|
|
263
|
+
userId: number | null;
|
|
264
|
+
/**
|
|
265
|
+
* Current user info, null if not logged in
|
|
266
|
+
*/
|
|
267
|
+
userInfo: UserInfo | null;
|
|
268
|
+
/**
|
|
269
|
+
* Current user token, null if not logged in
|
|
270
|
+
*/
|
|
271
|
+
userToken: string | null;
|
|
272
|
+
/**
|
|
273
|
+
* Whether user is logged in
|
|
274
|
+
*/
|
|
275
|
+
isLoggedIn: boolean;
|
|
276
|
+
/**
|
|
277
|
+
* Unified login method
|
|
278
|
+
*/
|
|
279
|
+
login: (params: LoginParams) => Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* Logout current user
|
|
282
|
+
*/
|
|
283
|
+
logout: () => void;
|
|
284
|
+
/**
|
|
285
|
+
* Request login callback
|
|
286
|
+
* Triggers config.onRequestLogin if provided
|
|
287
|
+
*/
|
|
288
|
+
requestLogin: () => void;
|
|
289
|
+
/**
|
|
290
|
+
* Refresh user info from server
|
|
291
|
+
* Call this after binding social accounts to update userInfo
|
|
292
|
+
*/
|
|
293
|
+
refreshUserInfo: () => Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Chain info list (loaded on init)
|
|
296
|
+
* Used for determining chain types for wallet binding
|
|
297
|
+
*/
|
|
298
|
+
chains: ChainInfo[];
|
|
299
|
+
/**
|
|
300
|
+
* Community info (auto-loaded on init based on apiKey)
|
|
301
|
+
* Used for displaying community logo and name in reward cards
|
|
302
|
+
*/
|
|
303
|
+
communityInfo: CommunityInfo | null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* TaskOn Provider Component
|
|
308
|
+
*
|
|
309
|
+
* Root component for TaskOn Widget, providing:
|
|
310
|
+
* - TaskOn client management (based on @taskon/core)
|
|
311
|
+
* - User authentication (login/logout)
|
|
312
|
+
* - Locale configuration
|
|
313
|
+
* - Wallet management (uses window.ethereum adapter)
|
|
314
|
+
* - Widget locale preloading (optional)
|
|
315
|
+
* - Toast notifications (internal, user-transparent)
|
|
316
|
+
*/
|
|
317
|
+
export declare function TaskOnProvider({ config, children, preloadLocales, }: TaskOnProviderProps): ReactNode;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* TaskOn Provider configuration
|
|
321
|
+
*/
|
|
322
|
+
export declare interface TaskOnProviderConfig {
|
|
323
|
+
/**
|
|
324
|
+
* API Key for authentication (X-API-Key header)
|
|
325
|
+
* Note: apiKey already contains community info, no need to configure communityId/communityKey separately
|
|
326
|
+
*/
|
|
327
|
+
apiKey: string;
|
|
328
|
+
/**
|
|
329
|
+
* API base URL (optional)
|
|
330
|
+
* @default https://white-label-api.taskon.xyz
|
|
331
|
+
*/
|
|
332
|
+
baseURL?: string;
|
|
333
|
+
/**
|
|
334
|
+
* Locale setting for internationalization
|
|
335
|
+
* @default auto-detect from browser
|
|
336
|
+
*/
|
|
337
|
+
locale?: Locale;
|
|
338
|
+
/**
|
|
339
|
+
* Wallet configuration for blockchain interactions
|
|
340
|
+
*
|
|
341
|
+
* When not provided, TaskOn will use built-in window.ethereum adapter
|
|
342
|
+
* for EVM wallet connections (MetaMask, etc.)
|
|
343
|
+
*/
|
|
344
|
+
walletConfig?: WalletConfig;
|
|
345
|
+
/**
|
|
346
|
+
* Callback when user requests to login
|
|
347
|
+
*
|
|
348
|
+
* This is triggered when user clicks on login overlay in widgets.
|
|
349
|
+
* Use this to show your login modal or redirect to login page.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```tsx
|
|
353
|
+
* <TaskOnProvider
|
|
354
|
+
* config={{
|
|
355
|
+
* apiKey: 'your-api-key',
|
|
356
|
+
* onRequestLogin: () => {
|
|
357
|
+
* setShowLoginModal(true);
|
|
358
|
+
* },
|
|
359
|
+
* }}
|
|
360
|
+
* >
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
onRequestLogin?: () => void;
|
|
364
|
+
/**
|
|
365
|
+
* OAuth tool URL for social account binding
|
|
366
|
+
*
|
|
367
|
+
* When users need to bind Twitter/Discord/Telegram accounts,
|
|
368
|
+
* this URL will be used to open the OAuth authorization popup.
|
|
369
|
+
*
|
|
370
|
+
* @default https://generalauthservice.com (main environment)
|
|
371
|
+
*
|
|
372
|
+
* For stage/test environment, use: https://stage.generalauthservice.com
|
|
373
|
+
*/
|
|
374
|
+
oauthToolUrl?: string;
|
|
375
|
+
/**
|
|
376
|
+
* WalletConnect Project ID
|
|
377
|
+
*
|
|
378
|
+
* Required for WalletConnect functionality.
|
|
379
|
+
* Get your project ID at https://cloud.walletconnect.com
|
|
380
|
+
*
|
|
381
|
+
* If not provided, WalletConnect option will be disabled in the wallet dialog.
|
|
382
|
+
*/
|
|
383
|
+
walletConnectProjectId?: string;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export declare interface TaskOnProviderProps {
|
|
387
|
+
/**
|
|
388
|
+
* TaskOn configuration object
|
|
389
|
+
*/
|
|
390
|
+
config: TaskOnProviderConfig;
|
|
391
|
+
/**
|
|
392
|
+
* Child components
|
|
393
|
+
*/
|
|
394
|
+
children: ReactNode;
|
|
395
|
+
/**
|
|
396
|
+
* List of widgets to preload locales for
|
|
397
|
+
*/
|
|
398
|
+
preloadLocales?: WidgetName[];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Resolved theme object (returned by useTaskOnTheme)
|
|
403
|
+
*/
|
|
404
|
+
export declare interface TaskOnTheme {
|
|
405
|
+
/** Current mode (resolved, never "auto") */
|
|
406
|
+
mode: "light" | "dark";
|
|
407
|
+
/** Whether compact mode is enabled */
|
|
408
|
+
compact: boolean;
|
|
409
|
+
/** All tokens (resolved) */
|
|
410
|
+
tokens: Required<MapToken>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Theme configuration
|
|
415
|
+
*/
|
|
416
|
+
export declare interface TaskOnThemeConfig {
|
|
417
|
+
/** Theme mode */
|
|
418
|
+
mode?: ThemeMode;
|
|
419
|
+
/** Compact mode */
|
|
420
|
+
compact?: boolean;
|
|
421
|
+
/** Seed tokens */
|
|
422
|
+
seed?: SeedToken;
|
|
423
|
+
/** Map tokens (override derived values) */
|
|
424
|
+
map?: MapToken;
|
|
425
|
+
/** Light mode specific configuration */
|
|
426
|
+
light?: ModeThemeConfig;
|
|
427
|
+
/** Dark mode specific configuration */
|
|
428
|
+
dark?: ModeThemeConfig;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Translation function type
|
|
433
|
+
*/
|
|
434
|
+
export declare type TFunction<T> = <K extends keyof T>(key: K, params?: InterpolationParams) => string;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Theme mode
|
|
438
|
+
* - light: Light mode
|
|
439
|
+
* - dark: Dark mode
|
|
440
|
+
* - auto: Follow system preference
|
|
441
|
+
*/
|
|
442
|
+
export declare type ThemeMode = "light" | "dark" | "auto";
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Theme Provider Component
|
|
446
|
+
*
|
|
447
|
+
* Provides theme configuration with support for:
|
|
448
|
+
* - light/dark/auto modes
|
|
449
|
+
* - Seed token derivation
|
|
450
|
+
* - Map token overrides
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```tsx
|
|
454
|
+
* <ThemeProvider theme={{ mode: 'dark', seed: { colorPrimary: '#6366f1' } }}>
|
|
455
|
+
* <App />
|
|
456
|
+
* </ThemeProvider>
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
export declare function ThemeProvider({ theme: themeConfig, children, }: ThemeProviderProps): ReactNode;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* ThemeProvider Props
|
|
463
|
+
*/
|
|
464
|
+
export declare interface ThemeProviderProps {
|
|
465
|
+
/** Theme configuration */
|
|
466
|
+
theme?: TaskOnThemeConfig;
|
|
467
|
+
/** Child components */
|
|
468
|
+
children: React.ReactNode;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Hook for loading common locale messages
|
|
473
|
+
*
|
|
474
|
+
* @returns Object containing common messages and loading state
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```tsx
|
|
478
|
+
* function MyWidget() {
|
|
479
|
+
* const { messages: common, isLoading } = useCommonLocale();
|
|
480
|
+
*
|
|
481
|
+
* if (isLoading) return <div>{common.loading}</div>;
|
|
482
|
+
*
|
|
483
|
+
* return <button onClick={retry}>{common.retry}</button>;
|
|
484
|
+
* }
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
export declare function useCommonLocale(): UseWidgetLocaleResult<CommonMessages>;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Hook to access EVM wallet
|
|
491
|
+
*/
|
|
492
|
+
export declare function useEvmWallet(): {
|
|
493
|
+
adapter: WalletAdapter | null;
|
|
494
|
+
address: string | null;
|
|
495
|
+
chainId: number | null;
|
|
496
|
+
isConnected: boolean;
|
|
497
|
+
connect: () => Promise<string | null>;
|
|
498
|
+
disconnect: () => Promise<void>;
|
|
499
|
+
signMessage: (message: string) => Promise<string | null>;
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
export { UserInfo }
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Public hook for TaskOn authentication
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```tsx
|
|
509
|
+
* const { login, logout, userId, isLoggedIn, requestLogin } = useTaskOnAuth();
|
|
510
|
+
*
|
|
511
|
+
* // EVM wallet login
|
|
512
|
+
* await login({ method: 'evm_wallet', value: '0x...', sign, timestamp });
|
|
513
|
+
*
|
|
514
|
+
* // Email login
|
|
515
|
+
* await login({ method: 'email', value: 'user@example.com', sign, timestamp });
|
|
516
|
+
*
|
|
517
|
+
* // Discord login
|
|
518
|
+
* await login({ method: 'discord', value: oauthToken, sign, timestamp });
|
|
519
|
+
*
|
|
520
|
+
* // Request login (triggers config.onRequestLogin)
|
|
521
|
+
* requestLogin();
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
export declare function useTaskOnAuth(): {
|
|
525
|
+
userId: number | null;
|
|
526
|
+
isLoggedIn: boolean;
|
|
527
|
+
isInitializing: boolean;
|
|
528
|
+
login: (params: LoginParams) => Promise<void>;
|
|
529
|
+
logout: () => void;
|
|
530
|
+
requestLogin: () => void;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Get current theme
|
|
535
|
+
* Must be used within a ThemeProvider
|
|
536
|
+
*/
|
|
537
|
+
export declare function useTaskOnTheme(): TaskOnTheme;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Hook for widget translations with interpolation support
|
|
541
|
+
*
|
|
542
|
+
* This is a higher-level hook that wraps useWidgetLocale and adds
|
|
543
|
+
* a `t` function for convenient string interpolation.
|
|
544
|
+
*
|
|
545
|
+
* @template T - The shape of the messages object
|
|
546
|
+
* @param options - Same options as useWidgetLocale
|
|
547
|
+
* @returns Object containing t function, messages, and loading state
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```tsx
|
|
551
|
+
* // messages/en.ts
|
|
552
|
+
* export default {
|
|
553
|
+
* greeting: 'Hello, {name}!',
|
|
554
|
+
* points: 'You have {count} points',
|
|
555
|
+
* title: 'Task Widget',
|
|
556
|
+
* };
|
|
557
|
+
*
|
|
558
|
+
* // Component
|
|
559
|
+
* function TaskWidget() {
|
|
560
|
+
* const { t, isLoading } = useTranslation({
|
|
561
|
+
* widgetId: 'TaskWidget',
|
|
562
|
+
* defaultMessages: enMessages,
|
|
563
|
+
* loadMessages,
|
|
564
|
+
* });
|
|
565
|
+
*
|
|
566
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
567
|
+
*
|
|
568
|
+
* return (
|
|
569
|
+
* <div>
|
|
570
|
+
* <h1>{t('title')}</h1>
|
|
571
|
+
* <p>{t('greeting', { name: 'John' })}</p>
|
|
572
|
+
* <p>{t('points', { count: 100 })}</p>
|
|
573
|
+
* </div>
|
|
574
|
+
* );
|
|
575
|
+
* }
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
export declare function useTranslation<T>(options: UseWidgetLocaleOptions<T>): UseTranslationResult<T>;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Return type for useTranslation hook
|
|
582
|
+
*/
|
|
583
|
+
export declare interface UseTranslationResult<T> {
|
|
584
|
+
/**
|
|
585
|
+
* Translation function with interpolation support
|
|
586
|
+
*
|
|
587
|
+
* @example
|
|
588
|
+
* ```ts
|
|
589
|
+
* t('greeting', { name: 'John' }) // => 'Hello, John!'
|
|
590
|
+
* t('points', { count: 100 }) // => 'You have 100 points'
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
t: TFunction<T>;
|
|
594
|
+
/**
|
|
595
|
+
* Raw messages object (without interpolation)
|
|
596
|
+
* Useful when you need direct access to message strings
|
|
597
|
+
*/
|
|
598
|
+
messages: T;
|
|
599
|
+
/**
|
|
600
|
+
* Whether translations are currently loading
|
|
601
|
+
*/
|
|
602
|
+
isLoading: boolean;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Hook to access wallet context
|
|
607
|
+
* Returns wallet state and actions for EVM
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
610
|
+
* ```tsx
|
|
611
|
+
* const { evmAddress, isEvmConnected, connectEvm, signEvmMessage } = useWallet();
|
|
612
|
+
*
|
|
613
|
+
* // Connect EVM wallet
|
|
614
|
+
* const address = await connectEvm();
|
|
615
|
+
*
|
|
616
|
+
* // Sign message
|
|
617
|
+
* const signature = await signEvmMessage("Hello World");
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
export declare function useWallet(): WalletContextValue;
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Hook for loading widget-specific locale messages
|
|
624
|
+
*
|
|
625
|
+
* @template T - The shape of the messages object
|
|
626
|
+
* @param options - Configuration options
|
|
627
|
+
* @param options.defaultMessages - English messages (inlined, no loading needed)
|
|
628
|
+
* @param options.loadMessages - Function to dynamically import other locales
|
|
629
|
+
* @returns Object containing messages and loading state
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```tsx
|
|
633
|
+
* import enMessages from './locales/en';
|
|
634
|
+
*
|
|
635
|
+
* function TaskWidget() {
|
|
636
|
+
* const { messages, isLoading } = useWidgetLocale({
|
|
637
|
+
* defaultMessages: enMessages,
|
|
638
|
+
* loadMessages: (locale) => import(`./locales/${locale}.ts`),
|
|
639
|
+
* });
|
|
640
|
+
*
|
|
641
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
642
|
+
*
|
|
643
|
+
* return <button>{messages.claim}</button>;
|
|
644
|
+
* }
|
|
645
|
+
* ```
|
|
646
|
+
*/
|
|
647
|
+
export declare function useWidgetLocale<T>(options: UseWidgetLocaleOptions<T>): UseWidgetLocaleResult<T>;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Options for useWidgetLocale hook
|
|
651
|
+
*
|
|
652
|
+
* @template T - The shape of the messages object
|
|
653
|
+
*/
|
|
654
|
+
export declare interface UseWidgetLocaleOptions<T> {
|
|
655
|
+
/**
|
|
656
|
+
* Unique identifier for this widget
|
|
657
|
+
* Used as cache key prefix to avoid conflicts between widgets
|
|
658
|
+
*
|
|
659
|
+
* @example "TaskWidget", "WalletWidget"
|
|
660
|
+
*/
|
|
661
|
+
widgetId: string;
|
|
662
|
+
/**
|
|
663
|
+
* Default messages (English) - inlined in bundle
|
|
664
|
+
* These are used immediately without any loading
|
|
665
|
+
*/
|
|
666
|
+
defaultMessages: T;
|
|
667
|
+
/**
|
|
668
|
+
* Function to dynamically load messages for other locales
|
|
669
|
+
* Should return a dynamic import promise
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* loadMessages: (locale) => import(`./locales/${locale}.ts`)
|
|
674
|
+
* ```
|
|
675
|
+
*/
|
|
676
|
+
loadMessages: (locale: Locale) => Promise<{
|
|
677
|
+
default: T;
|
|
678
|
+
}>;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Return type for useWidgetLocale hook
|
|
683
|
+
*
|
|
684
|
+
* @template T - The shape of the messages object
|
|
685
|
+
*/
|
|
686
|
+
export declare interface UseWidgetLocaleResult<T> {
|
|
687
|
+
/**
|
|
688
|
+
* Current messages object based on active locale
|
|
689
|
+
* Falls back to default (English) messages if loading fails
|
|
690
|
+
*/
|
|
691
|
+
messages: T;
|
|
692
|
+
/**
|
|
693
|
+
* Whether the locale messages are currently loading
|
|
694
|
+
* Only true when switching to a non-default locale
|
|
695
|
+
*/
|
|
696
|
+
isLoading: boolean;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Wallet adapter interface for blockchain interactions
|
|
701
|
+
*
|
|
702
|
+
* This interface abstracts wallet operations, allowing widgets to work with
|
|
703
|
+
* different wallet providers (custom implementations or built-in adapters)
|
|
704
|
+
*/
|
|
705
|
+
export declare interface WalletAdapter {
|
|
706
|
+
/**
|
|
707
|
+
* Connect to wallet and return the connected address
|
|
708
|
+
* Should open wallet selection UI if needed
|
|
709
|
+
*/
|
|
710
|
+
connect: () => Promise<string>;
|
|
711
|
+
/**
|
|
712
|
+
* Disconnect from wallet
|
|
713
|
+
*/
|
|
714
|
+
disconnect: () => Promise<void>;
|
|
715
|
+
/**
|
|
716
|
+
* Sign a message with the connected wallet
|
|
717
|
+
* @param message - The message to sign
|
|
718
|
+
* @returns The signature
|
|
719
|
+
*/
|
|
720
|
+
signMessage: (message: string) => Promise<string>;
|
|
721
|
+
/**
|
|
722
|
+
* Get the currently connected address
|
|
723
|
+
* @returns The address or null if not connected
|
|
724
|
+
*/
|
|
725
|
+
getAddress: () => string | null;
|
|
726
|
+
/**
|
|
727
|
+
* Get the current chain ID
|
|
728
|
+
* @returns The chain ID or null if not available
|
|
729
|
+
*/
|
|
730
|
+
getChainId?: () => number | null;
|
|
731
|
+
/**
|
|
732
|
+
* Switch to a different network
|
|
733
|
+
* @param chainId - The target chain ID
|
|
734
|
+
*/
|
|
735
|
+
switchNetwork?: (chainId: number) => Promise<void>;
|
|
736
|
+
/**
|
|
737
|
+
* Invoke a smart contract method
|
|
738
|
+
* @param params - Contract invocation parameters
|
|
739
|
+
* @returns Transaction hash
|
|
740
|
+
*/
|
|
741
|
+
invokeContract?: (params: InvokeContractParams) => Promise<string>;
|
|
742
|
+
/**
|
|
743
|
+
* Get wallet's native token balance (for gas estimation)
|
|
744
|
+
* @returns Balance in wei (string)
|
|
745
|
+
*/
|
|
746
|
+
getBalance?: () => Promise<string>;
|
|
747
|
+
/**
|
|
748
|
+
* Subscribe to account changes
|
|
749
|
+
* @param callback - Called when account changes
|
|
750
|
+
* @returns Unsubscribe function
|
|
751
|
+
*/
|
|
752
|
+
onAccountChange?: (callback: (address: string | null) => void) => () => void;
|
|
753
|
+
/**
|
|
754
|
+
* Subscribe to chain/network changes
|
|
755
|
+
* @param callback - Called when chain changes
|
|
756
|
+
* @returns Unsubscribe function
|
|
757
|
+
*/
|
|
758
|
+
onChainChange?: (callback: (chainId: number) => void) => () => void;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Wallet configuration for TaskOnProvider
|
|
763
|
+
*/
|
|
764
|
+
export declare interface WalletConfig {
|
|
765
|
+
/**
|
|
766
|
+
* Custom EVM wallet adapter
|
|
767
|
+
* If not provided, uses built-in window.ethereum adapter
|
|
768
|
+
*/
|
|
769
|
+
evmAdapter?: WalletAdapter;
|
|
770
|
+
/**
|
|
771
|
+
* Disable auto-detection of wallet providers
|
|
772
|
+
* When true, only uses adapter explicitly provided above
|
|
773
|
+
* @default false
|
|
774
|
+
*/
|
|
775
|
+
disableAutoDetect?: boolean;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Wallet context value type
|
|
780
|
+
*/
|
|
781
|
+
declare interface WalletContextValue extends WalletState {
|
|
782
|
+
connectEvm: () => Promise<string | null>;
|
|
783
|
+
disconnectEvm: () => Promise<void>;
|
|
784
|
+
signEvmMessage: (message: string) => Promise<string | null>;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Wallet state exposed through context
|
|
789
|
+
*/
|
|
790
|
+
export declare interface WalletState {
|
|
791
|
+
evmAdapter: WalletAdapter | null;
|
|
792
|
+
evmAddress: string | null;
|
|
793
|
+
evmChainId: number | null;
|
|
794
|
+
isEvmConnected: boolean;
|
|
795
|
+
isDetecting: boolean;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Supported widget names for preloading
|
|
800
|
+
*/
|
|
801
|
+
export declare type WidgetName = "CommunityTask";
|
|
802
|
+
|
|
803
|
+
export { }
|