From 806e250e9830c34e8db190f666d7d490237e8cc7 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 31 Dec 2019 11:31:20 -0500 Subject: [PATCH] move reset and init methods to blockchain class --- src/app/tabs/runTab/model/blockchain.js | 10 ++++ src/app/udapp/run-tab.js | 64 +++++++++++-------------- 2 files changed, 38 insertions(+), 36 deletions(-) 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)