set execution context for hardhat provider

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent 83996bc1b4
commit 773031fa5f
  1. 46
      apps/remix-ide/src/app/tabs/hardhat-provider.js
  2. 39
      apps/remix-ide/src/app/tabs/runTab/settings.js
  3. 2
      apps/remix-ide/src/blockchain/execution-context.js

@ -1,8 +1,5 @@
import * as packageJson from '../../../../../package.json' import * as packageJson from '../../../../../package.json'
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
const yo = require('yo-yo')
const modalDialogCustom = require('../ui/modal-dialog-custom')
import Web3 from 'web3'
const profile = { const profile = {
name: 'hardhat-provider', name: 'hardhat-provider',
@ -14,38 +11,23 @@ const profile = {
} }
export default class HardhatProvider extends Plugin { export default class HardhatProvider extends Plugin {
constructor () { constructor () {
super(profile) super(profile)
this.provider = null this.provider = null
} }
hardhatProviderDialogBody () { sendAsync (data) {
return yo` return new Promise((resolve, reject) => {
<div class=""> if (this.provider) {
Hardhat Provider Endpoint this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, (error, message) => {
</div> if (error) return reject(error)
` resolve(message)
}
sendAsync (data) {
console.log('Inside sendAsync - modalDialogCustom', modalDialogCustom)
modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => {
console.log('target--->', target)
this.provider = new Web3.providers.HttpProvider(target)
return new Promise((resolve, reject) => {
console.log('inside sendAsync promise')
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})
}
}) })
}) } else {
resolve({ jsonrpc: '2.0', result: [], id: data.id })
} }
})
}
} }
module.exports = HardhatProvider module.exports = HardhatProvider

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

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

Loading…
Cancel
Save