diff --git a/src/app/tabs/runTab/model/blockchain.js b/src/app/tabs/runTab/model/blockchain.js index 3c8f422f53..d64aa01478 100644 --- a/src/app/tabs/runTab/model/blockchain.js +++ b/src/app/tabs/runTab/model/blockchain.js @@ -308,6 +308,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 diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index 24171f6ab8..2c1c04e5ff 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -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`
` @@ -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)