remove executionContext dependecy from renderer

pull/1/head
yann300 8 years ago
parent b4957dc242
commit cf9fb48936
  1. 23
      src/app.js
  2. 22
      src/app/renderer.js
  3. 22
      src/universal-dapp.js

@ -503,9 +503,20 @@ var run = function () {
}
}
var ethToolAPI = {
toWei: (value, unit) => {
return executionContext.web3().toWei(value, unit)
var transactionContextAPI = {
getAddress: (cb) => {
cb(null, $('#txorigin').val())
},
getValue: (cb) => {
try {
var comp = $('#value').val().split(' ')
cb(null, executionContext.web3().toWei(comp[0], comp.slice(1).join(' ')))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
cb(null, $('#gasLimit').val())
}
}
@ -558,8 +569,8 @@ var run = function () {
}, transactionDebugger)
var udappAPI = {
reset: (udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier) => {
udapp.reset(udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier)
reset: (udappContracts, renderOutputModifier) => {
udapp.reset(udappContracts, transactionContextAPI, renderOutputModifier)
},
render: () => {
return udapp.render()
@ -592,7 +603,7 @@ var run = function () {
return ''
}
}
var renderer = new Renderer(editorAPIRenderer, udappAPI, ethToolAPI, formalVerification.event, compiler.event) // eslint-disable-line
var renderer = new Renderer(editorAPIRenderer, udappAPI, formalVerification.event, compiler.event) // eslint-disable-line
var rendererAPI = {
renderItem: (label, warningContainer, type) => {
return renderer.error(label, warningContainer, type)

@ -4,10 +4,9 @@ var $ = require('jquery')
var utils = require('./utils')
function Renderer (editorAPI, udappAPI, ethToolAPI, formalVerificationEvent, compilerEvent) {
function Renderer (editorAPI, udappAPI, formalVerificationEvent, compilerEvent) {
this.editorAPI = editorAPI
this.udappAPI = udappAPI
this.ethToolAPI = ethToolAPI
var self = this
formalVerificationEvent.register('compilationFinished', this, function (success, message, container, options) {
if (!success) {
@ -283,24 +282,7 @@ Renderer.prototype.contracts = function (data, source) {
return $contractOutput
}
var getAddress = function (cb) {
cb(null, $('#txorigin').val())
}
var getValue = function (cb) {
try {
var comp = $('#value').val().split(' ')
cb(null, self.ethToolAPI.toWei(comp[0], comp.slice(1).join(' ')))
} catch (e) {
cb(e)
}
}
var getGasLimit = function (cb) {
cb(null, $('#gasLimit').val())
}
this.udappAPI.reset(udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier)
this.udappAPI.reset(udappContracts, renderOutputModifier)
var $contractOutput = this.udappAPI.render()

@ -21,9 +21,7 @@ function UniversalDApp (executionContext, options, txdebugger) {
self.$el = $('<div class="udapp" />')
self.personalMode = self.options.personalMode || false
self.contracts
self.getAddress
self.getValue
self.getGasLimit
self.transactionContextAPI
self.txdebugger = txdebugger // temporary: will not be needed anymore when we'll add memory support to the VM
var defaultRenderOutputModifier = function (name, content) { return content }
self.renderOutputModifier = defaultRenderOutputModifier
@ -39,12 +37,10 @@ function UniversalDApp (executionContext, options, txdebugger) {
})
}
UniversalDApp.prototype.reset = function (contracts, getAddress, getValue, getGasLimit, renderer) {
UniversalDApp.prototype.reset = function (contracts, transactionContextAPI, renderer) {
this.$el.empty()
this.contracts = contracts
this.getAddress = getAddress
this.getValue = getValue
this.getGasLimit = getGasLimit
this.transactionContextAPI = transactionContextAPI
this.renderOutputModifier = renderer
this.accounts = {}
if (this.executionContext.isVM()) {
@ -734,8 +730,8 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) {
tx.gasLimit = 3000000
if (self.getGasLimit) {
self.getGasLimit(function (err, ret) {
if (self.transactionContextAPI.getGasLimit) {
self.transactionContextAPI.getGasLimit(function (err, ret) {
if (err) {
return callback(err)
}
@ -751,8 +747,8 @@ UniversalDApp.prototype.runTx = function (args, cb) {
function (callback) {
tx.value = 0
if (self.getValue) {
self.getValue(function (err, ret) {
if (self.transactionContextAPI.getValue) {
self.transactionContextAPI.getValue(function (err, ret) {
if (err) {
return callback(err)
}
@ -766,8 +762,8 @@ UniversalDApp.prototype.runTx = function (args, cb) {
},
// query address
function (callback) {
if (self.getAddress) {
self.getAddress(function (err, ret) {
if (self.transactionContextAPI.getAddress) {
self.transactionContextAPI.getAddress(function (err, ret) {
if (err) {
return callback(err)
}

Loading…
Cancel
Save