@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.
- package/babel.config.js +9 -9
- package/dist/cjs/index.cjs +4 -13
- package/dist/cjs/locales/en.js +1 -1
- package/dist/cjs/locales/zh.js +1 -1
- package/dist/index.js +4 -13
- package/dist/locales/en.js +1 -1
- package/dist/locales/zh.js +1 -1
- package/dist/types/ClientProvider.d.ts +1 -1
- package/dist/types/LangProvider.d.ts +1 -1
- package/dist/types/WalletConnect/AccountPage.d.ts +1 -1
- package/dist/types/WalletConnect/ActivityList.d.ts +5 -4
- package/dist/types/WalletConnect/ConnectAlchemy/index.d.ts +2 -1
- package/dist/types/WalletConnect/ConnectDialog.d.ts +2 -1
- package/dist/types/WalletConnect/ConnectLedger/ErrorDialog.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectLedger/LoadingDialog.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectLedger/LockedDialog.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectLedger/ProtocolDialog.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectLedger/SelectAddressDialog.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectLedger/SelectPathDialog.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectLedger/index.d.ts +1 -1
- package/dist/types/WalletConnect/ConnectPage.d.ts +1 -1
- package/dist/types/WalletConnect/HasBalanceTokenList.d.ts +1 -1
- package/dist/types/WalletConnect/ReceiveTokenPage.d.ts +2 -1
- package/dist/types/WalletConnect/SendTokenPage.d.ts +2 -1
- package/dist/types/WalletConnect/WalletDialog.d.ts +2 -1
- package/dist/types/WalletConnectProvider.d.ts +2 -2
- package/dist/types/components/AddressWithLinkAndCopy.d.ts +2 -2
- package/dist/types/components/Dialog.d.ts +3 -3
- package/dist/types/components/WalletTag.d.ts +1 -1
- package/lingui.config.ts +13 -13
- package/package.json +90 -90
- package/rollup.config.mjs +106 -103
- package/src/ClientProvider.tsx +17 -17
- package/src/LangProvider.tsx +36 -36
- package/src/WalletConnect/AccountPage.tsx +498 -498
- package/src/WalletConnect/ActivityList.tsx +606 -606
- package/src/WalletConnect/ConnectAlchemy/index.tsx +248 -248
- package/src/WalletConnect/ConnectAlchemy/useConnectAlchemy.ts +105 -105
- package/src/WalletConnect/ConnectDialog.tsx +35 -35
- 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/ConnectPage.tsx +508 -508
- package/src/WalletConnect/HasBalanceTokenList.tsx +202 -202
- package/src/WalletConnect/ReceiveTokenPage.tsx +145 -145
- package/src/WalletConnect/SendTokenPage.tsx +251 -251
- package/src/WalletConnect/WalletDialog.tsx +80 -80
- package/src/WalletConnectProvider.tsx +57 -57
- package/src/components/AddressWithLinkAndCopy.tsx +202 -202
- package/src/components/Dialog.tsx +158 -158
- package/src/components/TokenLogo.tsx +167 -167
- package/src/components/WalletTag.tsx +117 -117
- package/src/constants/localstorage.ts +24 -24
- package/src/hooks/useConnectWallet.ts +150 -150
- package/src/hooks/useFetchFiatPrice.ts +53 -53
- package/src/hooks/useFetchTokensBalance.ts +53 -53
- package/src/hooks/useHasBalanceTokenList.ts +95 -95
- package/src/hooks/useTransactionList.ts +89 -89
- package/src/index.tsx +7 -7
- package/src/locales/en.js +1 -1
- package/src/locales/en.po +8 -8
- package/src/locales/zh.js +1 -1
- package/src/locales/zh.po +4 -4
- package/src/react19-types.d.ts +12 -0
- package/src/utils/formatter.ts +102 -102
- package/src/utils/time.ts +21 -21
- package/src/utils/utils.ts +8 -8
- package/tsconfig.json +22 -22
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { ChainId, platformIdMap, RestApiRequests } from '@dodoex/api';
|
|
2
|
-
'use client';
|
|
3
|
-
|
|
4
|
-
import { useQuery } from '@tanstack/react-query';
|
|
5
|
-
import { TokenInfo } from '../components/TokenLogo';
|
|
6
|
-
import { setTokenFiatPriceList } from '../constants/localstorage';
|
|
7
|
-
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
8
|
-
|
|
9
|
-
export function getFiatPriceQueryKeys(tokens?: TokenInfo[]) {
|
|
10
|
-
return ['fetch', 'fetchFiatPrice', tokens];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function useFetchFiatPrice(tokens: TokenInfo[]) {
|
|
14
|
-
const { encryptFiatPriceToken, restApiRequests: restApiRequestsProps } =
|
|
15
|
-
useWalletConnectContext();
|
|
16
|
-
return useQuery({
|
|
17
|
-
enabled: !!tokens.length,
|
|
18
|
-
queryKey: getFiatPriceQueryKeys(tokens),
|
|
19
|
-
queryFn: async () => {
|
|
20
|
-
const token = encryptFiatPriceToken?.() || '';
|
|
21
|
-
const restApiRequests = restApiRequestsProps ?? new RestApiRequests();
|
|
22
|
-
const path = `/frontend-v2-price-api/current/batch`;
|
|
23
|
-
const { result } = await restApiRequests.postJson(
|
|
24
|
-
path,
|
|
25
|
-
{
|
|
26
|
-
networks: tokens.map(
|
|
27
|
-
(token) => platformIdMap[token.chainId as ChainId],
|
|
28
|
-
),
|
|
29
|
-
addresses: tokens.map((token) => token.address),
|
|
30
|
-
symbols: tokens.map((token) => token.symbol),
|
|
31
|
-
isCache: true,
|
|
32
|
-
},
|
|
33
|
-
undefined,
|
|
34
|
-
{
|
|
35
|
-
headers: {
|
|
36
|
-
'pass-key': token,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
const resultMap = new Map<string, number>();
|
|
41
|
-
if (result.data) {
|
|
42
|
-
result.data.forEach((item: { price: string; address: string }) => {
|
|
43
|
-
const tokenUSD = Number(item.price);
|
|
44
|
-
if (!Number.isNaN(tokenUSD) && tokenUSD > 0) {
|
|
45
|
-
resultMap.set(item.address, tokenUSD);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
setTokenFiatPriceList(Object.fromEntries(resultMap.entries()));
|
|
49
|
-
}
|
|
50
|
-
return resultMap;
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
1
|
+
import { ChainId, platformIdMap, RestApiRequests } from '@dodoex/api';
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import { useQuery } from '@tanstack/react-query';
|
|
5
|
+
import { TokenInfo } from '../components/TokenLogo';
|
|
6
|
+
import { setTokenFiatPriceList } from '../constants/localstorage';
|
|
7
|
+
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
8
|
+
|
|
9
|
+
export function getFiatPriceQueryKeys(tokens?: TokenInfo[]) {
|
|
10
|
+
return ['fetch', 'fetchFiatPrice', tokens];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function useFetchFiatPrice(tokens: TokenInfo[]) {
|
|
14
|
+
const { encryptFiatPriceToken, restApiRequests: restApiRequestsProps } =
|
|
15
|
+
useWalletConnectContext();
|
|
16
|
+
return useQuery({
|
|
17
|
+
enabled: !!tokens.length,
|
|
18
|
+
queryKey: getFiatPriceQueryKeys(tokens),
|
|
19
|
+
queryFn: async () => {
|
|
20
|
+
const token = encryptFiatPriceToken?.() || '';
|
|
21
|
+
const restApiRequests = restApiRequestsProps ?? new RestApiRequests();
|
|
22
|
+
const path = `/frontend-v2-price-api/current/batch`;
|
|
23
|
+
const { result } = await restApiRequests.postJson(
|
|
24
|
+
path,
|
|
25
|
+
{
|
|
26
|
+
networks: tokens.map(
|
|
27
|
+
(token) => platformIdMap[token.chainId as ChainId],
|
|
28
|
+
),
|
|
29
|
+
addresses: tokens.map((token) => token.address),
|
|
30
|
+
symbols: tokens.map((token) => token.symbol),
|
|
31
|
+
isCache: true,
|
|
32
|
+
},
|
|
33
|
+
undefined,
|
|
34
|
+
{
|
|
35
|
+
headers: {
|
|
36
|
+
'pass-key': token,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
const resultMap = new Map<string, number>();
|
|
41
|
+
if (result.data) {
|
|
42
|
+
result.data.forEach((item: { price: string; address: string }) => {
|
|
43
|
+
const tokenUSD = Number(item.price);
|
|
44
|
+
if (!Number.isNaN(tokenUSD) && tokenUSD > 0) {
|
|
45
|
+
resultMap.set(item.address, tokenUSD);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
setTokenFiatPriceList(Object.fromEntries(resultMap.entries()));
|
|
49
|
+
}
|
|
50
|
+
return resultMap;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { getFetchERC20BalanceOfQueryOptions } from '@dodoex/dodo-contract-request';
|
|
4
|
-
import { useQueries } from '@tanstack/react-query';
|
|
5
|
-
import { TokenInfo } from '../components/TokenLogo';
|
|
6
|
-
|
|
7
|
-
type TokenInfoMap = Map<string, bigint>;
|
|
8
|
-
|
|
9
|
-
export default function useFetchTokensBalance({
|
|
10
|
-
account,
|
|
11
|
-
tokenList,
|
|
12
|
-
blockNumber,
|
|
13
|
-
skip,
|
|
14
|
-
}: {
|
|
15
|
-
account: string | undefined;
|
|
16
|
-
tokenList?: TokenInfo[];
|
|
17
|
-
blockNumber?: number;
|
|
18
|
-
skip?: boolean;
|
|
19
|
-
}) {
|
|
20
|
-
const tokensQueries = useQueries({
|
|
21
|
-
queries: (tokenList ?? []).map((token) => {
|
|
22
|
-
const query = getFetchERC20BalanceOfQueryOptions(
|
|
23
|
-
skip ? undefined : token.chainId,
|
|
24
|
-
token?.address,
|
|
25
|
-
account,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
queryKey: blockNumber
|
|
30
|
-
? [...query.queryKey, blockNumber]
|
|
31
|
-
: query.queryKey,
|
|
32
|
-
enabled: query.enabled && !skip,
|
|
33
|
-
queryFn: query.queryFn,
|
|
34
|
-
};
|
|
35
|
-
}),
|
|
36
|
-
combine: (results) => {
|
|
37
|
-
const tokenInfoMap = new Map() as TokenInfoMap;
|
|
38
|
-
results.forEach((result, i) => {
|
|
39
|
-
const token = tokenList?.[i];
|
|
40
|
-
if (result.data && token) {
|
|
41
|
-
tokenInfoMap.set(`${token.chainId}-${token.address}`, result.data);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return {
|
|
45
|
-
tokenInfoMap,
|
|
46
|
-
data: results.map((result) => result.data),
|
|
47
|
-
isPending: results.some((result) => result.isPending),
|
|
48
|
-
isLoading: results.some((result) => result.isLoading),
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
return tokensQueries;
|
|
53
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { getFetchERC20BalanceOfQueryOptions } from '@dodoex/dodo-contract-request';
|
|
4
|
+
import { useQueries } from '@tanstack/react-query';
|
|
5
|
+
import { TokenInfo } from '../components/TokenLogo';
|
|
6
|
+
|
|
7
|
+
type TokenInfoMap = Map<string, bigint>;
|
|
8
|
+
|
|
9
|
+
export default function useFetchTokensBalance({
|
|
10
|
+
account,
|
|
11
|
+
tokenList,
|
|
12
|
+
blockNumber,
|
|
13
|
+
skip,
|
|
14
|
+
}: {
|
|
15
|
+
account: string | undefined;
|
|
16
|
+
tokenList?: TokenInfo[];
|
|
17
|
+
blockNumber?: number;
|
|
18
|
+
skip?: boolean;
|
|
19
|
+
}) {
|
|
20
|
+
const tokensQueries = useQueries({
|
|
21
|
+
queries: (tokenList ?? []).map((token) => {
|
|
22
|
+
const query = getFetchERC20BalanceOfQueryOptions(
|
|
23
|
+
skip ? undefined : token.chainId,
|
|
24
|
+
token?.address,
|
|
25
|
+
account,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
queryKey: blockNumber
|
|
30
|
+
? [...query.queryKey, blockNumber]
|
|
31
|
+
: query.queryKey,
|
|
32
|
+
enabled: query.enabled && !skip,
|
|
33
|
+
queryFn: query.queryFn,
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
combine: (results) => {
|
|
37
|
+
const tokenInfoMap = new Map() as TokenInfoMap;
|
|
38
|
+
results.forEach((result, i) => {
|
|
39
|
+
const token = tokenList?.[i];
|
|
40
|
+
if (result.data && token) {
|
|
41
|
+
tokenInfoMap.set(`${token.chainId}-${token.address}`, result.data);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
tokenInfoMap,
|
|
46
|
+
data: results.map((result) => result.data),
|
|
47
|
+
isPending: results.some((result) => result.isPending),
|
|
48
|
+
isLoading: results.some((result) => result.isLoading),
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return tokensQueries;
|
|
53
|
+
}
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import BigNumber from 'bignumber.js';
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
6
|
-
import useFetchTokensBalance from './useFetchTokensBalance';
|
|
7
|
-
import { useFetchFiatPrice } from './useFetchFiatPrice';
|
|
8
|
-
import { getTokenFiatPriceList } from '../constants/localstorage';
|
|
9
|
-
import { TokenInfo } from '../components/TokenLogo';
|
|
10
|
-
|
|
11
|
-
interface TokenResult extends TokenInfo {
|
|
12
|
-
balance: BigNumber;
|
|
13
|
-
}
|
|
14
|
-
export function useHasBalanceTokenList({
|
|
15
|
-
account,
|
|
16
|
-
visible,
|
|
17
|
-
}: {
|
|
18
|
-
account: string | undefined;
|
|
19
|
-
visible: boolean;
|
|
20
|
-
}) {
|
|
21
|
-
const { tokenList } = useWalletConnectContext();
|
|
22
|
-
const fetchTokenQuery = useFetchTokensBalance({
|
|
23
|
-
account,
|
|
24
|
-
tokenList,
|
|
25
|
-
skip: !visible,
|
|
26
|
-
});
|
|
27
|
-
const hasBalanceTokenList = React.useMemo(() => {
|
|
28
|
-
let newHasBalanceTokenList = [] as TokenResult[];
|
|
29
|
-
fetchTokenQuery.tokenInfoMap.forEach((value, key) => {
|
|
30
|
-
if (value > 0) {
|
|
31
|
-
const token = tokenList.find(
|
|
32
|
-
(token) => `${token.chainId}-${token.address}` === key,
|
|
33
|
-
);
|
|
34
|
-
if (token?.decimals !== undefined) {
|
|
35
|
-
newHasBalanceTokenList.push({
|
|
36
|
-
...token,
|
|
37
|
-
balance: new BigNumber(value.toString()).div(10 ** token.decimals),
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
newHasBalanceTokenList = newHasBalanceTokenList.sort((a, b) =>
|
|
43
|
-
a.balance.gt(b.balance) ? -1 : 1,
|
|
44
|
-
);
|
|
45
|
-
return newHasBalanceTokenList;
|
|
46
|
-
}, [fetchTokenQuery.tokenInfoMap]);
|
|
47
|
-
const fiatPriceQuery = useFetchFiatPrice(hasBalanceTokenList);
|
|
48
|
-
|
|
49
|
-
const tokenLoading = fetchTokenQuery.isLoading || fetchTokenQuery.isPending;
|
|
50
|
-
|
|
51
|
-
const hasBalanceList = React.useMemo(() => {
|
|
52
|
-
return hasBalanceTokenList
|
|
53
|
-
.map((token) => {
|
|
54
|
-
const fiatPriceBalance = fiatPriceQuery.data?.get(token.address)
|
|
55
|
-
? token.balance.times(fiatPriceQuery.data?.get(token.address) ?? 0)
|
|
56
|
-
: undefined;
|
|
57
|
-
return {
|
|
58
|
-
...token,
|
|
59
|
-
fiatPriceBalance,
|
|
60
|
-
};
|
|
61
|
-
})
|
|
62
|
-
.sort((a, b) => {
|
|
63
|
-
if (a.fiatPriceBalance && b.fiatPriceBalance) {
|
|
64
|
-
return a.fiatPriceBalance.gt(b.fiatPriceBalance) ? -1 : 1;
|
|
65
|
-
}
|
|
66
|
-
const cacheFiatPriceObject = getTokenFiatPriceList();
|
|
67
|
-
const aFiatPrice = cacheFiatPriceObject[a.address];
|
|
68
|
-
const bFiatPrice = cacheFiatPriceObject[b.address];
|
|
69
|
-
if (!aFiatPrice || !bFiatPrice) return a.balance.gt(b.balance) ? -1 : 1;
|
|
70
|
-
return a.balance.times(aFiatPrice).gt(b.balance.times(bFiatPrice))
|
|
71
|
-
? -1
|
|
72
|
-
: 1;
|
|
73
|
-
});
|
|
74
|
-
}, [hasBalanceTokenList, fiatPriceQuery.data]);
|
|
75
|
-
|
|
76
|
-
const allFiatPriceBalance = React.useMemo(() => {
|
|
77
|
-
let result = new BigNumber(0);
|
|
78
|
-
hasBalanceList.forEach((token) => {
|
|
79
|
-
if (token.fiatPriceBalance) {
|
|
80
|
-
result = result.plus(token.fiatPriceBalance);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
return result;
|
|
84
|
-
}, [hasBalanceList]);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
tokenLoading: !!tokenLoading && !hasBalanceList.length,
|
|
88
|
-
hasBalanceList,
|
|
89
|
-
fiatPriceQuery,
|
|
90
|
-
allFiatPriceBalance,
|
|
91
|
-
allFiatPriceBalanceLoading:
|
|
92
|
-
(fiatPriceQuery.isLoading && !!hasBalanceTokenList.length) ||
|
|
93
|
-
tokenLoading,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import BigNumber from 'bignumber.js';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
6
|
+
import useFetchTokensBalance from './useFetchTokensBalance';
|
|
7
|
+
import { useFetchFiatPrice } from './useFetchFiatPrice';
|
|
8
|
+
import { getTokenFiatPriceList } from '../constants/localstorage';
|
|
9
|
+
import { TokenInfo } from '../components/TokenLogo';
|
|
10
|
+
|
|
11
|
+
interface TokenResult extends TokenInfo {
|
|
12
|
+
balance: BigNumber;
|
|
13
|
+
}
|
|
14
|
+
export function useHasBalanceTokenList({
|
|
15
|
+
account,
|
|
16
|
+
visible,
|
|
17
|
+
}: {
|
|
18
|
+
account: string | undefined;
|
|
19
|
+
visible: boolean;
|
|
20
|
+
}) {
|
|
21
|
+
const { tokenList } = useWalletConnectContext();
|
|
22
|
+
const fetchTokenQuery = useFetchTokensBalance({
|
|
23
|
+
account,
|
|
24
|
+
tokenList,
|
|
25
|
+
skip: !visible,
|
|
26
|
+
});
|
|
27
|
+
const hasBalanceTokenList = React.useMemo(() => {
|
|
28
|
+
let newHasBalanceTokenList = [] as TokenResult[];
|
|
29
|
+
fetchTokenQuery.tokenInfoMap.forEach((value, key) => {
|
|
30
|
+
if (value > 0) {
|
|
31
|
+
const token = tokenList.find(
|
|
32
|
+
(token) => `${token.chainId}-${token.address}` === key,
|
|
33
|
+
);
|
|
34
|
+
if (token?.decimals !== undefined) {
|
|
35
|
+
newHasBalanceTokenList.push({
|
|
36
|
+
...token,
|
|
37
|
+
balance: new BigNumber(value.toString()).div(10 ** token.decimals),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
newHasBalanceTokenList = newHasBalanceTokenList.sort((a, b) =>
|
|
43
|
+
a.balance.gt(b.balance) ? -1 : 1,
|
|
44
|
+
);
|
|
45
|
+
return newHasBalanceTokenList;
|
|
46
|
+
}, [fetchTokenQuery.tokenInfoMap]);
|
|
47
|
+
const fiatPriceQuery = useFetchFiatPrice(hasBalanceTokenList);
|
|
48
|
+
|
|
49
|
+
const tokenLoading = fetchTokenQuery.isLoading || fetchTokenQuery.isPending;
|
|
50
|
+
|
|
51
|
+
const hasBalanceList = React.useMemo(() => {
|
|
52
|
+
return hasBalanceTokenList
|
|
53
|
+
.map((token) => {
|
|
54
|
+
const fiatPriceBalance = fiatPriceQuery.data?.get(token.address)
|
|
55
|
+
? token.balance.times(fiatPriceQuery.data?.get(token.address) ?? 0)
|
|
56
|
+
: undefined;
|
|
57
|
+
return {
|
|
58
|
+
...token,
|
|
59
|
+
fiatPriceBalance,
|
|
60
|
+
};
|
|
61
|
+
})
|
|
62
|
+
.sort((a, b) => {
|
|
63
|
+
if (a.fiatPriceBalance && b.fiatPriceBalance) {
|
|
64
|
+
return a.fiatPriceBalance.gt(b.fiatPriceBalance) ? -1 : 1;
|
|
65
|
+
}
|
|
66
|
+
const cacheFiatPriceObject = getTokenFiatPriceList();
|
|
67
|
+
const aFiatPrice = cacheFiatPriceObject[a.address];
|
|
68
|
+
const bFiatPrice = cacheFiatPriceObject[b.address];
|
|
69
|
+
if (!aFiatPrice || !bFiatPrice) return a.balance.gt(b.balance) ? -1 : 1;
|
|
70
|
+
return a.balance.times(aFiatPrice).gt(b.balance.times(bFiatPrice))
|
|
71
|
+
? -1
|
|
72
|
+
: 1;
|
|
73
|
+
});
|
|
74
|
+
}, [hasBalanceTokenList, fiatPriceQuery.data]);
|
|
75
|
+
|
|
76
|
+
const allFiatPriceBalance = React.useMemo(() => {
|
|
77
|
+
let result = new BigNumber(0);
|
|
78
|
+
hasBalanceList.forEach((token) => {
|
|
79
|
+
if (token.fiatPriceBalance) {
|
|
80
|
+
result = result.plus(token.fiatPriceBalance);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return result;
|
|
84
|
+
}, [hasBalanceList]);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
tokenLoading: !!tokenLoading && !hasBalanceList.length,
|
|
88
|
+
hasBalanceList,
|
|
89
|
+
fiatPriceQuery,
|
|
90
|
+
allFiatPriceBalance,
|
|
91
|
+
allFiatPriceBalanceLoading:
|
|
92
|
+
(fiatPriceQuery.isLoading && !!hasBalanceTokenList.length) ||
|
|
93
|
+
tokenLoading,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { GraphQLRequests, SystemApi } from '@dodoex/api';
|
|
4
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
7
|
-
|
|
8
|
-
export enum StateText {
|
|
9
|
-
Running = 'pending',
|
|
10
|
-
Success = 'success',
|
|
11
|
-
Failed = 'failed',
|
|
12
|
-
Warning = 'reset',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type NoticeTransactionList = NonNullable<
|
|
16
|
-
NonNullable<
|
|
17
|
-
ReturnType<
|
|
18
|
-
NonNullable<
|
|
19
|
-
typeof SystemApi.graphql.fetchNoticeCenterTransactionList['__apiType']
|
|
20
|
-
>
|
|
21
|
-
>['notice_center_transactionList']
|
|
22
|
-
>['list']
|
|
23
|
-
>;
|
|
24
|
-
|
|
25
|
-
export function useTransactionList({
|
|
26
|
-
account,
|
|
27
|
-
chainId,
|
|
28
|
-
}: {
|
|
29
|
-
account: string | undefined;
|
|
30
|
-
chainId?: number;
|
|
31
|
-
}) {
|
|
32
|
-
const { graphQLRequests } = useWalletConnectContext();
|
|
33
|
-
const infiniteQueryOptions = (
|
|
34
|
-
graphQLRequests as GraphQLRequests
|
|
35
|
-
)?.getInfiniteQuery(
|
|
36
|
-
SystemApi.graphql.fetchNoticeCenterTransactionList,
|
|
37
|
-
'page',
|
|
38
|
-
{
|
|
39
|
-
where: {
|
|
40
|
-
limit: 10,
|
|
41
|
-
user: account,
|
|
42
|
-
chainId,
|
|
43
|
-
refreshNow: true,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
) ?? {
|
|
47
|
-
queryKey: [1],
|
|
48
|
-
queryFn: () => {
|
|
49
|
-
// empty
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
const fetchQuery = useInfiniteQuery({
|
|
53
|
-
...infiniteQueryOptions,
|
|
54
|
-
enabled: !!account && !!graphQLRequests,
|
|
55
|
-
initialPageParam: 1,
|
|
56
|
-
getNextPageParam: (item) => {
|
|
57
|
-
const { page, limit, count } = item.notice_center_transactionList ?? {};
|
|
58
|
-
if (!page || !limit || !count) return null;
|
|
59
|
-
let totalPage = Math.floor(count / limit);
|
|
60
|
-
if (count % limit) {
|
|
61
|
-
totalPage += 1;
|
|
62
|
-
}
|
|
63
|
-
if (page >= totalPage) return null;
|
|
64
|
-
return page + 1;
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const [list, pendingList] = React.useMemo(() => {
|
|
69
|
-
const list = [] as NoticeTransactionList;
|
|
70
|
-
|
|
71
|
-
fetchQuery.data?.pages?.forEach((page) => {
|
|
72
|
-
page.notice_center_transactionList?.list?.forEach((item) => {
|
|
73
|
-
if (!item?.extend?.safeTxHash) {
|
|
74
|
-
list.push(item);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
const pendingList =
|
|
79
|
-
list.filter((item) => item?.extend.status === StateText.Running) ?? [];
|
|
80
|
-
|
|
81
|
-
return [list, pendingList];
|
|
82
|
-
}, [fetchQuery.data]);
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
...fetchQuery,
|
|
86
|
-
list,
|
|
87
|
-
pendingList,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { GraphQLRequests, SystemApi } from '@dodoex/api';
|
|
4
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useWalletConnectContext } from '../WalletConnectProvider';
|
|
7
|
+
|
|
8
|
+
export enum StateText {
|
|
9
|
+
Running = 'pending',
|
|
10
|
+
Success = 'success',
|
|
11
|
+
Failed = 'failed',
|
|
12
|
+
Warning = 'reset',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type NoticeTransactionList = NonNullable<
|
|
16
|
+
NonNullable<
|
|
17
|
+
ReturnType<
|
|
18
|
+
NonNullable<
|
|
19
|
+
typeof SystemApi.graphql.fetchNoticeCenterTransactionList['__apiType']
|
|
20
|
+
>
|
|
21
|
+
>['notice_center_transactionList']
|
|
22
|
+
>['list']
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
export function useTransactionList({
|
|
26
|
+
account,
|
|
27
|
+
chainId,
|
|
28
|
+
}: {
|
|
29
|
+
account: string | undefined;
|
|
30
|
+
chainId?: number;
|
|
31
|
+
}) {
|
|
32
|
+
const { graphQLRequests } = useWalletConnectContext();
|
|
33
|
+
const infiniteQueryOptions = (
|
|
34
|
+
graphQLRequests as GraphQLRequests
|
|
35
|
+
)?.getInfiniteQuery(
|
|
36
|
+
SystemApi.graphql.fetchNoticeCenterTransactionList,
|
|
37
|
+
'page',
|
|
38
|
+
{
|
|
39
|
+
where: {
|
|
40
|
+
limit: 10,
|
|
41
|
+
user: account,
|
|
42
|
+
chainId,
|
|
43
|
+
refreshNow: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
) ?? {
|
|
47
|
+
queryKey: [1],
|
|
48
|
+
queryFn: () => {
|
|
49
|
+
// empty
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
const fetchQuery = useInfiniteQuery({
|
|
53
|
+
...infiniteQueryOptions,
|
|
54
|
+
enabled: !!account && !!graphQLRequests,
|
|
55
|
+
initialPageParam: 1,
|
|
56
|
+
getNextPageParam: (item) => {
|
|
57
|
+
const { page, limit, count } = item.notice_center_transactionList ?? {};
|
|
58
|
+
if (!page || !limit || !count) return null;
|
|
59
|
+
let totalPage = Math.floor(count / limit);
|
|
60
|
+
if (count % limit) {
|
|
61
|
+
totalPage += 1;
|
|
62
|
+
}
|
|
63
|
+
if (page >= totalPage) return null;
|
|
64
|
+
return page + 1;
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const [list, pendingList] = React.useMemo(() => {
|
|
69
|
+
const list = [] as NoticeTransactionList;
|
|
70
|
+
|
|
71
|
+
fetchQuery.data?.pages?.forEach((page) => {
|
|
72
|
+
page.notice_center_transactionList?.list?.forEach((item) => {
|
|
73
|
+
if (!item?.extend?.safeTxHash) {
|
|
74
|
+
list.push(item);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const pendingList =
|
|
79
|
+
list.filter((item) => item?.extend.status === StateText.Running) ?? [];
|
|
80
|
+
|
|
81
|
+
return [list, pendingList];
|
|
82
|
+
}, [fetchQuery.data]);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...fetchQuery,
|
|
86
|
+
list,
|
|
87
|
+
pendingList,
|
|
88
|
+
};
|
|
89
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { default as WalletDialog } from './WalletConnect/WalletDialog';
|
|
2
|
-
export { WalletConnectProvider } from './WalletConnectProvider';
|
|
3
|
-
export { default as ClientProvider } from './ClientProvider';
|
|
4
|
-
export { default as LangProvider } from './LangProvider';
|
|
5
|
-
export { useWalletListByNetwork } from './hooks/useConnectWallet';
|
|
6
|
-
export { default as ConnectDialog } from './WalletConnect/ConnectDialog';
|
|
7
|
-
export { default as ConnectPage } from './WalletConnect/ConnectPage';
|
|
1
|
+
export { default as WalletDialog } from './WalletConnect/WalletDialog';
|
|
2
|
+
export { WalletConnectProvider } from './WalletConnectProvider';
|
|
3
|
+
export { default as ClientProvider } from './ClientProvider';
|
|
4
|
+
export { default as LangProvider } from './LangProvider';
|
|
5
|
+
export { useWalletListByNetwork } from './hooks/useConnectWallet';
|
|
6
|
+
export { default as ConnectDialog } from './WalletConnect/ConnectDialog';
|
|
7
|
+
export { default as ConnectPage } from './WalletConnect/ConnectPage';
|
package/src/locales/en.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/*eslint-disable*/module.exports={messages:JSON.parse("{\"
|
|
1
|
+
/*eslint-disable*/module.exports={messages:JSON.parse("{\"14s9LL\":[\"Create Liquidity Mining\"],\"3UCJ3e\":[\"Check your email and click the link to complete login\"],\"3XBvkd\":[\"Remove Liquidity\"],\"3y6FjD\":[\"Log in with your email or a passkey\"],\"6KnyG0\":[\"Enter email\"],\"6Ui8nZ\":[\"Log in with your email\"],\"6V3Ea3\":[\"Copied\"],\"7Bj3x9\":[\"Failed\"],\"8OiU8L\":[\"Pool Creation\"],\"9ow2PX\":[\"Installed Wallet\"],\"9zb2WA\":[\"Connecting\"],\"AeXO77\":[\"Account\"],\"B2Tpo0\":[\"Invalid email\"],\"BzEFor\":[\"or\"],\"CtByM7\":[\"Connect Wallet\"],\"Du6bPw\":[\"Address\"],\"E/yE9x\":[\"Before proceeding make sure\"],\"EYDfo2\":[\"Loading more\"],\"FzJ11V\":[\"This is empty\"],\"JE8mMQ\":[\"No tokens\"],\"JYKRJS\":[\"Stake\"],\"JlFcis\":[\"Send\"],\"KAbcm2\":[\"Succeeded\"],\"LobdAW\":[\"Unknown Error\"],\"Mlg3Ds\":[\"Choose existing passkey\"],\"OBdohg\":[\"Add Liquidity\"],\"OfhWJH\":[\"Reset\"],\"OzjK0A\":[\"Create new passkey\"],\"QHcLEN\":[\"Connected\"],\"RETKSh\":[\"Connect Alchemy\"],\"S0kLOH\":[\"ID\"],\"Sz0SkD\":[\"1、Ledger Live APP is closed\",[\"BR\"],\"2、The device plugged in via USB,NOT Bluetooth\",[\"BR\"],\"3、The device is unlocked and in the \",[\"ledgerAppName\"],\" app\",[\"BR\"],\"4、”Blind Signing” is enabled in \",[\"ledgerAppName\"],\" app\"],\"TP9/K5\":[\"Token\"],\"U8oDGg\":[\"On-chain transaction records\"],\"UbRKMZ\":[\"Pending\"],\"XJOV1Y\":[\"Activity\"],\"Z3FXyt\":[\"Loading...\"],\"Z7ZXbT\":[\"Approve\"],\"fsBGk0\":[\"Balance\"],\"gCNLBV\":[\"Copy wallet address\"],\"gPbbTL\":[\"The Ledger Device is locked\\\\nPlease unlock from the device\"],\"hQRttt\":[\"Submit\"],\"lDgVWA\":[\"Receive\"],\"pkRuyd\":[\"Receiver address\"],\"rwC96V\":[\"Invalid wallet address\"],\"sr0UJD\":[\"Go Back\"],\"vH2C/2\":[\"Swap\"],\"vN+hAq\":[\"Available Ledger Account\"],\"xGVfLh\":[\"Continue\"],\"xHr8Pp\":[\"Last connection\"],\"yN5k0R\":[\"More Wallets\"],\"z5vMiF\":[\"End mining\\n\"],\"zPGNJm\":[\"Transfer\"],\"zXCpR0\":[\"Claim Rewards\"],\"zga9sT\":[\"OK\"]}")};
|
package/src/locales/en.po
CHANGED
|
@@ -105,8 +105,12 @@ msgid "Create new passkey"
|
|
|
105
105
|
msgstr "Create new passkey"
|
|
106
106
|
|
|
107
107
|
#: src/WalletConnect/ActivityList.tsx:402
|
|
108
|
-
msgid "
|
|
109
|
-
|
|
108
|
+
msgid ""
|
|
109
|
+
"End mining\n"
|
|
110
|
+
""
|
|
111
|
+
msgstr ""
|
|
112
|
+
"End mining\n"
|
|
113
|
+
""
|
|
110
114
|
|
|
111
115
|
#: src/WalletConnect/ConnectAlchemy/index.tsx:131
|
|
112
116
|
msgid "Enter email"
|
|
@@ -227,12 +231,8 @@ msgid "Swap"
|
|
|
227
231
|
msgstr "Swap"
|
|
228
232
|
|
|
229
233
|
#: src/WalletConnect/ConnectLedger/LockedDialog.tsx:37
|
|
230
|
-
msgid ""
|
|
231
|
-
"The Ledger Device is locked
|
|
232
|
-
"Please unlock from the device"
|
|
233
|
-
msgstr ""
|
|
234
|
-
"The Ledger Device is locked\n"
|
|
235
|
-
"Please unlock from the device"
|
|
234
|
+
msgid "The Ledger Device is locked\\nPlease unlock from the device"
|
|
235
|
+
msgstr "The Ledger Device is locked\\nPlease unlock from the device"
|
|
236
236
|
|
|
237
237
|
#: src/WalletConnect/ActivityList.tsx:137
|
|
238
238
|
msgid "This is empty"
|