better error message if no connection to web3

pull/7/head
yann300 8 years ago
parent 3d4e5c0af0
commit 8a2e46fcea
  1. 27
      src/TxBrowser.js
  2. 5
      src/index.js
  3. 18
      test-browser/init.js

@ -33,7 +33,7 @@ TxBrowser.prototype.setDefaultValues = function () {
this.blockNumber = null
this.txNumber = '0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff'
this.connectInfo = ''
this.checkWeb3()
this.updateWeb3Url(this.web3.currentProvider.host)
}
TxBrowser.prototype.submit = function () {
@ -70,18 +70,27 @@ TxBrowser.prototype.submit = function () {
yo.update(this.view, this.render())
}
TxBrowser.prototype.updateWeb3Url = function (ev) {
init.setProvider(this.web3, ev.target.value)
this.checkWeb3()
yo.update(this.view, this.render())
TxBrowser.prototype.updateWeb3Url = function (newhost) {
init.setProvider(this.web3, newhost)
var self = this
this.checkWeb3(function (error, block) {
if (!error) {
self.connectInfo = 'Connected to ' + self.web3.currentProvider.host + '. Current block number: ' + block
} else {
self.connectInfo = 'Unable to connect to ' + self.web3.currentProvider.host + '. ' + error.message
}
yo.update(self.view, self.render())
})
}
TxBrowser.prototype.checkWeb3 = function () {
TxBrowser.prototype.checkWeb3 = function (callback) {
try {
this.connectInfo = 'Connected to ' + this.web3.currentProvider.host
this.web3.eth.getBlockNumber(function (error, block) {
callback(error, block)
})
} catch (e) {
console.log(e)
this.connectInfo = e.message
callback(e.message, null)
}
}
@ -101,7 +110,7 @@ TxBrowser.prototype.init = function (ev) {
TxBrowser.prototype.render = function () {
var self = this
var view = yo`<div style=${ui.formatCss(style.container)}>
<span>Node URL: </span><input onkeyup=${function () { self.updateWeb3Url(arguments[0]) }} value=${this.web3.currentProvider ? this.web3.currentProvider.host : ' - none - '} type='text' />
<span>Node URL: </span><input onkeyup=${function () { self.updateWeb3Url(arguments[0].target.value) }} value=${this.web3.currentProvider ? this.web3.currentProvider.host : ' - none - '} type='text' />
<span>${this.connectInfo}</span>
<br />
<br />

@ -2,8 +2,7 @@
var Debugger = require('./Ethdebugger')
function init () {
var container = document.getElementById('app')
window.vmdebugger = new Debugger()
container.appendChild(window.vmdebugger.render())
container.vmdebugger = new Debugger()
container.appendChild(container.vmdebugger.render())
}
init()

@ -14,9 +14,9 @@ function injectScript (file, browser, callback) {
init.readFile(file, function (error, result) {
if (!error) {
browser.execute(function (data) {
// var vmdebugger = window.vmdebugger // document.getElementById('app').vmdebugger
var vmdebugger = document.getElementById('app').vmdebugger
data = JSON.parse(data)
window.vmdebugger.web3.eth.getCode = function (address, callback) {
vmdebugger.web3.eth.getCode = function (address, callback) {
if (callback) {
callback(null, data.testCodes[address])
} else {
@ -24,15 +24,15 @@ function injectScript (file, browser, callback) {
}
}
window.vmdebugger.web3.debug.traceTransaction = function (txHash, options, callback) {
vmdebugger.web3.debug.traceTransaction = function (txHash, options, callback) {
callback(null, data.testTraces[txHash])
}
window.vmdebugger.web3.debug.storageAt = function (blockNumber, txIndex, address, callback) {
vmdebugger.web3.debug.storageAt = function (blockNumber, txIndex, address, callback) {
callback(null, {})
}
window.vmdebugger.web3.eth.getTransaction = function (txHash, callback) {
vmdebugger.web3.eth.getTransaction = function (txHash, callback) {
if (callback) {
callback(null, data.testTxs[txHash])
} else {
@ -40,7 +40,7 @@ function injectScript (file, browser, callback) {
}
}
window.vmdebugger.web3.eth.getTransactionFromBlock = function (blockNumber, txIndex, callback) {
vmdebugger.web3.eth.getTransactionFromBlock = function (blockNumber, txIndex, callback) {
if (callback) {
callback(null, data.testTxsByBlock[blockNumber + '-' + txIndex])
} else {
@ -48,11 +48,9 @@ function injectScript (file, browser, callback) {
}
}
window.vmdebugger.web3.eth.getBlockNumber = function (callback) { callback('web3 modified testing purposes :)') }
vmdebugger.web3.eth.getBlockNumber = function (callback) { callback(null, 'web3 modified for testing purposes :)') }
window.vmdebugger.web3.eth.getBlockNumber(function (r) {
console.log('rrrr' + r)
})
vmdebugger.web3.currentProvider = {host: 'web3 modified for testing purposes :)'}
}, [result], function () {
callback()
})

Loading…
Cancel
Save