aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-06-04 06:18:20 +0800
committerDan Finlay <dan@danfinlay.com>2016-06-04 06:18:20 +0800
commitd49ef1a2e54b0a9ac7a3d23d7744990543246ec6 (patch)
tree38970967e820a5365c8fcde7e134c2fccf705301
parent2422c78ce20a032a81545bf8cc03394e12c599d5 (diff)
downloadtangerine-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
-rw-r--r--app/scripts/background.js19
-rw-r--r--app/scripts/lib/idStore.js16
-rw-r--r--package.json2
-rw-r--r--ui/app/components/network.js10
4 files changed, 26 insertions, 21 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){
diff --git a/package.json b/package.json
index e9faea36c..af032a79a 100644
--- a/package.json
+++ b/package.json
@@ -62,7 +62,7 @@
"through2": "^2.0.1",
"vreme": "^3.0.2",
"web3": "ethereum/web3.js#0.16.0",
- "web3-provider-engine": "^7.7.0",
+ "web3-provider-engine": "^7.8.1",
"web3-stream-provider": "^2.0.1",
"xtend": "^4.0.1"
},
diff --git a/ui/app/components/network.js b/ui/app/components/network.js
index 90c307ed6..37046fd30 100644
--- a/ui/app/components/network.js
+++ b/ui/app/components/network.js
@@ -16,14 +16,12 @@ Network.prototype.render = function() {
let iconName, hoverText
const imagePath = "/images/"
- if (networkNumber == undefined || networkNumber == "error") {
- hoverText = 'No Blockchain Connection'
- iconName = 'no-connection'
- } else if (networkNumber == 'loading') {
+ if (networkNumber == 'loading') {
return h('img', {
- title: 'Contacting network...',
+ title: 'Attempting to connect to blockchain.',
style: {
width: '27px',
+ marginRight: '-16px'
},
src: 'images/loading.svg',
})
@@ -39,7 +37,7 @@ Network.prototype.render = function() {
}
return (
h('#network_component.flex-center', {
- style: {},
+ style: { marginRight: '-16px' },
title: hoverText,
},[ h('img',{src: imagePath + iconName + ".jpg", width: '25px'}) ])
)