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.blockNumber = null
this.txNumber = '0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff' this.txNumber = '0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff'
this.connectInfo = '' this.connectInfo = ''
this.checkWeb3() this.updateWeb3Url(this.web3.currentProvider.host)
} }
TxBrowser.prototype.submit = function () { TxBrowser.prototype.submit = function () {
@ -70,18 +70,27 @@ TxBrowser.prototype.submit = function () {
yo.update(this.view, this.render()) yo.update(this.view, this.render())
} }
TxBrowser.prototype.updateWeb3Url = function (ev) { TxBrowser.prototype.updateWeb3Url = function (newhost) {
init.setProvider(this.web3, ev.target.value) init.setProvider(this.web3, newhost)
this.checkWeb3() var self = this
yo.update(this.view, this.render()) 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 { try {
this.connectInfo = 'Connected to ' + this.web3.currentProvider.host this.web3.eth.getBlockNumber(function (error, block) {
callback(error, block)
})
} catch (e) { } catch (e) {
console.log(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 () { TxBrowser.prototype.render = function () {
var self = this var self = this
var view = yo`<div style=${ui.formatCss(style.container)}> 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> <span>${this.connectInfo}</span>
<br /> <br />
<br /> <br />

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

@ -14,9 +14,9 @@ function injectScript (file, browser, callback) {
init.readFile(file, function (error, result) { init.readFile(file, function (error, result) {
if (!error) { if (!error) {
browser.execute(function (data) { browser.execute(function (data) {
// var vmdebugger = window.vmdebugger // document.getElementById('app').vmdebugger var vmdebugger = document.getElementById('app').vmdebugger
data = JSON.parse(data) data = JSON.parse(data)
window.vmdebugger.web3.eth.getCode = function (address, callback) { vmdebugger.web3.eth.getCode = function (address, callback) {
if (callback) { if (callback) {
callback(null, data.testCodes[address]) callback(null, data.testCodes[address])
} else { } 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]) 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, {}) callback(null, {})
} }
window.vmdebugger.web3.eth.getTransaction = function (txHash, callback) { vmdebugger.web3.eth.getTransaction = function (txHash, callback) {
if (callback) { if (callback) {
callback(null, data.testTxs[txHash]) callback(null, data.testTxs[txHash])
} else { } 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) { if (callback) {
callback(null, data.testTxsByBlock[blockNumber + '-' + txIndex]) callback(null, data.testTxsByBlock[blockNumber + '-' + txIndex])
} else { } 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) { vmdebugger.web3.currentProvider = {host: 'web3 modified for testing purposes :)'}
console.log('rrrr' + r)
})
}, [result], function () { }, [result], function () {
callback() callback()
}) })

Loading…
Cancel
Save