1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Blockchain status now updates on availability change

This commit is contained in:
Dan Finlay 2016-06-03 15:18:20 -07:00
parent 2422c78ce2
commit d49ef1a2e5
4 changed files with 26 additions and 21 deletions

View File

@ -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() {

View File

@ -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){

View File

@ -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"
},

View File

@ -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'}) ])
)