@dodoex/wallet-web3-react 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/babel.config.js +9 -0
  2. package/dist/index.js +72 -0
  3. package/dist/types/ClientProvider.d.ts +2 -0
  4. package/dist/types/LangProvider.d.ts +11 -0
  5. package/dist/types/WalletConnect/AccountPage.d.ts +11 -0
  6. package/dist/types/WalletConnect/ActivityList.d.ts +20 -0
  7. package/dist/types/WalletConnect/ConnectAlchemy/index.d.ts +6 -0
  8. package/dist/types/WalletConnect/ConnectAlchemy/useConnectAlchemy.d.ts +12 -0
  9. package/dist/types/WalletConnect/ConnectLedger/ErrorDialog.d.ts +4 -0
  10. package/dist/types/WalletConnect/ConnectLedger/LoadingDialog.d.ts +3 -0
  11. package/dist/types/WalletConnect/ConnectLedger/LockedDialog.d.ts +4 -0
  12. package/dist/types/WalletConnect/ConnectLedger/ProtocolDialog.d.ts +6 -0
  13. package/dist/types/WalletConnect/ConnectLedger/SelectAddressDialog.d.ts +8 -0
  14. package/dist/types/WalletConnect/ConnectLedger/SelectPathDialog.d.ts +5 -0
  15. package/dist/types/WalletConnect/ConnectLedger/helper.d.ts +2 -0
  16. package/dist/types/WalletConnect/ConnectLedger/index.d.ts +6 -0
  17. package/dist/types/WalletConnect/ConnectPage.d.ts +9 -0
  18. package/dist/types/WalletConnect/HasBalanceTokenList.d.ts +4 -0
  19. package/dist/types/WalletConnect/ReceiveTokenPage.d.ts +4 -0
  20. package/dist/types/WalletConnect/SendTokenPage.d.ts +5 -0
  21. package/dist/types/WalletConnect/WalletDialog.d.ts +6 -0
  22. package/dist/types/WalletConnectProvider.d.ts +72 -0
  23. package/dist/types/components/AddressWithLinkAndCopy.d.ts +28 -0
  24. package/dist/types/components/Dialog.d.ts +15 -0
  25. package/dist/types/components/TokenLogo.d.ts +26 -0
  26. package/dist/types/components/WalletTag.d.ts +7 -0
  27. package/dist/types/constants/localstorage.d.ts +6 -0
  28. package/dist/types/hooks/useConnectWalet.d.ts +30 -0
  29. package/dist/types/hooks/useFetchFiatPrice.d.ts +3 -0
  30. package/dist/types/hooks/useFetchTokensBalance.d.ts +14 -0
  31. package/dist/types/hooks/useHasBalanceTokenList.d.ts +21 -0
  32. package/dist/types/hooks/useTransactionList.d.ts +272 -0
  33. package/dist/types/index.d.ts +4 -0
  34. package/dist/types/utils/formatter.d.ts +20 -0
  35. package/dist/types/utils/time.d.ts +3 -0
  36. package/dist/types/utils/utils.d.ts +2 -0
  37. package/lingui.config.ts +13 -0
  38. package/locales/en.po +251 -0
  39. package/locales/en.ts +1 -0
  40. package/locales/zh.po +249 -0
  41. package/locales/zh.ts +1 -0
  42. package/package.json +68 -0
  43. package/rollup.config.mjs +64 -0
  44. package/src/ClientProvider.tsx +15 -0
  45. package/src/LangProvider.tsx +32 -0
  46. package/src/WalletConnect/AccountPage.tsx +535 -0
  47. package/src/WalletConnect/ActivityList.tsx +597 -0
  48. package/src/WalletConnect/ConnectAlchemy/index.tsx +246 -0
  49. package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +101 -0
  50. package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -0
  51. package/src/WalletConnect/ConnectLedger/LoadingDialog.tsx +106 -0
  52. package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -0
  53. package/src/WalletConnect/ConnectLedger/ProtocolDialog.tsx +61 -0
  54. package/src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx +326 -0
  55. package/src/WalletConnect/ConnectLedger/SelectPathDialog.tsx +68 -0
  56. package/src/WalletConnect/ConnectLedger/helper.ts +14 -0
  57. package/src/WalletConnect/ConnectLedger/index.tsx +89 -0
  58. package/src/WalletConnect/ConnectPage.tsx +459 -0
  59. package/src/WalletConnect/HasBalanceTokenList.tsx +201 -0
  60. package/src/WalletConnect/ReceiveTokenPage.tsx +143 -0
  61. package/src/WalletConnect/SendTokenPage.tsx +249 -0
  62. package/src/WalletConnect/WalletDialog.tsx +72 -0
  63. package/src/WalletConnectProvider.tsx +54 -0
  64. package/src/components/AddressWithLinkAndCopy.tsx +200 -0
  65. package/src/components/Dialog.tsx +155 -0
  66. package/src/components/TokenLogo.tsx +165 -0
  67. package/src/components/WalletTag.tsx +113 -0
  68. package/src/constants/localstorage.ts +22 -0
  69. package/src/hooks/useConnectWalet.ts +144 -0
  70. package/src/hooks/useFetchFiatPrice.ts +51 -0
  71. package/src/hooks/useFetchTokensBalance.ts +52 -0
  72. package/src/hooks/useHasBalanceTokenList.ts +157 -0
  73. package/src/hooks/useTransactionList.ts +87 -0
  74. package/src/index.tsx +4 -0
  75. package/src/utils/formatter.ts +102 -0
  76. package/src/utils/time.ts +21 -0
  77. package/src/utils/utils.ts +8 -0
  78. package/tsconfig.json +22 -0
