UniversalDApp refactor

pull/3094/head
yann300 7 years ago
parent ec492d8fdd
commit a9c4b1f936
  1. 19
      src/app.js
  2. 4
      src/app/panels/editor-panel.js
  3. 50
      src/universal-dapp.js

@ -374,24 +374,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// @TODO should put this in runtab
registry.put({api: transactionContextAPI, name: 'transactionContextAPI'})
var udapp = new UniversalDApp({
api: {
logMessage: (msg) => {
self._components.editorpanel.log({ type: 'log', value: msg })
},
logHtmlMessage: (msg) => {
self._components.editorpanel.log({ type: 'html', value: msg })
},
config: self._api.config,
detectNetwork: (cb) => {
executionContext.detectNetwork(cb)
},
personalMode: () => {
return self._api.config.get('settings/personal-mode')
}
},
opt: { removable: false, removable_instances: true }
})
var udapp = new UniversalDApp({ removable: false, removable_instances: true })
registry.put({api: udapp, name: 'udapp'})
var udappUI = new UniversalDAppUI(udapp)

@ -100,6 +100,10 @@ class EditorPanel {
var self = this
self.log({type: 'log', value: msg})
}
logHtmlMessage (msg) {
var self = this
self.log({type: 'html', value: msg})
}
render () {
var self = this
if (self._view.el) return self._view.el

@ -15,6 +15,7 @@ var txHelper = remixLib.execution.txHelper
var executionContext = require('./execution-context')
var modalCustom = require('./app/ui/modal-dialog-custom')
var uiUtil = require('./app/ui/util')
var globalRegistry = require('./global/registry')
var modalDialog = require('./app/ui/modaldialog')
var typeConversion = remixLib.execution.typeConversion
@ -23,20 +24,35 @@ var confirmDialog = require('./app/execution/confirmDialog')
/*
trigger debugRequested
*/
function UniversalDApp (opts = {}) {
function UniversalDApp (opts, localRegistry) {
this.event = new EventManager()
var self = this
self._api = opts.api
self.removable = opts.opt.removable
self.removable_instances = opts.opt.removable_instances
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
}
executionContext.event.register('contextChanged', this, function (context) {
self.reset(self.contracts)
})
self.txRunner = new TxRunner({}, opts.api)
self._txRunnerAPI = {
config: self._deps.config,
detectNetwork: (cb) => {
executionContext.detectNetwork(cb)
},
personalMode: () => {
return self._deps.config.get('settings/personal-mode')
}
}
self.txRunner = new TxRunner({}, self._txRunnerAPI)
}
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
@ -50,12 +66,12 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) {
this._addAccount('71975fbf7fe448e004ac7ae54cad0a383c3906055a65468714156a07385e96ce', '0x56BC75E2D63100000')
executionContext.vm().stateManager.cache.flush(function () {})
}
this.txRunner = new TxRunner(this.accounts, this._api)
this.txRunner = new TxRunner(this.accounts, this._txRunnerAPI)
this.txRunner.event.register('transactionBroadcasted', (txhash) => {
this._api.detectNetwork((error, network) => {
executionContext.detectNetwork((error, network) => {
if (!error && network) {
var txLink = executionContext.txDetailsLink(network.name, txhash)
if (txLink) this._api.logHtmlMessage(yo`<a href="${txLink}" target="_blank">${txLink}</a>`)
if (txLink) this._deps.editorpanel.logHtmlMessage(yo`<a href="${txLink}" target="_blank">${txLink}</a>`)
}
})
})
@ -63,7 +79,7 @@ UniversalDApp.prototype.reset = function (contracts, transactionContextAPI) {
UniversalDApp.prototype.newAccount = function (password, cb) {
if (!executionContext.isVM()) {
if (!this._api.personalMode()) {
if (!this._deps.config.get('settings/personal-mode')) {
return cb('Not running in personal mode')
}
modalCustom.promptPassphraseCreation((error, passphrase) => {
@ -106,7 +122,7 @@ UniversalDApp.prototype.getAccounts = function (cb) {
if (!executionContext.isVM()) {
// Weirdness of web3: listAccounts() is sync, `getListAccounts()` is async
// See: https://github.com/ethereum/web3.js/issues/442
if (this._api.personalMode()) {
if (this._deps.config.get('settings/personal-mode')) {
executionContext.web3().personal.getListAccounts(cb)
} else {
executionContext.web3().eth.getAccounts(cb)
@ -177,9 +193,9 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly,
if (!error) {
if (isUserAction) {
if (!args.funABI.constant) {
self._api.logMessage(`${logMsg} pending ... `)
self._deps.editorpanel.logMessage(`${logMsg} pending ... `)
} else {
self._api.logMessage(`${logMsg}`)
self._deps.editorpanel.logMessage(`${logMsg}`)
}
}
self.callFunction(args.address, data, args.funABI, (error, txResult) => {
@ -188,7 +204,7 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly,
if (isVM) {
var vmError = txExecution.checkVMError(txResult)
if (vmError.error) {
self._api.logMessage(`${logMsg} errored: ${vmError.message} `)
self._deps.editorpanel.logMessage(`${logMsg} errored: ${vmError.message} `)
return
}
}
@ -197,14 +213,14 @@ UniversalDApp.prototype.call = function (isUserAction, args, value, lookupOnly,
outputCb(decoded)
}
} else {
self._api.logMessage(`${logMsg} errored: ${error} `)
self._deps.editorpanel.logMessage(`${logMsg} errored: ${error} `)
}
})
} else {
self._api.logMessage(`${logMsg} errored: ${error} `)
self._deps.editorpanel.logMessage(`${logMsg} errored: ${error} `)
}
}, (msg) => {
self._api.logMessage(msg)
self._deps.editorpanel.logMessage(msg)
}, (data, runTxCallback) => {
// called for libraries deployment
self.runTx(data, runTxCallback)

Loading…
Cancel
Save