From ab609b93c0aa41b1dc567bba2163c95b71434828 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 29 Jan 2021 16:21:34 +0200 Subject: [PATCH] refetch balance (#357) --- src/helpers/NetworkMonitor.tsx | 13 ++++++++++++- src/utils/profile.ts | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/helpers/NetworkMonitor.tsx b/src/helpers/NetworkMonitor.tsx index 4e06541ba..36ec1a9e9 100644 --- a/src/helpers/NetworkMonitor.tsx +++ b/src/helpers/NetworkMonitor.tsx @@ -4,6 +4,7 @@ import { getOceanConfig } from './wrapRootElement' import { Logger } from '@oceanprotocol/lib' import { ConfigHelperConfig } from '@oceanprotocol/lib/dist/node/utils/ConfigHelper' +const refreshInterval = 5000 // 5 sec. export function NetworkMonitor(): ReactElement { const { connect, @@ -11,7 +12,8 @@ export function NetworkMonitor(): ReactElement { web3, networkId, config, - accountId + refreshBalance, + account } = useOcean() async function handleNetworkChanged(chainId: string | number) { @@ -37,7 +39,16 @@ export function NetworkMonitor(): ReactElement { Logger.error(error.message) } } + useEffect(() => { + if (!account) return + refreshBalance() + const balanceInterval = setInterval(() => refreshBalance(), refreshInterval) + + return () => { + clearInterval(balanceInterval) + } + }, [networkId, account]) // Re-connect on mount when network is different from user network. // Bit nasty to just overwrite the initialConfig passed to OceanProvider // while it's connecting to that, but YOLO. diff --git a/src/utils/profile.ts b/src/utils/profile.ts index b8e075663..ccc368cad 100644 --- a/src/utils/profile.ts +++ b/src/utils/profile.ts @@ -89,7 +89,7 @@ export default async function get3BoxProfile( ) return - Logger.log(`3Box profile found for ${accountId}`, response.data) + // Logger.log(`3Box profile found for ${accountId}`, response.data) const profile = transformResponse(response.data) return profile // eslint-disable-next-line no-empty