package/locales/zh.po ADDED
@@ -0,0 +1,249 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "POT-Creation-Date: 2024-12-24 19:12+0800\n"
4
+ "MIME-Version: 1.0\n"
5
+ "Content-Type: text/plain; charset=utf-8\n"
6
+ "Content-Transfer-Encoding: 8bit\n"
7
+ "X-Generator: @lingui/cli\n"
8
+ "Language: zh\n"
9
+ "Project-Id-Version: \n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "PO-Revision-Date: \n"
12
+ "Last-Translator: \n"
13
+ "Language-Team: \n"
14
+ "Plural-Forms: \n"
15
+
16
+ #: src/WalletConnect/ConnectLedger/ProtocolDialog.tsx:46
17
+ msgid "1、Ledger Live APP is closed{BR}2、The device plugged in via USB,NOT Bluetooth{BR}3、The device is unlocked and in the {ledgerAppName} app{BR}4、”Blind Signing” is enabled in {ledgerAppName} app"
18
+ msgstr ""
19
+
20
+ #: src/WalletConnect/ConnectLedger/LoadingDialog.tsx:84
21
+ msgid "Account"
22
+ msgstr ""
23
+
24
+ #: src/WalletConnect/AccountPage.tsx:313
25
+ msgid "Activity"
26
+ msgstr ""
27
+
28
+ #: src/WalletConnect/ActivityList.tsx:381
29
+ msgid "Add Liquidity"
30
+ msgstr ""
31
+
32
+ #: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:202
33
+ msgid "Address"
34
+ msgstr ""
35
+
36
+ #: src/WalletConnect/ActivityList.tsx:362
37
+ msgid "Approve"
38
+ msgstr ""
39
+
40
+ #: src/WalletConnect/ConnectLedger/LoadingDialog.tsx:92
41
+ #: src/WalletConnect/ConnectLedger/SelectPathDialog.tsx:25
42
+ msgid "Available Ledger Account"
43
+ msgstr ""
44
+
45
+ #: src/WalletConnect/AccountPage.tsx:172
46
+ #: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:206
47
+ msgid "Balance"
48
+ msgstr ""
49
+
50
+ #: src/WalletConnect/ConnectLedger/ProtocolDialog.tsx:36
51
+ #: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:155
52
+ msgid "Before proceeding make sure"
53
+ msgstr ""
54
+
55
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:85
56
+ msgid "Check your email and click the link to complete login"
57
+ msgstr ""
58
+
59
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:232
60
+ msgid "Choose existing passkey"
61
+ msgstr ""
62
+
63
+ #: src/WalletConnect/ActivityList.tsx:396
64
+ msgid "Claim Rewards"
65
+ msgstr ""
66
+
67
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:46
68
+ msgid "Connect Alchemy"
69
+ msgstr ""
70
+
71
+ #: src/WalletConnect/ConnectPage.tsx:234
72
+ msgid "Connect Wallet"
73
+ msgstr ""
74
+
75
+ #: src/components/WalletTag.tsx:58
76
+ msgid "Connected"
77
+ msgstr ""
78
+
79
+ #: src/components/WalletTag.tsx:42
80
+ msgid "Connecting"
81
+ msgstr ""
82
+
83
+ #: src/WalletConnect/ConnectLedger/ProtocolDialog.tsx:57
84
+ #: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:321
85
+ #: src/WalletConnect/ConnectLedger/SelectPathDialog.tsx:63
86
+ msgid "Continue"
87
+ msgstr ""
88
+
89
+ #: src/WalletConnect/AccountPage.tsx:399
90
+ #: src/WalletConnect/HasBalanceTokenList.tsx:118
91
+ #: src/WalletConnect/ReceiveTokenPage.tsx:99
92
+ msgid "Copied"
93
+ msgstr ""
94
+
95
+ #: src/WalletConnect/ReceiveTokenPage.tsx:136
96
+ msgid "Copy wallet address"
97
+ msgstr ""
98
+
99
+ #: src/WalletConnect/ActivityList.tsx:398
100
+ msgid "Create Liquidity Mining"
101
+ msgstr ""
102
+
103
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:207
104
+ msgid "Create new passkey"
105
+ msgstr ""
106
+
107
+ #: src/WalletConnect/ActivityList.tsx:393
108
+ msgid "End mining\\n"
109
+ msgstr ""
110
+
111
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:129
112
+ msgid "Enter email"
113
+ msgstr ""
114
+
115
+ #: src/WalletConnect/ActivityList.tsx:349
116
+ msgid "Failed"
117
+ msgstr ""
118
+
119
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:105
120
+ msgid "Go Back"
121
+ msgstr ""
122
+
123
+ #: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:194
124
+ msgid "ID"
125
+ msgstr ""
126
+
127
+ #: src/components/WalletTag.tsx:107
128
+ msgid "Installed Wallet"
129
+ msgstr ""
130
+
131
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:132
132
+ msgid "Invalid email"
133
+ msgstr ""
134
+
135
+ #: src/WalletConnect/SendTokenPage.tsx:186
136
+ msgid "Invalid wallet address"
137
+ msgstr ""
138
+
139
+ #: src/components/WalletTag.tsx:74
140
+ msgid "Last connection"
141
+ msgstr ""
142
+
143
+ #: src/WalletConnect/ActivityList.tsx:264
144
+ msgid "Loading more"
145
+ msgstr ""
146
+
147
+ #: src/WalletConnect/ConnectLedger/LoadingDialog.tsx:101
148
+ msgid "Loading..."
149
+ msgstr ""
150
+
151
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:73
152
+ msgid "Log in with your email"
153
+ msgstr ""
154
+
155
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:126
156
+ msgid "Log in with your email or a passkey"
157
+ msgstr ""
158
+
159
+ #: src/WalletConnect/ConnectPage.tsx:342
160
+ msgid "More Wallets"
161
+ msgstr ""
162
+
163
+ #: src/WalletConnect/HasBalanceTokenList.tsx:51
164
+ msgid "No tokens"
165
+ msgstr ""
166
+
167
+ #: src/WalletConnect/ConnectLedger/ErrorDialog.tsx:56
168
+ #: src/WalletConnect/ConnectLedger/LockedDialog.tsx:49
169
+ msgid "OK"
170
+ msgstr ""
171
+
172
+ #: src/WalletConnect/AccountPage.tsx:305
173
+ msgid "On-chain transaction records"
174
+ msgstr ""
175
+
176
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:187
177
+ msgid "or"
178
+ msgstr ""
179
+
180
+ #: src/WalletConnect/ActivityList.tsx:350
181
+ msgid "Pending"
182
+ msgstr ""
183
+
184
+ #: src/WalletConnect/ActivityList.tsx:389
185
+ msgid "Pool Creation"
186
+ msgstr ""
187
+
188
+ #: src/WalletConnect/AccountPage.tsx:253
189
+ #: src/WalletConnect/ReceiveTokenPage.tsx:50
190
+ msgid "Receive"
191
+ msgstr ""
192
+
193
+ #: src/WalletConnect/SendTokenPage.tsx:144
194
+ msgid "Receiver address"
195
+ msgstr ""
196
+
197
+ #: src/WalletConnect/ActivityList.tsx:385
198
+ msgid "Remove Liquidity"
199
+ msgstr ""
200
+
201
+ #: src/WalletConnect/ActivityList.tsx:351
202
+ #: src/WalletConnect/ActivityList.tsx:361
203
+ msgid "Reset"
204
+ msgstr ""
205
+
206
+ #: src/WalletConnect/AccountPage.tsx:224
207
+ #: src/WalletConnect/ActivityList.tsx:401
208
+ #: src/WalletConnect/SendTokenPage.tsx:116
209
+ #: src/WalletConnect/SendTokenPage.tsx:244
210
+ msgid "Send"
211
+ msgstr ""
212
+
213
+ #: src/WalletConnect/ActivityList.tsx:391
214
+ msgid "Stake"
215
+ msgstr ""
216
+
217
+ #: src/WalletConnect/ConnectAlchemy/index.tsx:156
218
+ msgid "Submit"
219
+ msgstr ""
220
+
221
+ #: src/WalletConnect/ActivityList.tsx:348
222
+ msgid "Succeeded"
223
+ msgstr ""
224
+
225
+ #: src/WalletConnect/ActivityList.tsx:375
226
+ msgid "Swap"
227
+ msgstr ""
228
+
229
+ #: src/WalletConnect/ConnectLedger/LockedDialog.tsx:37
230
+ msgid ""
231
+ "The Ledger Device is locked\n"
232
+ "Please unlock from the device"
233
+ msgstr ""
234
+
235
+ #: src/WalletConnect/ActivityList.tsx:129
236
+ msgid "This is empty"
237
+ msgstr ""
238
+
239
+ #: src/WalletConnect/AccountPage.tsx:301
240
+ msgid "Token"
241
+ msgstr ""
242
+
243
+ #: src/WalletConnect/ActivityList.tsx:377
244
+ msgid "Transfer"
245
+ msgstr ""
246
+
247
+ #: src/WalletConnect/ConnectLedger/ErrorDialog.tsx:36
248
+ msgid "Unknown Error"
249
+ msgstr ""
package/locales/zh.ts ADDED
@@ -0,0 +1 @@
1
+ /*eslint-disable*/import type{Messages}from"@lingui/core";export const messages=JSON.parse("{\"Sz0SkD\":[\"1、Ledger Live APP is closed\",[\"BR\"],\"2、The device plugged in via USB,NOT Bluetooth\",[\"BR\"],\"3、The device is unlocked and in the \",[\"ledgerAppName\"],\" app\",[\"BR\"],\"4、”Blind Signing” is enabled in \",[\"ledgerAppName\"],\" app\"],\"AeXO77\":\"Account\",\"XJOV1Y\":\"Activity\",\"OBdohg\":\"Add Liquidity\",\"Du6bPw\":\"Address\",\"Z7ZXbT\":\"Approve\",\"vN+hAq\":\"Available Ledger Account\",\"fsBGk0\":\"Balance\",\"E/yE9x\":\"Before proceeding make sure\",\"3UCJ3e\":\"Check your email and click the link to complete login\",\"Mlg3Ds\":\"Choose existing passkey\",\"zXCpR0\":\"Claim Rewards\",\"RETKSh\":\"Connect Alchemy\",\"CtByM7\":\"Connect Wallet\",\"QHcLEN\":\"Connected\",\"9zb2WA\":\"Connecting\",\"xGVfLh\":\"Continue\",\"6V3Ea3\":\"Copied\",\"gCNLBV\":\"Copy wallet address\",\"14s9LL\":\"Create Liquidity Mining\",\"OzjK0A\":\"Create new passkey\",\"WZRsOg\":\"End mining\\\\n\",\"6KnyG0\":\"Enter email\",\"7Bj3x9\":\"Failed\",\"sr0UJD\":\"Go Back\",\"S0kLOH\":\"ID\",\"9ow2PX\":\"Installed Wallet\",\"B2Tpo0\":\"Invalid email\",\"rwC96V\":\"Invalid wallet address\",\"xHr8Pp\":\"Last connection\",\"EYDfo2\":\"Loading more\",\"Z3FXyt\":\"Loading...\",\"6Ui8nZ\":\"Log in with your email\",\"3y6FjD\":\"Log in with your email or a passkey\",\"yN5k0R\":\"More Wallets\",\"JE8mMQ\":\"No tokens\",\"zga9sT\":\"OK\",\"U8oDGg\":\"On-chain transaction records\",\"BzEFor\":\"or\",\"UbRKMZ\":\"Pending\",\"8OiU8L\":\"Pool Creation\",\"lDgVWA\":\"Receive\",\"pkRuyd\":\"Receiver address\",\"3XBvkd\":\"Remove Liquidity\",\"OfhWJH\":\"Reset\",\"JlFcis\":\"Send\",\"JYKRJS\":\"Stake\",\"hQRttt\":\"Submit\",\"KAbcm2\":\"Succeeded\",\"vH2C/2\":\"Swap\",\"kdetxi\":\"The Ledger Device is locked\\nPlease unlock from the device\",\"FzJ11V\":\"This is empty\",\"TP9/K5\":\"Token\",\"zPGNJm\":\"Transfer\",\"LobdAW\":\"Unknown Error\"}")as Messages;
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@dodoex/wallet-web3-react",
3
+ "version": "0.0.1-beta.0",
4
+ "source": "src/index.tsx",
5
+ "types": "dist/types/index.d.ts",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "scripts": {
9
+ "start": "yarn workspace doc start",
10
+ "build": "rm -rf dist/* && yarn extract && yarn compile && rollup -c",
11
+ "extract": "lingui extract --clean",
12
+ "compile": "lingui compile --typescript"
13
+ },
14
+ "author": "",
15
+ "license": "GPL-3.0-or-later",
16
+ "description": "",
17
+ "keywords": [
18
+ "dodo",
19
+ "wallet",
20
+ "ethereum"
21
+ ],
22
+ "browserslist": {
23
+ "production": [
24
+ ">0.2%",
25
+ "not dead",
26
+ "not op_mini all"
27
+ ],
28
+ "development": [
29
+ "last 1 chrome version",
30
+ "last 1 firefox version",
31
+ "last 1 safari version"
32
+ ]
33
+ },
34
+ "peerDependencies": {
35
+ "@dodoex/wallet-web3": "0.0.61-beta.0"
36
+ },
37
+ "devDependencies": {
38
+ "@lingui/cli": "^4.11.4",
39
+ "@lingui/loader": "^4.11.4",
40
+ "@lingui/swc-plugin": "4.0.6",
41
+ "@rollup/plugin-terser": "^0.4.4",
42
+ "@rollup/plugin-typescript": "^12.1.1",
43
+ "@rollup/plugin-url": "^8.0.2",
44
+ "@svgr/rollup": "^8.1.0",
45
+ "@types/identicon.js": "^2.3.5",
46
+ "@types/react-infinite-scroller": "^1.2.5",
47
+ "rollup": "^4.28.0",
48
+ "rollup-plugin-clear": "^2.0.7",
49
+ "rollup-plugin-import-css": "^3.5.7",
50
+ "typescript": "^4.7.3"
51
+ },
52
+ "dependencies": {
53
+ "@dodoex/api": "^3.0.2",
54
+ "@dodoex/components": "^3.0.0",
55
+ "@dodoex/contract-request": "1.x",
56
+ "@dodoex/dodo-contract-request": "1.x",
57
+ "@dodoex/icons": "^2.0.2",
58
+ "@lingui/macro": "^4.11.4",
59
+ "@lingui/react": "^4.11.4",
60
+ "@tanstack/react-query": "^5.62.8",
61
+ "bignumber.js": "^9.1.2",
62
+ "copy-to-clipboard": "^3.3.3",
63
+ "dayjs": "^1.11.13",
64
+ "identicon.js": "^2.3.3",
65
+ "qrcode.react": "^4.2.0",
66
+ "react-infinite-scroller": "^1.2.6"
67
+ }
68
+ }
@@ -0,0 +1,64 @@
1
+ import { babel } from '@rollup/plugin-babel';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import json from '@rollup/plugin-json';
4
+ import typescript from '@rollup/plugin-typescript';
5
+ import terser from '@rollup/plugin-terser';
6
+ import url from '@rollup/plugin-url';
7
+ import resolve from '@rollup/plugin-node-resolve';
8
+ import svgr from '@svgr/rollup';
9
+ import pkg from './package.json' with { type: 'json' };
10
+ import css from 'rollup-plugin-import-css';
11
+ import clear from 'rollup-plugin-clear';
12
+
13
+ const extensions = ['.js', '.jsx', '.ts', '.tsx'];
14
+ const baseConfig = {
15
+ input: pkg.source,
16
+ plugins: [
17
+ url(),
18
+ svgr({
19
+ svgo: true,
20
+ svgoConfig: {
21
+ plugins: [
22
+ {
23
+ name: 'removeViewBox',
24
+ active: false,
25
+ },
26
+ ],
27
+ },
28
+ }),
29
+ json(),
30
+ typescript(),
31
+ commonjs(),
32
+ resolve(),
33
+ babel({
34
+ extensions,
35
+ babelHelpers: 'bundled',
36
+ }),
37
+ css(),
38
+ clear({
39
+ // required, point out which directories should be clear.
40
+ targets: ['dist'],
41
+ // optional, whether clear the directores when rollup recompile on --watch mode.
42
+ watch: true, // default: false
43
+ }),
44
+ ],
45
+ external: [
46
+ ...Object.keys(pkg.dependencies || {}).filter(
47
+ (key) => !['@dodoex/icons'].includes(key),
48
+ ),
49
+ ...Object.keys(pkg.peerDependencies || {}),
50
+ ],
51
+ };
52
+
53
+ export default [
54
+ {
55
+ output: [
56
+ {
57
+ dir: 'dist',
58
+ format: 'es',
59
+ plugins: [terser()],
60
+ },
61
+ ],
62
+ ...baseConfig,
63
+ },
64
+ ];
@@ -0,0 +1,15 @@
1
+ import { createTheme, ThemeProvider } from '@dodoex/components';
2
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
3
+ import LangProvider from './LangProvider';
4
+
5
+ export default function ClientProvider({ children }: React.PropsWithChildren) {
6
+ const queryClient = new QueryClient();
7
+ const theme = createTheme();
8
+ return (
9
+ <QueryClientProvider client={queryClient}>
10
+ <ThemeProvider theme={theme}>
11
+ <LangProvider>{children}</LangProvider>
12
+ </ThemeProvider>
13
+ </QueryClientProvider>
14
+ );
15
+ }
@@ -0,0 +1,32 @@
1
+ import { i18n } from '@lingui/core';
2
+ import { I18nProvider } from '@lingui/react';
3
+ import { ReactNode, useEffect } from 'react';
4
+
5
+ export const supportedLang = ['en', 'zh'];
6
+ export type SupportedLang = typeof supportedLang[number];
7
+
8
+ export const defaultLang: SupportedLang = 'en';
9
+
10
+ interface LangProviderProps {
11
+ locale?: SupportedLang;
12
+ children: ReactNode;
13
+ }
14
+
15
+ export async function loadI18(locale: SupportedLang = defaultLang) {
16
+ try {
17
+ const catalog = await import(`../locales/${locale}.js`);
18
+ i18n.load(locale, catalog.messages || catalog.default.messages);
19
+ } catch {}
20
+ i18n.activate(locale);
21
+ }
22
+ export function LangProvider({ locale, children }: LangProviderProps) {
23
+ useEffect(() => {
24
+ const loadLocale = async () => {
25
+ await loadI18(locale);
26
+ };
27
+ loadLocale();
28
+ }, [locale]);
29
+ return <I18nProvider i18n={i18n}>{children}</I18nProvider>;
30
+ }
31
+
32
+ export default LangProvider;