@dodoex/wallet-web3-react 0.0.1-beta.3 → 0.0.1-beta.4
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/dist/index.cjs +4 -4
- package/dist/index.js +5 -5
- package/dist/types/hooks/useHasBalanceTokenList.d.ts +1 -2
- package/package.json +2 -3
- package/src/LangProvider.tsx +4 -2
- package/src/WalletConnect/AccountPage.tsx +0 -23
- package/src/WalletConnect/ActivityList.tsx +1 -1
- package/src/WalletConnect/HasBalanceTokenList.tsx +0 -1
- package/src/WalletConnect/WalletDialog.tsx +4 -4
- package/src/components/Dialog.tsx +1 -0
- package/src/hooks/useFetchTokensBalance.ts +0 -1
- package/src/hooks/useHasBalanceTokenList.ts +18 -82
- package/src/locales/en.po +9 -9
- package/src/locales/zh.po +9 -9
- package/tsconfig.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
export declare function useHasBalanceTokenList({ account,
|
|
2
|
+
export declare function useHasBalanceTokenList({ account, visible, }: {
|
|
3
3
|
account: string | undefined;
|
|
4
|
-
chainId: number;
|
|
5
4
|
visible: boolean;
|
|
6
5
|
}): {
|
|
7
6
|
tokenLoading: boolean;
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dodoex/wallet-web3-react",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.4",
|
|
4
4
|
"source": "src/index.tsx",
|
|
5
5
|
"types": "dist/types/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
|
-
"module": "dist/index.js",
|
|
8
7
|
"scripts": {
|
|
9
8
|
"start": "yarn workspace doc start",
|
|
10
9
|
"build": "yarn extract && yarn compile && rollup -c",
|
|
@@ -39,7 +38,6 @@
|
|
|
39
38
|
"devDependencies": {
|
|
40
39
|
"@lingui/cli": "^4.11.4",
|
|
41
40
|
"@lingui/loader": "^4.11.4",
|
|
42
|
-
"@lingui/swc-plugin": "4.0.6",
|
|
43
41
|
"@rollup/plugin-replace": "^6.0.2",
|
|
44
42
|
"@rollup/plugin-terser": "^0.4.4",
|
|
45
43
|
"@rollup/plugin-typescript": "^12.1.1",
|
|
@@ -47,6 +45,7 @@
|
|
|
47
45
|
"@svgr/rollup": "^8.1.0",
|
|
48
46
|
"@types/identicon.js": "^2.3.5",
|
|
49
47
|
"@types/react-infinite-scroller": "^1.2.5",
|
|
48
|
+
"babel-plugin-macros": "^3.1.0",
|
|
50
49
|
"rollup": "^4.28.0",
|
|
51
50
|
"rollup-plugin-clear": "^2.0.7",
|
|
52
51
|
"rollup-plugin-import-css": "^3.5.7",
|
package/src/LangProvider.tsx
CHANGED
|
@@ -14,9 +14,11 @@ interface LangProviderProps {
|
|
|
14
14
|
|
|
15
15
|
export async function loadI18(locale: SupportedLang = defaultLang) {
|
|
16
16
|
try {
|
|
17
|
-
const catalog = await import(
|
|
17
|
+
const catalog = await import(`./locales/${locale}.js`);
|
|
18
18
|
i18n.load(locale, catalog.messages || catalog.default.messages);
|
|
19
|
-
} catch {
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(error);
|
|
21
|
+
}
|
|
20
22
|
i18n.activate(locale);
|
|
21
23
|
}
|
|
22
24
|
export function LangProvider({ locale, children }: LangProviderProps) {
|
|
@@ -33,28 +33,6 @@ import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
|
33
33
|
import ActivityList from './ActivityList';
|
|
34
34
|
import HasBalanceTokenList from './HasBalanceTokenList';
|
|
35
35
|
|
|
36
|
-
function CardIcon({ sx, ...other }: BoxProps) {
|
|
37
|
-
return (
|
|
38
|
-
<Box
|
|
39
|
-
sx={{
|
|
40
|
-
display: 'flex',
|
|
41
|
-
justifyContent: 'center',
|
|
42
|
-
alignItems: 'center',
|
|
43
|
-
width: 52,
|
|
44
|
-
height: 52,
|
|
45
|
-
borderRadius: '50%',
|
|
46
|
-
backgroundColor: alpha('#1a1a1b', 0.1),
|
|
47
|
-
cursor: 'pointer',
|
|
48
|
-
'&:hover': {
|
|
49
|
-
backgroundColor: '#FFE804',
|
|
50
|
-
},
|
|
51
|
-
...sx,
|
|
52
|
-
}}
|
|
53
|
-
{...other}
|
|
54
|
-
/>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
36
|
function AccountCardInfoBg({
|
|
59
37
|
children,
|
|
60
38
|
chainLogo,
|
|
@@ -289,7 +267,6 @@ function AccountPage({
|
|
|
289
267
|
|
|
290
268
|
const balanceListData = useHasBalanceTokenList({
|
|
291
269
|
account,
|
|
292
|
-
chainId,
|
|
293
270
|
visible: listTab === ListTab.tokens,
|
|
294
271
|
});
|
|
295
272
|
|
|
@@ -15,8 +15,8 @@ export default function WalletDialog({
|
|
|
15
15
|
onClose: () => void;
|
|
16
16
|
walletWeb3: WalletWeb3;
|
|
17
17
|
}) {
|
|
18
|
-
const { SendTokenPage } = useWalletConnectContext();
|
|
19
|
-
const { account, chainId } = useWalletStore();
|
|
18
|
+
const { SendTokenPage, chainId: selectedChainId } = useWalletConnectContext();
|
|
19
|
+
const { account, chainId: connectChainId } = useWalletStore();
|
|
20
20
|
const [showSendTokenPage, setShowSendTokenPage] = React.useState(false);
|
|
21
21
|
const [showReceiveTokenPage, setShowReceiveTokenPage] = React.useState(false);
|
|
22
22
|
return (
|
|
@@ -48,7 +48,7 @@ export default function WalletDialog({
|
|
|
48
48
|
) : (
|
|
49
49
|
<>
|
|
50
50
|
<AccountPage
|
|
51
|
-
chainId={
|
|
51
|
+
chainId={selectedChainId ?? connectChainId}
|
|
52
52
|
account={account}
|
|
53
53
|
walletWeb3={walletWeb3}
|
|
54
54
|
onClose={onClose}
|
|
@@ -60,7 +60,7 @@ export default function WalletDialog({
|
|
|
60
60
|
</>
|
|
61
61
|
) : (
|
|
62
62
|
<ConnectPage
|
|
63
|
-
chainId={
|
|
63
|
+
chainId={connectChainId}
|
|
64
64
|
account={account}
|
|
65
65
|
walletWeb3={walletWeb3}
|
|
66
66
|
showOtherInjectWallet
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { isEqualWith } from 'lodash';
|
|
5
3
|
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
6
4
|
import useFetchTokensBalance from './useFetchTokensBalance';
|
|
7
5
|
import { useFetchFiatPrice } from './useFetchFiatPrice';
|
|
8
|
-
import { getFetchERC20HelperIsERC20QueryOptions } from '@dodoex/dodo-contract-request';
|
|
9
6
|
import { getTokenFiatPriceList } from '../constants/localstorage';
|
|
10
7
|
import { TokenInfo } from '../components/TokenLogo';
|
|
11
8
|
|
|
@@ -14,99 +11,38 @@ interface TokenResult extends TokenInfo {
|
|
|
14
11
|
}
|
|
15
12
|
export function useHasBalanceTokenList({
|
|
16
13
|
account,
|
|
17
|
-
chainId,
|
|
18
14
|
visible,
|
|
19
15
|
}: {
|
|
20
16
|
account: string | undefined;
|
|
21
|
-
chainId: number;
|
|
22
17
|
visible: boolean;
|
|
23
18
|
}) {
|
|
24
|
-
const queryClient = useQueryClient();
|
|
25
|
-
const [hasBalanceTokenList, setHasBalanceTokenList] = React.useState<
|
|
26
|
-
Array<TokenResult>
|
|
27
|
-
>([]);
|
|
28
|
-
const fiatPriceQuery = useFetchFiatPrice(hasBalanceTokenList);
|
|
29
|
-
|
|
30
19
|
const { tokenList } = useWalletConnectContext();
|
|
31
20
|
const fetchTokenQuery = useFetchTokensBalance({
|
|
32
21
|
account,
|
|
33
22
|
tokenList,
|
|
34
23
|
skip: !visible,
|
|
35
24
|
});
|
|
36
|
-
React.
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
undefined,
|
|
43
|
-
).queryKey.filter((item) => !!item);
|
|
44
|
-
const unSubscribe = queryClient.getQueryCache().subscribe((event) => {
|
|
45
|
-
try {
|
|
46
|
-
const isNotMatch = commonKey.some(
|
|
47
|
-
(key) => !event.query.queryKey.includes(key),
|
|
25
|
+
const hasBalanceTokenList = React.useMemo(() => {
|
|
26
|
+
let newHasBalanceTokenList = [] as TokenResult[];
|
|
27
|
+
fetchTokenQuery.tokenInfoMap.forEach((value, key) => {
|
|
28
|
+
if (value > 0) {
|
|
29
|
+
const token = tokenList.find(
|
|
30
|
+
(token) => `${token.chainId}-${token.address}` === key,
|
|
48
31
|
);
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
let newHasBalanceTokenList = [] as TokenResult[];
|
|
56
|
-
const hasBalanceAddressSet = new Set<string>();
|
|
57
|
-
tokenQueriesData.forEach((value) => {
|
|
58
|
-
const balance = value[1];
|
|
59
|
-
const queryKey = value[0];
|
|
60
|
-
const token = tokenList.find(
|
|
61
|
-
(token) =>
|
|
62
|
-
`${token.chainId}-${token.address}` ===
|
|
63
|
-
`${queryKey[1]}-${queryKey[2]}`,
|
|
64
|
-
);
|
|
65
|
-
if (
|
|
66
|
-
token &&
|
|
67
|
-
balance &&
|
|
68
|
-
balance > 0 &&
|
|
69
|
-
!hasBalanceAddressSet.has(token.address) &&
|
|
70
|
-
token.decimals !== undefined
|
|
71
|
-
) {
|
|
72
|
-
hasBalanceAddressSet.add(token.address);
|
|
73
|
-
newHasBalanceTokenList.push({
|
|
74
|
-
...token,
|
|
75
|
-
balance: new BigNumber(balance.toString()).div(
|
|
76
|
-
10 ** token.decimals,
|
|
77
|
-
),
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
newHasBalanceTokenList = newHasBalanceTokenList.sort((a, b) =>
|
|
82
|
-
a.balance.gt(b.balance) ? -1 : 1,
|
|
83
|
-
);
|
|
84
|
-
if (
|
|
85
|
-
!isEqualWith(
|
|
86
|
-
newHasBalanceTokenList,
|
|
87
|
-
hasBalanceTokenList,
|
|
88
|
-
(newValue, oldValue, key) => {
|
|
89
|
-
if (key === 'balance' && BigNumber.isBigNumber(newValue)) {
|
|
90
|
-
return newValue.isEqualTo(oldValue);
|
|
91
|
-
}
|
|
92
|
-
return undefined;
|
|
93
|
-
},
|
|
94
|
-
)
|
|
95
|
-
) {
|
|
96
|
-
setHasBalanceTokenList(newHasBalanceTokenList);
|
|
97
|
-
}
|
|
98
|
-
}, 100);
|
|
32
|
+
if (token?.decimals !== undefined) {
|
|
33
|
+
newHasBalanceTokenList.push({
|
|
34
|
+
...token,
|
|
35
|
+
balance: new BigNumber(value.toString()).div(10 ** token.decimals),
|
|
36
|
+
});
|
|
99
37
|
}
|
|
100
|
-
|
|
101
|
-
} catch (error) {}
|
|
38
|
+
}
|
|
102
39
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, [queryClient, account, chainId]);
|
|
40
|
+
newHasBalanceTokenList = newHasBalanceTokenList.sort((a, b) =>
|
|
41
|
+
a.balance.gt(b.balance) ? -1 : 1,
|
|
42
|
+
);
|
|
43
|
+
return newHasBalanceTokenList;
|
|
44
|
+
}, [fetchTokenQuery.tokenInfoMap]);
|
|
45
|
+
const fiatPriceQuery = useFetchFiatPrice(hasBalanceTokenList);
|
|
110
46
|
|
|
111
47
|
const tokenLoading = fetchTokenQuery.isLoading || fetchTokenQuery.isPending;
|
|
112
48
|
|
package/src/locales/en.po
CHANGED
|
@@ -21,7 +21,7 @@ msgstr "1、Ledger Live APP is closed{BR}2、The device plugged in via USB,NOT
|
|
|
21
21
|
msgid "Account"
|
|
22
22
|
msgstr "Account"
|
|
23
23
|
|
|
24
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
24
|
+
#: src/WalletConnect/AccountPage.tsx:290
|
|
25
25
|
msgid "Activity"
|
|
26
26
|
msgstr "Activity"
|
|
27
27
|
|
|
@@ -42,7 +42,7 @@ msgstr "Approve"
|
|
|
42
42
|
msgid "Available Ledger Account"
|
|
43
43
|
msgstr "Available Ledger Account"
|
|
44
44
|
|
|
45
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
45
|
+
#: src/WalletConnect/AccountPage.tsx:150
|
|
46
46
|
#: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:206
|
|
47
47
|
msgid "Balance"
|
|
48
48
|
msgstr "Balance"
|
|
@@ -86,8 +86,8 @@ msgstr "Connecting"
|
|
|
86
86
|
msgid "Continue"
|
|
87
87
|
msgstr "Continue"
|
|
88
88
|
|
|
89
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
90
|
-
#: src/WalletConnect/HasBalanceTokenList.tsx:
|
|
89
|
+
#: src/WalletConnect/AccountPage.tsx:376
|
|
90
|
+
#: src/WalletConnect/HasBalanceTokenList.tsx:117
|
|
91
91
|
#: src/WalletConnect/ReceiveTokenPage.tsx:99
|
|
92
92
|
msgid "Copied"
|
|
93
93
|
msgstr "Copied"
|
|
@@ -160,7 +160,7 @@ msgstr "Log in with your email or a passkey"
|
|
|
160
160
|
msgid "More Wallets"
|
|
161
161
|
msgstr "More Wallets"
|
|
162
162
|
|
|
163
|
-
#: src/WalletConnect/HasBalanceTokenList.tsx:
|
|
163
|
+
#: src/WalletConnect/HasBalanceTokenList.tsx:50
|
|
164
164
|
msgid "No tokens"
|
|
165
165
|
msgstr "No tokens"
|
|
166
166
|
|
|
@@ -169,7 +169,7 @@ msgstr "No tokens"
|
|
|
169
169
|
msgid "OK"
|
|
170
170
|
msgstr "OK"
|
|
171
171
|
|
|
172
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
172
|
+
#: src/WalletConnect/AccountPage.tsx:282
|
|
173
173
|
msgid "On-chain transaction records"
|
|
174
174
|
msgstr "On-chain transaction records"
|
|
175
175
|
|
|
@@ -185,7 +185,7 @@ msgstr "Pending"
|
|
|
185
185
|
msgid "Pool Creation"
|
|
186
186
|
msgstr "Pool Creation"
|
|
187
187
|
|
|
188
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
188
|
+
#: src/WalletConnect/AccountPage.tsx:231
|
|
189
189
|
#: src/WalletConnect/ReceiveTokenPage.tsx:50
|
|
190
190
|
msgid "Receive"
|
|
191
191
|
msgstr "Receive"
|
|
@@ -203,7 +203,7 @@ msgstr "Remove Liquidity"
|
|
|
203
203
|
msgid "Reset"
|
|
204
204
|
msgstr "Reset"
|
|
205
205
|
|
|
206
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
206
|
+
#: src/WalletConnect/AccountPage.tsx:202
|
|
207
207
|
#: src/WalletConnect/ActivityList.tsx:401
|
|
208
208
|
#: src/WalletConnect/SendTokenPage.tsx:116
|
|
209
209
|
#: src/WalletConnect/SendTokenPage.tsx:244
|
|
@@ -238,7 +238,7 @@ msgstr ""
|
|
|
238
238
|
msgid "This is empty"
|
|
239
239
|
msgstr "This is empty"
|
|
240
240
|
|
|
241
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
241
|
+
#: src/WalletConnect/AccountPage.tsx:278
|
|
242
242
|
msgid "Token"
|
|
243
243
|
msgstr "Token"
|
|
244
244
|
|
package/src/locales/zh.po
CHANGED
|
@@ -21,7 +21,7 @@ msgstr ""
|
|
|
21
21
|
msgid "Account"
|
|
22
22
|
msgstr ""
|
|
23
23
|
|
|
24
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
24
|
+
#: src/WalletConnect/AccountPage.tsx:290
|
|
25
25
|
msgid "Activity"
|
|
26
26
|
msgstr ""
|
|
27
27
|
|
|
@@ -42,7 +42,7 @@ msgstr ""
|
|
|
42
42
|
msgid "Available Ledger Account"
|
|
43
43
|
msgstr ""
|
|
44
44
|
|
|
45
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
45
|
+
#: src/WalletConnect/AccountPage.tsx:150
|
|
46
46
|
#: src/WalletConnect/ConnectLedger/SelectAddressDialog.tsx:206
|
|
47
47
|
msgid "Balance"
|
|
48
48
|
msgstr ""
|
|
@@ -86,8 +86,8 @@ msgstr ""
|
|
|
86
86
|
msgid "Continue"
|
|
87
87
|
msgstr ""
|
|
88
88
|
|
|
89
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
90
|
-
#: src/WalletConnect/HasBalanceTokenList.tsx:
|
|
89
|
+
#: src/WalletConnect/AccountPage.tsx:376
|
|
90
|
+
#: src/WalletConnect/HasBalanceTokenList.tsx:117
|
|
91
91
|
#: src/WalletConnect/ReceiveTokenPage.tsx:99
|
|
92
92
|
msgid "Copied"
|
|
93
93
|
msgstr ""
|
|
@@ -160,7 +160,7 @@ msgstr ""
|
|
|
160
160
|
msgid "More Wallets"
|
|
161
161
|
msgstr ""
|
|
162
162
|
|
|
163
|
-
#: src/WalletConnect/HasBalanceTokenList.tsx:
|
|
163
|
+
#: src/WalletConnect/HasBalanceTokenList.tsx:50
|
|
164
164
|
msgid "No tokens"
|
|
165
165
|
msgstr ""
|
|
166
166
|
|
|
@@ -169,7 +169,7 @@ msgstr ""
|
|
|
169
169
|
msgid "OK"
|
|
170
170
|
msgstr ""
|
|
171
171
|
|
|
172
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
172
|
+
#: src/WalletConnect/AccountPage.tsx:282
|
|
173
173
|
msgid "On-chain transaction records"
|
|
174
174
|
msgstr ""
|
|
175
175
|
|
|
@@ -185,7 +185,7 @@ msgstr ""
|
|
|
185
185
|
msgid "Pool Creation"
|
|
186
186
|
msgstr ""
|
|
187
187
|
|
|
188
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
188
|
+
#: src/WalletConnect/AccountPage.tsx:231
|
|
189
189
|
#: src/WalletConnect/ReceiveTokenPage.tsx:50
|
|
190
190
|
msgid "Receive"
|
|
191
191
|
msgstr ""
|
|
@@ -203,7 +203,7 @@ msgstr ""
|
|
|
203
203
|
msgid "Reset"
|
|
204
204
|
msgstr ""
|
|
205
205
|
|
|
206
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
206
|
+
#: src/WalletConnect/AccountPage.tsx:202
|
|
207
207
|
#: src/WalletConnect/ActivityList.tsx:401
|
|
208
208
|
#: src/WalletConnect/SendTokenPage.tsx:116
|
|
209
209
|
#: src/WalletConnect/SendTokenPage.tsx:244
|
|
@@ -236,7 +236,7 @@ msgstr ""
|
|
|
236
236
|
msgid "This is empty"
|
|
237
237
|
msgstr ""
|
|
238
238
|
|
|
239
|
-
#: src/WalletConnect/AccountPage.tsx:
|
|
239
|
+
#: src/WalletConnect/AccountPage.tsx:278
|
|
240
240
|
msgid "Token"
|
|
241
241
|
msgstr ""
|
|
242
242
|
|