move reset and init methods to blockchain class

pull/5370/head
Iuri Matias 5 years ago
parent 2986c8067b
commit a9315ebb39
  1. 10
      src/app/tabs/runTab/model/blockchain.js
  2. 64
      src/app/udapp/run-tab.js

@ -310,6 +310,16 @@ class Blockchain {
return (this.executionContext.isVM() ? 'memory' : 'blockchain')
}
// NOTE: the config is only needed because exectuionContext.init does
// if config.get('settings/always-use-vm'), we can simplify this later
resetAndInit (config, transactionContext) {
this.udapp.resetAPI(transactionContext)
this.executionContext.init(config)
this.executionContext.stopListenOnLastBlock()
this.executionContext.listenOnLastBlock()
this.udapp.resetEnvironment()
}
}
module.exports = Blockchain

@ -48,37 +48,6 @@ export class RunTab extends LibraryPlugin {
this.networkModule = networkModule
}
onActivationInternal () {
this.udappUI = new UniversalDAppUI(this.blockchain, this.logCallback)
this.udapp.resetAPI({
getAddress: (cb) => {
cb(null, $('#txorigin').val())
},
getValue: (cb) => {
try {
const number = document.querySelector('#value').value
const select = document.getElementById('unit')
const index = select.selectedIndex
const selectedUnit = select.querySelectorAll('option')[index].dataset.unit
let unit = 'ether' // default
if (['ether', 'finney', 'gwei', 'wei'].indexOf(selectedUnit) >= 0) {
unit = selectedUnit
}
cb(null, Web3.utils.toWei(number, unit))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
try {
cb(null, '0x' + new ethJSUtil.BN($('#gasLimit').val(), 10).toString(16))
} catch (e) {
cb(e.message)
}
}
})
}
renderContainer () {
this.container = yo`<div class="${css.runTabView} py-0 px-2" id="runTabView" ></div>`
@ -200,11 +169,34 @@ export class RunTab extends LibraryPlugin {
}
render () {
this.onActivationInternal()
this.executionContext.init(this.config)
this.executionContext.stopListenOnLastBlock()
this.executionContext.listenOnLastBlock()
this.udapp.resetEnvironment()
this.udappUI = new UniversalDAppUI(this.blockchain, this.logCallback)
this.blockchain.resetAndInit(this.config, {
getAddress: (cb) => {
cb(null, $('#txorigin').val())
},
getValue: (cb) => {
try {
const number = document.querySelector('#value').value
const select = document.getElementById('unit')
const index = select.selectedIndex
const selectedUnit = select.querySelectorAll('option')[index].dataset.unit
let unit = 'ether' // default
if (['ether', 'finney', 'gwei', 'wei'].indexOf(selectedUnit) >= 0) {
unit = selectedUnit
}
cb(null, Web3.utils.toWei(number, unit))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
try {
cb(null, '0x' + new ethJSUtil.BN($('#gasLimit').val(), 10).toString(16))
} catch (e) {
cb(e.message)
}
}
})
this.renderInstanceContainer()
this.renderSettings()
this.renderDropdown(this.udappUI, this.fileManager, this.compilersArtefacts, this.config, this.editor, this.logCallback)

Loading…
Cancel
Save