UniversalDApp refactor

pull/1/head
yann300 6 years ago
parent c3b3f42587
commit 846fa9119d
  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 // @TODO should put this in runtab
registry.put({api: transactionContextAPI, name: 'transactionContextAPI'}) registry.put({api: transactionContextAPI, name: 'transactionContextAPI'})
var udapp = new UniversalDApp({ var udapp = new UniversalDApp({ removable: false, removable_instances: true })
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 }
})
registry.put({api: udapp, name: 'udapp'}) registry.put({api: udapp, name: 'udapp'})
var udappUI = new UniversalDAppUI(udapp) var udappUI = new UniversalDAppUI(udapp)

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

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

Loading…
Cancel
Save