diff options
author | Dan Finlay <dan@danfinlay.com> | 2016-06-04 06:18:20 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2016-06-04 06:18:20 +0800 |
commit | d49ef1a2e54b0a9ac7a3d23d7744990543246ec6 (patch) | |
tree | 38970967e820a5365c8fcde7e134c2fccf705301 /app/scripts | |
parent | 2422c78ce20a032a81545bf8cc03394e12c599d5 (diff) | |
download | tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.tar tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.tar.gz tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.tar.bz2 tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.tar.lz tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.tar.xz tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.tar.zst tangerine-wallet-browser-d49ef1a2e54b0a9ac7a3d23d7744990543246ec6.zip |
Blockchain status now updates on availability change
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/background.js | 19 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 16 |
2 files changed, 21 insertions, 14 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index bfd1fc92b..209360a2d 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) @@ -145,7 +152,7 @@ function setupPublicConfig(stream){ } function setupProviderConnection(stream, originDomain){ - + stream.on('data', function onRpcRequest(payload){ // Append origin to rpc payload payload.origin = originDomain @@ -246,7 +253,7 @@ function newUnsignedTransaction(txParams, cb){ }) var txId = idStore.addUnconfirmedTransaction(txParams, cb) } else { - addUnconfirmedTx(txParams, cb) + addUnconfirmedTx(txParams, cb) } } @@ -258,7 +265,7 @@ function newUnsignedMessage(msgParams, cb){ }) var msgId = idStore.addUnconfirmedMessage(msgParams, cb) } else { - addUnconfirmedMsg(msgParams, cb) + addUnconfirmedMsg(msgParams, cb) } } @@ -290,13 +297,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 7f2659381..85e8c8301 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -130,23 +130,23 @@ IdentityStore.prototype.revealAccount = function(cb) { cb(null) } -IdentityStore.prototype.getNetwork = function(tries) { +IdentityStore.prototype.getNetwork = function(err) { - if (tries === 0) { - this._currentState.network = 'error' + if (err) { + this._currentState.network = 'loading' this._didUpdate() - return } + 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() }) - - this._currentState.network = 'loading' - this._didUpdate() } IdentityStore.prototype.setLocked = function(cb){ |