Skip to content

Commit 48bed6b

Browse files
fix(ui-ux): show v1 token on EVM side (#4190)
fix(ui-ux): show v1 token on evm side
1 parent 8bd46d3 commit 48bed6b

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { useEffect, useState } from "react";
2-
import { WalletToken, useNetworkContext } from "@waveshq/walletkit-ui";
2+
import {
3+
WalletToken,
4+
useNetworkContext,
5+
useWhaleApiClient,
6+
} from "@waveshq/walletkit-ui";
37
import { utils } from "ethers";
48
import { batch, useSelector } from "react-redux";
59
import { RootState } from "@store";
@@ -12,13 +16,15 @@ import { useEVMProvider } from "@contexts/EVMProvider";
1216
import { useIsFocused } from "@react-navigation/native";
1317
import { getAddressFromDST20TokenId } from "@api/transaction/transfer_domain";
1418
import { useCustomServiceProviderContext } from "@contexts/CustomServiceProvider";
19+
import { getPaginatedResponse } from "@waveshq/walletkit-core";
1520

1621
interface AssociatedToken {
1722
[key: string]: TokenData;
1823
}
1924

2025
export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
2126
const { evmAddress } = useWalletContext();
27+
const client = useWhaleApiClient();
2228
const [evmTokens, setEvmTokens] = useState<WalletToken[]>([]);
2329
const [allTokensWithAddress, setAllTokensWithAddress] =
2430
useState<AssociatedToken>({});
@@ -29,14 +35,25 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
2935
const logger = useLogger();
3036
const isFocused = useIsFocused();
3137

32-
const { allTokens } = useSelector((state: RootState) => state.wallet);
33-
const tokenIds = Object.keys(allTokens).reduce((current: string[], key) => {
34-
const token = allTokens[key];
38+
const [allTokens, setAllTokens] = useState<TokenData[]>([]);
39+
const getAllTokens = async () => {
40+
const allTokens: TokenData[] = await getPaginatedResponse<TokenData>(
41+
(limit, next) => client.tokens.list(limit, next),
42+
);
43+
setAllTokens(allTokens?.filter((token) => token.isDAT));
44+
};
45+
46+
useEffect(() => {
47+
void getAllTokens();
48+
}, [isFocused]);
49+
50+
const tokenIds = allTokens.reduce((current: string[], token) => {
3551
if (token.id !== "0" && token.isDAT && !token.isLPS) {
3652
return [...current, token.id];
3753
}
3854
return current;
3955
}, []);
56+
4057
const { evmWalletDetails, evmTokenBalances } = useSelector(
4158
(state: RootState) => state.evm,
4259
);
@@ -114,8 +131,7 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
114131

115132
useEffect(() => {
116133
setAllTokensWithAddress(
117-
Object.keys(allTokens).reduce((current, each) => {
118-
const tokenDetails = allTokens[each];
134+
allTokens?.reduce((current, tokenDetails) => {
119135
const key = getAddressFromDST20TokenId(tokenDetails.id);
120136
return Object.assign(current, { [key]: tokenDetails });
121137
}, {}),

0 commit comments

Comments
 (0)