Skip to content

Commit

Permalink
fix(ui-ux): show v1 token on EVM side (#4190)
Browse files Browse the repository at this point in the history
fix(ui-ux): show v1 token on evm side
  • Loading branch information
fullstackninja864 authored Aug 19, 2024
1 parent 8bd46d3 commit 48bed6b
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { useEffect, useState } from "react";
import { WalletToken, useNetworkContext } from "@waveshq/walletkit-ui";
import {
WalletToken,
useNetworkContext,
useWhaleApiClient,
} from "@waveshq/walletkit-ui";
import { utils } from "ethers";
import { batch, useSelector } from "react-redux";
import { RootState } from "@store";
Expand All @@ -12,13 +16,15 @@ import { useEVMProvider } from "@contexts/EVMProvider";
import { useIsFocused } from "@react-navigation/native";
import { getAddressFromDST20TokenId } from "@api/transaction/transfer_domain";
import { useCustomServiceProviderContext } from "@contexts/CustomServiceProvider";
import { getPaginatedResponse } from "@waveshq/walletkit-core";

interface AssociatedToken {
[key: string]: TokenData;
}

export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
const { evmAddress } = useWalletContext();
const client = useWhaleApiClient();
const [evmTokens, setEvmTokens] = useState<WalletToken[]>([]);
const [allTokensWithAddress, setAllTokensWithAddress] =
useState<AssociatedToken>({});
Expand All @@ -29,14 +35,25 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
const logger = useLogger();
const isFocused = useIsFocused();

const { allTokens } = useSelector((state: RootState) => state.wallet);
const tokenIds = Object.keys(allTokens).reduce((current: string[], key) => {
const token = allTokens[key];
const [allTokens, setAllTokens] = useState<TokenData[]>([]);
const getAllTokens = async () => {
const allTokens: TokenData[] = await getPaginatedResponse<TokenData>(
(limit, next) => client.tokens.list(limit, next),
);
setAllTokens(allTokens?.filter((token) => token.isDAT));
};

useEffect(() => {
void getAllTokens();
}, [isFocused]);

const tokenIds = allTokens.reduce((current: string[], token) => {
if (token.id !== "0" && token.isDAT && !token.isLPS) {
return [...current, token.id];
}
return current;
}, []);

const { evmWalletDetails, evmTokenBalances } = useSelector(
(state: RootState) => state.evm,
);
Expand Down Expand Up @@ -114,8 +131,7 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {

useEffect(() => {
setAllTokensWithAddress(
Object.keys(allTokens).reduce((current, each) => {
const tokenDetails = allTokens[each];
allTokens?.reduce((current, tokenDetails) => {
const key = getAddressFromDST20TokenId(tokenDetails.id);
return Object.assign(current, { [key]: tokenDetails });
}, {}),
Expand Down

0 comments on commit 48bed6b

Please sign in to comment.