@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,158 +1,158 @@
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
+ '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,167 +1,167 @@
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
- }
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
+ }