move reset and init methods to blockchain class

pull/1/head
Iuri Matias 5 years ago committed by yann300
parent 57b2963f56
commit 806e250e98
  1. 10
      src/app/tabs/runTab/model/blockchain.js
  2. 64
      src/app/udapp/run-tab.js

@ -308,6 +308,16 @@ class Blockchain {
return (this.executionContext.isVM() ? 'memory' : '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 module.exports = Blockchain

@ -48,37 +48,6 @@ export class RunTab extends LibraryPlugin {
this.networkModule = networkModule 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 () { renderContainer () {
this.container = yo`<div class="${css.runTabView} py-0 px-2" id="runTabView" ></div>` this.container = yo`<div class="${css.runTabView} py-0 px-2" id="runTabView" ></div>`
@ -200,11 +169,34 @@ export class RunTab extends LibraryPlugin {
} }
render () { render () {
this.onActivationInternal() this.udappUI = new UniversalDAppUI(this.blockchain, this.logCallback)
this.executionContext.init(this.config) this.blockchain.resetAndInit(this.config, {
this.executionContext.stopListenOnLastBlock() getAddress: (cb) => {
this.executionContext.listenOnLastBlock() cb(null, $('#txorigin').val())
this.udapp.resetEnvironment() },
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.renderInstanceContainer()
this.renderSettings() this.renderSettings()
this.renderDropdown(this.udappUI, this.fileManager, this.compilersArtefacts, this.config, this.editor, this.logCallback) this.renderDropdown(this.udappUI, this.fileManager, this.compilersArtefacts, this.config, this.editor, this.logCallback)

Loading…
Cancel
Save