@dodoex/wallet-web3-react 0.4.0 → 0.4.2

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 (68) hide show
  1. package/babel.config.js +9 -9
  2. package/dist/cjs/index.cjs +4 -13
  3. package/dist/cjs/locales/en.js +1 -1
  4. package/dist/cjs/locales/zh.js +1 -1
  5. package/dist/index.js +4 -13
  6. package/dist/locales/en.js +1 -1
  7. package/dist/locales/zh.js +1 -1
  8. package/dist/types/ClientProvider.d.ts +1 -1
  9. package/dist/types/LangProvider.d.ts +1 -1
  10. package/dist/types/WalletConnect/AccountPage.d.ts +1 -1
  11. package/dist/types/WalletConnect/ActivityList.d.ts +5 -4
  12. package/dist/types/WalletConnect/ConnectAlchemy/index.d.ts +2 -1
  13. package/dist/types/WalletConnect/ConnectDialog.d.ts +2 -1
  14. package/dist/types/WalletConnect/ConnectLedger/ErrorDialog.d.ts +1 -1
  15. package/dist/types/WalletConnect/ConnectLedger/LoadingDialog.d.ts +1 -1
  16. package/dist/types/WalletConnect/ConnectLedger/LockedDialog.d.ts +1 -1
  17. package/dist/types/WalletConnect/ConnectLedger/ProtocolDialog.d.ts +1 -1
  18. package/dist/types/WalletConnect/ConnectLedger/SelectAddressDialog.d.ts +1 -1
  19. package/dist/types/WalletConnect/ConnectLedger/SelectPathDialog.d.ts +1 -1
  20. package/dist/types/WalletConnect/ConnectLedger/index.d.ts +1 -1
  21. package/dist/types/WalletConnect/ConnectPage.d.ts +1 -1
  22. package/dist/types/WalletConnect/HasBalanceTokenList.d.ts +1 -1
  23. package/dist/types/WalletConnect/ReceiveTokenPage.d.ts +2 -1
  24. package/dist/types/WalletConnect/SendTokenPage.d.ts +2 -1
  25. package/dist/types/WalletConnect/WalletDialog.d.ts +2 -1
  26. package/dist/types/WalletConnectProvider.d.ts +2 -2
  27. package/dist/types/components/AddressWithLinkAndCopy.d.ts +2 -2
  28. package/dist/types/components/Dialog.d.ts +3 -3
  29. package/dist/types/components/WalletTag.d.ts +1 -1
  30. package/lingui.config.ts +13 -13
  31. package/package.json +90 -90
  32. package/rollup.config.mjs +106 -103
  33. package/src/ClientProvider.tsx +17 -17
  34. package/src/LangProvider.tsx +36 -36
  35. package/src/WalletConnect/AccountPage.tsx +498 -498
  36. package/src/WalletConnect/ActivityList.tsx +606 -606
  37. package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -248
  38. package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
  39. package/src/WalletConnect/ConnectDialog.tsx +35 -35
  40. package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -61
  41. package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -54
  42. package/src/WalletConnect/ConnectLedger/helper.ts +14 -14
  43. package/src/WalletConnect/ConnectPage.tsx +508 -508
  44. package/src/WalletConnect/HasBalanceTokenList.tsx +202 -202
  45. package/src/WalletConnect/ReceiveTokenPage.tsx +145 -145
  46. package/src/WalletConnect/SendTokenPage.tsx +251 -251
  47. package/src/WalletConnect/WalletDialog.tsx +80 -80
  48. package/src/WalletConnectProvider.tsx +57 -57
  49. package/src/components/AddressWithLinkAndCopy.tsx +202 -202
  50. package/src/components/Dialog.tsx +158 -158
  51. package/src/components/TokenLogo.tsx +167 -167
  52. package/src/components/WalletTag.tsx +117 -117
  53. package/src/constants/localstorage.ts +24 -24
  54. package/src/hooks/useConnectWallet.ts +150 -150
  55. package/src/hooks/useFetchFiatPrice.ts +53 -53
  56. package/src/hooks/useFetchTokensBalance.ts +53 -53
  57. package/src/hooks/useHasBalanceTokenList.ts +95 -95
  58. package/src/hooks/useTransactionList.ts +89 -89
  59. package/src/index.tsx +7 -7
  60. package/src/locales/en.js +1 -1
  61. package/src/locales/en.po +8 -8
  62. package/src/locales/zh.js +1 -1
  63. package/src/locales/zh.po +4 -4
  64. package/src/react19-types.d.ts +12 -0
  65. package/src/utils/formatter.ts +102 -102
  66. package/src/utils/time.ts +21 -21
  67. package/src/utils/utils.ts +8 -8
  68. package/tsconfig.json +22 -22
