Commit c7799a18 authored by aniket-engg's avatar aniket-engg Committed by Aniket

plugin code segregation

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