@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.
Files changed (40) hide show
  1. package/babel.config.js +9 -9
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +1 -1
  4. package/lingui.config.ts +13 -13
  5. package/package.json +90 -77
  6. package/rollup.config.mjs +100 -100
  7. package/src/ClientProvider.tsx +17 -15
  8. package/src/LangProvider.tsx +36 -34
  9. package/src/WalletConnect/AccountPage.tsx +496 -494
  10. package/src/WalletConnect/ActivityList.tsx +606 -604
  11. package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -246
  12. package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
  13. package/src/WalletConnect/ConnectDialog.tsx +35 -33
  14. package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -61
  15. package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -54
  16. package/src/WalletConnect/ConnectLedger/helper.ts +14 -14
  17. package/src/WalletConnect/ConnectLedger/index.tsx +2 -0
  18. package/src/WalletConnect/ConnectPage.tsx +508 -506
  19. package/src/WalletConnect/HasBalanceTokenList.tsx +202 -200
  20. package/src/WalletConnect/ReceiveTokenPage.tsx +145 -143
  21. package/src/WalletConnect/SendTokenPage.tsx +251 -249
  22. package/src/WalletConnect/WalletDialog.tsx +80 -78
  23. package/src/WalletConnectProvider.tsx +57 -55
  24. package/src/components/AddressWithLinkAndCopy.tsx +202 -200
  25. package/src/components/Dialog.tsx +158 -156
  26. package/src/components/TokenLogo.tsx +167 -165
  27. package/src/components/WalletTag.tsx +117 -115
  28. package/src/constants/localstorage.ts +24 -22
  29. package/src/hooks/useConnectWallet.ts +150 -148
  30. package/src/hooks/useFetchFiatPrice.ts +53 -51
  31. package/src/hooks/useFetchTokensBalance.ts +53 -51
  32. package/src/hooks/useHasBalanceTokenList.ts +95 -93
  33. package/src/hooks/useTransactionList.ts +89 -87
  34. package/src/index.tsx +7 -7
  35. package/src/locales/en.po +51 -51
  36. package/src/locales/zh.po +51 -51
  37. package/src/utils/formatter.ts +102 -102
  38. package/src/utils/time.ts +21 -21
  39. package/src/utils/utils.ts +8 -8
  40. package/tsconfig.json +23 -23
