move treeview ui out of the udapp logic

pull/1/head
Iuri Matias 6 years ago committed by yann300
parent 0cf33086bc
commit 6de3a31d7c
  1. 78
      src/universal-dapp-ui.js
  2. 68
      src/universal-dapp.js

@ -3,22 +3,43 @@
var $ = require('jquery')
var yo = require('yo-yo')
var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN
var helper = require('./lib/helper')
var copyToClipboard = require('./app/ui/copy-to-clipboard')
var css = require('./universal-dapp-styles')
var MultiParamManager = require('./multiParamManager')
var remixLib = require('remix-lib')
var typeConversion = remixLib.execution.typeConversion
var txExecution = remixLib.execution.txExecution
var txFormat = remixLib.execution.txFormat
var executionContext = require('./execution-context')
var modalDialog = require('./app/ui/modaldialog')
var confirmDialog = require('./app/execution/confirmDialog')
var TreeView = require('./app/ui/TreeView')
function UniversalDAppUI (udapp, opts = {}) {
this.udapp = udapp
}
function decodeResponseToTreeView (response, fnabi) {
var treeView = new TreeView({
extractData: (item, parent, key) => {
var ret = {}
if (BN.isBN(item)) {
ret.self = item.toString(10)
ret.children = []
} else {
ret = treeView.extractDataDefault(item, parent, key)
}
return ret
}
})
return treeView.render(txFormat.decodeResponse(response, fnabi))
}
UniversalDAppUI.prototype.renderInstance = function (contract, address, contractName) {
var noInstances = document.querySelector('[class^="noInstancesText"]')
if (noInstances) {
@ -97,14 +118,21 @@ UniversalDAppUI.prototype.getCallButton = function (args) {
var outputOverride = yo`<div class=${css.value}></div>` // show return value
function clickButton (valArr, inputsValues) {
self.udapp.call(true, args, inputsValues, lookupOnly,
var logMsg
if (!args.funABI.constant) {
logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}`
} else {
logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}`
}
var value = inputsValues
(network, tx, gasEstimation, continueTxExecution, cancelCb) => {
var confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
if (network.name !== 'Main') {
return continueTxExecution(null)
}
var amount = executionContext.web3().fromWei(typeConversion.toInt(tx.value), 'ether')
var content = confirmDialog(tx, amount, gasEstimation, self,
var content = confirmDialog(tx, amount, gasEstimation, self.udapp,
(gasPrice, cb) => {
let txFeeText, priceStatus
// TODO: this try catch feels like an anti pattern, can/should be
@ -137,7 +165,7 @@ UniversalDAppUI.prototype.getCallButton = function (args) {
modalDialog('Confirm transaction', content,
{ label: 'Confirm',
fn: () => {
self._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
self.udapp._deps.config.setUnpersistedProperty('doNotShowTransactionConfirmationAgain', content.querySelector('input#confirmsetting').checked)
// TODO: check if this is check is still valid given the refactor
if (!content.gasPriceStatus) {
cancelCb('Given gas price is not correct')
@ -151,13 +179,49 @@ UniversalDAppUI.prototype.getCallButton = function (args) {
return cancelCb('Transaction canceled by user.')
}
})
},
}
(decoded) => {
var outputCb = (decoded) => {
outputOverride.innerHTML = ''
outputOverride.appendChild(decoded)
}
)
// contractsDetails is used to resolve libraries
txFormat.buildData(args.contractName, args.contractAbi, self.udapp.data.contractsDetails, false, args.funABI, args.funABI.type !== 'fallback' ? value : '', (error, data) => {
if (!error) {
if (!args.funABI.constant) {
self.udapp._deps.logCallback(`${logMsg} pending ... `)
} else {
self.udapp._deps.logCallback(`${logMsg}`)
}
if (args.funABI.type === 'fallback') data.dataHex = value
self.udapp.callFunction(args.address, data, args.funABI, confirmationCb, (error, txResult) => {
if (!error) {
var isVM = executionContext.isVM()
if (isVM) {
var vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
self.udapp._deps.logCallback(`${logMsg} errored: ${vmError.message} `)
return
}
}
if (lookupOnly) {
var decoded = decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI)
outputCb(decoded)
}
} else {
self.udapp._deps.logCallback(`${logMsg} errored: ${error} `)
}
})
} else {
self.udapp._deps.logCallback(`${logMsg} errored: ${error} `)
}
}, (msg) => {
self.udapp._deps.logCallback(msg)
}, (data, runTxCallback) => {
// called for libraries deployment
self.udapp.runTx(data, confirmationCb, runTxCallback)
})
}
var multiParamManager = new MultiParamManager(lookupOnly, args.funABI, (valArray, inputsValues, domEl) => {

@ -9,31 +9,12 @@ var remixLib = require('remix-lib')
var EventManager = require('./lib/events')
var crypto = require('crypto')
var TxRunner = remixLib.execution.txRunner
var txExecution = remixLib.execution.txExecution
var txFormat = remixLib.execution.txFormat
var txHelper = remixLib.execution.txHelper
var executionContext = require('./execution-context')
var globalRegistry = require('./global/registry')
var modalCustom = require('./app/ui/modal-dialog-custom')
var modalDialog = require('./app/ui/modaldialog')
var TreeView = require('./app/ui/TreeView')
function decodeResponseToTreeView (response, fnabi) {
var treeView = new TreeView({
extractData: (item, parent, key) => {
var ret = {}
if (BN.isBN(item)) {
ret.self = item.toString(10)
ret.children = []
} else {
ret = treeView.extractDataDefault(item, parent, key)
}
return ret
}
})
return treeView.render(txFormat.decodeResponse(response, fnabi))
}
function UniversalDApp () {
this.event = new EventManager()
@ -202,55 +183,6 @@ UniversalDApp.prototype.pendingTransactionsCount = function () {
return Object.keys(this.txRunner.pendingTxs).length
}
UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly, confirmationCb, outputCb) {
const self = this
var logMsg
if (isUserAction) {
if (!args.funABI.constant) {
logMsg = `transact to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}`
} else {
logMsg = `call to ${args.contractName}.${(args.funABI.name) ? args.funABI.name : '(fallback)'}`
}
}
txFormat.buildData(args.contractName, args.contractAbi, self._deps.compilersartefacts['__last'].getData().contracts, false, args.funABI, args.funABI.type !== 'fallback' ? value : '', (error, data) => {
if (!error) {
if (isUserAction) {
if (!args.funABI.constant) {
self._deps.logCallback(`${logMsg} pending ... `)
} else {
self._deps.logCallback(`${logMsg}`)
}
}
if (args.funABI.type === 'fallback') data.dataHex = value
self.callFunction(args.address, data, args.funABI, confirmationCb, (error, txResult) => {
if (!error) {
var isVM = executionContext.isVM()
if (isVM) {
var vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
self._deps.logCallback(`${logMsg} errored: ${vmError.message} `)
return
}
}
if (lookupOnly) {
var decoded = decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI)
outputCb(decoded)
}
} else {
self._deps.logCallback(`${logMsg} errored: ${error} `)
}
})
} else {
self._deps.logCallback(`${logMsg} errored: ${error} `)
}
}, (msg) => {
self._deps.logCallback(msg)
}, (data, runTxCallback) => {
// called for libraries deployment
self.runTx(data, confirmationCb, runTxCallback)
})
}
/**
* deploy the given contract
*

Loading…
Cancel
Save