From 55ad8ad58e8fed5c9d7abdab3d55ee41162f929c Mon Sep 17 00:00:00 2001 From: Lyka Labrada Date: Tue, 10 Oct 2023 18:02:46 +0800 Subject: [PATCH] update deps array when fetching evm details --- .../Portfolio/hooks/EvmTokenBalances.ts | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts b/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts index 393a2467c9..0255b93b4f 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts @@ -2,10 +2,8 @@ import { useEffect, useState } from "react"; import { formatEther, formatUnits } from "viem"; import { WalletToken, useNetworkContext } from "@waveshq/walletkit-ui"; import { utils } from "ethers"; -import { DomainType, useDomainContext } from "@contexts/DomainContext"; import { batch, useSelector } from "react-redux"; import { RootState } from "@store"; -import { useIsFocused } from "@react-navigation/native"; import { TokenData } from "@defichain/whale-api-client/dist/api/tokens"; import { useLogger } from "@shared-contexts/NativeLoggingProvider"; import { useWalletContext } from "@shared-contexts/WalletContext"; @@ -23,8 +21,6 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { useState({}); const blockCount = useSelector((state: RootState) => state.block.count); const { network } = useNetworkContext(); - const isFocused = useIsFocused(); - const { domain } = useDomainContext(); const logger = useLogger(); const { allTokens } = useSelector((state: RootState) => state.wallet); @@ -33,23 +29,6 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { ); const dispatch = useAppDispatch(); - useEffect(() => { - batch(() => { - dispatch(fetchEvmWalletDetails({ network, evmAddress })); - dispatch(fetchEvmTokenBalances({ network, evmAddress })); - }); - }, [network, evmAddress, blockCount]); - - useEffect(() => { - setAllTokensWithAddress( - Object.keys(allTokens).reduce((current, each) => { - const tokenDetails = allTokens[each]; - const key = getAddressFromDST20TokenId(tokenDetails.id); - return Object.assign(current, { [key]: tokenDetails }); - }, {}), - ); - }, [allTokens]); - const getEvmTokens = async () => { const dfiToken: WalletToken = { id: "0-EVM", @@ -105,10 +84,25 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { }; useEffect(() => { - if (isFocused && domain === DomainType.EVM) { - getEvmTokens(); - } - }, [evmAddress, blockCount, isFocused, domain, evmWalletDetails]); + batch(() => { + dispatch(fetchEvmWalletDetails({ network, evmAddress })); + dispatch(fetchEvmTokenBalances({ network, evmAddress })); + }); + }, [network, evmAddress, blockCount]); + + useEffect(() => { + setAllTokensWithAddress( + Object.keys(allTokens).reduce((current, each) => { + const tokenDetails = allTokens[each]; + const key = getAddressFromDST20TokenId(tokenDetails.id); + return Object.assign(current, { [key]: tokenDetails }); + }, {}), + ); + }, [allTokens]); + + useEffect(() => { + getEvmTokens(); + }, [evmWalletDetails]); return { evmTokens }; }