@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,156 +1,158 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Modal, ModalProps } from '@mui/base/Modal';
|
|
4
|
+
import { Error } from '@dodoex/icons';
|
|
5
|
+
import clsx from 'clsx';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Box, BoxProps, ButtonBase, useTheme } from '@dodoex/components';
|
|
8
|
+
|
|
9
|
+
export function DialogTitle({
|
|
10
|
+
children,
|
|
11
|
+
center,
|
|
12
|
+
onClose,
|
|
13
|
+
sx,
|
|
14
|
+
}: React.PropsWithChildren<{
|
|
15
|
+
center?: boolean;
|
|
16
|
+
onClose?: () => void;
|
|
17
|
+
sx?: BoxProps['sx'];
|
|
18
|
+
}>) {
|
|
19
|
+
return (
|
|
20
|
+
<Box
|
|
21
|
+
sx={{
|
|
22
|
+
position: 'relative',
|
|
23
|
+
display: 'flex',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
p: 20,
|
|
26
|
+
justifyContent: center ? 'center' : 'flex-start',
|
|
27
|
+
...sx,
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
<Box
|
|
31
|
+
component="h5"
|
|
32
|
+
sx={{
|
|
33
|
+
typography: 'h5',
|
|
34
|
+
margin: 0,
|
|
35
|
+
padding: 0,
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
</Box>
|
|
40
|
+
{!!onClose && (
|
|
41
|
+
<Box
|
|
42
|
+
component={ButtonBase}
|
|
43
|
+
onClick={() => onClose()}
|
|
44
|
+
sx={{
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
top: 20,
|
|
47
|
+
right: 20,
|
|
48
|
+
color: 'text.secondary',
|
|
49
|
+
'&:hover': {
|
|
50
|
+
color: 'text.primary',
|
|
51
|
+
},
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<Box
|
|
55
|
+
component={Error}
|
|
56
|
+
sx={{
|
|
57
|
+
width: 24,
|
|
58
|
+
height: 24,
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
</Box>
|
|
62
|
+
)}
|
|
63
|
+
</Box>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const Backdrop = React.forwardRef<
|
|
68
|
+
HTMLDivElement,
|
|
69
|
+
{ open?: boolean; className: string }
|
|
70
|
+
>((props, ref) => {
|
|
71
|
+
const { open, className, ...other } = props;
|
|
72
|
+
return (
|
|
73
|
+
<Box
|
|
74
|
+
className={clsx({ 'MuiBackdrop-open': open }, className)}
|
|
75
|
+
sx={{
|
|
76
|
+
position: 'fixed',
|
|
77
|
+
inset: 0,
|
|
78
|
+
zIndex: -1,
|
|
79
|
+
backgroundColor: 'background.backdrop',
|
|
80
|
+
'-webkitTapHighlightColor': 'transparent',
|
|
81
|
+
}}
|
|
82
|
+
ref={ref}
|
|
83
|
+
{...other}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
Backdrop.displayName = 'Backdrop';
|
|
88
|
+
|
|
89
|
+
export function DialogBase({ className, slots, ...props }: ModalProps) {
|
|
90
|
+
return (
|
|
91
|
+
<Modal
|
|
92
|
+
className={clsx('fixed z-modal inset-0 flex', className)}
|
|
93
|
+
slots={{
|
|
94
|
+
backdrop: Backdrop,
|
|
95
|
+
...slots,
|
|
96
|
+
}}
|
|
97
|
+
{...props}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default function Dialog({
|
|
103
|
+
children,
|
|
104
|
+
sx,
|
|
105
|
+
bodySx,
|
|
106
|
+
slots,
|
|
107
|
+
width,
|
|
108
|
+
...props
|
|
109
|
+
}: Omit<ModalProps, 'children'> & {
|
|
110
|
+
children: React.ReactNode;
|
|
111
|
+
sx?: BoxProps['sx'];
|
|
112
|
+
bodySx?: BoxProps['sx'];
|
|
113
|
+
width?: number;
|
|
114
|
+
}) {
|
|
115
|
+
const theme = useTheme();
|
|
116
|
+
return (
|
|
117
|
+
<Box
|
|
118
|
+
component={Modal}
|
|
119
|
+
slots={{
|
|
120
|
+
backdrop: Backdrop,
|
|
121
|
+
...slots,
|
|
122
|
+
}}
|
|
123
|
+
sx={{
|
|
124
|
+
position: 'fixed',
|
|
125
|
+
inset: 0,
|
|
126
|
+
display: 'flex',
|
|
127
|
+
alignItems: 'flex-end',
|
|
128
|
+
[theme.breakpoints.up('tablet')]: {
|
|
129
|
+
alignItems: 'center',
|
|
130
|
+
justifyContent: 'center',
|
|
131
|
+
},
|
|
132
|
+
zIndex: (theme.zIndex as any)?.modal ?? 100,
|
|
133
|
+
...sx,
|
|
134
|
+
}}
|
|
135
|
+
{...props}
|
|
136
|
+
>
|
|
137
|
+
<Box
|
|
138
|
+
sx={{
|
|
139
|
+
display: 'flex',
|
|
140
|
+
flexDirection: 'column',
|
|
141
|
+
backgroundColor: 'background.paper',
|
|
142
|
+
borderTopWidth: 1,
|
|
143
|
+
maxHeight: '80vh',
|
|
144
|
+
borderRadius: theme.spacing(6, 6, 0, 0),
|
|
145
|
+
width: '100%',
|
|
146
|
+
[theme.breakpoints.up('tablet')]: {
|
|
147
|
+
minWidth: width ?? 420,
|
|
148
|
+
width,
|
|
149
|
+
borderRadius: 12,
|
|
150
|
+
},
|
|
151
|
+
...bodySx,
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
{children}
|
|
155
|
+
</Box>
|
|
156
|
+
</Box>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
@@ -1,165 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
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
|
-
const [
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const
|
|
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
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
5
|
+
import Identicon from 'identicon.js';
|
|
6
|
+
import { Box, BoxProps } from '@dodoex/components';
|
|
7
|
+
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
8
|
+
|
|
9
|
+
export interface TokenInfo {
|
|
10
|
+
readonly chainId: number;
|
|
11
|
+
readonly address: string;
|
|
12
|
+
readonly symbol?: string;
|
|
13
|
+
readonly name?: string;
|
|
14
|
+
readonly decimals?: number;
|
|
15
|
+
readonly logoURI?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface TokenLogoProps {
|
|
19
|
+
address?: string;
|
|
20
|
+
logoURI?: string;
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
marginRight?: number;
|
|
24
|
+
url?: string;
|
|
25
|
+
zIndex?: number;
|
|
26
|
+
sx?: BoxProps['sx'];
|
|
27
|
+
chainId?: number;
|
|
28
|
+
noShowChain?: boolean;
|
|
29
|
+
noBorder?: boolean;
|
|
30
|
+
chainSize?: number;
|
|
31
|
+
logoOffset?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default function TokenLogo({
|
|
35
|
+
width = 24,
|
|
36
|
+
height = 24,
|
|
37
|
+
marginRight = 8,
|
|
38
|
+
zIndex,
|
|
39
|
+
address,
|
|
40
|
+
logoURI,
|
|
41
|
+
sx,
|
|
42
|
+
chainId,
|
|
43
|
+
noBorder,
|
|
44
|
+
chainSize = 12,
|
|
45
|
+
logoOffset: logoOffsetProps,
|
|
46
|
+
}: TokenLogoProps): React.ReactElement {
|
|
47
|
+
const [loaded, setLoaded] = useState(false);
|
|
48
|
+
const [defaultUrl, setDefaultUrl] = useState('');
|
|
49
|
+
const [error, setError] = useState(false);
|
|
50
|
+
const onLoad = useCallback(() => setLoaded(true), []);
|
|
51
|
+
const symbol = '';
|
|
52
|
+
const initial = symbol?.charAt(0).toUpperCase();
|
|
53
|
+
|
|
54
|
+
const { getTokenLogoUrl } = useWalletConnectContext();
|
|
55
|
+
const logoUrl =
|
|
56
|
+
getTokenLogoUrl?.({
|
|
57
|
+
chainId,
|
|
58
|
+
address,
|
|
59
|
+
width,
|
|
60
|
+
height,
|
|
61
|
+
}) || logoURI;
|
|
62
|
+
|
|
63
|
+
let logoOffset = logoOffsetProps;
|
|
64
|
+
if (!logoOffset) {
|
|
65
|
+
logoOffset = chainSize / 2 < 8 ? chainSize / 2 : chainSize - 8;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
setError(false);
|
|
70
|
+
}, [address, logoUrl]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
try {
|
|
74
|
+
let addr = address;
|
|
75
|
+
if (addr && addr.length < 15) {
|
|
76
|
+
addr = addr.padEnd(15, '0');
|
|
77
|
+
}
|
|
78
|
+
if (addr) {
|
|
79
|
+
const data = new Identicon(addr, {
|
|
80
|
+
size: width,
|
|
81
|
+
format: 'svg',
|
|
82
|
+
margin: 0.2,
|
|
83
|
+
background: [255, 234, 4, 255],
|
|
84
|
+
}).toString();
|
|
85
|
+
setDefaultUrl(`data:image/svg+xml;base64,${data}`);
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
// address is empty
|
|
89
|
+
console.error('generate Identicon error: ', err);
|
|
90
|
+
}
|
|
91
|
+
}, [address, width]);
|
|
92
|
+
|
|
93
|
+
const showChain = false;
|
|
94
|
+
|
|
95
|
+
const logo = (
|
|
96
|
+
<Box
|
|
97
|
+
sx={{
|
|
98
|
+
position: 'relative',
|
|
99
|
+
display: 'inline-flex',
|
|
100
|
+
alignItems: 'center',
|
|
101
|
+
justifyContent: 'center',
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
borderRadius: '50%',
|
|
105
|
+
...(noBorder
|
|
106
|
+
? {}
|
|
107
|
+
: {
|
|
108
|
+
border: 'solid 1px',
|
|
109
|
+
borderColor: 'border.main',
|
|
110
|
+
}),
|
|
111
|
+
flexShrink: 0,
|
|
112
|
+
...(showChain
|
|
113
|
+
? {}
|
|
114
|
+
: {
|
|
115
|
+
marginRight,
|
|
116
|
+
zIndex,
|
|
117
|
+
...sx,
|
|
118
|
+
}),
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
{!loaded && (
|
|
122
|
+
<Box
|
|
123
|
+
sx={{
|
|
124
|
+
typography: 'ht',
|
|
125
|
+
height: '100%',
|
|
126
|
+
width: '100%',
|
|
127
|
+
borderRadius: '50%',
|
|
128
|
+
border: 'transparent 2px solid',
|
|
129
|
+
borderColor: 'text.primary',
|
|
130
|
+
color: 'text.primary',
|
|
131
|
+
|
|
132
|
+
display: 'flex',
|
|
133
|
+
alignItems: 'center',
|
|
134
|
+
justifyContent: 'center',
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
{initial}
|
|
138
|
+
</Box>
|
|
139
|
+
)}
|
|
140
|
+
<Box
|
|
141
|
+
component="img"
|
|
142
|
+
src={!logoUrl || error ? defaultUrl : logoUrl}
|
|
143
|
+
onLoad={onLoad}
|
|
144
|
+
onError={(e: any) => {
|
|
145
|
+
const target = e.target as HTMLImageElement;
|
|
146
|
+
if (address && defaultUrl) {
|
|
147
|
+
setError(true);
|
|
148
|
+
}
|
|
149
|
+
target.onerror = null;
|
|
150
|
+
}}
|
|
151
|
+
sx={{
|
|
152
|
+
position: 'absolute',
|
|
153
|
+
top: '0',
|
|
154
|
+
bottom: '0',
|
|
155
|
+
left: '0',
|
|
156
|
+
right: '0',
|
|
157
|
+
borderRadius: '50%',
|
|
158
|
+
overflow: 'hidden',
|
|
159
|
+
width: '100%',
|
|
160
|
+
height: '100%',
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
</Box>
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
return logo;
|
|
167
|
+
}
|