@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,57 +1,57 @@
1
- 'use client';
2
-
3
- import { GraphQLRequests, RestApiRequests } from '@dodoex/api';
4
- import React from 'react';
5
- import { TokenInfo } from './components/TokenLogo';
6
- import { WalletItem } from './hooks/useConnectWallet';
7
-
8
- const WalletConnectContext = React.createContext<{
9
- chainId?: number;
10
- termsOfServiceLink?: React.ReactNode;
11
- connectTimeout?: number;
12
- graphQLRequests?: GraphQLRequests;
13
- tokenList: Array<TokenInfo>;
14
- restApiRequests?: RestApiRequests;
15
- SendTokenPage?: (params: {
16
- open?: boolean;
17
- onClose: () => void;
18
- onBack: () => void;
19
- }) => JSX.Element;
20
- encryptFiatPriceToken?: () => string;
21
- loadAccountListEthBalance?: (
22
- accountList: string[],
23
- chainId?: number,
24
- ) => Promise<Map<string, number | null>>;
25
- getChain: (chainId: number) => null | {
26
- name: string;
27
- scanUrl: string;
28
- gasToken: {
29
- symbol: string;
30
- decimals: number;
31
- };
32
- logo: React.ReactNode;
33
- logoBg?: React.ReactNode;
34
- };
35
- getTokenLogoUrl?: (op: {
36
- chainId?: number | null;
37
- address?: string | null;
38
- width?: number;
39
- height?: number;
40
- }) => string | null;
41
- onConnectTimeout?: () => void;
42
- switchNetwork?: (chainId: number) => void;
43
- onConnected?: (chainId: number, wallet: WalletItem) => void;
44
- onClickToken?: (token: TokenInfo) => void;
45
- }>({
46
- connectTimeout: 15000,
47
- tokenList: [],
48
- getChain: () => {
49
- throw new Error('getChain is undefined');
50
- },
51
- });
52
-
53
- export const WalletConnectProvider = WalletConnectContext.Provider;
54
-
55
- export const useWalletConnectContext = () => {
56
- return React.useContext(WalletConnectContext);
57
- };
1
+ 'use client';
2
+
3
+ import { GraphQLRequests, RestApiRequests } from '@dodoex/api';
4
+ import React from 'react';
5
+ import { TokenInfo } from './components/TokenLogo';
6
+ import { WalletItem } from './hooks/useConnectWallet';
7
+
8
+ const WalletConnectContext = React.createContext<{
9
+ chainId?: number;
10
+ termsOfServiceLink?: React.ReactNode;
11
+ connectTimeout?: number;
12
+ graphQLRequests?: GraphQLRequests;
13
+ tokenList: Array<TokenInfo>;
14
+ restApiRequests?: RestApiRequests;
15
+ SendTokenPage?: (params: {
16
+ open?: boolean;
17
+ onClose: () => void;
18
+ onBack: () => void;
19
+ }) => React.JSX.Element;
20
+ encryptFiatPriceToken?: () => string;
21
+ loadAccountListEthBalance?: (
22
+ accountList: string[],
23
+ chainId?: number,
24
+ ) => Promise<Map<string, number | null>>;
25
+ getChain: (chainId: number) => null | {
26
+ name: string;
27
+ scanUrl: string;
28
+ gasToken: {
29
+ symbol: string;
30
+ decimals: number;
31
+ };
32
+ logo: React.ReactNode;
33
+ logoBg?: React.ReactNode;
34
+ };
35
+ getTokenLogoUrl?: (op: {
36
+ chainId?: number | null;
37
+ address?: string | null;
38
+ width?: number;
39
+ height?: number;
40
+ }) => string | null;
41
+ onConnectTimeout?: () => void;
42
+ switchNetwork?: (chainId: number) => void;
43
+ onConnected?: (chainId: number, wallet: WalletItem) => void;
44
+ onClickToken?: (token: TokenInfo) => void;
45
+ }>({
46
+ connectTimeout: 15000,
47
+ tokenList: [],
48
+ getChain: () => {
49
+ throw new Error('getChain is undefined');
50
+ },
51
+ });
52
+
53
+ export const WalletConnectProvider = WalletConnectContext.Provider;
54
+
55
+ export const useWalletConnectContext = () => {
56
+ return React.useContext(WalletConnectContext);
57
+ };
@@ -1,202 +1,202 @@
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
- }
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
+ }