@@ -1,494 +1,496 @@
1
- import {
2
- LoadingSkeleton,
3
- Tabs,
4
- alpha,
5
- Box,
6
- BoxProps,
7
- ThemeProvider,
8
- useTheme,
9
- createTheme,
10
- Tooltip,
11
- RotatingIcon,
12
- TabsGroup,
13
- TabPanel,
14
- ButtonBase,
15
- } from '@dodoex/components';
16
- import {
17
- ArrowBack,
18
- ArrowTopRightBorder,
19
- Copy,
20
- Disconnect,
21
- } from '@dodoex/icons';
22
- import copy from 'copy-to-clipboard';
23
- import WalletWeb3, { useWalletStore } from '@dodoex/wallet-web3';
24
- import { Trans } from '@lingui/macro';
25
- import { BigNumber } from 'bignumber.js';
26
- import React from 'react';
27
- import { truncatePoolAddress } from '../components/AddressWithLinkAndCopy';
28
- import { DialogTitle } from '../components/Dialog';
29
- import { useHasBalanceTokenList } from '../hooks/useHasBalanceTokenList';
30
- import { useTransactionList } from '../hooks/useTransactionList';
31
- import { formatReadableNumber, formatShortNumber } from '../utils/formatter';
32
- import { useWalletConnectContext } from '../WalletConnectProvider';
33
- import ActivityList from './ActivityList';
34
- import HasBalanceTokenList from './HasBalanceTokenList';
35
-
36
- function AccountCardInfoBg({
37
- children,
38
- chainLogo,
39
- }: React.PropsWithChildren<{
40
- chainLogo: React.ReactNode;
41
- }>) {
42
- return (
43
- <Box
44
- sx={{
45
- position: 'relative',
46
- padding: 20,
47
- borderRadius: 12,
48
- border: 'solid 1px',
49
- borderColor: 'border.main',
50
- color: 'text.primary',
51
- zIndex: 0,
52
- }}
53
- >
54
- <Box
55
- sx={{
56
- position: 'absolute',
57
- top: 0,
58
- bottom: 0,
59
- left: 0,
60
- right: 0,
61
- zIndex: -1,
62
- overflow: 'hidden',
63
- borderRadius: 12,
64
- }}
65
- >
66
- <Box
67
- sx={{
68
- position: 'absolute',
69
- top: 0,
70
- bottom: 0,
71
- left: 0,
72
- right: 0,
73
- backgroundColor: '#F6F6F6',
74
- }}
75
- />
76
- <Box
77
- sx={{
78
- position: 'absolute',
79
- top: 0,
80
- bottom: 0,
81
- left: 0,
82
- right: 0,
83
- '& > img, & > svg': {
84
- height: 'auto',
85
- width: 'calc(100% + 2px)',
86
- position: 'absolute',
87
- '&:first-child': {
88
- top: '50%',
89
- transform: 'translateY(-50%)',
90
- opacity: 0.5,
91
- filter: 'blur(99.99999237060547px)',
92
- },
93
- '&:last-child': {
94
- left: 60,
95
- bottom: 40,
96
- opacity: 0.2,
97
- filter: 'blur(7.499999523162842px)',
98
- },
99
- },
100
- }}
101
- >
102
- {chainLogo}
103
- {chainLogo}
104
- </Box>
105
- <Box
106
- sx={{
107
- position: 'absolute',
108
- top: 0,
109
- bottom: 0,
110
- left: 0,
111
- right: 0,
112
- background:
113
- 'linear-gradient(108deg, rgba(255, 255, 255, 0.90) 9.8%, rgba(255, 255, 255, 0.00) 49.94%)',
114
- }}
115
- />
116
- </Box>
117
- {children}
118
- </Box>
119
- );
120
- }
121
-
122
- function AccountCardInfo({
123
- chainId,
124
- setShowSendTokenPage,
125
- setShowReceiveTokenPage,
126
- allFiatPriceBalance,
127
- allFiatPriceBalanceLoading,
128
- }: {
129
- chainId: number;
130
- setShowSendTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
131
- setShowReceiveTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
132
- allFiatPriceBalance: BigNumber;
133
- allFiatPriceBalanceLoading: boolean;
134
- }) {
135
- const { getChain } = useWalletConnectContext();
136
- const chain = getChain(chainId);
137
- const theme = createTheme({
138
- mode: 'light',
139
- });
140
-
141
- return (
142
- <ThemeProvider theme={theme}>
143
- <AccountCardInfoBg chainLogo={chain?.logoBg ?? chain?.logo}>
144
- <Box
145
- sx={{
146
- typography: 'body2',
147
- color: 'text.secondary',
148
- }}
149
- >
150
- <Trans>Balance</Trans>
151
- </Box>
152
- <LoadingSkeleton
153
- component="div"
154
- loading={allFiatPriceBalanceLoading}
155
- loadingSx={{
156
- width: 120,
157
- }}
158
- sx={{
159
- mt: 4,
160
- typography: 'h1',
161
- }}
162
- title={formatReadableNumber({ input: allFiatPriceBalance })}
163
- >
164
- ${formatShortNumber(allFiatPriceBalance)}
165
- </LoadingSkeleton>
166
- <Box
167
- sx={{
168
- display: 'flex',
169
- justifyContent: 'space-between',
170
- alignItems: 'center',
171
- gap: 20,
172
- mt: 28,
173
- }}
174
- >
175
- {/* send */}
176
- <ButtonBase
177
- sx={{
178
- flex: 1,
179
- display: 'flex',
180
- flexDirection: 'column',
181
- gap: 12,
182
- px: 20,
183
- py: 12,
184
- typography: 'body2',
185
- backgroundColor: 'background.paperDarkContrast',
186
- borderRadius: 12,
187
- textAlign: 'left',
188
- '&:hover': {
189
- backgroundColor: 'primary.main',
190
- color: 'primary.contrastText',
191
- },
192
- }}
193
- onClick={() => {
194
- setShowSendTokenPage(true);
195
- }}
196
- >
197
- <Box
198
- component={ArrowBack}
199
- sx={{
200
- transform: 'rotate(90deg)',
201
- }}
202
- />
203
- <Trans>Send</Trans>
204
- </ButtonBase>
205
- {/* receive */}
206
- <ButtonBase
207
- sx={{
208
- flex: 1,
209
- display: 'flex',
210
- flexDirection: 'column',
211
- gap: 12,
212
- px: 20,
213
- py: 12,
214
- typography: 'body2',
215
- backgroundColor: 'background.paperDarkContrast',
216
- borderRadius: 12,
217
- textAlign: 'left',
218
- '&:hover': {
219
- backgroundColor: 'primary.main',
220
- color: 'primary.contrastText',
221
- },
222
- }}
223
- onClick={() => {
224
- setShowReceiveTokenPage(true);
225
- }}
226
- >
227
- <Box
228
- component={ArrowBack}
229
- sx={{
230
- transform: 'rotate(-90deg)',
231
- }}
232
- />
233
- <Trans>Receive</Trans>
234
- </ButtonBase>
235
- </Box>
236
- </AccountCardInfoBg>
237
- </ThemeProvider>
238
- );
239
- }
240
-
241
- enum ListTab {
242
- tokens = 'tokens',
243
- activity = 'activity',
244
- }
245
- function AccountPage({
246
- chainId,
247
- account,
248
- walletWeb3,
249
- onClose,
250
- setShowSendTokenPage,
251
- setShowReceiveTokenPage,
252
- }: {
253
- chainId: number;
254
- account?: string;
255
- walletWeb3?: WalletWeb3;
256
- onClose: () => void;
257
- setShowSendTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
258
- setShowReceiveTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
259
- }) {
260
- const { getChain } = useWalletConnectContext();
261
- const { connected } = useWalletStore();
262
- const connectedWallet = connected?.wallet;
263
- const [listTab, setListTab] = React.useState(ListTab.tokens);
264
- const scrollableNodeRef = React.useRef<HTMLDivElement>(null);
265
- const getScrollParent = React.useCallback(() => {
266
- if (scrollableNodeRef) return scrollableNodeRef.current;
267
- return null;
268
- }, [scrollableNodeRef]);
269
-
270
- const balanceListData = useHasBalanceTokenList({
271
- account,
272
- visible: listTab === ListTab.tokens,
273
- });
274
-
275
- const fetchTransactionQuery = useTransactionList({
276
- account,
277
- chainId,
278
- });
279
- const tabs = [
280
- { key: ListTab.tokens, value: <Trans>Token</Trans> },
281
- {
282
- key: ListTab.activity,
283
- value: (
284
- <Tooltip title={<Trans>On-chain transaction records</Trans>}>
285
- <Box
286
- sx={{
287
- display: 'flex',
288
- alignItems: 'center',
289
- gap: 8,
290
- }}
291
- >
292
- <Trans>Activity</Trans>
293
- {!!fetchTransactionQuery.pendingList.length && <RotatingIcon />}
294
- </Box>
295
- </Tooltip>
296
- ),
297
- },
298
- ];
299
-
300
- const [showCopyTooltip, setShowCopyTooltip] = React.useState(false);
301
- const autoCloseShowCopyTooltip = React.useCallback(() => {
302
- const time = setTimeout(() => {
303
- setShowCopyTooltip(false);
304
- }, 1500);
305
-
306
- return () => {
307
- clearTimeout(time);
308
- };
309
- }, []);
310
-
311
- const chain = getChain(chainId);
312
- if (!account || !connectedWallet) return null;
313
- return (
314
- <>
315
- <DialogTitle onClose={onClose}>
316
- <Box
317
- sx={{
318
- display: 'flex',
319
- gap: 8,
320
- alignItems: 'center',
321
- height: 34,
322
- borderRadius: 8,
323
- backgroundColor: 'background.paperContrast',
324
- }}
325
- >
326
- <Box
327
- sx={{
328
- display: 'flex',
329
- alignItems: 'center',
330
- gap: 4,
331
- pl: 8,
332
- }}
333
- >
334
- <Box
335
- sx={{
336
- position: 'relative',
337
- pr: 6,
338
- width: 28,
339
- height: 22,
340
- }}
341
- >
342
- {!!connectedWallet.logo && (
343
- <img
344
- src={connectedWallet.logo}
345
- alt={connectedWallet.showName}
346
- width={22}
347
- height={22}
348
- />
349
- )}
350
- {!!chain?.logo && (
351
- <Box
352
- sx={{
353
- position: 'absolute',
354
- bottom: 0,
355
- right: 0,
356
- width: 12,
357
- height: 12,
358
- '& > img, & > svg': {
359
- position: 'absolute',
360
- inset: 0,
361
- width: '100%',
362
- height: '100%',
363
- borderRadius: '50%',
364
- border: 'solid 1px',
365
- borderColor: 'border.main',
366
- },
367
- }}
368
- >
369
- {chain?.logo}
370
- </Box>
371
- )}
372
- </Box>
373
- {truncatePoolAddress(account)}
374
- </Box>
375
- <Tooltip
376
- onlyClick
377
- arrow={false}
378
- title={<Trans>Copied</Trans>}
379
- open={showCopyTooltip}
380
- onOpen={() => {
381
- setShowCopyTooltip(true);
382
- autoCloseShowCopyTooltip();
383
- }}
384
- onClose={() => setShowCopyTooltip(false)}
385
- >
386
- <Box
387
- component={Copy}
388
- onClick={() => {
389
- copy(account);
390
- }}
391
- sx={{
392
- width: 18,
393
- height: 18,
394
- cursor: 'pointer',
395
- color: 'text.secondary',
396
- '&:hover': {
397
- color: 'text.primary',
398
- },
399
- }}
400
- />
401
- </Tooltip>
402
- <Box
403
- component="a"
404
- rel="noopener noreferrer"
405
- target="_blank"
406
- href={chain?.scanUrl + '/address/' + account}
407
- sx={{
408
- display: 'flex',
409
- lineHeight: 1,
410
- color: 'text.secondary',
411
- '&:hover': {
412
- color: 'text.primary',
413
- },
414
- }}
415
- >
416
- <Box
417
- component={ArrowTopRightBorder}
418
- sx={{
419
- width: 18,
420
- height: 18,
421
- }}
422
- />
423
- </Box>
424
- <ButtonBase
425
- sx={{
426
- display: 'flex',
427
- alignItems: 'center',
428
- justifyContent: 'center',
429
- height: '100%',
430
- px: 8,
431
- border: 'solid 0',
432
- borderLeftWidth: 1,
433
- borderColor: 'border.main',
434
- color: 'error.main',
435
- '&:hover': {
436
- backgroundColor: 'background.tag',
437
- },
438
- }}
439
- onClick={() => {
440
- walletWeb3?.disconnectWallet();
441
- onClose();
442
- }}
443
- >
444
- <Box
445
- component={Disconnect}
446
- sx={{
447
- width: 18,
448
- height: 18,
449
- }}
450
- />
451
- </ButtonBase>
452
- </Box>
453
- </DialogTitle>
454
- <Box
455
- sx={{
456
- display: 'flex',
457
-
458
- flexDirection: 'column',
459
- overflowY: 'auto',
460
- overflowX: 'hidden',
461
- px: 20,
462
- }}
463
- ref={scrollableNodeRef}
464
- >
465
- <AccountCardInfo
466
- chainId={chainId}
467
- setShowSendTokenPage={setShowSendTokenPage}
468
- setShowReceiveTokenPage={setShowReceiveTokenPage}
469
- allFiatPriceBalanceLoading={
470
- balanceListData.allFiatPriceBalanceLoading
471
- }
472
- allFiatPriceBalance={balanceListData.allFiatPriceBalance}
473
- />
474
- <Tabs
475
- value={listTab}
476
- onChange={(_: any, v: ListTab) => setListTab(v as ListTab)}
477
- >
478
- <TabsGroup tabs={tabs} />
479
- <TabPanel value={ListTab.tokens}>
480
- <HasBalanceTokenList balanceListData={balanceListData} />
481
- </TabPanel>
482
- <TabPanel value={ListTab.activity} className="pt-2">
483
- <ActivityList
484
- fetchTransactionQuery={fetchTransactionQuery}
485
- getScrollParent={getScrollParent}
486
- />
487
- </TabPanel>
488
- </Tabs>
489
- </Box>
490
- </>
491
- );
492
- }
493
-
494
- export default AccountPage;
1
+ 'use client';
2
+
3
+ import {
4
+ LoadingSkeleton,
5
+ Tabs,
6
+ alpha,
7
+ Box,
8
+ BoxProps,
9
+ ThemeProvider,
10
+ useTheme,
11
+ createTheme,
12
+ Tooltip,
13
+ RotatingIcon,
14
+ TabsGroup,
15
+ TabPanel,
16
+ ButtonBase,
17
+ } from '@dodoex/components';
18
+ import {
19
+ ArrowBack,
20
+ ArrowTopRightBorder,
21
+ Copy,
22
+ Disconnect,
23
+ } from '@dodoex/icons';
24
+ import copy from 'copy-to-clipboard';
25
+ import WalletWeb3, { useWalletStore } from '@dodoex/wallet-web3';
26
+ import { Trans } from '@lingui/macro';
27
+ import { BigNumber } from 'bignumber.js';
28
+ import React from 'react';
29
+ import { truncatePoolAddress } from '../components/AddressWithLinkAndCopy';
30
+ import { DialogTitle } from '../components/Dialog';
31
+ import { useHasBalanceTokenList } from '../hooks/useHasBalanceTokenList';
32
+ import { useTransactionList } from '../hooks/useTransactionList';
33
+ import { formatReadableNumber, formatShortNumber } from '../utils/formatter';
34
+ import { useWalletConnectContext } from '../WalletConnectProvider';
35
+ import ActivityList from './ActivityList';
36
+ import HasBalanceTokenList from './HasBalanceTokenList';
37
+
38
+ function AccountCardInfoBg({
39
+ children,
40
+ chainLogo,
41
+ }: React.PropsWithChildren<{
42
+ chainLogo: React.ReactNode;
43
+ }>) {
44
+ return (
45
+ <Box
46
+ sx={{
47
+ position: 'relative',
48
+ padding: 20,
49
+ borderRadius: 12,
50
+ border: 'solid 1px',
51
+ borderColor: 'border.main',
52
+ color: 'text.primary',
53
+ zIndex: 0,
54
+ }}
55
+ >
56
+ <Box
57
+ sx={{
58
+ position: 'absolute',
59
+ top: 0,
60
+ bottom: 0,
61
+ left: 0,
62
+ right: 0,
63
+ zIndex: -1,
64
+ overflow: 'hidden',
65
+ borderRadius: 12,
66
+ }}
67
+ >
68
+ <Box
69
+ sx={{
70
+ position: 'absolute',
71
+ top: 0,
72
+ bottom: 0,
73
+ left: 0,
74
+ right: 0,
75
+ backgroundColor: '#F6F6F6',
76
+ }}
77
+ />
78
+ <Box
79
+ sx={{
80
+ position: 'absolute',
81
+ top: 0,
82
+ bottom: 0,
83
+ left: 0,
84
+ right: 0,
85
+ '& > img, & > svg': {
86
+ height: 'auto',
87
+ width: 'calc(100% + 2px)',
88
+ position: 'absolute',
89
+ '&:first-child': {
90
+ top: '50%',
91
+ transform: 'translateY(-50%)',
92
+ opacity: 0.5,
93
+ filter: 'blur(99.99999237060547px)',
94
+ },
95
+ '&:last-child': {
96
+ left: 60,
97
+ bottom: 40,
98
+ opacity: 0.2,
99
+ filter: 'blur(7.499999523162842px)',
100
+ },
101
+ },
102
+ }}
103
+ >
104
+ {chainLogo}
105
+ {chainLogo}
106
+ </Box>
107
+ <Box
108
+ sx={{
109
+ position: 'absolute',
110
+ top: 0,
111
+ bottom: 0,
112
+ left: 0,
113
+ right: 0,
114
+ background:
115
+ 'linear-gradient(108deg, rgba(255, 255, 255, 0.90) 9.8%, rgba(255, 255, 255, 0.00) 49.94%)',
116
+ }}
117
+ />
118
+ </Box>
119
+ {children}
120
+ </Box>
121
+ );
122
+ }
123
+
124
+ function AccountCardInfo({
125
+ chainId,
126
+ setShowSendTokenPage,
127
+ setShowReceiveTokenPage,
128
+ allFiatPriceBalance,
129
+ allFiatPriceBalanceLoading,
130
+ }: {
131
+ chainId: number;
132
+ setShowSendTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
133
+ setShowReceiveTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
134
+ allFiatPriceBalance: BigNumber;
135
+ allFiatPriceBalanceLoading: boolean;
136
+ }) {
137
+ const { getChain } = useWalletConnectContext();
138
+ const chain = getChain(chainId);
139
+ const theme = createTheme({
140
+ mode: 'light',
141
+ });
142
+
143
+ return (
144
+ <ThemeProvider theme={theme}>
145
+ <AccountCardInfoBg chainLogo={chain?.logoBg ?? chain?.logo}>
146
+ <Box
147
+ sx={{
148
+ typography: 'body2',
149
+ color: 'text.secondary',
150
+ }}
151
+ >
152
+ <Trans>Balance</Trans>
153
+ </Box>
154
+ <LoadingSkeleton
155
+ component="div"
156
+ loading={allFiatPriceBalanceLoading}
157
+ loadingSx={{
158
+ width: 120,
159
+ }}
160
+ sx={{
161
+ mt: 4,
162
+ typography: 'h1',
163
+ }}
164
+ title={formatReadableNumber({ input: allFiatPriceBalance })}
165
+ >
166
+ ${formatShortNumber(allFiatPriceBalance)}
167
+ </LoadingSkeleton>
168
+ <Box
169
+ sx={{
170
+ display: 'flex',
171
+ justifyContent: 'space-between',
172
+ alignItems: 'center',
173
+ gap: 20,
174
+ mt: 28,
175
+ }}
176
+ >
177
+ {/* send */}
178
+ <ButtonBase
179
+ sx={{
180
+ flex: 1,
181
+ display: 'flex',
182
+ flexDirection: 'column',
183
+ gap: 12,
184
+ px: 20,
185
+ py: 12,
186
+ typography: 'body2',
187
+ backgroundColor: 'background.paperDarkContrast',
188
+ borderRadius: 12,
189
+ textAlign: 'left',
190
+ '&:hover': {
191
+ backgroundColor: 'primary.main',
192
+ color: 'primary.contrastText',
193
+ },
194
+ }}
195
+ onClick={() => {
196
+ setShowSendTokenPage(true);
197
+ }}
198
+ >
199
+ <Box
200
+ component={ArrowBack}
201
+ sx={{
202
+ transform: 'rotate(90deg)',
203
+ }}
204
+ />
205
+ <Trans>Send</Trans>
206
+ </ButtonBase>
207
+ {/* receive */}
208
+ <ButtonBase
209
+ sx={{
210
+ flex: 1,
211
+ display: 'flex',
212
+ flexDirection: 'column',
213
+ gap: 12,
214
+ px: 20,
215
+ py: 12,
216
+ typography: 'body2',
217
+ backgroundColor: 'background.paperDarkContrast',
218
+ borderRadius: 12,
219
+ textAlign: 'left',
220
+ '&:hover': {
221
+ backgroundColor: 'primary.main',
222
+ color: 'primary.contrastText',
223
+ },
224
+ }}
225
+ onClick={() => {
226
+ setShowReceiveTokenPage(true);
227
+ }}
228
+ >
229
+ <Box
230
+ component={ArrowBack}
231
+ sx={{
232
+ transform: 'rotate(-90deg)',
233
+ }}
234
+ />
235
+ <Trans>Receive</Trans>
236
+ </ButtonBase>
237
+ </Box>
238
+ </AccountCardInfoBg>
239
+ </ThemeProvider>
240
+ );
241
+ }
242
+
243
+ enum ListTab {
244
+ tokens = 'tokens',
245
+ activity = 'activity',
246
+ }
247
+ function AccountPage({
248
+ chainId,
249
+ account,
250
+ walletWeb3,
251
+ onClose,
252
+ setShowSendTokenPage,
253
+ setShowReceiveTokenPage,
254
+ }: {
255
+ chainId: number;
256
+ account?: string;
257
+ walletWeb3?: WalletWeb3;
258
+ onClose: () => void;
259
+ setShowSendTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
260
+ setShowReceiveTokenPage: React.Dispatch<React.SetStateAction<boolean>>;
261
+ }) {
262
+ const { getChain } = useWalletConnectContext();
263
+ const { connected } = useWalletStore();
264
+ const connectedWallet = connected?.wallet;
265
+ const [listTab, setListTab] = React.useState(ListTab.tokens);
266
+ const scrollableNodeRef = React.useRef<HTMLDivElement>(null);
267
+ const getScrollParent = React.useCallback(() => {
268
+ if (scrollableNodeRef) return scrollableNodeRef.current;
269
+ return null;
270
+ }, [scrollableNodeRef]);
271
+
272
+ const balanceListData = useHasBalanceTokenList({
273
+ account,
274
+ visible: listTab === ListTab.tokens,
275
+ });
276
+
277
+ const fetchTransactionQuery = useTransactionList({
278
+ account,
279
+ chainId,
280
+ });
281
+ const tabs = [
282
+ { key: ListTab.tokens, value: <Trans>Token</Trans> },
283
+ {
284
+ key: ListTab.activity,
285
+ value: (
286
+ <Tooltip title={<Trans>On-chain transaction records</Trans>}>
287
+ <Box
288
+ sx={{
289
+ display: 'flex',
290
+ alignItems: 'center',
291
+ gap: 8,
292
+ }}
293
+ >
294
+ <Trans>Activity</Trans>
295
+ {!!fetchTransactionQuery.pendingList.length && <RotatingIcon />}
296
+ </Box>
297
+ </Tooltip>
298
+ ),
299
+ },
300
+ ];
301
+
302
+ const [showCopyTooltip, setShowCopyTooltip] = React.useState(false);
303
+ const autoCloseShowCopyTooltip = React.useCallback(() => {
304
+ const time = setTimeout(() => {
305
+ setShowCopyTooltip(false);
306
+ }, 1500);
307
+
308
+ return () => {
309
+ clearTimeout(time);
310
+ };
311
+ }, []);
312
+
313
+ const chain = getChain(chainId);
314
+ if (!account || !connectedWallet) return null;
315
+ return (
316
+ <>
317
+ <DialogTitle onClose={onClose}>
318
+ <Box
319
+ sx={{
320
+ display: 'flex',
321
+ gap: 8,
322
+ alignItems: 'center',
323
+ height: 34,
324
+ borderRadius: 8,
325
+ backgroundColor: 'background.paperContrast',
326
+ }}
327
+ >
328
+ <Box
329
+ sx={{
330
+ display: 'flex',
331
+ alignItems: 'center',
332
+ gap: 4,
333
+ pl: 8,
334
+ }}
335
+ >
336
+ <Box
337
+ sx={{
338
+ position: 'relative',
339
+ pr: 6,
340
+ width: 28,
341
+ height: 22,
342
+ }}
343
+ >
344
+ {!!connectedWallet.logo && (
345
+ <img
346
+ src={connectedWallet.logo}
347
+ alt={connectedWallet.showName}
348
+ width={22}
349
+ height={22}
350
+ />
351
+ )}
352
+ {!!chain?.logo && (
353
+ <Box
354
+ sx={{
355
+ position: 'absolute',
356
+ bottom: 0,
357
+ right: 0,
358
+ width: 12,
359
+ height: 12,
360
+ '& > img, & > svg': {
361
+ position: 'absolute',
362
+ inset: 0,
363
+ width: '100%',
364
+ height: '100%',
365
+ borderRadius: '50%',
366
+ border: 'solid 1px',
367
+ borderColor: 'border.main',
368
+ },
369
+ }}
370
+ >
371
+ {chain?.logo}
372
+ </Box>
373
+ )}
374
+ </Box>
375
+ {truncatePoolAddress(account)}
376
+ </Box>
377
+ <Tooltip
378
+ onlyClick
379
+ arrow={false}
380
+ title={<Trans>Copied</Trans>}
381
+ open={showCopyTooltip}
382
+ onOpen={() => {
383
+ setShowCopyTooltip(true);
384
+ autoCloseShowCopyTooltip();
385
+ }}
386
+ onClose={() => setShowCopyTooltip(false)}
387
+ >
388
+ <Box
389
+ component={Copy}
390
+ onClick={() => {
391
+ copy(account);
392
+ }}
393
+ sx={{
394
+ width: 18,
395
+ height: 18,
396
+ cursor: 'pointer',
397
+ color: 'text.secondary',
398
+ '&:hover': {
399
+ color: 'text.primary',
400
+ },
401
+ }}
402
+ />
403
+ </Tooltip>
404
+ <Box
405
+ component="a"
406
+ rel="noopener noreferrer"
407
+ target="_blank"
408
+ href={chain?.scanUrl + '/address/' + account}
409
+ sx={{
410
+ display: 'flex',
411
+ lineHeight: 1,
412
+ color: 'text.secondary',
413
+ '&:hover': {
414
+ color: 'text.primary',
415
+ },
416
+ }}
417
+ >
418
+ <Box
419
+ component={ArrowTopRightBorder}
420
+ sx={{
421
+ width: 18,
422
+ height: 18,
423
+ }}
424
+ />
425
+ </Box>
426
+ <ButtonBase
427
+ sx={{
428
+ display: 'flex',
429
+ alignItems: 'center',
430
+ justifyContent: 'center',
431
+ height: '100%',
432
+ px: 8,
433
+ border: 'solid 0',
434
+ borderLeftWidth: 1,
435
+ borderColor: 'border.main',
436
+ color: 'error.main',
437
+ '&:hover': {
438
+ backgroundColor: 'background.tag',
439
+ },
440
+ }}
441
+ onClick={() => {
442
+ walletWeb3?.disconnectWallet();
443
+ onClose();
444
+ }}
445
+ >
446
+ <Box
447
+ component={Disconnect}
448
+ sx={{
449
+ width: 18,
450
+ height: 18,
451
+ }}
452
+ />
453
+ </ButtonBase>
454
+ </Box>
455
+ </DialogTitle>
456
+ <Box
457
+ sx={{
458
+ display: 'flex',
459
+
460
+ flexDirection: 'column',
461
+ overflowY: 'auto',
462
+ overflowX: 'hidden',
463
+ px: 20,
464
+ }}
465
+ ref={scrollableNodeRef}
466
+ >
467
+ <AccountCardInfo
468
+ chainId={chainId}
469
+ setShowSendTokenPage={setShowSendTokenPage}
470
+ setShowReceiveTokenPage={setShowReceiveTokenPage}
471
+ allFiatPriceBalanceLoading={
472
+ balanceListData.allFiatPriceBalanceLoading
473
+ }
474
+ allFiatPriceBalance={balanceListData.allFiatPriceBalance}
475
+ />
476
+ <Tabs
477
+ value={listTab}
478
+ onChange={(_: any, v: ListTab) => setListTab(v as ListTab)}
479
+ >
480
+ <TabsGroup tabs={tabs} />
481
+ <TabPanel value={ListTab.tokens}>
482
+ <HasBalanceTokenList balanceListData={balanceListData} />
483
+ </TabPanel>
484
+ <TabPanel value={ListTab.activity} className="pt-2">
485
+ <ActivityList
486
+ fetchTransactionQuery={fetchTransactionQuery}
487
+ getScrollParent={getScrollParent}
488
+ />
489
+ </TabPanel>
490
+ </Tabs>
491
+ </Box>
492
+ </>
493
+ );
494
+ }
495
+
496
+ export default AccountPage;