diff --git a/.env b/.env index 1360eed2b5..ede8f6cc70 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ REACT_APP_CHAIN_ID="1" -REACT_APP_NETWORK_URL="https://mainnet.infura.io/v3/b8800ce81b8c451698081d269b86692b" \ No newline at end of file +REACT_APP_NETWORK_URL="https://mainnet.infura.io/v3/acb7e55995d04c49bfb52b7141599467" \ No newline at end of file diff --git a/.env.production b/.env.production index 9f3022af6d..3d6db5df87 100644 --- a/.env.production +++ b/.env.production @@ -1,5 +1,5 @@ REACT_APP_CHAIN_ID="1" -REACT_APP_NETWORK_URL="https://mainnet.infura.io/v3/2acb2baa4c06402792e0c701a3697d10" +REACT_APP_NETWORK_URL="https://mainnet.infura.io/v3/febcb10ca2754433a61e0805bc6c047d" REACT_APP_PORTIS_ID="c0e2bf01-4b08-4fd5-ac7b-8e26b58cd236" REACT_APP_FORTMATIC_KEY="pk_live_F937DF033A1666BF" REACT_APP_GOOGLE_ANALYTICS_ID="UA-128182339-4" diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 0dae605e40..0f5a3b7293 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -71,10 +71,9 @@ Cypress.Commands.overwrite('visit', (original, url, options) => { ...options, onBeforeLoad(win) { options && options.onBeforeLoad && options.onBeforeLoad(win) - const provider = new JsonRpcProvider('https://rinkeby.infura.io/v3/b8800ce81b8c451698081d269b86692b', 4) + const provider = new JsonRpcProvider('https://rinkeby.infura.io/v3/acb7e55995d04c49bfb52b7141599467', 4) const signer = new Wallet(PRIVATE_KEY_TEST_NEVER_USE, provider) - const bridge = new CustomizedBridge(signer, provider) - win.ethereum = bridge + win.ethereum = new CustomizedBridge(signer, provider) } }) }) diff --git a/src/hooks/useIsWindowVisible.ts b/src/hooks/useIsWindowVisible.ts new file mode 100644 index 0000000000..5505c635d1 --- /dev/null +++ b/src/hooks/useIsWindowVisible.ts @@ -0,0 +1,20 @@ +import { useCallback, useEffect, useState } from 'react' + +/** + * Returns whether the window is currently visible to the user. + */ +export default function useIsWindowVisible(): boolean { + const [focused, setFocused] = useState(true) + const listener = useCallback(() => { + setFocused(document.visibilityState !== 'hidden') + }, [setFocused]) + + useEffect(() => { + document.addEventListener('visibilitychange', listener) + return () => { + document.removeEventListener('visibilitychange', listener) + } + }, [listener]) + + return focused +} diff --git a/src/state/application/updater.ts b/src/state/application/updater.ts index 5a4e4c4459..3962bc1506 100644 --- a/src/state/application/updater.ts +++ b/src/state/application/updater.ts @@ -1,5 +1,6 @@ import { useEffect, useState } from 'react' import { useDebounce, useActiveWeb3React } from '../../hooks' +import useIsWindowVisible from '../../hooks/useIsWindowVisible' import { updateBlockNumber } from './actions' import { useDispatch } from 'react-redux' @@ -7,6 +8,7 @@ export default function Updater() { const { library, chainId } = useActiveWeb3React() const dispatch = useDispatch() + const windowVisible = useIsWindowVisible() const [maxBlockNumber, setMaxBlockNumber] = useState(null) // because blocks arrive in bunches with longer polling periods, we just want // to process the latest one. @@ -38,8 +40,10 @@ export default function Updater() { useEffect(() => { if (!chainId || !debouncedMaxBlockNumber) return - dispatch(updateBlockNumber({ chainId, blockNumber: debouncedMaxBlockNumber })) - }, [chainId, debouncedMaxBlockNumber, dispatch]) + if (windowVisible) { + dispatch(updateBlockNumber({ chainId, blockNumber: debouncedMaxBlockNumber })) + } + }, [chainId, debouncedMaxBlockNumber, windowVisible, dispatch]) return null }