From fe6bc2fd2704de37ea6f293e192bceb91f7cd2d7 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 28 Oct 2024 15:21:56 +0100 Subject: [PATCH] fix request --- apps/remix-dapp/src/utils/txRunner.ts | 2 +- apps/remix-ide/src/app/udapp/run-tab.tsx | 22 ++++++++++--------- libs/remix-lib/src/execution/txRunnerWeb3.ts | 6 ++++- .../run-tab/src/lib/actions/deploy.ts | 11 +++++++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/apps/remix-dapp/src/utils/txRunner.ts b/apps/remix-dapp/src/utils/txRunner.ts index 6f22ca6c13..1914302c02 100644 --- a/apps/remix-dapp/src/utils/txRunner.ts +++ b/apps/remix-dapp/src/utils/txRunner.ts @@ -267,7 +267,7 @@ export class TxRunner { }; } catch (error: any) { console.log( - `Send transaction failed: ${error.message} . if you use an injected provider, please check it is properly unlocked. ` + `Send transaction failed: ${error.message || error.error} . if you use an injected provider, please check it is properly unlocked. ` ); return { error }; } diff --git a/apps/remix-ide/src/app/udapp/run-tab.tsx b/apps/remix-ide/src/app/udapp/run-tab.tsx index b513a76c2e..b94d6cfb80 100644 --- a/apps/remix-ide/src/app/udapp/run-tab.tsx +++ b/apps/remix-ide/src/app/udapp/run-tab.tsx @@ -198,16 +198,18 @@ export class RunTab extends ViewPlugin { sendAsync (payload) { return udapp.call(name, 'sendAsync', payload) }, - async request (payload) { - try { - const requestResult = await udapp.call(name, 'sendAsync', payload) - if (requestResult.error) { - throw new Error(requestResult.error.message) - } - return requestResult.result - } catch (err) { - throw new Error(err.message) - } + request (payload) { + return new Promise((resolve, reject) => { + udapp.call(name, 'sendAsync', payload).then((response) => { + if (response.error) { + reject(response.error.message) + } else { + resolve(response) + } + }).catch((err) => { + reject(err) + }) + }) } } }) diff --git a/libs/remix-lib/src/execution/txRunnerWeb3.ts b/libs/remix-lib/src/execution/txRunnerWeb3.ts index 0cdb0ee978..b2c46feff4 100644 --- a/libs/remix-lib/src/execution/txRunnerWeb3.ts +++ b/libs/remix-lib/src/execution/txRunnerWeb3.ts @@ -66,7 +66,7 @@ export class TxRunnerWeb3 { const res = await (this.getWeb3() as any).eth.personal.sendTransaction({ ...tx, value }, { checkRevertBeforeSending: false, ignoreGasPricing: true }) cb(null, res.transactionHash) } catch (e) { - console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) + console.log(`Send transaction failed: ${e.message || e.error} . if you use an injected provider, please check it is properly unlocked. `) // in case the receipt is available, we consider that only the execution failed but the transaction went through. // So we don't consider this to be an error. if (e.receipt) cb(null, e.receipt.transactionHash) @@ -82,6 +82,10 @@ export class TxRunnerWeb3 { const res = await this.getWeb3().eth.sendTransaction(tx, null, { checkRevertBeforeSending: false, ignoreGasPricing: true }) cb(null, res.transactionHash) } catch (e) { + if (!e.message) e.message = '' + if (e.error) { + e.message = e.message + ' ' + e.error + } console.log(`Send transaction failed: ${e.message} . if you use an injected provider, please check it is properly unlocked. `) // in case the receipt is available, we consider that only the execution failed but the transaction went through. // So we don't consider this to be an error. diff --git a/libs/remix-ui/run-tab/src/lib/actions/deploy.ts b/libs/remix-ui/run-tab/src/lib/actions/deploy.ts index dd08d62a36..2c2ee360c4 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/deploy.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/deploy.ts @@ -119,10 +119,19 @@ const getConfirmationCb = (plugin: RunTab, dispatch: React.Dispatch, confir export const continueHandler = (dispatch: React.Dispatch, gasEstimationPrompt: (msg: string) => JSX.Element, error, continueTxExecution, cancelCb) => { if (error) { - let msg = typeof error !== 'string' ? error.message : error + let msg = '' + if (typeof error === 'string') { + msg = error + } if (error && error.innerError) { msg += '\n' + error.innerError } + if (error && error.message) { + msg += '\n' + error.message + } + if (error && error.error) { + msg += '\n' + error.error + } if (msg.includes('invalid opcode')) msg += '\nThe EVM version used by the selected environment is not compatible with the compiler EVM version.'