1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Fix race condition in network controller lookup() method.

This commit is contained in:
Dan Miller 2018-12-06 16:12:57 -03:30
parent d1996509de
commit 246dcf689c

View File

@ -105,12 +105,18 @@ module.exports = class NetworkController extends EventEmitter {
if (!this._provider) {
return log.warn('NetworkController - lookupNetwork aborted due to missing provider')
}
var { type } = this.providerStore.getState()
const { type } = this.providerStore.getState()
const ethQuery = new EthQuery(this._provider)
const initialNetwork = this.getNetworkState()
ethQuery.sendAsync({ method: 'net_version' }, (err, network) => {
if (err) return this.setNetworkState('loading')
log.info('web3.getNetwork returned ' + network)
this.setNetworkState(network, type)
const currentNetwork = this.getNetworkState()
if (initialNetwork === currentNetwork) {
if (err) {
return this.setNetworkState('loading')
}
log.info('web3.getNetwork returned ' + network)
this.setNetworkState(network, type)
}
})
}