diff --git a/src/index.tsx b/src/index.tsx index 2621223e4..167b5fd3d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -13,6 +13,7 @@ import { useConnect, useGameDataFetch, useGameLoadDataFetch, + usePopulationFetch, useWallet, useWalletChange, useWalletOnboarding, @@ -66,6 +67,7 @@ function DApp() { useWallet() useGameLoadDataFetch() useBalanceFetch() + usePopulationFetch() useGameDataFetch() useWalletChange() diff --git a/src/shared/hooks/wallets.ts b/src/shared/hooks/wallets.ts index abe3be68f..3d5c7fa63 100644 --- a/src/shared/hooks/wallets.ts +++ b/src/shared/hooks/wallets.ts @@ -12,6 +12,7 @@ import { connectArbitrumProvider, selectDisplayedRealmId, connectArbitrumProviderFallback, + fetchPopulation, } from "redux-state" import { ARBITRUM_SEPOLIA, @@ -106,6 +107,22 @@ export function useBalanceFetch() { useInterval(walletBalancesCallback, account ? BALANCE_UPDATE_INTERVAL : null) } +export function usePopulationFetch() { + const dispatch = useDappDispatch() + const account = useDappSelector(selectWalletAddress) + + const populationFetchCallback = useCallback(async () => { + if (account && dispatch) { + await dispatch(fetchPopulation()) + } + }, [account, dispatch]) + + useInterval( + populationFetchCallback, + account ? BALANCE_UPDATE_INTERVAL * 2 : null + ) +} + export function useWallet() { const [{ wallet }] = useConnectWallet() const arbitrumProvider = useArbitrumProvider()