diff options
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/background.js | 13 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 16 |
2 files changed, 21 insertions, 8 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index 432040c53..f64209ecc 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -76,13 +76,20 @@ var providerOpts = { var provider = MetaMaskProvider(providerOpts) var web3 = new Web3(provider) idStore.web3 = web3 -idStore.getNetwork(3) +idStore.getNetwork() // log new blocks provider.on('block', function(block){ console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex')) + + // Check network when restoring connectivity: + if (idStore._currentState.network === 'loading') { + idStore.getNetwork() + } }) +provider.on('error', idStore.getNetwork.bind(idStore)) + var ethStore = new EthStore(provider) idStore.setStore(ethStore) @@ -292,13 +299,13 @@ function addUnconfirmedMsg(msgParams, cb){ function setRpcTarget(rpcTarget){ configManager.setRpcTarget(rpcTarget) chrome.runtime.reload() - idStore.getNetwork(3) // 3 retry attempts + idStore.getNetwork() } function setProviderType(type) { configManager.setProviderType(type) chrome.runtime.reload() - idStore.getNetwork(3) + idStore.getNetwork() } function useEtherscanProvider() { diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index e9fc10cea..33d842d54 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -137,16 +137,22 @@ IdentityStore.prototype.revealAccount = function(cb) { cb(null) } -IdentityStore.prototype.getNetwork = function(tries) { - if (tries === 0) { - this._currentState.network = 'error' - return +IdentityStore.prototype.getNetwork = function(err) { + + if (err) { + this._currentState.network = 'loading' + this._didUpdate() } + this.web3.version.getNetwork((err, network) => { if (err) { - return this.getNetwork(tries - 1, cb) + this._currentState.network = 'loading' + return this._didUpdate() } + + console.log('web3.getNetwork returned ' + network) this._currentState.network = network + this._didUpdate() }) } |