From 0a40c3a6cf449b319a271ba72eaa6383c9af1a8e Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 14 Jan 2021 11:44:58 +0100 Subject: [PATCH] Migrate runtab to viewplugin, method getSettings rm unused rm pluginudapp use settingsUI --- apps/remix-ide/src/app.js | 3 -- .../remix-ide/src/app/tabs/runTab/settings.js | 4 ++ apps/remix-ide/src/app/udapp/run-tab.js | 47 +++++++++++++++++-- apps/remix-ide/src/blockchain/pluginUDapp.js | 33 ------------- 4 files changed, 46 insertions(+), 41 deletions(-) delete mode 100644 apps/remix-ide/src/blockchain/pluginUDapp.js diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index 602ee1cc57..4dc3a8d37c 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -42,7 +42,6 @@ var CompilerMetadata = require('./app/files/compiler-metadata') var CompilerImport = require('./app/compiler/compiler-imports') const Blockchain = require('./blockchain/blockchain.js') -const PluginUDapp = require('./blockchain/pluginUDapp.js') const PluginManagerComponent = require('./app/components/plugin-manager-component') const CompilersArtefacts = require('./app/compiler/compiler-artefacts') @@ -257,7 +256,6 @@ Please make a backup of your contracts and start using http://remix.ethereum.org const contentImport = new CompilerImport(fileManager) const blockchain = new Blockchain(registry.get('config').api) - const pluginUdapp = new PluginUDapp(blockchain) // ----------------- compilation metadata generation service --------- const compilerMetadataGenerator = new CompilerMetadata(blockchain, fileManager, registry.get('config').api) @@ -359,7 +357,6 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ) const run = new RunTab( blockchain, - pluginUdapp, registry.get('config').api, registry.get('filemanager').api, registry.get('editor').api, diff --git a/apps/remix-ide/src/app/tabs/runTab/settings.js b/apps/remix-ide/src/app/tabs/runTab/settings.js index 944ff092b8..8008034812 100644 --- a/apps/remix-ide/src/app/tabs/runTab/settings.js +++ b/apps/remix-ide/src/app/tabs/runTab/settings.js @@ -319,6 +319,10 @@ class SettingsUI { ) } + getSelectedAccount () { + return this.el.querySelector('#txorigin').selectedOptions[0].value + } + signMessage () { this.blockchain.getAccounts((err, accounts) => { if (err) { diff --git a/apps/remix-ide/src/app/udapp/run-tab.js b/apps/remix-ide/src/app/udapp/run-tab.js index 4aada9431e..ec414da60d 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.js +++ b/apps/remix-ide/src/app/udapp/run-tab.js @@ -1,4 +1,4 @@ -import { LibraryPlugin } from '@remixproject/engine' +import { ViewPlugin } from '@remixproject/engine-web' import * as packageJson from '../../../../../package.json' const $ = require('jquery') @@ -28,12 +28,12 @@ const profile = { version: packageJson.version, permission: true, events: ['newTransaction'], - methods: ['createVMAccount', 'sendTransaction', 'getAccounts', 'pendingTransactionsCount'] + methods: ['createVMAccount', 'sendTransaction', 'getAccounts', 'pendingTransactionsCount', 'getSettings'] } -export class RunTab extends LibraryPlugin { - constructor (blockchain, pluginUDapp, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView, fileProvider) { - super(pluginUDapp, profile) +export class RunTab extends ViewPlugin { + constructor (blockchain, config, fileManager, editor, filePanel, compilersArtefacts, networkModule, mainView, fileProvider) { + super(profile) this.event = new EventManager() this.config = config this.blockchain = blockchain @@ -44,6 +44,43 @@ export class RunTab extends LibraryPlugin { this.compilersArtefacts = compilersArtefacts this.networkModule = networkModule this.fileProvider = fileProvider + this.setupEvents() + } + + setupEvents () { + this.blockchain.events.on('newTransaction', (tx, receipt) => { + this.emit('newTransaction', tx, receipt) + }) + } + + getSettings () { + return new Promise((resolve, reject) => { + if (!this.container) reject(new Error('UI not ready')) + else { + resolve({ + selectedAccount: this.settingsUI.getSelectedAccount(), + selectedEnvMode: this.container.querySelector('#selectExEnvOptions').selectedOptions[0].value, + networkEnvironment: this.container.querySelector('*[data-id="settingsNetworkEnv"]').textContent + } + ) + } + }) + } + + createVMAccount (newAccount) { + return this.blockchain.createVMAccount(newAccount) + } + + sendTransaction (tx) { + return this.blockchain.sendTransaction(tx) + } + + getAccounts (cb) { + return this.blockchain.getAccounts(cb) + } + + pendingTransactionsCount () { + return this.blockchain.pendingTransactionsCount() } renderContainer () { diff --git a/apps/remix-ide/src/blockchain/pluginUDapp.js b/apps/remix-ide/src/blockchain/pluginUDapp.js deleted file mode 100644 index 38edc1984d..0000000000 --- a/apps/remix-ide/src/blockchain/pluginUDapp.js +++ /dev/null @@ -1,33 +0,0 @@ -const { EventEmitter } = require('events') - -class PluginUdapp { - constructor (blockchain) { - this.blockchain = blockchain - this.events = new EventEmitter() - this.setupEvents() - } - - setupEvents () { - this.blockchain.events.on('newTransaction', (tx, receipt) => { - this.events.emit('newTransaction', tx, receipt) - }) - } - - createVMAccount (newAccount) { - return this.blockchain.createVMAccount(newAccount) - } - - sendTransaction (tx) { - return this.blockchain.sendTransaction(tx) - } - - getAccounts (cb) { - return this.blockchain.getAccounts(cb) - } - - pendingTransactionsCount () { - return this.blockchain.pendingTransactionsCount() - } -} - -module.exports = PluginUdapp