Skip to content

Commit

Permalink
move transactionContextAPI to runTab and reset udapp from there
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Jul 4, 2018
1 parent bb6142a commit aa848ac
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 59 deletions.
41 changes: 5 additions & 36 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,48 +395,17 @@ Please make a backup of your contracts and start using http://remix.ethereum.org

var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'})
// ----------------- UniversalDApp -----------------
var 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 (selectedUnit === 'ether') {
unit = 'ether'
} else if (selectedUnit === 'finney') {
unit = 'finney'
} else if (selectedUnit === 'gwei') {
unit = 'gwei'
} else if (selectedUnit === 'wei') {
unit = 'wei'
}
cb(null, executionContext.web3().toWei(number, unit))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
cb(null, $('#gasLimit').val())
}
}
// @TODO should put this in runtab
registry.put({api: transactionContextAPI, name: 'transactionContextAPI'})

var udapp = new UniversalDApp({ removable: false, removable_instances: true })
// ----------------- UniversalDApp -----------------
var udapp = new UniversalDApp({
removable: false,
removable_instances: true
})
registry.put({api: udapp, name: 'udapp'})

var udappUI = new UniversalDAppUI(udapp)
registry.put({api: udappUI, name: 'udappUI'})

udapp.reset({})
udappUI.reset()

// ----------------- Tx listener -----------------
var transactionReceiptResolver = new TransactionReceiptResolver()

Expand Down
8 changes: 0 additions & 8 deletions src/app/tabs/compile-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ module.exports = class CompileTab {
// dependencies
self._deps = {
app: self._components.registry.get('app').api,
udapp: self._components.registry.get('udapp').api,
udappUI: self._components.registry.get('udappUI').api,
editor: self._components.registry.get('editor').api,
config: self._components.registry.get('config').api,
compiler: self._components.registry.get('compiler').api,
staticAnalysis: self._components.registry.get('staticanalysis').api,
renderer: self._components.registry.get('renderer').api,
fileManager: self._components.registry.get('filemanager').api,
transactionContextAPI: self._components.registry.get('transactionContextAPI').api,
rightHandPanel: self._components.registry.get('righthandpanel').api
}
self.data = {
Expand Down Expand Up @@ -113,12 +109,8 @@ module.exports = class CompileTab {
var contractName = yo`<option>${contract.name}</option>`
self._view.contractNames.appendChild(contractName)
})
self._deps.udapp.reset(self.data.contractsDetails, self._deps.transactionContextAPI)
self._deps.udappUI.reset()
} else {
self._view.contractNames.setAttribute('disabled', true)
self._deps.udapp.reset({}, self._deps.transactionContextAPI)
self._deps.udappUI.reset()
}
// hightlight the tab if error
if (success) document.querySelector('.compileView').style.color = '' // @TODO: compileView tab
Expand Down
33 changes: 32 additions & 1 deletion src/app/tabs/run-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var addTooltip = require('../ui/tooltip')
var css = require('./styles/run-tab-styles')
var MultiParamManager = require('../../multiParamManager')

function runTab (localRegistry) {
function runTab (opts, localRegistry) {
/* -------------------------
VARIABLES
--------------------------- */
Expand All @@ -35,15 +35,46 @@ function runTab (localRegistry) {
}
self._components = {}
self._components.registry = localRegistry || globlalRegistry
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 (selectedUnit === 'ether') {
unit = 'ether'
} else if (selectedUnit === 'finney') {
unit = 'finney'
} else if (selectedUnit === 'gwei') {
unit = 'gwei'
} else if (selectedUnit === 'wei') {
unit = 'wei'
}
cb(null, executionContext.web3().toWei(number, unit))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
cb(null, $('#gasLimit').val())
}
}
// dependencies
self._deps = {
compiler: self._components.registry.get('compiler').api,
udapp: self._components.registry.get('udapp').api,
udappUI: self._components.registry.get('udappUI').api,
config: self._components.registry.get('config').api,
fileManager: self._components.registry.get('filemanager').api,
editor: self._components.registry.get('editor').api,
logCallback: self._components.registry.get('logCallback').api
}
self._deps.udapp.resetAPI(self._components.transactionContextAPI)
self._view.recorderCount = yo`<span>0</span>`
self._view.instanceContainer = yo`<div class="${css.instanceContainer}"></div>`
self._view.clearInstanceElement = yo`
Expand Down
3 changes: 0 additions & 3 deletions src/universal-dapp-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ function UniversalDAppUI (udapp, opts = {}) {
this.udapp = udapp
}

UniversalDAppUI.prototype.reset = function () {
}

UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) {
var noInstances = document.querySelector('[class^="noInstancesText"]')
if (noInstances) {
Expand Down
29 changes: 18 additions & 11 deletions src/universal-dapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ var confirmDialog = require('./app/execution/confirmDialog')
function UniversalDApp (opts, localRegistry) {
this.event = new EventManager()
var self = this
self.data = {}
self._components = {}
self._components.registry = localRegistry || globalRegistry
self.removable = opts.removable
self.removable_instances = opts.removable_instances
self._deps = {
config: self._components.registry.get('config').api,
compiler: self._components.registry.get('compiler').api,
logCallback: self._components.registry.get('logCallback').api
}
executionContext.event.register('contextChanged', this, function (context) {
self.reset(self.contracts)
self.resetEnvironment()
})
self._txRunnerAPI = {
config: self._deps.config,
Expand All @@ -44,16 +47,15 @@ function UniversalDApp (opts, localRegistry) {
}
}
self.txRunner = new TxRunner({}, self._txRunnerAPI)
self.data.contractsDetails = {}
self._deps.compiler.event.register('compilationFinished', (success, data, source) => {
self.data.contractsDetails = success && data ? data.contracts : {}
})
self.accounts = {}
self.resetEnvironment()
}

UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) {
this._deps.editorpanel = this._components.registry.get('editorpanel')
if (this._deps.editorpanel) this._deps.editorpanel = this._deps.editorpanel.api

this.contracts = contracts
if (transactionContextAPI) {
this.transactionContextAPI = transactionContextAPI
}
UniversalDApp.prototype.resetEnvironment = function () {
this.accounts = {}
if (executionContext.isVM()) {
this._addAccount('3cd7232cd6f3fc66a57a6bedc1a8ed6c228fff0a327e169c2bcc5e869ed49511', '0x56BC75E2D63100000')
Expand All @@ -68,12 +70,16 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) {
executionContext.detectNetwork((error, network) => {
if (!error && network) {
var txLink = executionContext.txDetailsLink(network.name, txhash)
if (txLink) this._deps.editorpanel.logHtmlMessage(yo`<a href="${txLink}" target="_blank">${txLink}</a>`)
if (txLink) this._deps.logCallback(yo`<a href="${txLink}" target="_blank">${txLink}</a>`)
}
})
})
}

UniversalDApp.prototype.resetAPI = function (transactionContextAPI) {
this.transactionContextAPI = transactionContextAPI
}

UniversalDApp.prototype.newAccount = function (password, cb) {
if (!executionContext.isVM()) {
if (!this._deps.config.get('settings/personal-mode')) {
Expand Down Expand Up @@ -186,7 +192,8 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly,
logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}`
}
}
txFormat.buildData(args.contractName, args.contractAbi, self.contracts, false, args.funABI, value, (error, data) => {
// contractsDetails is used to resolve libraries
txFormat.buildData(args.contractName, args.contractAbi, self.data.contractsDetails, false, args.funABI, value, (error, data) => {
if (!error) {
if (isUserAction) {
if (!args.funABI.constant) {
Expand Down

0 comments on commit aa848ac

Please sign in to comment.