@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,498 +1,498 @@
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: string | number | null) => {
479
- if (v !== null) setListTab(v as ListTab);
480
- }}
481
- >
482
- <TabsGroup tabs={tabs} />
483
- <TabPanel value={ListTab.tokens}>
484
- <HasBalanceTokenList balanceListData={balanceListData} />
485
- </TabPanel>
486
- <TabPanel value={ListTab.activity} className="pt-2">
487
- <ActivityList
488
- fetchTransactionQuery={fetchTransactionQuery}
489
- getScrollParent={getScrollParent}
490
- />
491
- </TabPanel>
492
- </Tabs>
493
- </Box>
494
- </>
495
- );
496
- }
497
-
498
- 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: string | number | null) => {
479
+ if (v !== null) setListTab(v as ListTab);
480
+ }}
481
+ >
482
+ <TabsGroup tabs={tabs} />
483
+ <TabPanel value={ListTab.tokens}>
484
+ <HasBalanceTokenList balanceListData={balanceListData} />
485
+ </TabPanel>
486
+ <TabPanel value={ListTab.activity} className="pt-2">
487
+ <ActivityList
488
+ fetchTransactionQuery={fetchTransactionQuery}
489
+ getScrollParent={getScrollParent}
490
+ />
491
+ </TabPanel>
492
+ </Tabs>
493
+ </Box>
494
+ </>
495
+ );
496
+ }
497
+
498
+ export default AccountPage;