@@ -1,508 +1,508 @@
1
- 'use client';
2
-
3
- import React from 'react';
4
- import WalletWeb3, { useWalletStore, WalletType } from '@dodoex/wallet-web3';
5
- import { useConnectWallet, WalletItem } from '../hooks/useConnectWallet';
6
- import { alpha, Box, ButtonBase, Checkbox, useTheme } from '@dodoex/components';
7
- import { useWalletConnectContext } from '../WalletConnectProvider';
8
- import WalletTag, { WalletTagProps } from '../components/WalletTag';
9
- import { ArrowRight, More } from '@dodoex/icons';
10
- import { Trans } from '@lingui/macro';
11
- import ConnectLedger from './ConnectLedger';
12
- import { checkAlchemyCache } from './ConnectAlchemy/useConnectAlchemy';
13
- import ConnectAlchemy from './ConnectAlchemy';
14
- import { DialogTitle } from '../components/Dialog';
15
-
16
- const walletGroupStyle = {
17
- display: 'grid',
18
- gap: 12,
19
- gridTemplateColumns: 'repeat(1, 1fr)',
20
- alignItems: 'start',
21
- px: 8,
22
- py: 6,
23
- };
24
-
25
- export type ConnectDialogWalletTag = React.FC<
26
- WalletTagProps & {
27
- children?: React.ReactNode;
28
- }
29
- >;
30
-
31
- function WalletGroupItem({
32
- chainId,
33
- wallet,
34
- loggedIn,
35
- matchChain,
36
- selectedChainId,
37
- disabled,
38
- activeWalletType,
39
- installed,
40
- disabledClick,
41
- onShowLedgerConnect,
42
- onShowAlchemyConnect,
43
- onConnectWallet,
44
- WalletTag: WalletTagProps,
45
- }: {
46
- chainId?: number;
47
- wallet: WalletItem;
48
- loggedIn: boolean;
49
- matchChain: boolean;
50
- selectedChainId: number | undefined;
51
- disabled?: boolean;
52
- activeWalletType?: WalletType;
53
- installed?: boolean;
54
- disabledClick: () => void;
55
- onShowLedgerConnect: () => void;
56
- onShowAlchemyConnect: () => void;
57
- onConnectWallet?: (wallet: WalletItem) => void | Promise<void>;
58
- WalletTag?: ConnectDialogWalletTag;
59
- }) {
60
- const theme = useTheme();
61
- const isChecked =
62
- loggedIn &&
63
- activeWalletType === wallet.currentType &&
64
- (matchChain || activeWalletType.toLocaleLowerCase() === 'walletconnect');
65
-
66
- const [loading, setLoading] = React.useState(false);
67
- const { connectTimeout, onConnectTimeout, switchNetwork, onConnected } =
68
- useWalletConnectContext();
69
- return (
70
- <Box
71
- component={ButtonBase}
72
- sx={{
73
- display: 'flex',
74
- justifyContent: 'space-between',
75
- alignItems: 'center',
76
- p: theme.spacing(10, 12),
77
- width: '100%',
78
- color: 'text.primary',
79
- borderRadius: 8,
80
- opacity: disabled ? 0.3 : 1,
81
- '&:hover': {
82
- backgroundColor: theme.palette.background.tag,
83
- },
84
- }}
85
- onClick={async () => {
86
- if (disabled) {
87
- disabledClick();
88
- return;
89
- }
90
- if (isChecked) {
91
- return;
92
- }
93
- if (wallet.currentType === WalletType.LedgerUSB) {
94
- if (wallet.disabled) return;
95
- onShowLedgerConnect();
96
- return;
97
- }
98
- if (wallet.currentType === WalletType.Alchemy) {
99
- if (wallet.disabled) return;
100
- const hasCache = await checkAlchemyCache(chainId ?? 1);
101
- if (!hasCache) {
102
- onShowAlchemyConnect();
103
- return;
104
- }
105
- }
106
- setLoading(true);
107
- let timeout: NodeJS.Timeout | undefined = undefined;
108
- try {
109
- await Promise.race([
110
- (async () => {
111
- if (onConnectWallet) {
112
- try {
113
- await onConnectWallet(wallet);
114
- const connectedChainId = useWalletStore.getState().chainId;
115
- if (onConnected) {
116
- onConnected(connectedChainId, wallet);
117
- }
118
- } finally {
119
- setLoading(false);
120
- }
121
- return;
122
- }
123
-
124
- if (
125
- switchNetwork &&
126
- wallet.currentType === activeWalletType &&
127
- (!matchChain || !loggedIn) &&
128
- selectedChainId
129
- ) {
130
- const res = await switchNetwork(selectedChainId);
131
- if (res !== undefined) {
132
- setLoading(false);
133
- return;
134
- }
135
- }
136
- if (wallet.onClick) {
137
- try {
138
- await wallet.onClick();
139
- const connectedChainId = useWalletStore.getState().chainId;
140
- if (onConnected) {
141
- onConnected(connectedChainId, wallet);
142
- }
143
- } finally {
144
- setLoading(false);
145
- }
146
- }
147
- })(),
148
- onConnectTimeout
149
- ? new Promise(
150
- (_, reject) =>
151
- (timeout = setTimeout(() => {
152
- onConnectTimeout();
153
- reject();
154
- }, connectTimeout ?? 15000)),
155
- )
156
- : undefined,
157
- ]);
158
- } catch (error) {
159
- setLoading(false);
160
- throw error;
161
- }
162
- if (timeout) {
163
- clearTimeout(timeout);
164
- }
165
- }}
166
- >
167
- <Box
168
- sx={{
169
- position: 'relative',
170
- display: 'flex',
171
- alignItems: 'center',
172
- gap: 12,
173
- justifyContent: 'center',
174
- typography: 'body1',
175
- fontWeight: 600,
176
- }}
177
- >
178
- <Box
179
- component="img"
180
- src={wallet.icon}
181
- sx={{
182
- width: 40,
183
- height: 40,
184
- borderRadius: 12,
185
- border: 'solid 1px',
186
- borderColor: 'border.main',
187
- }}
188
- />
189
- {wallet.title}
190
- </Box>
191
- {WalletTagProps ? (
192
- <WalletTagProps
193
- loading={loading}
194
- wallet={wallet}
195
- isChecked={isChecked}
196
- installed={!!installed}
197
- >
198
- <WalletTag
199
- loading={loading}
200
- wallet={wallet}
201
- isChecked={isChecked}
202
- installed={!!installed}
203
- />
204
- </WalletTagProps>
205
- ) : (
206
- <WalletTag
207
- loading={loading}
208
- wallet={wallet}
209
- isChecked={isChecked}
210
- installed={!!installed}
211
- />
212
- )}
213
- </Box>
214
- );
215
- }
216
-
217
- export interface ConnectPageProps {
218
- chainId: number;
219
- account?: string;
220
- walletWeb3?: WalletWeb3;
221
- showOtherInjectWallet?: boolean;
222
- onClose: () => void;
223
- onConnectWallet?: (wallet: WalletItem) => void | Promise<void>;
224
- WalletTag?: ConnectDialogWalletTag;
225
- }
226
- function ConnectPage({
227
- chainId,
228
- account,
229
- walletWeb3,
230
- showOtherInjectWallet,
231
- onClose,
232
- onConnectWallet,
233
- WalletTag,
234
- }: ConnectPageProps) {
235
- const theme = useTheme();
236
- const highlightBackgroundColor =
237
- theme.palette.mode === 'dark' ? alpha('#F1F902', 0.1) : '#F1F902';
238
- const { termsOfServiceLink, chainId: needConnectChainId } =
239
- useWalletConnectContext();
240
-
241
- const selectedChainId = needConnectChainId ?? chainId;
242
-
243
- const [isDisabledClick, setIsDisabledClick] = React.useState(false);
244
- const [showLedgerConnect, setShowLedgerConnect] = React.useState(false);
245
- const [showAlchemyConnect, setShowAlchemyConnect] = React.useState(false);
246
- const disabledClick = React.useCallback(() => {
247
- setIsDisabledClick(true);
248
- const time = setTimeout(() => {
249
- setIsDisabledClick(false);
250
- }, 1800);
251
-
252
- return () => {
253
- clearTimeout(time);
254
- };
255
- }, []);
256
-
257
- const {
258
- walletList,
259
- userReadAndChecked,
260
- handleChangeUserReadAndChecked,
261
- activeWalletType,
262
- } = useConnectWallet({
263
- walletWeb3,
264
- matchTestChain: true,
265
- showOtherInjectWallet,
266
- selectedChainId,
267
- hasTermsOfServiceLink: !!termsOfServiceLink,
268
- });
269
- const [showAllWallet, setShowAllWallet] = React.useState(false);
270
- const showWalletList = React.useMemo(() => {
271
- if (showAllWallet) return walletList;
272
- return walletList.slice(0, 6);
273
- }, [walletList, showAllWallet]);
274
- const morePriorityWalletList = React.useMemo(() => {
275
- return walletList.slice(6, 9);
276
- }, [walletList]);
277
-
278
- return (
279
- <>
280
- <DialogTitle onClose={onClose}>
281
- <Trans>Connect Wallet</Trans>
282
- </DialogTitle>
283
- <Box
284
- sx={{
285
- height: '100%',
286
- display: 'flex',
287
- flexDirection: 'column',
288
- overflow: 'hidden',
289
- pb: termsOfServiceLink ? 0 : 20,
290
- }}
291
- >
292
- <Box
293
- sx={{
294
- overflowY: 'auto',
295
- }}
296
- >
297
- <Box
298
- sx={{
299
- ...walletGroupStyle,
300
- }}
301
- >
302
- {showWalletList.map((wallet) => {
303
- return (
304
- <WalletGroupItem
305
- key={wallet.title}
306
- wallet={wallet}
307
- disabled={!userReadAndChecked}
308
- loggedIn={!!account}
309
- selectedChainId={selectedChainId}
310
- matchChain={selectedChainId === chainId}
311
- activeWalletType={activeWalletType}
312
- installed={wallet.isInstalled}
313
- disabledClick={disabledClick}
314
- onShowLedgerConnect={() => setShowLedgerConnect(true)}
315
- onShowAlchemyConnect={() => setShowAlchemyConnect(true)}
316
- onConnectWallet={onConnectWallet}
317
- WalletTag={WalletTag}
318
- />
319
- );
320
- })}
321
- </Box>
322
- {morePriorityWalletList.length ? (
323
- <Box
324
- sx={{
325
- mx: 20,
326
- display: 'flex',
327
- justifyContent: 'center',
328
- position: 'relative',
329
- opacity: userReadAndChecked ? 1 : 0.5,
330
- }}
331
- >
332
- <Box
333
- sx={{
334
- position: 'absolute',
335
- top: '50%',
336
- right: 0,
337
- left: 0,
338
- height: '1px',
339
- backgroundColor: 'border.main',
340
- transform: 'translateY(-50%)',
341
- }}
342
- />
343
- {showAllWallet ? (
344
- <Box
345
- component={ButtonBase}
346
- disabled={!userReadAndChecked}
347
- sx={{
348
- position: 'relative',
349
- padding: theme.spacing(0, 12),
350
- height: 34,
351
- borderRadius: 20,
352
- backgroundColor: 'background.paper',
353
- border: 'solid 1px',
354
- borderColor: 'border.main',
355
- '&:hover': {
356
- backgroundColor: 'background.paperContrast',
357
- },
358
- }}
359
- onClick={() => setShowAllWallet(false)}
360
- >
361
- <Box
362
- component={ArrowRight}
363
- sx={{
364
- color: 'text.secondary',
365
- transform: 'rotate(-90deg)',
366
- }}
367
- />
368
- </Box>
369
- ) : (
370
- <Box
371
- component={ButtonBase}
372
- disabled={!userReadAndChecked}
373
- sx={{
374
- position: 'relative',
375
- display: 'flex',
376
- alignItems: 'center',
377
- padding: theme.spacing(0, 12),
378
- height: 34,
379
- borderRadius: 20,
380
- border: 'solid 1px',
381
- borderColor: 'border.main',
382
- backgroundColor: 'background.paper',
383
- typography: 'h6',
384
- color: 'text.secondary',
385
- '&:hover': {
386
- backgroundColor: 'background.paperContrast',
387
- },
388
- }}
389
- onClick={() => setShowAllWallet(true)}
390
- >
391
- <Trans>More Wallets</Trans>
392
- {morePriorityWalletList.map((item, index) => {
393
- return (
394
- <Box
395
- key={item.title}
396
- component="img"
397
- src={item.icon}
398
- alt="icon"
399
- sx={{
400
- width: 18,
401
- height: 18,
402
- ...(index !== 0
403
- ? {
404
- position: 'relative',
405
- left: -2,
406
- }
407
- : {
408
- ml: 12,
409
- }),
410
- }}
411
- />
412
- );
413
- })}
414
- <Box
415
- sx={{
416
- width: 18,
417
- height: 18,
418
- display: 'flex',
419
- justifyContent: 'center',
420
- alignItems: 'center',
421
- backgroundColor: 'background.paperContrast',
422
- borderRadius: '50%',
423
- }}
424
- >
425
- <Box
426
- component={More}
427
- sx={{
428
- width: 18,
429
- height: 18,
430
- }}
431
- />
432
- </Box>
433
- <Box
434
- component={ArrowRight}
435
- sx={{
436
- transform: 'rotate(90deg)',
437
- }}
438
- />
439
- </Box>
440
- )}
441
- </Box>
442
- ) : (
443
- ''
444
- )}
445
- <ConnectLedger
446
- on={showLedgerConnect}
447
- chainId={selectedChainId}
448
- onClose={() => setShowLedgerConnect(false)}
449
- onConnect={(path, account) => {
450
- walletList
451
- .find((wallet) => wallet.currentType === WalletType.LedgerUSB)
452
- ?.onClick({
453
- ledgerParams: {
454
- path,
455
- account,
456
- },
457
- });
458
- }}
459
- />
460
- {!!walletWeb3 && (
461
- <ConnectAlchemy
462
- open={showAlchemyConnect}
463
- setOpen={setShowAlchemyConnect}
464
- walletWeb3={walletWeb3}
465
- />
466
- )}
467
- </Box>
468
- {!!termsOfServiceLink && (
469
- <Checkbox
470
- checked={userReadAndChecked}
471
- onChange={(evt: any) =>
472
- handleChangeUserReadAndChecked(evt.target.checked)
473
- }
474
- label={
475
- <Box
476
- sx={{
477
- typography: 'body2',
478
- '& a': {
479
- fontWeight: 600,
480
- color: 'primary.main',
481
- // textDecoration: 'underline',
482
- },
483
- }}
484
- >
485
- {termsOfServiceLink}
486
- </Box>
487
- }
488
- sx={{
489
- m: 0,
490
- p: 20,
491
- alignItems: 'flex-start',
492
- display: 'flex',
493
- backgroundColor: isDisabledClick
494
- ? highlightBackgroundColor
495
- : 'transparent',
496
- '& > span': {
497
- p: 0,
498
- mr: 8,
499
- },
500
- }}
501
- />
502
- )}
503
- </Box>
504
- </>
505
- );
506
- }
507
-
508
- export default ConnectPage;
1
+ 'use client';
2
+
3
+ import React from 'react';
4
+ import WalletWeb3, { useWalletStore, WalletType } from '@dodoex/wallet-web3';
5
+ import { useConnectWallet, WalletItem } from '../hooks/useConnectWallet';
6
+ import { alpha, Box, ButtonBase, Checkbox, useTheme } from '@dodoex/components';
7
+ import { useWalletConnectContext } from '../WalletConnectProvider';
8
+ import WalletTag, { WalletTagProps } from '../components/WalletTag';
9
+ import { ArrowRight, More } from '@dodoex/icons';
10
+ import { Trans } from '@lingui/macro';
11
+ import ConnectLedger from './ConnectLedger';
12
+ import { checkAlchemyCache } from './ConnectAlchemy/useConnectAlchemy';
13
+ import ConnectAlchemy from './ConnectAlchemy';
14
+ import { DialogTitle } from '../components/Dialog';
15
+
16
+ const walletGroupStyle = {
17
+ display: 'grid',
18
+ gap: 12,
19
+ gridTemplateColumns: 'repeat(1, 1fr)',
20
+ alignItems: 'start',
21
+ px: 8,
22
+ py: 6,
23
+ };
24
+
25
+ export type ConnectDialogWalletTag = React.FC<
26
+ WalletTagProps & {
27
+ children?: React.ReactNode;
28
+ }
29
+ >;
30
+
31
+ function WalletGroupItem({
32
+ chainId,
33
+ wallet,
34
+ loggedIn,
35
+ matchChain,
36
+ selectedChainId,
37
+ disabled,
38
+ activeWalletType,
39
+ installed,
40
+ disabledClick,
41
+ onShowLedgerConnect,
42
+ onShowAlchemyConnect,
43
+ onConnectWallet,
44
+ WalletTag: WalletTagProps,
45
+ }: {
46
+ chainId?: number;
47
+ wallet: WalletItem;
48
+ loggedIn: boolean;
49
+ matchChain: boolean;
50
+ selectedChainId: number | undefined;
51
+ disabled?: boolean;
52
+ activeWalletType?: WalletType;
53
+ installed?: boolean;
54
+ disabledClick: () => void;
55
+ onShowLedgerConnect: () => void;
56
+ onShowAlchemyConnect: () => void;
57
+ onConnectWallet?: (wallet: WalletItem) => void | Promise<void>;
58
+ WalletTag?: ConnectDialogWalletTag;
59
+ }) {
60
+ const theme = useTheme();
61
+ const isChecked =
62
+ loggedIn &&
63
+ activeWalletType === wallet.currentType &&
64
+ (matchChain || activeWalletType.toLocaleLowerCase() === 'walletconnect');
65
+
66
+ const [loading, setLoading] = React.useState(false);
67
+ const { connectTimeout, onConnectTimeout, switchNetwork, onConnected } =
68
+ useWalletConnectContext();
69
+ return (
70
+ <Box
71
+ component={ButtonBase}
72
+ sx={{
73
+ display: 'flex',
74
+ justifyContent: 'space-between',
75
+ alignItems: 'center',
76
+ p: theme.spacing(10, 12),
77
+ width: '100%',
78
+ color: 'text.primary',
79
+ borderRadius: 8,
80
+ opacity: disabled ? 0.3 : 1,
81
+ '&:hover': {
82
+ backgroundColor: theme.palette.background.tag,
83
+ },
84
+ }}
85
+ onClick={async () => {
86
+ if (disabled) {
87
+ disabledClick();
88
+ return;
89
+ }
90
+ if (isChecked) {
91
+ return;
92
+ }
93
+ if (wallet.currentType === WalletType.LedgerUSB) {
94
+ if (wallet.disabled) return;
95
+ onShowLedgerConnect();
96
+ return;
97
+ }
98
+ if (wallet.currentType === WalletType.Alchemy) {
99
+ if (wallet.disabled) return;
100
+ const hasCache = await checkAlchemyCache(chainId ?? 1);
101
+ if (!hasCache) {
102
+ onShowAlchemyConnect();
103
+ return;
104
+ }
105
+ }
106
+ setLoading(true);
107
+ let timeout: NodeJS.Timeout | undefined = undefined;
108
+ try {
109
+ await Promise.race([
110
+ (async () => {
111
+ if (onConnectWallet) {
112
+ try {
113
+ await onConnectWallet(wallet);
114
+ const connectedChainId = useWalletStore.getState().chainId;
115
+ if (onConnected) {
116
+ onConnected(connectedChainId, wallet);
117
+ }
118
+ } finally {
119
+ setLoading(false);
120
+ }
121
+ return;
122
+ }
123
+
124
+ if (
125
+ switchNetwork &&
126
+ wallet.currentType === activeWalletType &&
127
+ (!matchChain || !loggedIn) &&
128
+ selectedChainId
129
+ ) {
130
+ const res = await switchNetwork(selectedChainId);
131
+ if (res !== undefined) {
132
+ setLoading(false);
133
+ return;
134
+ }
135
+ }
136
+ if (wallet.onClick) {
137
+ try {
138
+ await wallet.onClick();
139
+ const connectedChainId = useWalletStore.getState().chainId;
140
+ if (onConnected) {
141
+ onConnected(connectedChainId, wallet);
142
+ }
143
+ } finally {
144
+ setLoading(false);
145
+ }
146
+ }
147
+ })(),
148
+ onConnectTimeout
149
+ ? new Promise(
150
+ (_, reject) =>
151
+ (timeout = setTimeout(() => {
152
+ onConnectTimeout();
153
+ reject();
154
+ }, connectTimeout ?? 15000)),
155
+ )
156
+ : undefined,
157
+ ]);
158
+ } catch (error) {
159
+ setLoading(false);
160
+ throw error;
161
+ }
162
+ if (timeout) {
163
+ clearTimeout(timeout);
164
+ }
165
+ }}
166
+ >
167
+ <Box
168
+ sx={{
169
+ position: 'relative',
170
+ display: 'flex',
171
+ alignItems: 'center',
172
+ gap: 12,
173
+ justifyContent: 'center',
174
+ typography: 'body1',
175
+ fontWeight: 600,
176
+ }}
177
+ >
178
+ <Box
179
+ component="img"
180
+ src={wallet.icon}
181
+ sx={{
182
+ width: 40,
183
+ height: 40,
184
+ borderRadius: 12,
185
+ border: 'solid 1px',
186
+ borderColor: 'border.main',
187
+ }}
188
+ />
189
+ {wallet.title}
190
+ </Box>
191
+ {WalletTagProps ? (
192
+ <WalletTagProps
193
+ loading={loading}
194
+ wallet={wallet}
195
+ isChecked={isChecked}
196
+ installed={!!installed}
197
+ >
198
+ <WalletTag
199
+ loading={loading}
200
+ wallet={wallet}
201
+ isChecked={isChecked}
202
+ installed={!!installed}
203
+ />
204
+ </WalletTagProps>
205
+ ) : (
206
+ <WalletTag
207
+ loading={loading}
208
+ wallet={wallet}
209
+ isChecked={isChecked}
210
+ installed={!!installed}
211
+ />
212
+ )}
213
+ </Box>
214
+ );
215
+ }
216
+
217
+ export interface ConnectPageProps {
218
+ chainId: number;
219
+ account?: string;
220
+ walletWeb3?: WalletWeb3;
221
+ showOtherInjectWallet?: boolean;
222
+ onClose: () => void;
223
+ onConnectWallet?: (wallet: WalletItem) => void | Promise<void>;
224
+ WalletTag?: ConnectDialogWalletTag;
225
+ }
226
+ function ConnectPage({
227
+ chainId,
228
+ account,
229
+ walletWeb3,
230
+ showOtherInjectWallet,
231
+ onClose,
232
+ onConnectWallet,
233
+ WalletTag,
234
+ }: ConnectPageProps) {
235
+ const theme = useTheme();
236
+ const highlightBackgroundColor =
237
+ theme.palette.mode === 'dark' ? alpha('#F1F902', 0.1) : '#F1F902';
238
+ const { termsOfServiceLink, chainId: needConnectChainId } =
239
+ useWalletConnectContext();
240
+
241
+ const selectedChainId = needConnectChainId ?? chainId;
242
+
243
+ const [isDisabledClick, setIsDisabledClick] = React.useState(false);
244
+ const [showLedgerConnect, setShowLedgerConnect] = React.useState(false);
245
+ const [showAlchemyConnect, setShowAlchemyConnect] = React.useState(false);
246
+ const disabledClick = React.useCallback(() => {
247
+ setIsDisabledClick(true);
248
+ const time = setTimeout(() => {
249
+ setIsDisabledClick(false);
250
+ }, 1800);
251
+
252
+ return () => {
253
+ clearTimeout(time);
254
+ };
255
+ }, []);
256
+
257
+ const {
258
+ walletList,
259
+ userReadAndChecked,
260
+ handleChangeUserReadAndChecked,
261
+ activeWalletType,
262
+ } = useConnectWallet({
263
+ walletWeb3,
264
+ matchTestChain: true,
265
+ showOtherInjectWallet,
266
+ selectedChainId,
267
+ hasTermsOfServiceLink: !!termsOfServiceLink,
268
+ });
269
+ const [showAllWallet, setShowAllWallet] = React.useState(false);
270
+ const showWalletList = React.useMemo(() => {
271
+ if (showAllWallet) return walletList;
272
+ return walletList.slice(0, 6);
273
+ }, [walletList, showAllWallet]);
274
+ const morePriorityWalletList = React.useMemo(() => {
275
+ return walletList.slice(6, 9);
276
+ }, [walletList]);
277
+
278
+ return (
279
+ <>
280
+ <DialogTitle onClose={onClose}>
281
+ <Trans>Connect Wallet</Trans>
282
+ </DialogTitle>
283
+ <Box
284
+ sx={{
285
+ height: '100%',
286
+ display: 'flex',
287
+ flexDirection: 'column',
288
+ overflow: 'hidden',
289
+ pb: termsOfServiceLink ? 0 : 20,
290
+ }}
291
+ >
292
+ <Box
293
+ sx={{
294
+ overflowY: 'auto',
295
+ }}
296
+ >
297
+ <Box
298
+ sx={{
299
+ ...walletGroupStyle,
300
+ }}
301
+ >
302
+ {showWalletList.map((wallet) => {
303
+ return (
304
+ <WalletGroupItem
305
+ key={wallet.title}
306
+ wallet={wallet}
307
+ disabled={!userReadAndChecked}
308
+ loggedIn={!!account}
309
+ selectedChainId={selectedChainId}
310
+ matchChain={selectedChainId === chainId}
311
+ activeWalletType={activeWalletType}
312
+ installed={wallet.isInstalled}
313
+ disabledClick={disabledClick}
314
+ onShowLedgerConnect={() => setShowLedgerConnect(true)}
315
+ onShowAlchemyConnect={() => setShowAlchemyConnect(true)}
316
+ onConnectWallet={onConnectWallet}
317
+ WalletTag={WalletTag}
318
+ />
319
+ );
320
+ })}
321
+ </Box>
322
+ {morePriorityWalletList.length ? (
323
+ <Box
324
+ sx={{
325
+ mx: 20,
326
+ display: 'flex',
327
+ justifyContent: 'center',
328
+ position: 'relative',
329
+ opacity: userReadAndChecked ? 1 : 0.5,
330
+ }}
331
+ >
332
+ <Box
333
+ sx={{
334
+ position: 'absolute',
335
+ top: '50%',
336
+ right: 0,
337
+ left: 0,
338
+ height: '1px',
339
+ backgroundColor: 'border.main',
340
+ transform: 'translateY(-50%)',
341
+ }}
342
+ />
343
+ {showAllWallet ? (
344
+ <Box
345
+ component={ButtonBase}
346
+ disabled={!userReadAndChecked}
347
+ sx={{
348
+ position: 'relative',
349
+ padding: theme.spacing(0, 12),
350
+ height: 34,
351
+ borderRadius: 20,
352
+ backgroundColor: 'background.paper',
353
+ border: 'solid 1px',
354
+ borderColor: 'border.main',
355
+ '&:hover': {
356
+ backgroundColor: 'background.paperContrast',
357
+ },
358
+ }}
359
+ onClick={() => setShowAllWallet(false)}
360
+ >
361
+ <Box
362
+ component={ArrowRight}
363
+ sx={{
364
+ color: 'text.secondary',
365
+ transform: 'rotate(-90deg)',
366
+ }}
367
+ />
368
+ </Box>
369
+ ) : (
370
+ <Box
371
+ component={ButtonBase}
372
+ disabled={!userReadAndChecked}
373
+ sx={{
374
+ position: 'relative',
375
+ display: 'flex',
376
+ alignItems: 'center',
377
+ padding: theme.spacing(0, 12),
378
+ height: 34,
379
+ borderRadius: 20,
380
+ border: 'solid 1px',
381
+ borderColor: 'border.main',
382
+ backgroundColor: 'background.paper',
383
+ typography: 'h6',
384
+ color: 'text.secondary',
385
+ '&:hover': {
386
+ backgroundColor: 'background.paperContrast',
387
+ },
388
+ }}
389
+ onClick={() => setShowAllWallet(true)}
390
+ >
391
+ <Trans>More Wallets</Trans>
392
+ {morePriorityWalletList.map((item, index) => {
393
+ return (
394
+ <Box
395
+ key={item.title}
396
+ component="img"
397
+ src={item.icon}
398
+ alt="icon"
399
+ sx={{
400
+ width: 18,
401
+ height: 18,
402
+ ...(index !== 0
403
+ ? {
404
+ position: 'relative',
405
+ left: -2,
406
+ }
407
+ : {
408
+ ml: 12,
409
+ }),
410
+ }}
411
+ />
412
+ );
413
+ })}
414
+ <Box
415
+ sx={{
416
+ width: 18,
417
+ height: 18,
418
+ display: 'flex',
419
+ justifyContent: 'center',
420
+ alignItems: 'center',
421
+ backgroundColor: 'background.paperContrast',
422
+ borderRadius: '50%',
423
+ }}
424
+ >
425
+ <Box
426
+ component={More}
427
+ sx={{
428
+ width: 18,
429
+ height: 18,
430
+ }}
431
+ />
432
+ </Box>
433
+ <Box
434
+ component={ArrowRight}
435
+ sx={{
436
+ transform: 'rotate(90deg)',
437
+ }}
438
+ />
439
+ </Box>
440
+ )}
441
+ </Box>
442
+ ) : (
443
+ ''
444
+ )}
445
+ <ConnectLedger
446
+ on={showLedgerConnect}
447
+ chainId={selectedChainId}
448
+ onClose={() => setShowLedgerConnect(false)}
449
+ onConnect={(path, account) => {
450
+ walletList
451
+ .find((wallet) => wallet.currentType === WalletType.LedgerUSB)
452
+ ?.onClick({
453
+ ledgerParams: {
454
+ path,
455
+ account,
456
+ },
457
+ });
458
+ }}
459
+ />
460
+ {!!walletWeb3 && (
461
+ <ConnectAlchemy
462
+ open={showAlchemyConnect}
463
+ setOpen={setShowAlchemyConnect}
464
+ walletWeb3={walletWeb3}
465
+ />
466
+ )}
467
+ </Box>
468
+ {!!termsOfServiceLink && (
469
+ <Checkbox
470
+ checked={userReadAndChecked}
471
+ onChange={(evt: any) =>
472
+ handleChangeUserReadAndChecked(evt.target.checked)
473
+ }
474
+ label={
475
+ <Box
476
+ sx={{
477
+ typography: 'body2',
478
+ '& a': {
479
+ fontWeight: 600,
480
+ color: 'primary.main',
481
+ // textDecoration: 'underline',
482
+ },
483
+ }}
484
+ >
485
+ {termsOfServiceLink}
486
+ </Box>
487
+ }
488
+ sx={{
489
+ m: 0,
490
+ p: 20,
491
+ alignItems: 'flex-start',
492
+ display: 'flex',
493
+ backgroundColor: isDisabledClick
494
+ ? highlightBackgroundColor
495
+ : 'transparent',
496
+ '& > span': {
497
+ p: 0,
498
+ mr: 8,
499
+ },
500
+ }}
501
+ />
502
+ )}
503
+ </Box>
504
+ </>
505
+ );
506
+ }
507
+
508
+ export default ConnectPage;