1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-11-23 02:00:27 +01:00

lazy handle account & network change

- ref #59
This commit is contained in:
Matthias Kretschmann 2020-07-30 20:54:33 +02:00
parent 19eb296ab2
commit 942b542e8b
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -75,11 +75,11 @@ function OceanProvider({
opts = await getDefaultProviders()
}
const instance = new Web3Modal(opts)
const instance = web3Modal || new Web3Modal(opts)
setWeb3Modal(instance)
Logger.log('Web3Modal instance created.', instance)
const provider = await instance.connect()
const provider = web3Provider || (await instance.connect())
setWeb3Provider(provider)
const web3 = new Web3(provider)
@ -137,16 +137,8 @@ function OceanProvider({
const handleAccountsChanged = async (accounts: string[]) => {
console.debug("Handling 'accountsChanged' event with payload", accounts)
if (status === ProviderStatus.CONNECTED) {
connect(web3ModalOpts)
}
// if (accounts.length > 0) {
// setAccountId(accounts[0])
// if (web3) {
// const balance = await getBalance(web3, accounts[0])
// setBalance(balance)
// }
// if (status === ProviderStatus.CONNECTED) {
connect(web3ModalOpts)
// }
}
@ -157,9 +149,9 @@ function OceanProvider({
networkId,
status
)
if (status === ProviderStatus.CONNECTED) {
connect(web3ModalOpts)
}
// if (status === ProviderStatus.CONNECTED) {
connect(web3ModalOpts)
// }
}
useEffect(() => {