set execution context for hardhat provider

pull/1222/head
aniket-engg 4 years ago committed by Aniket
parent e28981701d
commit 231895c009
  1. 48
      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 { Plugin } from '@remixproject/engine'
const yo = require('yo-yo')
const modalDialogCustom = require('../ui/modal-dialog-custom')
import Web3 from 'web3'
const profile = {
name: 'hardhat-provider',
@ -14,38 +11,23 @@ const profile = {
}
export default class HardhatProvider extends Plugin {
constructor () {
super(profile)
this.provider = null
}
constructor () {
super(profile)
this.provider = null
}
hardhatProviderDialogBody () {
return yo`
<div class="">
Hardhat Provider Endpoint
</div>
`
}
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})
}
sendAsync (data) {
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 })
}
})
}
}
module.exports = HardhatProvider
module.exports = HardhatProvider

@ -244,16 +244,29 @@ class SettingsUI {
}
setExecutionContext (context) {
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()
})
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))
} 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))
}, (alertMsg) => {
addTooltip(alertMsg)
}, this.setFinalContext.bind(this))
}
}
web3ProviderDialogBody () {
@ -278,6 +291,14 @@ class SettingsUI {
`
}
hardhatProviderDialogBody () {
return yo`
<div class="">
Hardhat Provider 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') {
if (context === 'web3' || context === 'Hardhat Provider') {
confirmCb(cb)
}

Loading…
Cancel
Save