plugin code segregation

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent ff1850af6f
commit 5a2f4e139f
  1. 37
      apps/remix-ide/src/app/tabs/hardhat-provider.js
  2. 19
      apps/remix-ide/src/app/tabs/runTab/settings.js
  3. 2
      apps/remix-ide/src/blockchain/execution-context.js

@ -1,5 +1,8 @@
import * as packageJson from '../../../../../package.json'
import { Plugin } from '@remixproject/engine'
import Web3 from 'web3'
const yo = require('yo-yo')
const modalDialogCustom = require('../ui/modal-dialog-custom')
const profile = {
name: 'hardhat-provider',
@ -13,20 +16,34 @@ const profile = {
export default class HardhatProvider extends Plugin {
constructor (blockchain) {
super(profile)
this.provider = null
this.blockchain = blockchain
}
hardhatProviderDialogBody () {
return yo`
<div class="">
Hardhat JSON-RPC Endpoint
</div>
`
}
sendAsync (data) {
return new Promise((resolve, reject) => {
const provider = this.blockchain.web3().currentProvider
if (provider) {
provider[provider.sendAsync ? 'sendAsync' : 'send'](data, (error, message) => {
if (error) return reject(error)
resolve(message)
})
} else {
resolve({ jsonrpc: '2.0', result: [], id: data.id })
}
modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => {
this.blockchain.setProviderFromEndpoint(target, 'Hardhat Provider', (alertMsg) => {
console.log('target-->', target)
this.provider = new Web3.providers.HttpProvider(target)
return new Promise((resolve, reject) => {
if (this.provider) {
this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, (error, message) => {
if (error) return reject(error)
resolve(message)
})
} else {
resolve({ jsonrpc: '2.0', result: [], id: data.id })
}
})
})
})
}
}

@ -245,16 +245,7 @@ class SettingsUI {
setExecutionContext (context) {
if (context === 'Hardhat Provider') {
this.blockchain.changeExecutionContext(context, () => {
modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => {
this.blockchain.setProviderFromEndpoint(target, context, (alertMsg) => {
if (alertMsg) addTooltip(alertMsg)
this.setFinalContext()
})
}, this.setFinalContext.bind(this))
}, (alertMsg) => {
addTooltip(alertMsg)
}, this.setFinalContext.bind(this))
this.blockchain.changeExecutionContext(context)
} else {
this.blockchain.changeExecutionContext(context, () => {
modalDialogCustom.prompt('External node request', this.web3ProviderDialogBody(), 'http://127.0.0.1:8545', (target) => {
@ -291,14 +282,6 @@ class SettingsUI {
`
}
hardhatProviderDialogBody () {
return yo`
<div class="">
Hardhat JSON-RPC Endpoint
</div>
`
}
setFinalContext () {
// set the final context. Cause it is possible that this is not the one we've originaly selected
this.selectExEnv.value = this.blockchain.getProvider()

@ -142,7 +142,7 @@ export class ExecutionContext {
}
}
if (context === 'web3' || context === 'Hardhat Provider') {
if (context === 'web3') {
confirmCb(cb)
}

Loading…
Cancel
Save