From 151a96665bf414601f57852016c025edf7256006 Mon Sep 17 00:00:00 2001 From: Jagoda Berry Rybacka Date: Thu, 26 Oct 2023 17:44:40 +0200 Subject: [PATCH] Add population refresh every minute --- src/index.tsx | 2 ++ src/shared/hooks/wallets.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) 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()