@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,249 +1,251 @@
|
|
|
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
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const [
|
|
36
|
-
const [
|
|
37
|
-
const [
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
!
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let
|
|
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
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useWalletStore } from '@dodoex/wallet-web3';
|
|
4
|
+
import { isAddress } from '@ethersproject/address';
|
|
5
|
+
import { ArrowBack, Loading } from '@dodoex/icons';
|
|
6
|
+
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { TokenInfo } from '../components/TokenLogo';
|
|
9
|
+
import { useMutation } from '@tanstack/react-query';
|
|
10
|
+
import BigNumber from 'bignumber.js';
|
|
11
|
+
import { Trans } from '@lingui/macro';
|
|
12
|
+
import { DialogTitle } from '../components/Dialog';
|
|
13
|
+
import { Box, Button, ButtonBase, useTheme } from '@dodoex/components';
|
|
14
|
+
import { truncatePoolAddress } from '../components/AddressWithLinkAndCopy';
|
|
15
|
+
|
|
16
|
+
export default function SendTokenPage({
|
|
17
|
+
open,
|
|
18
|
+
onClose,
|
|
19
|
+
onBack,
|
|
20
|
+
}: {
|
|
21
|
+
open?: boolean;
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
onBack: () => void;
|
|
24
|
+
}) {
|
|
25
|
+
const theme = useTheme();
|
|
26
|
+
const { getChain } = useWalletConnectContext();
|
|
27
|
+
const { chainId } = useWalletStore();
|
|
28
|
+
const chain = getChain(chainId);
|
|
29
|
+
const defaultToken = chain
|
|
30
|
+
? ({
|
|
31
|
+
...chain?.gasToken,
|
|
32
|
+
chainId,
|
|
33
|
+
} as TokenInfo)
|
|
34
|
+
: null;
|
|
35
|
+
const [token, setToken] = React.useState<TokenInfo | null>(defaultToken);
|
|
36
|
+
const [amount, setAmount] = React.useState('');
|
|
37
|
+
const [receiverAddress, setReceiverAddress] = React.useState('');
|
|
38
|
+
const [receiverAddressFormat, setReceiverAddressFormat] = React.useState('');
|
|
39
|
+
const [invalidReceiver, setInvalidReceiver] = React.useState(false);
|
|
40
|
+
|
|
41
|
+
const disabled =
|
|
42
|
+
!amount ||
|
|
43
|
+
!receiverAddress ||
|
|
44
|
+
invalidReceiver ||
|
|
45
|
+
!isAddress(receiverAddress);
|
|
46
|
+
|
|
47
|
+
const sendTokenMutation = useMutation({
|
|
48
|
+
mutationFn: async () => {
|
|
49
|
+
if (disabled || !token || token.decimals === undefined) return;
|
|
50
|
+
const amountWei = new BigNumber(amount).times(10 ** token.decimals);
|
|
51
|
+
const amountWeiStr = `0x${amountWei.toString(16)}`;
|
|
52
|
+
let data = '';
|
|
53
|
+
let paramsValue = '';
|
|
54
|
+
let to = token.address;
|
|
55
|
+
// if (
|
|
56
|
+
// token.address.toLowerCase() === defaultToken?.address?.toLowerCase()
|
|
57
|
+
// ) {
|
|
58
|
+
// paramsValue = amountWeiStr;
|
|
59
|
+
// data = '0x';
|
|
60
|
+
// to = receiverAddress;
|
|
61
|
+
// } else {
|
|
62
|
+
// paramsValue = '0x0';
|
|
63
|
+
// data = await TokenApi.encode.transferEncodeABI(
|
|
64
|
+
// receiverAddress,
|
|
65
|
+
// amountWeiStr,
|
|
66
|
+
// );
|
|
67
|
+
// }
|
|
68
|
+
// const result = await execute({
|
|
69
|
+
// brief: 'wallet.account.card.operate.send',
|
|
70
|
+
// spec: {
|
|
71
|
+
// opcode: OpCode.TX,
|
|
72
|
+
// value: paramsValue,
|
|
73
|
+
// to,
|
|
74
|
+
// data,
|
|
75
|
+
// },
|
|
76
|
+
// successBack: () => {
|
|
77
|
+
// // queryClient.invalidateQueries({
|
|
78
|
+
// // queryKey: ['graphql', 'FetchCrossChainDODOOrderList'],
|
|
79
|
+
// // });
|
|
80
|
+
// },
|
|
81
|
+
// metadata: {
|
|
82
|
+
// [MetadataFlag.sendToken]: true,
|
|
83
|
+
// },
|
|
84
|
+
// });
|
|
85
|
+
// if (result === ExecutionResult.Success) {
|
|
86
|
+
// setAmount('');
|
|
87
|
+
// }
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
if (open) {
|
|
93
|
+
setToken(defaultToken);
|
|
94
|
+
setAmount('');
|
|
95
|
+
sendTokenMutation.reset();
|
|
96
|
+
}
|
|
97
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
|
+
}, [open]);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<>
|
|
102
|
+
<DialogTitle onClose={onClose}>
|
|
103
|
+
<ButtonBase
|
|
104
|
+
onClick={onBack}
|
|
105
|
+
sx={{
|
|
106
|
+
display: 'flex',
|
|
107
|
+
gap: 8,
|
|
108
|
+
alignItems: 'center',
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<Box
|
|
112
|
+
component={ArrowBack}
|
|
113
|
+
sx={{
|
|
114
|
+
width: 16,
|
|
115
|
+
height: 16,
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
<Trans>Send</Trans>
|
|
119
|
+
</ButtonBase>
|
|
120
|
+
</DialogTitle>
|
|
121
|
+
<Box
|
|
122
|
+
sx={{
|
|
123
|
+
display: 'flex',
|
|
124
|
+
flexDirection: 'column',
|
|
125
|
+
justifyContent: 'space-between',
|
|
126
|
+
flex: 1,
|
|
127
|
+
px: 20,
|
|
128
|
+
pb: 20,
|
|
129
|
+
overflowY: 'auto',
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
<Box>
|
|
133
|
+
<Box
|
|
134
|
+
sx={{
|
|
135
|
+
p: 20,
|
|
136
|
+
backgroundColor: 'background.input',
|
|
137
|
+
borderRadius: 16,
|
|
138
|
+
}}
|
|
139
|
+
>
|
|
140
|
+
<Box
|
|
141
|
+
sx={{
|
|
142
|
+
color: 'text.secondary',
|
|
143
|
+
typography: 'h5',
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<Trans>Receiver address</Trans>
|
|
147
|
+
</Box>
|
|
148
|
+
<Box
|
|
149
|
+
component="input"
|
|
150
|
+
sx={{
|
|
151
|
+
mt: 12,
|
|
152
|
+
width: '100%',
|
|
153
|
+
fontSize: '36px',
|
|
154
|
+
lineHeight: '40px',
|
|
155
|
+
fontWeight: 600,
|
|
156
|
+
backgroundColor: 'transparent',
|
|
157
|
+
'&::placeholder': {
|
|
158
|
+
color: 'text.disabled',
|
|
159
|
+
},
|
|
160
|
+
}}
|
|
161
|
+
placeholder="0x..."
|
|
162
|
+
value={receiverAddressFormat || receiverAddress}
|
|
163
|
+
onChange={(evt) => {
|
|
164
|
+
setReceiverAddress(evt.target.value);
|
|
165
|
+
setInvalidReceiver(false);
|
|
166
|
+
}}
|
|
167
|
+
onFocus={() => {
|
|
168
|
+
setReceiverAddressFormat('');
|
|
169
|
+
}}
|
|
170
|
+
onBlur={(evt) => {
|
|
171
|
+
const value = evt.target.value;
|
|
172
|
+
if (!value) return;
|
|
173
|
+
if (!isAddress(value)) {
|
|
174
|
+
setInvalidReceiver(true);
|
|
175
|
+
} else {
|
|
176
|
+
setReceiverAddressFormat(truncatePoolAddress(value));
|
|
177
|
+
}
|
|
178
|
+
}}
|
|
179
|
+
/>
|
|
180
|
+
{!!invalidReceiver && (
|
|
181
|
+
<Box
|
|
182
|
+
sx={{
|
|
183
|
+
mt: 4,
|
|
184
|
+
color: 'error.main',
|
|
185
|
+
typography: 'h6',
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
<Trans>Invalid wallet address</Trans>
|
|
189
|
+
</Box>
|
|
190
|
+
)}
|
|
191
|
+
</Box>
|
|
192
|
+
{/* <Widget>
|
|
193
|
+
<TokenCard
|
|
194
|
+
amt={amount}
|
|
195
|
+
onInputChange={(v) => setAmount(v)}
|
|
196
|
+
token={token}
|
|
197
|
+
onTokenChange={(token) => setToken(token)}
|
|
198
|
+
showPercentage
|
|
199
|
+
sx={{
|
|
200
|
+
mt: 12,
|
|
201
|
+
pb: 20,
|
|
202
|
+
'&&& input': {
|
|
203
|
+
typography: 'h1',
|
|
204
|
+
'&::placeholder': {
|
|
205
|
+
typography: 'h1',
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
}}
|
|
209
|
+
/>
|
|
210
|
+
</Widget> */}
|
|
211
|
+
</Box>
|
|
212
|
+
<Button
|
|
213
|
+
disabled={disabled}
|
|
214
|
+
fullWidth
|
|
215
|
+
onClick={() => {
|
|
216
|
+
if (sendTokenMutation.isPending) return;
|
|
217
|
+
sendTokenMutation.mutate();
|
|
218
|
+
}}
|
|
219
|
+
sx={{
|
|
220
|
+
gap: 4,
|
|
221
|
+
mt: 12,
|
|
222
|
+
width: '100%',
|
|
223
|
+
fontWeight: 600,
|
|
224
|
+
}}
|
|
225
|
+
>
|
|
226
|
+
{sendTokenMutation.isPending && (
|
|
227
|
+
<Box
|
|
228
|
+
component={Loading}
|
|
229
|
+
sx={{
|
|
230
|
+
width: 20,
|
|
231
|
+
'& path': {
|
|
232
|
+
fill: theme.palette.primary.contrastText,
|
|
233
|
+
},
|
|
234
|
+
animation: 'loadingRotate 1.1s infinite linear',
|
|
235
|
+
'@keyframes loadingRotate': {
|
|
236
|
+
'0%': {
|
|
237
|
+
transform: 'rotate(0deg)',
|
|
238
|
+
},
|
|
239
|
+
'100%': {
|
|
240
|
+
transform: 'rotate(359deg)',
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
<Trans>Send</Trans>
|
|
247
|
+
</Button>
|
|
248
|
+
</Box>
|
|
249
|
+
</>
|
|
250
|
+
);
|
|
251
|
+
}
|