|
|
@ -1,8 +1,5 @@ |
|
|
|
var $ = require('jquery') |
|
|
|
|
|
|
|
var yo = require('yo-yo') |
|
|
|
var yo = require('yo-yo') |
|
|
|
var EventManager = require('../../lib/events') |
|
|
|
var EventManager = require('../../lib/events') |
|
|
|
var globlalRegistry = require('../../global/registry') |
|
|
|
|
|
|
|
var executionContext = require('../../execution-context') |
|
|
|
|
|
|
|
var Card = require('../ui/card') |
|
|
|
var Card = require('../ui/card') |
|
|
|
var css = require('./styles/run-tab-styles') |
|
|
|
var css = require('./styles/run-tab-styles') |
|
|
|
|
|
|
|
|
|
|
@ -15,170 +12,140 @@ var ContractDropdownUI = require('./runTab/contractDropdown.js') |
|
|
|
var Recorder = require('./runTab/model/recorder.js') |
|
|
|
var Recorder = require('./runTab/model/recorder.js') |
|
|
|
var RecorderUI = require('./runTab/recorder.js') |
|
|
|
var RecorderUI = require('./runTab/recorder.js') |
|
|
|
|
|
|
|
|
|
|
|
function runTab (opts, localRegistry) { |
|
|
|
class RunTab { |
|
|
|
var self = this |
|
|
|
|
|
|
|
self.event = new EventManager() |
|
|
|
constructor (udapp, udappUI, config, fileManager, editor, logCallback, filePanel, pluginManager, compilersArtefacts) { |
|
|
|
self._view = {} |
|
|
|
this.event = new EventManager() |
|
|
|
self.data = { |
|
|
|
|
|
|
|
count: 0, |
|
|
|
this.renderInstanceContainer() |
|
|
|
text: `All transactions (deployed contracts and function executions) in this environment can be saved and replayed in
|
|
|
|
this.renderSettings(udapp) |
|
|
|
another environment. e.g Transactions created in Javascript VM can be replayed in the Injected Web3.` |
|
|
|
this.renderDropdown(udappUI, fileManager, pluginManager, compilersArtefacts, config, editor, udapp, filePanel, logCallback) |
|
|
|
} |
|
|
|
this.renderRecorder(udapp, udappUI, fileManager, config, logCallback) |
|
|
|
self._components = {} |
|
|
|
this.renderRecorderCard() |
|
|
|
self._components.registry = localRegistry || globlalRegistry |
|
|
|
this.renderContainer() |
|
|
|
self._components.transactionContextAPI = { |
|
|
|
|
|
|
|
getAddress: (cb) => { |
|
|
|
|
|
|
|
cb(null, $('#txorigin').val()) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getValue: (cb) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var number = document.querySelector('#value').value |
|
|
|
|
|
|
|
var select = document.getElementById('unit') |
|
|
|
|
|
|
|
var index = select.selectedIndex |
|
|
|
|
|
|
|
var selectedUnit = select.querySelectorAll('option')[index].dataset.unit |
|
|
|
|
|
|
|
var unit = 'ether' // default
|
|
|
|
|
|
|
|
if (['ether', 'finney', 'gwei', 'wei'].indexOf(selectedUnit) >= 0) { |
|
|
|
|
|
|
|
unit = selectedUnit |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cb(null, executionContext.web3().toWei(number, unit)) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
cb(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getGasLimit: (cb) => { |
|
|
|
|
|
|
|
cb(null, $('#gasLimit').val()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// dependencies
|
|
|
|
|
|
|
|
self._deps = { |
|
|
|
renderContainer () { |
|
|
|
udapp: self._components.registry.get('udapp').api, |
|
|
|
this.container = yo`<div class="${css.runTabView}" id="runTabView" ></div>` |
|
|
|
udappUI: self._components.registry.get('udappUI').api, |
|
|
|
|
|
|
|
config: self._components.registry.get('config').api, |
|
|
|
var el = yo` |
|
|
|
fileManager: self._components.registry.get('filemanager').api, |
|
|
|
<div> |
|
|
|
editor: self._components.registry.get('editor').api, |
|
|
|
${this.settingsUI.render()} |
|
|
|
logCallback: self._components.registry.get('logCallback').api, |
|
|
|
${this.contractDropdownUI.render()} |
|
|
|
filePanel: self._components.registry.get('filepanel').api, |
|
|
|
${this.recorderCard.render()} |
|
|
|
pluginManager: self._components.registry.get('pluginmanager').api, |
|
|
|
${this.instanceContainer} |
|
|
|
compilersArtefacts: self._components.registry.get('compilersartefacts').api |
|
|
|
</div> |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
this.container.appendChild(el) |
|
|
|
} |
|
|
|
} |
|
|
|
self._deps.udapp.resetAPI(self._components.transactionContextAPI) |
|
|
|
|
|
|
|
self._view.recorderCount = yo`<span>0</span>` |
|
|
|
renderInstanceContainer () { |
|
|
|
self._view.instanceContainer = yo`<div class="${css.instanceContainer}"></div>` |
|
|
|
this.instanceContainer = yo`<div class="${css.instanceContainer}"></div>` |
|
|
|
self._view.clearInstanceElement = yo` |
|
|
|
|
|
|
|
<i class="${css.clearinstance} ${css.icon} fa fa-trash" onclick=${() => self.event.trigger('clearInstance', [])} |
|
|
|
const instanceContainerTitle = yo` |
|
|
|
title="Clear instances list and reset recorder" aria-hidden="true"> |
|
|
|
|
|
|
|
</i>` |
|
|
|
|
|
|
|
self._view.instanceContainerTitle = yo` |
|
|
|
|
|
|
|
<div class=${css.instanceContainerTitle} |
|
|
|
<div class=${css.instanceContainerTitle} |
|
|
|
title="Autogenerated generic user interfaces for interaction with deployed contracts"> |
|
|
|
title="Autogenerated generic user interfaces for interaction with deployed contracts"> |
|
|
|
Deployed Contracts |
|
|
|
Deployed Contracts |
|
|
|
${self._view.clearInstanceElement} |
|
|
|
<i class="${css.clearinstance} ${css.icon} fa fa-trash" onclick=${() => this.event.trigger('clearInstance', [])} |
|
|
|
|
|
|
|
title="Clear instances list and reset recorder" aria-hidden="true"> |
|
|
|
|
|
|
|
</i> |
|
|
|
</div>` |
|
|
|
</div>` |
|
|
|
self._view.noInstancesText = yo` |
|
|
|
|
|
|
|
|
|
|
|
this.noInstancesText = yo` |
|
|
|
<div class="${css.noInstancesText}"> |
|
|
|
<div class="${css.noInstancesText}"> |
|
|
|
Currently you have no contract instances to interact with. |
|
|
|
Currently you have no contract instances to interact with. |
|
|
|
</div>` |
|
|
|
</div>` |
|
|
|
|
|
|
|
|
|
|
|
var container = yo`<div class="${css.runTabView}" id="runTabView" ></div>` |
|
|
|
this.event.register('clearInstance', () => { |
|
|
|
|
|
|
|
this.instanceContainer.innerHTML = '' // clear the instances list
|
|
|
|
|
|
|
|
this.instanceContainer.appendChild(instanceContainerTitle) |
|
|
|
|
|
|
|
this.instanceContainer.appendChild(this.noInstancesText) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.instanceContainer.appendChild(instanceContainerTitle) |
|
|
|
|
|
|
|
this.instanceContainer.appendChild(this.noInstancesText) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderSettings (udapp) { |
|
|
|
|
|
|
|
var settings = new Settings(udapp) |
|
|
|
|
|
|
|
this.settingsUI = new SettingsUI(settings) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.settingsUI.event.register('clearInstance', () => { |
|
|
|
|
|
|
|
this.event.trigger('clearInstance', []) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderDropdown (udappUI, fileManager, pluginManager, compilersArtefacts, config, editor, udapp, filePanel, logCallback) { |
|
|
|
|
|
|
|
var dropdownLogic = new DropdownLogic(fileManager, pluginManager, compilersArtefacts, config, editor, udapp, filePanel) |
|
|
|
|
|
|
|
this.contractDropdownUI = new ContractDropdownUI(dropdownLogic, logCallback) |
|
|
|
|
|
|
|
|
|
|
|
var recorder = new Recorder(self._deps.udapp, self._deps.fileManager, self._deps.config) |
|
|
|
this.contractDropdownUI.event.register('clearInstance', () => { |
|
|
|
recorder.event.register('newTxRecorded', (count) => { |
|
|
|
var noInstancesText = this.noInstancesText |
|
|
|
this.data.count = count |
|
|
|
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } |
|
|
|
this._view.recorderCount.innerText = count |
|
|
|
}) |
|
|
|
|
|
|
|
this.contractDropdownUI.event.register('newContractABIAdded', (abi, address) => { |
|
|
|
|
|
|
|
this.instanceContainer.appendChild(udappUI.renderInstanceFromABI(abi, address, address)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
recorder.event.register('cleared', () => { |
|
|
|
this.contractDropdownUI.event.register('newContractInstanceAdded', (contractObject, address, value) => { |
|
|
|
this.data.count = 0 |
|
|
|
this.instanceContainer.appendChild(udappUI.renderInstance(contractObject, address, value)) |
|
|
|
this._view.recorderCount.innerText = 0 |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
executionContext.event.register('contextChanged', recorder.clearAll.bind(recorder)) |
|
|
|
} |
|
|
|
self.event.register('clearInstance', recorder.clearAll.bind(recorder)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var recorderInterface = new RecorderUI(recorder, self) |
|
|
|
renderRecorder (udapp, udappUI, fileManager, config, logCallback) { |
|
|
|
recorderInterface.render() |
|
|
|
this.recorderCount = yo`<span>0</span>` |
|
|
|
|
|
|
|
|
|
|
|
self._view.collapsedView = yo` |
|
|
|
var recorder = new Recorder(udapp, fileManager, config) |
|
|
|
|
|
|
|
recorder.event.register('recorderCountChange', (count) => { |
|
|
|
|
|
|
|
this.recorderCount.innerText = count |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
this.event.register('clearInstance', recorder.clearAll.bind(recorder)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.recorderInterface = new RecorderUI(recorder, logCallback) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.recorderInterface.event.register('newScenario', (abi, address, contractName) => { |
|
|
|
|
|
|
|
var noInstancesText = this.noInstancesText |
|
|
|
|
|
|
|
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } |
|
|
|
|
|
|
|
this.instanceContainer.appendChild(udappUI.renderInstanceFromABI(abi, address, contractName)) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.recorderInterface.render() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderRecorderCard () { |
|
|
|
|
|
|
|
const collapsedView = yo` |
|
|
|
<div class=${css.recorderCollapsedView}> |
|
|
|
<div class=${css.recorderCollapsedView}> |
|
|
|
<div class=${css.recorderCount}>${self._view.recorderCount}</div> |
|
|
|
<div class=${css.recorderCount}>${this.recorderCount}</div> |
|
|
|
</div>` |
|
|
|
</div>` |
|
|
|
|
|
|
|
|
|
|
|
self._view.expandedView = yo` |
|
|
|
const expandedView = yo` |
|
|
|
<div class=${css.recorderExpandedView}> |
|
|
|
<div class=${css.recorderExpandedView}> |
|
|
|
<div class=${css.recorderDescription}> |
|
|
|
<div class=${css.recorderDescription}> |
|
|
|
${self.data.text} |
|
|
|
All transactions (deployed contracts and function executions) in this environment can be saved and replayed in |
|
|
|
|
|
|
|
another environment. e.g Transactions created in Javascript VM can be replayed in the Injected Web3. |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div class="${css.transactionActions}"> |
|
|
|
<div class="${css.transactionActions}"> |
|
|
|
${recorderInterface.recordButton} |
|
|
|
${this.recorderInterface.recordButton} |
|
|
|
${recorderInterface.runButton} |
|
|
|
${this.recorderInterface.runButton} |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div>` |
|
|
|
</div>` |
|
|
|
|
|
|
|
|
|
|
|
self.recorderOpts = { |
|
|
|
this.recorderCard = new Card({}, {}, { title: 'Transactions recorded:', collapsedView: collapsedView }) |
|
|
|
title: 'Transactions recorded:', |
|
|
|
this.recorderCard.event.register('expandCollapseCard', (arrow, body, status) => { |
|
|
|
collapsedView: self._view.collapsedView |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var recorderCard = new Card({}, {}, self.recorderOpts) |
|
|
|
|
|
|
|
recorderCard.event.register('expandCollapseCard', (arrow, body, status) => { |
|
|
|
|
|
|
|
body.innerHTML = '' |
|
|
|
body.innerHTML = '' |
|
|
|
status.innerHTML = '' |
|
|
|
status.innerHTML = '' |
|
|
|
if (arrow === 'down') { |
|
|
|
if (arrow === 'down') { |
|
|
|
status.appendChild(self._view.collapsedView) |
|
|
|
status.appendChild(collapsedView) |
|
|
|
body.appendChild(self._view.expandedView) |
|
|
|
body.appendChild(expandedView) |
|
|
|
} else if (arrow === 'up') { |
|
|
|
} else if (arrow === 'up') { |
|
|
|
status.appendChild(self._view.collapsedView) |
|
|
|
status.appendChild(collapsedView) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var settings = new Settings(self._deps.udapp) |
|
|
|
render () { |
|
|
|
var settingsUI = new SettingsUI(settings) |
|
|
|
return this.container |
|
|
|
|
|
|
|
} |
|
|
|
self.event.register('clearInstance', () => { |
|
|
|
|
|
|
|
this._view.instanceContainer.innerHTML = '' // clear the instances list
|
|
|
|
|
|
|
|
this._view.instanceContainer.appendChild(self._view.instanceContainerTitle) |
|
|
|
|
|
|
|
this._view.instanceContainer.appendChild(self._view.noInstancesText) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
settingsUI.event.register('clearInstance', () => { |
|
|
|
|
|
|
|
this.event.trigger('clearInstance', []) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dropdownLogic = new DropdownLogic( |
|
|
|
|
|
|
|
this._deps.fileManager, |
|
|
|
|
|
|
|
this._deps.pluginManager, |
|
|
|
|
|
|
|
this._deps.compilersArtefacts, |
|
|
|
|
|
|
|
this._deps.compiler, |
|
|
|
|
|
|
|
this._deps.config, |
|
|
|
|
|
|
|
this._deps.editor, |
|
|
|
|
|
|
|
this._deps.udapp, |
|
|
|
|
|
|
|
this._deps.filePanel |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
var contractDropdownUI = new ContractDropdownUI(dropdownLogic, this._deps.logCallback) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contractDropdownUI.event.register('clearInstance', () => { |
|
|
|
|
|
|
|
var noInstancesText = this._view.noInstancesText |
|
|
|
|
|
|
|
if (noInstancesText.parentNode) { noInstancesText.parentNode.removeChild(noInstancesText) } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
contractDropdownUI.event.register('newContractABIAdded', (abi, address) => { |
|
|
|
|
|
|
|
this._view.instanceContainer.appendChild(this._deps.udappUI.renderInstanceFromABI(abi, address, address)) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
contractDropdownUI.event.register('newContractInstanceAdded', (contractObject, address, value) => { |
|
|
|
|
|
|
|
this._view.instanceContainer.appendChild(this._deps.udappUI.renderInstance(contractObject, address, value)) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._view.instanceContainer.appendChild(this._view.instanceContainerTitle) |
|
|
|
|
|
|
|
this._view.instanceContainer.appendChild(this._view.noInstancesText) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var el = yo` |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
${settingsUI.render()} |
|
|
|
|
|
|
|
${contractDropdownUI.render()} |
|
|
|
|
|
|
|
${recorderCard.render()} |
|
|
|
|
|
|
|
${self._view.instanceContainer} |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
` |
|
|
|
|
|
|
|
container.appendChild(el) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { render () { return container } } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = runTab |
|
|
|
module.exports = RunTab |
|
|
|