From baa3fc843297c92c8a1b5126c34d4f8093b30476 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 22 Jun 2021 15:39:57 +0530 Subject: [PATCH 1/9] fix hardhat modal reappearing --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index 037117fa85..88fe3b7c85 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -39,12 +39,17 @@ export default class HardhatProvider extends Plugin { sendAsync (data) { return new Promise((resolve, reject) => { - if (!this.provider) { + if (!this.provider || data.method === 'net_listening') { modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => { this.provider = new Web3.providers.HttpProvider(target) this.sendAsyncInternal(data, resolve, reject) }, () => { - this.sendAsyncInternal(data, resolve, reject) + if (data.method === 'net_listening') resolve({ jsonrpc: '2.0', result: 'canceled', id: data.id }) + else { + this.blockchain.changeExecutionContext('vm') + this.provider = this.blockchain.getCurrentProvider() + reject(new Error('Connection canceled')) + } }) } else { this.sendAsyncInternal(data, resolve, reject) @@ -62,8 +67,7 @@ export default class HardhatProvider extends Plugin { resolve(message) }) } else { - const result = data.method === 'net_listening' ? 'canceled' : [] - resolve({ jsonrpc: '2.0', result: result, id: data.id }) + resolve({ jsonrpc: '2.0', result: [], id: data.id }) } } } From 94910717816b82024628ca28a981c8fe722118cc Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 22 Jun 2021 16:04:45 +0530 Subject: [PATCH 2/9] specific error on tooltip --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index 88fe3b7c85..8c2cd0ae05 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -59,6 +59,9 @@ export default class HardhatProvider extends Plugin { sendAsyncInternal (data, resolve, reject) { if (this.provider) { + // Check the case where current environment is VM on UI and it still sends RPC requests + // This will be displayed on UI tooltip as 'cannot get account list: Environment Updated !!' + if (this.blockchain.getProvider() !== 'Hardhat Provider' && data.method !== 'net_listening') return reject(new Error('Environment Updated !!')) this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, (error, message) => { if (error) { this.provider = null From b1a0286707378f5efb50e1165919be9446570ae9 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 22 Jun 2021 19:02:01 +0530 Subject: [PATCH 3/9] comments --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index 8c2cd0ae05..0676d199d3 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -39,13 +39,17 @@ export default class HardhatProvider extends Plugin { sendAsync (data) { return new Promise((resolve, reject) => { + // If provider is not set, allow to open modal only when provider is trying to connect if (!this.provider || data.method === 'net_listening') { modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => { this.provider = new Web3.providers.HttpProvider(target) this.sendAsyncInternal(data, resolve, reject) }, () => { + // If 'cancel' is clicked while trying to connect, handle it in custom manner if (data.method === 'net_listening') resolve({ jsonrpc: '2.0', result: 'canceled', id: data.id }) else { + // When node is abruptly stopped, modal will appear + // On which clicking on 'Cancel' will set the Envrionment to VM this.blockchain.changeExecutionContext('vm') this.provider = this.blockchain.getCurrentProvider() reject(new Error('Connection canceled')) From 552324df22ef9fd31811f21a38c4117496f06365 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 22 Jun 2021 19:20:13 +0530 Subject: [PATCH 4/9] added info in modal --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index 0676d199d3..ec43d72ffc 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -32,12 +32,16 @@ export default class HardhatProvider extends Plugin {
For more info, visit: Hardhat Documentation

+ Note: Click on 'Cancel' if node is stopped. +

Hardhat JSON-RPC Endpoint ` } sendAsync (data) { + console.log('data in sendAsync-->', data) + console.log('provider in sendAsync-->', this.provider) return new Promise((resolve, reject) => { // If provider is not set, allow to open modal only when provider is trying to connect if (!this.provider || data.method === 'net_listening') { From 47117eda63fbe2be7325086ce825fc0c8f89b1d3 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Tue, 22 Jun 2021 19:22:01 +0530 Subject: [PATCH 5/9] consoles removed --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index ec43d72ffc..43fc613624 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -40,8 +40,6 @@ export default class HardhatProvider extends Plugin { } sendAsync (data) { - console.log('data in sendAsync-->', data) - console.log('provider in sendAsync-->', this.provider) return new Promise((resolve, reject) => { // If provider is not set, allow to open modal only when provider is trying to connect if (!this.provider || data.method === 'net_listening') { From c24b7e5926653c3ca7542aab97ee5dc0007a40d4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 28 Jun 2021 16:29:16 +0200 Subject: [PATCH 6/9] temporarily block provider --- .../src/app/tabs/hardhat-provider.js | 22 +++++++++---------- apps/remix-ide/src/remixAppManager.js | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index 43fc613624..fa99969d20 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -1,6 +1,7 @@ import * as packageJson from '../../../../../package.json' import { Plugin } from '@remixproject/engine' import Web3 from 'web3' +import toaster from '../ui/tooltip' const yo = require('yo-yo') const modalDialogCustom = require('../ui/modal-dialog-custom') @@ -17,11 +18,13 @@ export default class HardhatProvider extends Plugin { constructor (blockchain) { super(profile) this.provider = null + this.blocked = false // used to block any call when trying to recover after a failed connection. this.blockchain = blockchain } onDeactivation () { this.provider = null + this.blocked = false } hardhatProviderDialogBody () { @@ -41,21 +44,14 @@ export default class HardhatProvider extends Plugin { sendAsync (data) { return new Promise((resolve, reject) => { + if (this.blocked) return reject(new Error('provider temporarily blocked')) // If provider is not set, allow to open modal only when provider is trying to connect - if (!this.provider || data.method === 'net_listening') { + if (!this.provider) { modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => { this.provider = new Web3.providers.HttpProvider(target) this.sendAsyncInternal(data, resolve, reject) }, () => { - // If 'cancel' is clicked while trying to connect, handle it in custom manner - if (data.method === 'net_listening') resolve({ jsonrpc: '2.0', result: 'canceled', id: data.id }) - else { - // When node is abruptly stopped, modal will appear - // On which clicking on 'Cancel' will set the Envrionment to VM - this.blockchain.changeExecutionContext('vm') - this.provider = this.blockchain.getCurrentProvider() - reject(new Error('Connection canceled')) - } + this.sendAsyncInternal(data, resolve, reject) }) } else { this.sendAsyncInternal(data, resolve, reject) @@ -68,9 +64,13 @@ export default class HardhatProvider extends Plugin { // Check the case where current environment is VM on UI and it still sends RPC requests // This will be displayed on UI tooltip as 'cannot get account list: Environment Updated !!' if (this.blockchain.getProvider() !== 'Hardhat Provider' && data.method !== 'net_listening') return reject(new Error('Environment Updated !!')) - this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, (error, message) => { + this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, async (error, message) => { if (error) { + this.blocked = true + modalDialogCustom.alert('Hardhat', `Error while connecting to the hardhat provider: ${error.message}`) + await this.call('udapp', 'setEnvironmentMode', 'vm') this.provider = null + setTimeout(_ => this.blocked = false, 1000) return reject(error) } resolve(message) diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index 26f684e432..45bc5a7421 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -14,7 +14,7 @@ const requiredModules = [ // services + layout views + system views const dependentModules = ['git', 'hardhat'] // module which shouldn't be manually activated (e.g git is activated by remixd) export function isNative (name) { - const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity'] + const nativePlugins = ['vyper', 'workshops', 'debugger', 'remixd', 'menuicons', 'solidity', 'hardhat-provider'] return nativePlugins.includes(name) || requiredModules.includes(name) } From b4fde6a4364b86779449861de46c0d94357c52d9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 29 Jun 2021 15:47:21 +0200 Subject: [PATCH 7/9] linting --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index fa99969d20..afcd72276a 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -1,7 +1,6 @@ import * as packageJson from '../../../../../package.json' import { Plugin } from '@remixproject/engine' import Web3 from 'web3' -import toaster from '../ui/tooltip' const yo = require('yo-yo') const modalDialogCustom = require('../ui/modal-dialog-custom') @@ -70,7 +69,7 @@ export default class HardhatProvider extends Plugin { modalDialogCustom.alert('Hardhat', `Error while connecting to the hardhat provider: ${error.message}`) await this.call('udapp', 'setEnvironmentMode', 'vm') this.provider = null - setTimeout(_ => this.blocked = false, 1000) + setTimeout(_ => { this.blocked = false }, 1000) return reject(error) } resolve(message) From cc35bf1cbd46ffb14ad5ec40dc2bb6a68e777b9e Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 29 Jun 2021 16:41:54 +0200 Subject: [PATCH 8/9] label & comment --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index afcd72276a..06d9459426 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -43,7 +43,7 @@ export default class HardhatProvider extends Plugin { sendAsync (data) { return new Promise((resolve, reject) => { - if (this.blocked) return reject(new Error('provider temporarily blocked')) + if (this.blocked) return reject(new Error('provider unable to connect')) // If provider is not set, allow to open modal only when provider is trying to connect if (!this.provider) { modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => { @@ -66,10 +66,10 @@ export default class HardhatProvider extends Plugin { this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](data, async (error, message) => { if (error) { this.blocked = true - modalDialogCustom.alert('Hardhat', `Error while connecting to the hardhat provider: ${error.message}`) + modalDialogCustom.alert('Hardhat Provider', `Error while connecting to the hardhat provider: ${error.message}`) await this.call('udapp', 'setEnvironmentMode', 'vm') this.provider = null - setTimeout(_ => { this.blocked = false }, 1000) + setTimeout(_ => { this.blocked = false }, 1000) // we wait 1 second for letting remix to switch to vm return reject(error) } resolve(message) From 5631491b63f7a103b1dc9c10c4a7f04faa6186be Mon Sep 17 00:00:00 2001 From: Aniket <30843294+Aniket-Engg@users.noreply.github.com> Date: Wed, 30 Jun 2021 12:03:24 +0530 Subject: [PATCH 9/9] Update hardhat-provider.js --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index 06d9459426..805bc37e08 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -34,8 +34,6 @@ export default class HardhatProvider extends Plugin {
For more info, visit: Hardhat Documentation

- Note: Click on 'Cancel' if node is stopped. -

Hardhat JSON-RPC Endpoint ` @@ -75,7 +73,8 @@ export default class HardhatProvider extends Plugin { resolve(message) }) } else { - resolve({ jsonrpc: '2.0', result: [], id: data.id }) + const result = data.method === 'net_listening' ? 'canceled' : [] + resolve({ jsonrpc: '2.0', result: result, id: data.id }) } } }