@dodoex/wallet-web3-react 0.2.1 → 0.3.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.
- package/babel.config.js +9 -9
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/lingui.config.ts +13 -13
- package/package.json +90 -77
- package/rollup.config.mjs +100 -100
- package/src/ClientProvider.tsx +17 -15
- package/src/LangProvider.tsx +36 -34
- package/src/WalletConnect/AccountPage.tsx +496 -494
- package/src/WalletConnect/ActivityList.tsx +606 -604
- package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -246
- package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
- package/src/WalletConnect/ConnectDialog.tsx +35 -33
- package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -61
- package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -54
- package/src/WalletConnect/ConnectLedger/helper.ts +14 -14
- package/src/WalletConnect/ConnectLedger/index.tsx +2 -0
- package/src/WalletConnect/ConnectPage.tsx +508 -506
- package/src/WalletConnect/HasBalanceTokenList.tsx +202 -200
- package/src/WalletConnect/ReceiveTokenPage.tsx +145 -143
- package/src/WalletConnect/SendTokenPage.tsx +251 -249
- package/src/WalletConnect/WalletDialog.tsx +80 -78
- package/src/WalletConnectProvider.tsx +57 -55
- package/src/components/AddressWithLinkAndCopy.tsx +202 -200
- package/src/components/Dialog.tsx +158 -156
- package/src/components/TokenLogo.tsx +167 -165
- package/src/components/WalletTag.tsx +117 -115
- package/src/constants/localstorage.ts +24 -22
- package/src/hooks/useConnectWallet.ts +150 -148
- package/src/hooks/useFetchFiatPrice.ts +53 -51
- package/src/hooks/useFetchTokensBalance.ts +53 -51
- package/src/hooks/useHasBalanceTokenList.ts +95 -93
- package/src/hooks/useTransactionList.ts +89 -87
- package/src/index.tsx +7 -7
- package/src/locales/en.po +51 -51
- package/src/locales/zh.po +51 -51
- package/src/utils/formatter.ts +102 -102
- package/src/utils/time.ts +21 -21
- package/src/utils/utils.ts +8 -8
- package/tsconfig.json +23 -23
|
@@ -1,506 +1,508 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
const [
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
'
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
'
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
)
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
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;
|