Commit a7a2a9ed authored by ian-jh's avatar ian-jh

:quit

Merge branch 'beta' of https://github.com/Uniswap/uniswap-frontend into beta
parents 495fb062 81bc6926
...@@ -32,8 +32,10 @@ const SpinnerWrapper = styled(Spinner)` ...@@ -32,8 +32,10 @@ const SpinnerWrapper = styled(Spinner)`
` `
function tryToSetConnector(setConnector, setError) { function tryToSetConnector(setConnector, setError) {
setConnector('Injected', { suppressAndThrowErrors: true }).catch(error => { setConnector('Injected', { suppressAndThrowErrors: true }).catch(() => {
setConnector('Network') setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
}) })
} }
...@@ -54,25 +56,31 @@ export default function Web3ReactManager({ children }) { ...@@ -54,25 +56,31 @@ export default function Web3ReactManager({ children }) {
if (accounts.length >= 1) { if (accounts.length >= 1) {
tryToSetConnector(setConnector, setError) tryToSetConnector(setConnector, setError)
} else { } else {
setConnector('Network') setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
} }
}) })
} }
} else { } else {
setConnector('Network') setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
} }
} }
}, [active, error, setConnector, setError]) })
// parse the error // parse the error
useEffect(() => { useEffect(() => {
if (error) { if (error) {
// if the user changes to the wrong network, unset the connector // if the user changes to the wrong network, unset the connector
if (error.code === Connector.errorCodes.UNSUPPORTED_NETWORK) { if (error.code === Connector.errorCodes.UNSUPPORTED_NETWORK) {
setConnector('Network') setConnector('Network', { suppressAndThrowErrors: true }).catch(error => {
setError(error)
})
} }
} }
}, [error, setConnector]) })
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
useEffect(() => { useEffect(() => {
......
...@@ -68,12 +68,25 @@ export default function Provider({ children }) { ...@@ -68,12 +68,25 @@ export default function Provider({ children }) {
} }
export function Updater() { export function Updater() {
const { networkId, library } = useWeb3Context() const { networkId, library, connectorName } = useWeb3Context()
const globalBlockNumber = useBlockNumber() const globalBlockNumber = useBlockNumber()
const [, { updateBlockNumber, updateUSDPrice }] = useApplicationContext() const [, { updateBlockNumber, updateUSDPrice }] = useApplicationContext()
// slow down polling interval
useEffect(() => { useEffect(() => {
if (library) {
if (connectorName === 'Network') {
library.polling = false
} else {
library.pollingInterval = 5
}
}
}, [library, connectorName])
// update usd price
useEffect(() => {
if (library) {
let stale = false let stale = false
getUSDPrice(library) getUSDPrice(library)
...@@ -87,10 +100,12 @@ export function Updater() { ...@@ -87,10 +100,12 @@ export function Updater() {
updateUSDPrice(networkId, null) updateUSDPrice(networkId, null)
} }
}) })
}
}, [globalBlockNumber, library, networkId, updateUSDPrice]) }, [globalBlockNumber, library, networkId, updateUSDPrice])
// update block number
useEffect(() => { useEffect(() => {
if ((networkId || networkId === 0) && library) { if (library) {
let stale = false let stale = false
function update() { function update() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment