@dodoex/wallet-web3-react 0.2.0 → 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 +91 -76
  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 -146
  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,246 +1,248 @@
1
- import { Button, Input, Box, ButtonBase } from '@dodoex/components';
2
- import WalletWeb3 from '@dodoex/wallet-web3';
3
- import React from 'react';
4
- import {
5
- alchemyWallet,
6
- useConnectAlchemy,
7
- useConnectAlchemyQuery,
8
- USERNAME_PREFIX,
9
- } from './useConnectAlchemy';
10
- import { t, Trans } from '@lingui/macro';
11
- import { ArrowRight } from '@dodoex/icons';
12
- import { validateEmail } from '../../utils/utils';
13
- import Dialog, { DialogTitle } from '../../components/Dialog';
14
-
15
- export default function ConnectAlchemy({
16
- open,
17
- walletWeb3,
18
- setOpen,
19
- }: {
20
- open: boolean;
21
- walletWeb3: WalletWeb3;
22
- setOpen: (open: boolean) => void;
23
- }) {
24
- const [email, setEmail] = React.useState('');
25
- const invalidEmail = !!email && !validateEmail(email);
26
- const onClose = () => setOpen(false);
27
-
28
- useConnectAlchemyQuery({
29
- walletWeb3,
30
- showAlchemyConnect: () => setOpen(true),
31
- });
32
- const connectMutation = useConnectAlchemy({
33
- walletWeb3,
34
- });
35
-
36
- return (
37
- <Dialog open={open} onClose={onClose}>
38
- <DialogTitle
39
- sx={{
40
- p: 20,
41
- borderWidth: '0 0 1px',
42
- borderStyle: 'solid',
43
- borderColor: 'border.main',
44
- }}
45
- >
46
- <Trans>Connect Alchemy</Trans>
47
- </DialogTitle>
48
- <Box
49
- sx={{
50
- p: 20,
51
- }}
52
- >
53
- <Box
54
- component="img"
55
- src={alchemyWallet.logo}
56
- sx={{
57
- display: 'block',
58
- mx: 'auto',
59
- width: 40,
60
- height: 40,
61
- }}
62
- />
63
- {connectMutation.variables?.type === 'email' &&
64
- (connectMutation.isSuccess || connectMutation.isPending) ? (
65
- <>
66
- <Box
67
- sx={{
68
- mt: 20,
69
- textAlign: 'center',
70
- typography: 'caption',
71
- }}
72
- >
73
- <Trans>Log in with your email</Trans>
74
- </Box>
75
- <Box
76
- sx={{
77
- mt: 12,
78
- mx: 'auto',
79
- maxWidth: 300,
80
- textAlign: 'center',
81
- color: 'text.secondary',
82
- typography: 'body2',
83
- }}
84
- >
85
- <Trans>
86
- Check your email and click the link to complete login
87
- </Trans>
88
- </Box>
89
- <ButtonBase
90
- sx={{
91
- display: 'flex',
92
- justifyContent: 'center',
93
- alignItems: 'center',
94
- mt: 20,
95
- mx: 'auto',
96
- typography: 'body2',
97
- '&:hover': {
98
- color: 'text.secondary',
99
- },
100
- }}
101
- onClick={() => {
102
- connectMutation.reset();
103
- }}
104
- >
105
- <Trans>Go Back</Trans>
106
- <Box
107
- component={ArrowRight}
108
- sx={{
109
- width: 18,
110
- height: 18,
111
- }}
112
- />
113
- </ButtonBase>
114
- </>
115
- ) : (
116
- <>
117
- <Box
118
- sx={{
119
- mt: 20,
120
- mx: 'auto',
121
- textAlign: 'center',
122
- maxWidth: 300,
123
- typography: 'caption',
124
- }}
125
- >
126
- <Trans>Log in with your email or a passkey</Trans>
127
- </Box>
128
- <Input
129
- placeholder={t`Enter email`}
130
- fullWidth
131
- height={48}
132
- errorMsg={invalidEmail ? t`Invalid email` : undefined}
133
- value={email}
134
- onChange={(evt) => setEmail(evt.target.value)}
135
- sx={{
136
- mt: 20,
137
- }}
138
- />
139
- <Button
140
- fullWidth
141
- disabled={!email || invalidEmail}
142
- sx={{
143
- mt: 12,
144
- }}
145
- isLoading={
146
- connectMutation.variables?.type === 'email' &&
147
- connectMutation.isPending
148
- }
149
- onClick={() => {
150
- connectMutation.mutate({
151
- type: 'email',
152
- email,
153
- });
154
- }}
155
- >
156
- <Trans>Submit</Trans>
157
- </Button>
158
-
159
- <Box
160
- sx={{
161
- position: 'relative',
162
- mt: 20,
163
- textAlign: 'center',
164
- '&::before': {
165
- content: '""',
166
- display: 'block',
167
- position: 'absolute',
168
- top: '50%',
169
- left: 0,
170
- right: 0,
171
- transform: 'translateY(-50%)',
172
- height: '1px',
173
- backgroundColor: 'border.main',
174
- },
175
- }}
176
- >
177
- <Box
178
- component="span"
179
- sx={{
180
- px: 8,
181
- backgroundColor: 'background.paper',
182
- color: 'text.secondary',
183
- position: 'relative',
184
- zIndex: 1,
185
- }}
186
- >
187
- <Trans>or</Trans>
188
- </Box>
189
- </Box>
190
- <Button
191
- fullWidth
192
- variant={Button.Variant.outlined}
193
- sx={{
194
- mt: 20,
195
- }}
196
- onClick={async () => {
197
- await connectMutation.mutateAsync({
198
- type: 'passkey',
199
- createNew: true,
200
- username: `${USERNAME_PREFIX}_${Date.now()}`,
201
- });
202
- if (!connectMutation.isError) {
203
- onClose();
204
- }
205
- }}
206
- >
207
- <Trans>Create new passkey</Trans>
208
- </Button>
209
- <ButtonBase
210
- sx={{
211
- display: 'flex',
212
- justifyContent: 'center',
213
- alignItems: 'center',
214
- mt: 12,
215
- mx: 'auto',
216
- py: 8,
217
- typography: 'body2',
218
- '&:hover': {
219
- color: 'text.secondary',
220
- },
221
- }}
222
- onClick={async () => {
223
- await connectMutation.mutateAsync({
224
- type: 'passkey',
225
- createNew: false,
226
- });
227
- if (!connectMutation.isError) {
228
- onClose();
229
- }
230
- }}
231
- >
232
- <Trans>Choose existing passkey</Trans>
233
- <Box
234
- component={ArrowRight}
235
- sx={{
236
- width: 18,
237
- height: 18,
238
- }}
239
- />
240
- </ButtonBase>
241
- </>
242
- )}
243
- </Box>
244
- </Dialog>
245
- );
246
- }
1
+ 'use client';
2
+
3
+ import { Button, Input, Box, ButtonBase } from '@dodoex/components';
4
+ import WalletWeb3 from '@dodoex/wallet-web3';
5
+ import React from 'react';
6
+ import {
7
+ alchemyWallet,
8
+ useConnectAlchemy,
9
+ useConnectAlchemyQuery,
10
+ USERNAME_PREFIX,
11
+ } from './useConnectAlchemy';
12
+ import { t, Trans } from '@lingui/macro';
13
+ import { ArrowRight } from '@dodoex/icons';
14
+ import { validateEmail } from '../../utils/utils';
15
+ import Dialog, { DialogTitle } from '../../components/Dialog';
16
+
17
+ export default function ConnectAlchemy({
18
+ open,
19
+ walletWeb3,
20
+ setOpen,
21
+ }: {
22
+ open: boolean;
23
+ walletWeb3: WalletWeb3;
24
+ setOpen: (open: boolean) => void;
25
+ }) {
26
+ const [email, setEmail] = React.useState('');
27
+ const invalidEmail = !!email && !validateEmail(email);
28
+ const onClose = () => setOpen(false);
29
+
30
+ useConnectAlchemyQuery({
31
+ walletWeb3,
32
+ showAlchemyConnect: () => setOpen(true),
33
+ });
34
+ const connectMutation = useConnectAlchemy({
35
+ walletWeb3,
36
+ });
37
+
38
+ return (
39
+ <Dialog open={open} onClose={onClose}>
40
+ <DialogTitle
41
+ sx={{
42
+ p: 20,
43
+ borderWidth: '0 0 1px',
44
+ borderStyle: 'solid',
45
+ borderColor: 'border.main',
46
+ }}
47
+ >
48
+ <Trans>Connect Alchemy</Trans>
49
+ </DialogTitle>
50
+ <Box
51
+ sx={{
52
+ p: 20,
53
+ }}
54
+ >
55
+ <Box
56
+ component="img"
57
+ src={alchemyWallet.logo}
58
+ sx={{
59
+ display: 'block',
60
+ mx: 'auto',
61
+ width: 40,
62
+ height: 40,
63
+ }}
64
+ />
65
+ {connectMutation.variables?.type === 'email' &&
66
+ (connectMutation.isSuccess || connectMutation.isPending) ? (
67
+ <>
68
+ <Box
69
+ sx={{
70
+ mt: 20,
71
+ textAlign: 'center',
72
+ typography: 'caption',
73
+ }}
74
+ >
75
+ <Trans>Log in with your email</Trans>
76
+ </Box>
77
+ <Box
78
+ sx={{
79
+ mt: 12,
80
+ mx: 'auto',
81
+ maxWidth: 300,
82
+ textAlign: 'center',
83
+ color: 'text.secondary',
84
+ typography: 'body2',
85
+ }}
86
+ >
87
+ <Trans>
88
+ Check your email and click the link to complete login
89
+ </Trans>
90
+ </Box>
91
+ <ButtonBase
92
+ sx={{
93
+ display: 'flex',
94
+ justifyContent: 'center',
95
+ alignItems: 'center',
96
+ mt: 20,
97
+ mx: 'auto',
98
+ typography: 'body2',
99
+ '&:hover': {
100
+ color: 'text.secondary',
101
+ },
102
+ }}
103
+ onClick={() => {
104
+ connectMutation.reset();
105
+ }}
106
+ >
107
+ <Trans>Go Back</Trans>
108
+ <Box
109
+ component={ArrowRight}
110
+ sx={{
111
+ width: 18,
112
+ height: 18,
113
+ }}
114
+ />
115
+ </ButtonBase>
116
+ </>
117
+ ) : (
118
+ <>
119
+ <Box
120
+ sx={{
121
+ mt: 20,
122
+ mx: 'auto',
123
+ textAlign: 'center',
124
+ maxWidth: 300,
125
+ typography: 'caption',
126
+ }}
127
+ >
128
+ <Trans>Log in with your email or a passkey</Trans>
129
+ </Box>
130
+ <Input
131
+ placeholder={t`Enter email`}
132
+ fullWidth
133
+ height={48}
134
+ errorMsg={invalidEmail ? t`Invalid email` : undefined}
135
+ value={email}
136
+ onChange={(evt) => setEmail(evt.target.value)}
137
+ sx={{
138
+ mt: 20,
139
+ }}
140
+ />
141
+ <Button
142
+ fullWidth
143
+ disabled={!email || invalidEmail}
144
+ sx={{
145
+ mt: 12,
146
+ }}
147
+ isLoading={
148
+ connectMutation.variables?.type === 'email' &&
149
+ connectMutation.isPending
150
+ }
151
+ onClick={() => {
152
+ connectMutation.mutate({
153
+ type: 'email',
154
+ email,
155
+ });
156
+ }}
157
+ >
158
+ <Trans>Submit</Trans>
159
+ </Button>
160
+
161
+ <Box
162
+ sx={{
163
+ position: 'relative',
164
+ mt: 20,
165
+ textAlign: 'center',
166
+ '&::before': {
167
+ content: '""',
168
+ display: 'block',
169
+ position: 'absolute',
170
+ top: '50%',
171
+ left: 0,
172
+ right: 0,
173
+ transform: 'translateY(-50%)',
174
+ height: '1px',
175
+ backgroundColor: 'border.main',
176
+ },
177
+ }}
178
+ >
179
+ <Box
180
+ component="span"
181
+ sx={{
182
+ px: 8,
183
+ backgroundColor: 'background.paper',
184
+ color: 'text.secondary',
185
+ position: 'relative',
186
+ zIndex: 1,
187
+ }}
188
+ >
189
+ <Trans>or</Trans>
190
+ </Box>
191
+ </Box>
192
+ <Button
193
+ fullWidth
194
+ variant={Button.Variant.outlined}
195
+ sx={{
196
+ mt: 20,
197
+ }}
198
+ onClick={async () => {
199
+ await connectMutation.mutateAsync({
200
+ type: 'passkey',
201
+ createNew: true,
202
+ username: `${USERNAME_PREFIX}_${Date.now()}`,
203
+ });
204
+ if (!connectMutation.isError) {
205
+ onClose();
206
+ }
207
+ }}
208
+ >
209
+ <Trans>Create new passkey</Trans>
210
+ </Button>
211
+ <ButtonBase
212
+ sx={{
213
+ display: 'flex',
214
+ justifyContent: 'center',
215
+ alignItems: 'center',
216
+ mt: 12,
217
+ mx: 'auto',
218
+ py: 8,
219
+ typography: 'body2',
220
+ '&:hover': {
221
+ color: 'text.secondary',
222
+ },
223
+ }}
224
+ onClick={async () => {
225
+ await connectMutation.mutateAsync({
226
+ type: 'passkey',
227
+ createNew: false,
228
+ });
229
+ if (!connectMutation.isError) {
230
+ onClose();
231
+ }
232
+ }}
233
+ >
234
+ <Trans>Choose existing passkey</Trans>
235
+ <Box
236
+ component={ArrowRight}
237
+ sx={{
238
+ width: 18,
239
+ height: 18,
240
+ }}
241
+ />
242
+ </ButtonBase>
243
+ </>
244
+ )}
245
+ </Box>
246
+ </Dialog>
247
+ );
248
+ }