Commit 231895c0 authored by aniket-engg's avatar aniket-engg Committed by Aniket

set execution context for hardhat provider

parent e2898170
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 = { ...@@ -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
\ No newline at end of file
...@@ -244,16 +244,29 @@ class SettingsUI { ...@@ -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 { ...@@ -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 { ...@@ -142,7 +142,7 @@ export class ExecutionContext {
} }
} }
if (context === 'web3') { if (context === 'web3' || context === 'Hardhat Provider') {
confirmCb(cb) confirmCb(cb)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment