move transactionContextAPI to runTab and reset udapp from there

pull/1/head
yann300 6 years ago
parent 1d917f0930
commit 6334613215
  1. 41
      src/app.js
  2. 8
      src/app/tabs/compile-tab.js
  3. 33
      src/app/tabs/run-tab.js
  4. 3
      src/universal-dapp-ui.js
  5. 29
      src/universal-dapp.js

@ -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()

@ -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 = {
@ -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

@ -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
--------------------------- */
@ -35,6 +35,35 @@ 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,
@ -42,8 +71,10 @@ function runTab (localRegistry) {
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`

@ -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) {

@ -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,
@ -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')
@ -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')) {
@ -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) {

Loading…
Cancel
Save