From 8f773cb5a8c46bf53893f15196b009ed889236a0 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Wed, 26 May 2021 12:42:40 +0530 Subject: [PATCH] cancel click handled --- apps/remix-ide/src/app/tabs/hardhat-provider.js | 12 +++++------- apps/remix-ide/src/blockchain/execution-context.js | 7 ++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.js b/apps/remix-ide/src/app/tabs/hardhat-provider.js index fe1923474f..0816ea2600 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.js +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.js @@ -35,14 +35,11 @@ export default class HardhatProvider extends Plugin { sendAsync (data) { return new Promise((resolve, reject) => { if (!this.provider) { - modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => { - this.provider = new Web3.providers.HttpProvider(target) + modalDialogCustom.prompt('Hardhat node request', this.hardhatProviderDialogBody(), 'http://127.0.0.1:8545', (target) => { + this.provider = new Web3.providers.HttpProvider(target) sendAsyncInternal(this.provider, data, resolve, reject) }, () => { - console.log('cancel clicked', this.provider) - console.log('inside if--->', this.blockchain.getProvider()) - console.log('inside if-2-->', this.blockchain.getCurrentProvider()) - this.call('udapp', 'setEnvironmentMode', this.blockchain.getProvider()) + sendAsyncInternal(this.provider, data, resolve, reject) }) } else { sendAsyncInternal(this.provider, data, resolve, reject) @@ -58,7 +55,8 @@ const sendAsyncInternal = (provider, data, resolve, reject) => { 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 }) } } diff --git a/apps/remix-ide/src/blockchain/execution-context.js b/apps/remix-ide/src/blockchain/execution-context.js index 41588e3708..dbefacda87 100644 --- a/apps/remix-ide/src/blockchain/execution-context.js +++ b/apps/remix-ide/src/blockchain/execution-context.js @@ -145,7 +145,6 @@ export class ExecutionContext { if (context === 'web3') { confirmCb(cb) } - if (this.customNetWorks[context]) { var network = this.customNetWorks[context] this.setProviderFromEndpoint(network.provider, network.name, (error) => { @@ -189,14 +188,16 @@ export class ExecutionContext { const oldProvider = web3.currentProvider web3.setProvider(endpoint) - web3.eth.net.isListening((err, isConnected) => { - if (!err && isConnected) { + if (!err && isConnected === true) { this.executionContext = context this._updateBlockGasLimit() this.event.trigger('contextChanged', [context]) this.event.trigger('web3EndpointChanged') cb() + } else if (isConnected === 'canceled') { + web3.setProvider(oldProvider) + cb() } else { web3.setProvider(oldProvider) cb('Not possible to connect to the Web3 provider. Make sure the provider is running, a connection is open (via IPC or RPC) or that the provider plugin is properly configured.')