From 259c5f6e88363a01a1898b8aec701106c6b21750 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 3 May 2022 07:11:54 +0200 Subject: [PATCH] web3Provider --- apps/remix-ide/src/app/tabs/web3-provider.js | 50 ++++++++++++-------- apps/remix-ide/src/remixAppManager.js | 3 +- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/web3-provider.js b/apps/remix-ide/src/app/tabs/web3-provider.js index b79eaefdf3..a97da3da2b 100644 --- a/apps/remix-ide/src/app/tabs/web3-provider.js +++ b/apps/remix-ide/src/app/tabs/web3-provider.js @@ -21,27 +21,39 @@ export class Web3ProviderModule extends Plugin { Should be taken carefully and probably not be release as it is now. */ sendAsync (payload) { - return new Promise((resolve, reject) => { - const provider = this.blockchain.web3().currentProvider - // see https://github.com/ethereum/web3.js/pull/1018/files#diff-d25786686c1053b786cc2626dc6e048675050593c0ebaafbf0814e1996f22022R129 - provider[provider.sendAsync ? 'sendAsync' : 'send'](payload, async (error, message) => { - if (error) return reject(error) - if (payload.method === 'eth_sendTransaction') { - if (payload.params.length && !payload.params[0].to && message.result) { - setTimeout(async () => { - const receipt = await this.tryTillReceiptAvailable(message.result) - if (!receipt.contractAddress) { - console.log('receipt available but contract address not present', receipt) - return + console.log(payload) + return this.askUserPermission('sendAsync', `Calling ${payload.method} with parameters ${JSON.stringify(payload.params)}`).then( + async (result) => { + if(result){ + return new Promise((resolve, reject) => { + const provider = this.blockchain.web3().currentProvider + // see https://github.com/ethereum/web3.js/pull/1018/files#diff-d25786686c1053b786cc2626dc6e048675050593c0ebaafbf0814e1996f22022R129 + provider[provider.sendAsync ? 'sendAsync' : 'send'](payload, async (error, message) => { + if (error) return reject(error) + if (payload.method === 'eth_sendTransaction') { + if (payload.params.length && !payload.params[0].to && message.result) { + setTimeout(async () => { + const receipt = await this.tryTillReceiptAvailable(message.result) + if (!receipt.contractAddress) { + console.log('receipt available but contract address not present', receipt) + return + } + const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress) + if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) + }, 50) + } } - const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress) - if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name) - }, 50) - } + resolve(message) + }) + }) + }else{ + return new Promise((resolve, reject) => { + reject(new Error('User denied permission')) + }) } - resolve(message) - }) - }) + } + ) + } async tryTillReceiptAvailable (txhash) { diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index 053ff4a758..96d79aba39 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -14,7 +14,8 @@ const dependentModules = ['git', 'hardhat', 'truffle', 'slither'] // module whic const sensitiveCalls = { 'fileManager': ['writeFile', 'copyFile', 'rename', 'copyDir'], - 'contentImport': ['resolveAndSave'] + 'contentImport': ['resolveAndSave'], + 'web3Provider': ['sendAsync'], } export function isNative(name) {