@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,200 +1,202 @@
1
- import {
2
- Box,
3
- BoxProps,
4
- HoverOpacity,
5
- HoverAddBackground,
6
- HoverAddUnderLine,
7
- useTheme,
8
- ButtonBase,
9
- } from '@dodoex/components';
10
- import { ArrowRight, ArrowTopRightBorder } from '@dodoex/icons';
11
- import { useWalletStore } from '@dodoex/wallet-web3';
12
- import { useWalletConnectContext } from '../WalletConnectProvider';
13
-
14
- export function truncatePoolAddress(address: string): string {
15
- if (address.length <= 10) {
16
- return address;
17
- }
18
- return `${address.slice(0, 6)}...${address.slice(
19
- address.length - 4,
20
- address.length,
21
- )}`;
22
- }
23
-
24
- interface AddressTextProps {
25
- sx?: BoxProps['sx'];
26
- truncate?: boolean;
27
- address: string;
28
- disabledAddress?: boolean;
29
- addressHoverColor?: string;
30
- addressHoverShowIcon?: boolean;
31
- handleOpen?: (
32
- event: React.MouseEvent<HTMLDivElement, MouseEvent>,
33
- type: 'address' | 'icon',
34
- ) => void;
35
- }
36
-
37
- interface Props extends AddressTextProps {
38
- showCopy?: boolean;
39
- size?: 'small' | 'medium' | 'big';
40
- newTab?: boolean;
41
- iconSize?: number;
42
- iconSpace?: number;
43
- iconDarkHover?: boolean;
44
- customChainId?: number;
45
- onAddressClick?: (
46
- event: React.MouseEvent<HTMLDivElement, MouseEvent>,
47
- ) => void;
48
- }
49
-
50
- export function AddressText({
51
- truncate,
52
- address,
53
- disabledAddress,
54
- sx,
55
- handleOpen,
56
- addressHoverColor,
57
- addressHoverShowIcon,
58
- }: AddressTextProps & {
59
- typography?: string;
60
- domain?: string;
61
- }) {
62
- if (disabledAddress) {
63
- return <Box>{truncate ? truncatePoolAddress(address) : address}</Box>;
64
- }
65
- return (
66
- <HoverAddUnderLine
67
- lineSx={{
68
- bottom: -1,
69
- }}
70
- // @ts-ignore
71
- lineColor={addressHoverColor ?? (sx?.color || '')}
72
- hoverSx={{
73
- color: 'addressHoverColor',
74
- '& svg': {
75
- display: 'inline-block',
76
- },
77
- }}
78
- className="truncate-address-link"
79
- >
80
- <Box
81
- onClick={(evt) => {
82
- handleOpen?.(evt, 'address');
83
- }}
84
- sx={{
85
- display: 'flex',
86
- alignItems: 'center',
87
- cursor: 'pointer',
88
- }}
89
- >
90
- {truncate ? truncatePoolAddress(address) : address}
91
- {addressHoverShowIcon ? (
92
- <Box
93
- component={ArrowRight}
94
- sx={{
95
- display: 'none',
96
- width: 14,
97
- height: 14,
98
- }}
99
- />
100
- ) : (
101
- ''
102
- )}
103
- </Box>
104
- </HoverAddUnderLine>
105
- );
106
- }
107
-
108
- export function AddressWithLink({
109
- address,
110
- truncate,
111
- size = 'medium',
112
- iconSize,
113
- iconSpace: iconSpaceProps,
114
- sx,
115
- iconDarkHover,
116
- disabledAddress,
117
- addressHoverColor,
118
- addressHoverShowIcon,
119
- customChainId,
120
- handleOpen,
121
- onAddressClick,
122
- }: Props) {
123
- const theme = useTheme();
124
-
125
- const isBig = size === 'big';
126
- const isMedium = size === 'medium';
127
-
128
- const IconHoverBox = iconDarkHover ? HoverAddBackground : HoverOpacity;
129
- const getIconSpace = (isMediumRes?: boolean) => {
130
- let iconSpace = isMediumRes ? 12 : 8;
131
- if (iconSpaceProps) {
132
- iconSpace = iconSpaceProps;
133
- }
134
- if (iconDarkHover) {
135
- iconSpace -= 3;
136
- }
137
- return iconSpace;
138
- };
139
- // eslint-disable-next-line no-nested-ternary
140
- const typography = isBig ? 'h5' : isMedium ? 'body1' : 'body2';
141
- const { chainId: currentChainId } = useWalletStore();
142
- const chainId = customChainId ?? currentChainId;
143
- const { getChain } = useWalletConnectContext();
144
-
145
- const handleOpenResult: AddressTextProps['handleOpen'] = (evt, type) => {
146
- if (handleOpen) {
147
- handleOpen(evt, type);
148
- return;
149
- }
150
- if (chainId) {
151
- evt.stopPropagation();
152
- const scanUrl = getChain(chainId)?.scanUrl;
153
- if (!scanUrl) return;
154
- window.open(`https://${scanUrl}${address ? `/address/${address}` : ''}`);
155
- }
156
- };
157
-
158
- return (
159
- <Box
160
- sx={{
161
- display: 'flex',
162
- alignItems: 'center',
163
- typography,
164
- color: theme.palette.text.primary,
165
- lineHeight: 'normal',
166
- ...(sx || {}),
167
- }}
168
- >
169
- <AddressText
170
- truncate={truncate}
171
- address={address}
172
- disabledAddress={disabledAddress}
173
- sx={sx}
174
- typography={typography}
175
- handleOpen={onAddressClick ?? handleOpenResult}
176
- addressHoverColor={addressHoverColor}
177
- addressHoverShowIcon={addressHoverShowIcon}
178
- />
179
-
180
- <IconHoverBox
181
- sx={{
182
- display: 'inline-flex',
183
- ml: getIconSpace(isMedium),
184
- cursor: 'pointer',
185
- }}
186
- onClick={(evt) => {
187
- handleOpenResult(evt, 'icon');
188
- }}
189
- >
190
- <Box
191
- component={ArrowTopRightBorder}
192
- sx={{
193
- width: iconSize || (isMedium ? 16 : 14),
194
- height: iconSize || (isMedium ? 16 : 14),
195
- }}
196
- />
197
- </IconHoverBox>
198
- </Box>
199
- );
200
- }
1
+ 'use client';
2
+
3
+ import {
4
+ Box,
5
+ BoxProps,
6
+ HoverOpacity,
7
+ HoverAddBackground,
8
+ HoverAddUnderLine,
9
+ useTheme,
10
+ ButtonBase,
11
+ } from '@dodoex/components';
12
+ import { ArrowRight, ArrowTopRightBorder } from '@dodoex/icons';
13
+ import { useWalletStore } from '@dodoex/wallet-web3';
14
+ import { useWalletConnectContext } from '../WalletConnectProvider';
15
+
16
+ export function truncatePoolAddress(address: string): string {
17
+ if (address.length <= 10) {
18
+ return address;
19
+ }
20
+ return `${address.slice(0, 6)}...${address.slice(
21
+ address.length - 4,
22
+ address.length,
23
+ )}`;
24
+ }
25
+
26
+ interface AddressTextProps {
27
+ sx?: BoxProps['sx'];
28
+ truncate?: boolean;
29
+ address: string;
30
+ disabledAddress?: boolean;
31
+ addressHoverColor?: string;
32
+ addressHoverShowIcon?: boolean;
33
+ handleOpen?: (
34
+ event: React.MouseEvent<HTMLDivElement, MouseEvent>,
35
+ type: 'address' | 'icon',
36
+ ) => void;
37
+ }
38
+
39
+ interface Props extends AddressTextProps {
40
+ showCopy?: boolean;
41
+ size?: 'small' | 'medium' | 'big';
42
+ newTab?: boolean;
43
+ iconSize?: number;
44
+ iconSpace?: number;
45
+ iconDarkHover?: boolean;
46
+ customChainId?: number;
47
+ onAddressClick?: (
48
+ event: React.MouseEvent<HTMLDivElement, MouseEvent>,
49
+ ) => void;
50
+ }
51
+
52
+ export function AddressText({
53
+ truncate,
54
+ address,
55
+ disabledAddress,
56
+ sx,
57
+ handleOpen,
58
+ addressHoverColor,
59
+ addressHoverShowIcon,
60
+ }: AddressTextProps & {
61
+ typography?: string;
62
+ domain?: string;
63
+ }) {
64
+ if (disabledAddress) {
65
+ return <Box>{truncate ? truncatePoolAddress(address) : address}</Box>;
66
+ }
67
+ return (
68
+ <HoverAddUnderLine
69
+ lineSx={{
70
+ bottom: -1,
71
+ }}
72
+ // @ts-ignore
73
+ lineColor={addressHoverColor ?? (sx?.color || '')}
74
+ hoverSx={{
75
+ color: 'addressHoverColor',
76
+ '& svg': {
77
+ display: 'inline-block',
78
+ },
79
+ }}
80
+ className="truncate-address-link"
81
+ >
82
+ <Box
83
+ onClick={(evt) => {
84
+ handleOpen?.(evt, 'address');
85
+ }}
86
+ sx={{
87
+ display: 'flex',
88
+ alignItems: 'center',
89
+ cursor: 'pointer',
90
+ }}
91
+ >
92
+ {truncate ? truncatePoolAddress(address) : address}
93
+ {addressHoverShowIcon ? (
94
+ <Box
95
+ component={ArrowRight}
96
+ sx={{
97
+ display: 'none',
98
+ width: 14,
99
+ height: 14,
100
+ }}
101
+ />
102
+ ) : (
103
+ ''
104
+ )}
105
+ </Box>
106
+ </HoverAddUnderLine>
107
+ );
108
+ }
109
+
110
+ export function AddressWithLink({
111
+ address,
112
+ truncate,
113
+ size = 'medium',
114
+ iconSize,
115
+ iconSpace: iconSpaceProps,
116
+ sx,
117
+ iconDarkHover,
118
+ disabledAddress,
119
+ addressHoverColor,
120
+ addressHoverShowIcon,
121
+ customChainId,
122
+ handleOpen,
123
+ onAddressClick,
124
+ }: Props) {
125
+ const theme = useTheme();
126
+
127
+ const isBig = size === 'big';
128
+ const isMedium = size === 'medium';
129
+
130
+ const IconHoverBox = iconDarkHover ? HoverAddBackground : HoverOpacity;
131
+ const getIconSpace = (isMediumRes?: boolean) => {
132
+ let iconSpace = isMediumRes ? 12 : 8;
133
+ if (iconSpaceProps) {
134
+ iconSpace = iconSpaceProps;
135
+ }
136
+ if (iconDarkHover) {
137
+ iconSpace -= 3;
138
+ }
139
+ return iconSpace;
140
+ };
141
+ // eslint-disable-next-line no-nested-ternary
142
+ const typography = isBig ? 'h5' : isMedium ? 'body1' : 'body2';
143
+ const { chainId: currentChainId } = useWalletStore();
144
+ const chainId = customChainId ?? currentChainId;
145
+ const { getChain } = useWalletConnectContext();
146
+
147
+ const handleOpenResult: AddressTextProps['handleOpen'] = (evt, type) => {
148
+ if (handleOpen) {
149
+ handleOpen(evt, type);
150
+ return;
151
+ }
152
+ if (chainId) {
153
+ evt.stopPropagation();
154
+ const scanUrl = getChain(chainId)?.scanUrl;
155
+ if (!scanUrl) return;
156
+ window.open(`https://${scanUrl}${address ? `/address/${address}` : ''}`);
157
+ }
158
+ };
159
+
160
+ return (
161
+ <Box
162
+ sx={{
163
+ display: 'flex',
164
+ alignItems: 'center',
165
+ typography,
166
+ color: theme.palette.text.primary,
167
+ lineHeight: 'normal',
168
+ ...(sx || {}),
169
+ }}
170
+ >
171
+ <AddressText
172
+ truncate={truncate}
173
+ address={address}
174
+ disabledAddress={disabledAddress}
175
+ sx={sx}
176
+ typography={typography}
177
+ handleOpen={onAddressClick ?? handleOpenResult}
178
+ addressHoverColor={addressHoverColor}
179
+ addressHoverShowIcon={addressHoverShowIcon}
180
+ />
181
+
182
+ <IconHoverBox
183
+ sx={{
184
+ display: 'inline-flex',
185
+ ml: getIconSpace(isMedium),
186
+ cursor: 'pointer',
187
+ }}
188
+ onClick={(evt) => {
189
+ handleOpenResult(evt, 'icon');
190
+ }}
191
+ >
192
+ <Box
193
+ component={ArrowTopRightBorder}
194
+ sx={{
195
+ width: iconSize || (isMedium ? 16 : 14),
196
+ height: iconSize || (isMedium ? 16 : 14),
197
+ }}
198
+ />
199
+ </IconHoverBox>
200
+ </Box>
201
+ );
202
+ }