@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.
- package/babel.config.js +9 -9
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/lingui.config.ts +13 -13
- package/package.json +91 -76
- package/rollup.config.mjs +100 -100
- package/src/ClientProvider.tsx +17 -15
- package/src/LangProvider.tsx +36 -34
- package/src/WalletConnect/AccountPage.tsx +496 -494
- package/src/WalletConnect/ActivityList.tsx +606 -604
- package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -246
- package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
- package/src/WalletConnect/ConnectDialog.tsx +35 -33
- package/src/WalletConnect/ConnectLedger/ErrorDialog.tsx +61 -61
- package/src/WalletConnect/ConnectLedger/LockedDialog.tsx +54 -54
- package/src/WalletConnect/ConnectLedger/helper.ts +14 -14
- package/src/WalletConnect/ConnectLedger/index.tsx +2 -0
- package/src/WalletConnect/ConnectPage.tsx +508 -506
- package/src/WalletConnect/HasBalanceTokenList.tsx +202 -200
- package/src/WalletConnect/ReceiveTokenPage.tsx +145 -143
- package/src/WalletConnect/SendTokenPage.tsx +251 -249
- package/src/WalletConnect/WalletDialog.tsx +80 -78
- package/src/WalletConnectProvider.tsx +57 -55
- package/src/components/AddressWithLinkAndCopy.tsx +202 -200
- package/src/components/Dialog.tsx +158 -156
- package/src/components/TokenLogo.tsx +167 -165
- package/src/components/WalletTag.tsx +117 -115
- package/src/constants/localstorage.ts +24 -22
- package/src/hooks/useConnectWallet.ts +150 -146
- package/src/hooks/useFetchFiatPrice.ts +53 -51
- package/src/hooks/useFetchTokensBalance.ts +53 -51
- package/src/hooks/useHasBalanceTokenList.ts +95 -93
- package/src/hooks/useTransactionList.ts +89 -87
- package/src/index.tsx +7 -7
- package/src/locales/en.po +51 -51
- package/src/locales/zh.po +51 -51
- package/src/utils/formatter.ts +102 -102
- package/src/utils/time.ts +21 -21
- package/src/utils/utils.ts +8 -8
- package/tsconfig.json +23 -23
|
@@ -1,115 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { alpha, Box, RotatingIcon, useTheme } from '@dodoex/components';
|
|
4
|
+
import { WalletType } from '@dodoex/wallet-web3';
|
|
5
|
+
import { Trans } from '@lingui/macro';
|
|
6
|
+
import { WalletItem } from '../hooks/useConnectWallet';
|
|
7
|
+
|
|
8
|
+
export interface WalletTagProps {
|
|
9
|
+
loading: boolean;
|
|
10
|
+
wallet: WalletItem;
|
|
11
|
+
isChecked: boolean;
|
|
12
|
+
installed: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default function WalletTag({
|
|
16
|
+
loading,
|
|
17
|
+
wallet,
|
|
18
|
+
isChecked,
|
|
19
|
+
installed,
|
|
20
|
+
}: WalletTagProps) {
|
|
21
|
+
const theme = useTheme();
|
|
22
|
+
const greenColor = theme.palette.success.main;
|
|
23
|
+
const connectedColor = theme.palette.mode === 'light' ? '#EB8D27' : '#FFE804';
|
|
24
|
+
const connectedColorBg = alpha('#FFE804', 0.1);
|
|
25
|
+
if (loading) {
|
|
26
|
+
return (
|
|
27
|
+
<Box
|
|
28
|
+
sx={{
|
|
29
|
+
display: 'flex',
|
|
30
|
+
alignItems: 'center',
|
|
31
|
+
gap: 4,
|
|
32
|
+
p: theme.spacing(4, 8),
|
|
33
|
+
borderRadius: 6,
|
|
34
|
+
typography: 'body2',
|
|
35
|
+
backgroundColor: alpha(theme.palette.text.primary, 0.1),
|
|
36
|
+
color: 'text.secondary',
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
<RotatingIcon
|
|
40
|
+
sx={{
|
|
41
|
+
width: 18,
|
|
42
|
+
height: 18,
|
|
43
|
+
color: 'text.secondary',
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
<Trans>Connecting</Trans>··
|
|
47
|
+
</Box>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (isChecked) {
|
|
52
|
+
return (
|
|
53
|
+
<Box
|
|
54
|
+
sx={{
|
|
55
|
+
p: theme.spacing(4, 8),
|
|
56
|
+
borderRadius: 6,
|
|
57
|
+
typography: 'body2',
|
|
58
|
+
backgroundColor: connectedColorBg,
|
|
59
|
+
color: connectedColor,
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
<Trans>Connected</Trans>
|
|
63
|
+
</Box>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (wallet.isLastConnection) {
|
|
68
|
+
return (
|
|
69
|
+
<Box
|
|
70
|
+
sx={{
|
|
71
|
+
p: theme.spacing(4, 8),
|
|
72
|
+
borderRadius: 6,
|
|
73
|
+
typography: 'body2',
|
|
74
|
+
backgroundColor: alpha(theme.palette.text.primary, 0.1),
|
|
75
|
+
color: 'text.secondary',
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<Trans>Last connection</Trans>
|
|
79
|
+
</Box>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (wallet.currentType === WalletType.SocialLogin) {
|
|
84
|
+
return (
|
|
85
|
+
<Box
|
|
86
|
+
sx={{
|
|
87
|
+
mt: 4,
|
|
88
|
+
padding: theme.spacing(4, 8),
|
|
89
|
+
borderRadius: 6,
|
|
90
|
+
typography: 'body2',
|
|
91
|
+
backgroundColor: alpha(greenColor, 0.1),
|
|
92
|
+
color: greenColor,
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
New
|
|
96
|
+
</Box>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (installed) {
|
|
101
|
+
return (
|
|
102
|
+
<Box
|
|
103
|
+
sx={{
|
|
104
|
+
p: theme.spacing(4, 8),
|
|
105
|
+
borderRadius: 6,
|
|
106
|
+
typography: 'body2',
|
|
107
|
+
backgroundColor: alpha(theme.palette.text.primary, 0.1),
|
|
108
|
+
color: 'text.secondary',
|
|
109
|
+
}}
|
|
110
|
+
>
|
|
111
|
+
<Trans>Installed Wallet</Trans>
|
|
112
|
+
</Box>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const TOKEN_FIAT_PRICE_LIST = 'DODO_WIDGET_TOKEN_FIAT_PRICE_LIST';
|
|
4
|
+
interface FiatPriceCacheList {
|
|
5
|
+
[k: string]: number;
|
|
6
|
+
}
|
|
7
|
+
export function setTokenFiatPriceList(value: FiatPriceCacheList) {
|
|
8
|
+
const oldList = getTokenFiatPriceList();
|
|
9
|
+
const newList = {
|
|
10
|
+
...oldList,
|
|
11
|
+
...value,
|
|
12
|
+
};
|
|
13
|
+
localStorage.setItem(TOKEN_FIAT_PRICE_LIST, JSON.stringify(newList));
|
|
14
|
+
}
|
|
15
|
+
export function getTokenFiatPriceList(): FiatPriceCacheList {
|
|
16
|
+
const storage = localStorage.getItem(TOKEN_FIAT_PRICE_LIST);
|
|
17
|
+
try {
|
|
18
|
+
if (!storage) return {};
|
|
19
|
+
return JSON.parse(storage);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error(e);
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,146 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import WalletWeb3, { useWalletStore, Wallet } from '@dodoex/wallet-web3';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
const SETTINGS_ACCOUNT_RISK_CONFIRM = '0.settings:account:risk-confirm';
|
|
7
|
+
|
|
8
|
+
export interface WalletItem {
|
|
9
|
+
title: string;
|
|
10
|
+
icon: string;
|
|
11
|
+
currentType: string;
|
|
12
|
+
onClick: (
|
|
13
|
+
providerPackageOptions?: Partial<WalletWeb3['providerConfig']>,
|
|
14
|
+
) => void;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
isLastConnection: boolean;
|
|
17
|
+
isInstalled?: boolean;
|
|
18
|
+
source: Wallet;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useConnectWallet = ({
|
|
22
|
+
walletWeb3,
|
|
23
|
+
matchTestChain,
|
|
24
|
+
showOtherInjectWallet,
|
|
25
|
+
selectedChainId,
|
|
26
|
+
hasTermsOfServiceLink,
|
|
27
|
+
}: {
|
|
28
|
+
walletWeb3?: WalletWeb3;
|
|
29
|
+
/** Match the test chain and display the first bit of showName and chainIds as the matching test chain. If it is false or not transmitted, the main network information will still be displayed. */
|
|
30
|
+
matchTestChain?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* No need to display when switching wallets
|
|
33
|
+
*/
|
|
34
|
+
showOtherInjectWallet?: boolean;
|
|
35
|
+
selectedChainId?: number;
|
|
36
|
+
hasTermsOfServiceLink?: boolean;
|
|
37
|
+
}) => {
|
|
38
|
+
const activeWalletType = useWalletStore((state) => state.walletType);
|
|
39
|
+
|
|
40
|
+
const { walletList } = useWalletListByNetwork(
|
|
41
|
+
selectedChainId,
|
|
42
|
+
walletWeb3,
|
|
43
|
+
showOtherInjectWallet,
|
|
44
|
+
);
|
|
45
|
+
const [userReadAndChecked, setUserReadAndChecked] = React.useState<boolean>(
|
|
46
|
+
hasTermsOfServiceLink
|
|
47
|
+
? localStorage.getItem(SETTINGS_ACCOUNT_RISK_CONFIRM) === '1' || true
|
|
48
|
+
: true,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const handleChangeUserReadAndChecked = (val: boolean) => {
|
|
52
|
+
localStorage.setItem(SETTINGS_ACCOUNT_RISK_CONFIRM, val ? '1' : '0');
|
|
53
|
+
setUserReadAndChecked(val);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
walletList,
|
|
58
|
+
userReadAndChecked,
|
|
59
|
+
handleChangeUserReadAndChecked,
|
|
60
|
+
activeWalletType,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const connectToWallet = async (
|
|
65
|
+
walletWeb3: WalletWeb3 | undefined,
|
|
66
|
+
wallet: Wallet,
|
|
67
|
+
config?: Partial<WalletWeb3['providerConfig']>,
|
|
68
|
+
) => {
|
|
69
|
+
if (!walletWeb3 || !walletWeb3.connectWalletBefore(wallet)) return;
|
|
70
|
+
const providerConfig = {
|
|
71
|
+
...config,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return walletWeb3.connectToWallet(wallet, providerConfig);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function useWalletListByNetwork(
|
|
78
|
+
chainId?: number,
|
|
79
|
+
walletWeb3?: WalletWeb3,
|
|
80
|
+
showOtherInjectWallet?: boolean,
|
|
81
|
+
closeSingleWalletConnectModal?: () => void,
|
|
82
|
+
) {
|
|
83
|
+
const [walletList, setWalletList] = React.useState<WalletItem[]>([]);
|
|
84
|
+
const disabledWalletKeyList = useWalletStore(
|
|
85
|
+
(state) => state.disabledWalletKeyList,
|
|
86
|
+
);
|
|
87
|
+
const eip6963WalletList = useWalletStore((state) => state.eip6963WalletList);
|
|
88
|
+
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
const computed = async () => {
|
|
91
|
+
if (walletWeb3 && chainId !== undefined) {
|
|
92
|
+
// Reset disabled state before getting wallet list
|
|
93
|
+
await walletWeb3.setDisabledState();
|
|
94
|
+
const walletListOrigin = walletWeb3.getWalletList(chainId, {
|
|
95
|
+
eip6963WalletList,
|
|
96
|
+
});
|
|
97
|
+
const list = [] as WalletItem[];
|
|
98
|
+
let len = walletListOrigin.length;
|
|
99
|
+
for (let i = 0; i < len; i++) {
|
|
100
|
+
const item = walletListOrigin[i];
|
|
101
|
+
let isInstalled = false;
|
|
102
|
+
if (item.injected) {
|
|
103
|
+
isInstalled = item.injected();
|
|
104
|
+
}
|
|
105
|
+
if (!isInstalled && item.isInstalled) {
|
|
106
|
+
isInstalled = await item.isInstalled?.();
|
|
107
|
+
}
|
|
108
|
+
list.push({
|
|
109
|
+
title: item.showName,
|
|
110
|
+
icon: item.logo,
|
|
111
|
+
currentType: item.type,
|
|
112
|
+
source: item,
|
|
113
|
+
onClick: (providerPackageOptions) => {
|
|
114
|
+
try {
|
|
115
|
+
return connectToWallet(
|
|
116
|
+
walletWeb3,
|
|
117
|
+
item,
|
|
118
|
+
providerPackageOptions,
|
|
119
|
+
);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (closeSingleWalletConnectModal) {
|
|
122
|
+
closeSingleWalletConnectModal();
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
disabled: disabledWalletKeyList.includes(
|
|
128
|
+
`${item.type}-${item.showName}`,
|
|
129
|
+
),
|
|
130
|
+
isLastConnection:
|
|
131
|
+
item.type === walletWeb3.connectController.getLastConnectType(),
|
|
132
|
+
isInstalled,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
setWalletList(list);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
computed();
|
|
139
|
+
}, [
|
|
140
|
+
walletWeb3,
|
|
141
|
+
chainId,
|
|
142
|
+
showOtherInjectWallet,
|
|
143
|
+
disabledWalletKeyList,
|
|
144
|
+
eip6963WalletList,
|
|
145
|
+
]);
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
walletList,
|
|
149
|
+
};
|
|
150
|
+
}
|