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