mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Blockchain status now updates on availability change
This commit is contained in:
parent
2422c78ce2
commit
d49ef1a2e5
@ -76,13 +76,20 @@ var providerOpts = {
|
|||||||
var provider = MetaMaskProvider(providerOpts)
|
var provider = MetaMaskProvider(providerOpts)
|
||||||
var web3 = new Web3(provider)
|
var web3 = new Web3(provider)
|
||||||
idStore.web3 = web3
|
idStore.web3 = web3
|
||||||
idStore.getNetwork(3)
|
idStore.getNetwork()
|
||||||
|
|
||||||
// log new blocks
|
// log new blocks
|
||||||
provider.on('block', function(block){
|
provider.on('block', function(block){
|
||||||
console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
|
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)
|
var ethStore = new EthStore(provider)
|
||||||
idStore.setStore(ethStore)
|
idStore.setStore(ethStore)
|
||||||
|
|
||||||
@ -290,13 +297,13 @@ function addUnconfirmedMsg(msgParams, cb){
|
|||||||
function setRpcTarget(rpcTarget){
|
function setRpcTarget(rpcTarget){
|
||||||
configManager.setRpcTarget(rpcTarget)
|
configManager.setRpcTarget(rpcTarget)
|
||||||
chrome.runtime.reload()
|
chrome.runtime.reload()
|
||||||
idStore.getNetwork(3) // 3 retry attempts
|
idStore.getNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProviderType(type) {
|
function setProviderType(type) {
|
||||||
configManager.setProviderType(type)
|
configManager.setProviderType(type)
|
||||||
chrome.runtime.reload()
|
chrome.runtime.reload()
|
||||||
idStore.getNetwork(3)
|
idStore.getNetwork()
|
||||||
}
|
}
|
||||||
|
|
||||||
function useEtherscanProvider() {
|
function useEtherscanProvider() {
|
||||||
|
@ -130,23 +130,23 @@ IdentityStore.prototype.revealAccount = function(cb) {
|
|||||||
cb(null)
|
cb(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.getNetwork = function(tries) {
|
IdentityStore.prototype.getNetwork = function(err) {
|
||||||
|
|
||||||
if (tries === 0) {
|
if (err) {
|
||||||
this._currentState.network = 'error'
|
this._currentState.network = 'loading'
|
||||||
this._didUpdate()
|
this._didUpdate()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.web3.version.getNetwork((err, network) => {
|
this.web3.version.getNetwork((err, network) => {
|
||||||
if (err) {
|
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._currentState.network = network
|
||||||
this._didUpdate()
|
this._didUpdate()
|
||||||
})
|
})
|
||||||
|
|
||||||
this._currentState.network = 'loading'
|
|
||||||
this._didUpdate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.setLocked = function(cb){
|
IdentityStore.prototype.setLocked = function(cb){
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
"through2": "^2.0.1",
|
"through2": "^2.0.1",
|
||||||
"vreme": "^3.0.2",
|
"vreme": "^3.0.2",
|
||||||
"web3": "ethereum/web3.js#0.16.0",
|
"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",
|
"web3-stream-provider": "^2.0.1",
|
||||||
"xtend": "^4.0.1"
|
"xtend": "^4.0.1"
|
||||||
},
|
},
|
||||||
|
@ -16,14 +16,12 @@ Network.prototype.render = function() {
|
|||||||
let iconName, hoverText
|
let iconName, hoverText
|
||||||
const imagePath = "/images/"
|
const imagePath = "/images/"
|
||||||
|
|
||||||
if (networkNumber == undefined || networkNumber == "error") {
|
if (networkNumber == 'loading') {
|
||||||
hoverText = 'No Blockchain Connection'
|
|
||||||
iconName = 'no-connection'
|
|
||||||
} else if (networkNumber == 'loading') {
|
|
||||||
return h('img', {
|
return h('img', {
|
||||||
title: 'Contacting network...',
|
title: 'Attempting to connect to blockchain.',
|
||||||
style: {
|
style: {
|
||||||
width: '27px',
|
width: '27px',
|
||||||
|
marginRight: '-16px'
|
||||||
},
|
},
|
||||||
src: 'images/loading.svg',
|
src: 'images/loading.svg',
|
||||||
})
|
})
|
||||||
@ -39,7 +37,7 @@ Network.prototype.render = function() {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
h('#network_component.flex-center', {
|
h('#network_component.flex-center', {
|
||||||
style: {},
|
style: { marginRight: '-16px' },
|
||||||
title: hoverText,
|
title: hoverText,
|
||||||
},[ h('img',{src: imagePath + iconName + ".jpg", width: '25px'}) ])
|
},[ h('img',{src: imagePath + iconName + ".jpg", width: '25px'}) ])
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user