Merge pull request #2592 from ethereum/addWeb3ProviderPlugin

Add global web3 provider plugin
pull/5370/head
yann300 5 years ago committed by GitHub
commit 40f9b9f8a7
  1. 8
      src/app.js
  2. 31
      src/app/tabs/web3-provider.js
  3. 6
      src/app/ui/sendTxCallbacks.js
  4. 2
      src/app/ui/universal-dapp-ui.js
  5. 2
      src/remixAppManager.js

@ -48,6 +48,7 @@ import { FramingService } from './framingService'
import { MainView } from './app/panels/main-view' import { MainView } from './app/panels/main-view'
import { ThemeModule } from './app/tabs/theme-module' import { ThemeModule } from './app/tabs/theme-module'
import { NetworkModule } from './app/tabs/network-module' import { NetworkModule } from './app/tabs/network-module'
import { Web3ProviderModule } from './app/tabs/web3-provider'
import { SidePanel } from './app/components/side-panel' import { SidePanel } from './app/components/side-panel'
import { HiddenPanel } from './app/components/hidden-panel' import { HiddenPanel } from './app/components/hidden-panel'
import { VerticalIcons } from './app/components/vertical-icons' 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) ----- // ----------------- network service (resolve network id / name) -----
const networkModule = new NetworkModule(blockchain) const networkModule = new NetworkModule(blockchain)
// ----------------- represent the current selected web3 provider ----
const web3Provider = new Web3ProviderModule(blockchain)
// ----------------- convert offset to line/column service ----------- // ----------------- convert offset to line/column service -----------
const offsetToLineColumnConverter = new OffsetToLineColumnConverter() const offsetToLineColumnConverter = new OffsetToLineColumnConverter()
registry.put({api: offsetToLineColumnConverter, name: '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, networkModule,
offsetToLineColumnConverter, offsetToLineColumnConverter,
contextualListener, contextualListener,
terminal terminal,
web3Provider
]) ])
// LAYOUT & SYSTEM VIEWS // 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) 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(['mainPanel', 'menuicons'])
await appManager.activatePlugin(['home', 'sidePanel', 'hiddenPanel', 'pluginManager', 'fileExplorers', 'settings', 'contextualListener', 'scriptRunner', 'terminal']) await appManager.activatePlugin(['home', 'sidePanel', 'hiddenPanel', 'pluginManager', 'fileExplorers', 'settings', 'contextualListener', 'scriptRunner', 'terminal'])

@ -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)
})
})
}
}

@ -7,13 +7,13 @@ const typeConversion = remixLib.execution.typeConversion
const Web3 = require('web3') const Web3 = require('web3')
module.exports = { module.exports = {
getCallBacksWithContext: (udappUI, executionContext) => { getCallBacksWithContext: (udappUI, blockchain) => {
let callbacks = {} let callbacks = {}
callbacks.confirmationCb = confirmationCb callbacks.confirmationCb = confirmationCb
callbacks.continueCb = continueCb callbacks.continueCb = continueCb
callbacks.promptCb = promptCb callbacks.promptCb = promptCb
callbacks.udappUI = udappUI callbacks.udappUI = udappUI
callbacks.executionContext = executionContext callbacks.blockchain = blockchain
return callbacks return callbacks
} }
} }
@ -67,7 +67,7 @@ const confirmationCb = function (network, tx, gasEstimation, continueTxExecution
cb(txFeeText, priceStatus) cb(txFeeText, priceStatus)
}, },
(cb) => { (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. ' const warnMessage = ' Please fix this issue before sending any transaction. '
if (error) { if (error) {
return cb('Unable to retrieve the current network gas price.' + warnMessage + error) return cb('Unable to retrieve the current network gas price.' + warnMessage + error)

@ -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 functionName = args.funABI.type === 'function' ? args.funABI.name : `(${args.funABI.type})`
const logMsg = `${lookupOnly ? 'call' : 'transact'} to ${args.contractName}.${functionName}` 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) => { const outputCb = (returnValue) => {
if (outputOverride) { if (outputOverride) {

@ -4,7 +4,7 @@ import { EventEmitter } from 'events'
import QueryParams from './lib/query-params' import QueryParams from './lib/query-params'
const requiredModules = [ // services + layout views + system views 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', 'mainPanel', 'hiddenPanel', 'sidePanel', 'menuicons', 'fileExplorers',
'terminal', 'settings', 'pluginManager'] 'terminal', 'settings', 'pluginManager']

Loading…
Cancel
Save