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 = { var transactionContextAPI = {
toWei: (value, unit) => { getAddress: (cb) => {
return executionContext.web3().toWei(value, unit) 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) }, transactionDebugger)
var udappAPI = { var udappAPI = {
reset: (udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier) => { reset: (udappContracts, renderOutputModifier) => {
udapp.reset(udappContracts, getAddress, getValue, getGasLimit, renderOutputModifier) udapp.reset(udappContracts, transactionContextAPI, renderOutputModifier)
}, },
render: () => { render: () => {
return udapp.render() return udapp.render()
@ -592,7 +603,7 @@ var run = function () {
return '' 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 = { var rendererAPI = {
renderItem: (label, warningContainer, type) => { renderItem: (label, warningContainer, type) => {
return renderer.error(label, warningContainer, type) return renderer.error(label, warningContainer, type)

@ -4,10 +4,9 @@ var $ = require('jquery')
var utils = require('./utils') var utils = require('./utils')
function Renderer (editorAPI, udappAPI, ethToolAPI, formalVerificationEvent, compilerEvent) { function Renderer (editorAPI, udappAPI, formalVerificationEvent, compilerEvent) {
this.editorAPI = editorAPI this.editorAPI = editorAPI
this.udappAPI = udappAPI this.udappAPI = udappAPI
this.ethToolAPI = ethToolAPI
var self = this var self = this
formalVerificationEvent.register('compilationFinished', this, function (success, message, container, options) { formalVerificationEvent.register('compilationFinished', this, function (success, message, container, options) {
if (!success) { if (!success) {
@ -283,24 +282,7 @@ Renderer.prototype.contracts = function (data, source) {
return $contractOutput return $contractOutput
} }
var getAddress = function (cb) { this.udappAPI.reset(udappContracts, renderOutputModifier)
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)
var $contractOutput = this.udappAPI.render() var $contractOutput = this.udappAPI.render()

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

Loading…
Cancel
Save