diff --git a/src/app.js b/src/app.js index 7a0a6fabe2..3ab3c50a8c 100644 --- a/src/app.js +++ b/src/app.js @@ -48,6 +48,7 @@ import { FramingService } from './framingService' import { MainView } from './app/panels/main-view' import { ThemeModule } from './app/tabs/theme-module' import { NetworkModule } from './app/tabs/network-module' +import { Web3ProviderModule } from './app/tabs/web3-provider' import { SidePanel } from './app/components/side-panel' import { HiddenPanel } from './app/components/hidden-panel' import { VerticalIcons } from './app/components/vertical-icons' @@ -267,6 +268,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org // ----------------- network service (resolve network id / name) ----- const networkModule = new NetworkModule(blockchain) + // ----------------- represent the current selected web3 provider ---- + const web3Provider = new Web3ProviderModule(blockchain) // ----------------- convert offset to line/column service ----------- const offsetToLineColumnConverter = new OffsetToLineColumnConverter() registry.put({api: offsetToLineColumnConverter, name: 'offsettolinecolumnconverter'}) @@ -300,7 +303,8 @@ Please make a backup of your contracts and start using http://remix.ethereum.org networkModule, offsetToLineColumnConverter, contextualListener, - terminal + terminal, + web3Provider ]) // LAYOUT & SYSTEM VIEWS @@ -383,7 +387,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org console.log('couldn\'t register iframe plugins', e.message) } - await appManager.activatePlugin(['contentImport', 'theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'offsetToLineColumnConverter']) + await appManager.activatePlugin(['contentImport', 'theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter']) await appManager.activatePlugin(['mainPanel', 'menuicons']) await appManager.activatePlugin(['home', 'sidePanel', 'hiddenPanel', 'pluginManager', 'fileExplorers', 'settings', 'contextualListener', 'scriptRunner', 'terminal']) diff --git a/src/app/tabs/web3-provider.js b/src/app/tabs/web3-provider.js new file mode 100644 index 0000000000..88976e874e --- /dev/null +++ b/src/app/tabs/web3-provider.js @@ -0,0 +1,31 @@ +import { Plugin } from '@remixproject/engine' +import * as packageJson from '../../../package.json' + +export const profile = { + name: 'web3Provider', + displayName: 'Global Web3 Provider', + description: 'Represent the current web3 provider used by the app at global scope', + methods: ['sendAsync'], + version: packageJson.version, + kind: 'provider' +} + +export class Web3ProviderModule extends Plugin { + constructor (blockchain) { + super(profile) + this.blockchain = blockchain + } + + /* + that is used by plugins to call the current ethereum provider. + Should be taken carefully and probably not be release as it is now. + */ + sendAsync (payload) { + return new Promise((resolve, reject) => { + this.blockchain.web3().currentProvider.sendAsync(payload, (error, message) => { + if (error) return reject(error) + resolve(message) + }) + }) + } +} diff --git a/src/app/ui/sendTxCallbacks.js b/src/app/ui/sendTxCallbacks.js index 76dde8d6b6..02ed7e619c 100644 --- a/src/app/ui/sendTxCallbacks.js +++ b/src/app/ui/sendTxCallbacks.js @@ -7,13 +7,13 @@ const typeConversion = remixLib.execution.typeConversion const Web3 = require('web3') module.exports = { - getCallBacksWithContext: (udappUI, executionContext) => { + getCallBacksWithContext: (udappUI, blockchain) => { let callbacks = {} callbacks.confirmationCb = confirmationCb callbacks.continueCb = continueCb callbacks.promptCb = promptCb callbacks.udappUI = udappUI - callbacks.executionContext = executionContext + callbacks.blockchain = blockchain return callbacks } } @@ -67,7 +67,7 @@ const confirmationCb = function (network, tx, gasEstimation, continueTxExecution cb(txFeeText, priceStatus) }, (cb) => { - self.executionContext.web3().eth.getGasPrice((error, gasPrice) => { + self.blockchain.web3().eth.getGasPrice((error, gasPrice) => { const warnMessage = ' Please fix this issue before sending any transaction. ' if (error) { return cb('Unable to retrieve the current network gas price.' + warnMessage + error) diff --git a/src/app/ui/universal-dapp-ui.js b/src/app/ui/universal-dapp-ui.js index 2299a290c3..59381cbd23 100644 --- a/src/app/ui/universal-dapp-ui.js +++ b/src/app/ui/universal-dapp-ui.js @@ -233,7 +233,7 @@ UniversalDAppUI.prototype.runTransaction = function (lookupOnly, args, valArr, i const functionName = args.funABI.type === 'function' ? args.funABI.name : `(${args.funABI.type})` const logMsg = `${lookupOnly ? 'call' : 'transact'} to ${args.contractName}.${functionName}` - const callbacksInContext = txCallBacks.getCallBacksWithContext(this, this.executionContext) + const callbacksInContext = txCallBacks.getCallBacksWithContext(this, this.blockchain) const outputCb = (returnValue) => { if (outputOverride) { diff --git a/src/remixAppManager.js b/src/remixAppManager.js index 8c3dcd6fa1..8ad89c7a46 100644 --- a/src/remixAppManager.js +++ b/src/remixAppManager.js @@ -4,7 +4,7 @@ import { EventEmitter } from 'events' import QueryParams from './lib/query-params' const requiredModules = [ // services + layout views + system views - 'manager', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport', 'scriptRunner', + 'manager', 'compilerArtefacts', 'compilerMetadata', 'contextualListener', 'editor', 'offsetToLineColumnConverter', 'network', 'theme', 'fileManager', 'contentImport', 'web3Provider', 'scriptRunner', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons', 'fileExplorers', 'terminal', 'settings', 'pluginManager']