1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
This commit is contained in:
mihaisc 2020-08-11 15:32:24 +03:00
parent 69d0b14903
commit 881c4c4ae0
2 changed files with 23 additions and 23 deletions

View File

@ -5,31 +5,31 @@ import { useEffect } from 'react'
import { getOceanConfig } from './wrapRootElement'
export function NetworkMonitor() {
const { connect, web3Provider } = useOcean()
const { connect, web3Provider } = useOcean()
const handleNetworkChanged = (chainId: number) => {
// temp hack
let network = ''
switch (chainId) {
case 1: {
network = 'mainnet'
}
case 4: {
network = 'rinkeby'
}
}
const config = getOceanConfig(network)
connect(config)
const handleNetworkChanged = (chainId: number) => {
// temp hack
let network = ''
switch (chainId) {
case 1: {
network = 'mainnet'
}
case 4: {
network = 'rinkeby'
}
}
useEffect(() => {
if (!web3Provider) return
const config = getOceanConfig(network)
connect(config)
}
useEffect(() => {
if (!web3Provider) return
web3Provider.on('chainChanged', handleNetworkChanged)
web3Provider.on('chainChanged', handleNetworkChanged)
return () => {
web3Provider.removeListener('chainChanged', handleNetworkChanged)
}
}, [web3Provider])
return () => {
web3Provider.removeListener('chainChanged', handleNetworkChanged)
}
}, [web3Provider])
return (<></>)
return <></>
}

View File

@ -25,7 +25,7 @@ export default function wrapRootElement({
initialConfig={oceanInitialConfig}
web3ModalOpts={web3ModalOpts}
>
<NetworkMonitor/>
<NetworkMonitor />
{element}
</OceanProvider>
)