From 30115b42b7e308bf2596c92fe22d071c914fcccd Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 1 Mar 2023 21:03:05 +0100 Subject: [PATCH 1/5] fix using custom provider --- apps/remix-ide/src/app/providers/injected-provider.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/providers/injected-provider.tsx b/apps/remix-ide/src/app/providers/injected-provider.tsx index 13d7793d7a..3ba3efd94e 100644 --- a/apps/remix-ide/src/app/providers/injected-provider.tsx +++ b/apps/remix-ide/src/app/providers/injected-provider.tsx @@ -61,8 +61,11 @@ export class InjectedProvider extends Plugin implements IProvider { } try { if ((window as any) && typeof (window as any).ethereum.request === "function") (window as any).ethereum.request({ method: "eth_requestAccounts" }); - const resultData = await this.provider.currentProvider.send(data.method, data.params) - resolve({ jsonrpc: '2.0', result: resultData.result, id: data.id }) + let resultData = await this.provider.currentProvider.send(data.method, data.params) + if (resultData && resultData.jsonrpc === '2.0') { + resultData = resultData.result + } + resolve({ jsonrpc: '2.0', result: resultData, id: data.id }) } catch (error) { reject(error) } From c851dd1dfd6b516ed2d78fc97961e265eed10aea Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 2 Mar 2023 09:57:11 +0100 Subject: [PATCH 2/5] use infura --- apps/remix-ide/src/app/providers/mainnet-vm-fork-provider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/providers/mainnet-vm-fork-provider.tsx b/apps/remix-ide/src/app/providers/mainnet-vm-fork-provider.tsx index 582ded0745..ff0f305568 100644 --- a/apps/remix-ide/src/app/providers/mainnet-vm-fork-provider.tsx +++ b/apps/remix-ide/src/app/providers/mainnet-vm-fork-provider.tsx @@ -15,7 +15,7 @@ export class MainnetForkVMProvider extends BasicVMProvider { }, blockchain) this.blockchain = blockchain this.fork = 'london' - this.nodeUrl = 'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym' + this.nodeUrl = 'https://mainnet.infura.io/v3/08b2a484451e4635a28b3d8234f24332' this.blockNumber = 'latest' } From 3337742512c2675bc85de4870cbd22cee9634e58 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 2 Mar 2023 10:16:39 +0100 Subject: [PATCH 3/5] check property is set --- apps/remix-ide/src/app/providers/injected-provider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/providers/injected-provider.tsx b/apps/remix-ide/src/app/providers/injected-provider.tsx index 3ba3efd94e..a89eb7b899 100644 --- a/apps/remix-ide/src/app/providers/injected-provider.tsx +++ b/apps/remix-ide/src/app/providers/injected-provider.tsx @@ -62,7 +62,7 @@ export class InjectedProvider extends Plugin implements IProvider { try { if ((window as any) && typeof (window as any).ethereum.request === "function") (window as any).ethereum.request({ method: "eth_requestAccounts" }); let resultData = await this.provider.currentProvider.send(data.method, data.params) - if (resultData && resultData.jsonrpc === '2.0') { + if (resultData && resultData.jsonrpc && resultData.jsonrpc === '2.0') { resultData = resultData.result } resolve({ jsonrpc: '2.0', result: resultData, id: data.id }) From 220eac46336a3d42cef4e5c34a63f9a1292e6aa3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 2 Mar 2023 10:26:03 +0100 Subject: [PATCH 4/5] fix resolving from error --- .../src/app/providers/injected-provider.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/app/providers/injected-provider.tsx b/apps/remix-ide/src/app/providers/injected-provider.tsx index a89eb7b899..adbb614fe5 100644 --- a/apps/remix-ide/src/app/providers/injected-provider.tsx +++ b/apps/remix-ide/src/app/providers/injected-provider.tsx @@ -57,17 +57,21 @@ export class InjectedProvider extends Plugin implements IProvider { // This will be displayed on UI tooltip as 'cannot get account list: Environment Updated !!' if (!this.provider) { this.call('notification', 'toast', 'No injected provider (e.g Metamask) has been found.') - return reject(new Error('no injected provider found.')) + return resolve({ jsonrpc: '2.0', error: 'no injected provider found', id: data.id }) } try { if ((window as any) && typeof (window as any).ethereum.request === "function") (window as any).ethereum.request({ method: "eth_requestAccounts" }); let resultData = await this.provider.currentProvider.send(data.method, data.params) - if (resultData && resultData.jsonrpc && resultData.jsonrpc === '2.0') { - resultData = resultData.result + if (resultData) { + if (resultData.jsonrpc && resultData.jsonrpc === '2.0') { + resultData = resultData.result + } + resolve({ jsonrpc: '2.0', result: resultData, id: data.id }) + } else { + resolve({ jsonrpc: '2.0', error: 'no return data provided', id: data.id }) } - resolve({ jsonrpc: '2.0', result: resultData, id: data.id }) } catch (error) { - reject(error) + resolve({ jsonrpc: '2.0', error: error.message, id: data.id }) } } } From 502a128c5bec98255896b2cfc6c3a929594896b6 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 2 Mar 2023 10:31:21 +0100 Subject: [PATCH 5/5] fix types --- apps/remix-ide/src/app/providers/abstract-provider.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/providers/abstract-provider.tsx b/apps/remix-ide/src/app/providers/abstract-provider.tsx index a83b435e2b..5d9df384c3 100644 --- a/apps/remix-ide/src/app/providers/abstract-provider.tsx +++ b/apps/remix-ide/src/app/providers/abstract-provider.tsx @@ -13,7 +13,8 @@ export type JsonDataRequest = { export type JsonDataResult = { id: number, jsonrpc: string // version - result: any + result?: any, + error?: any, } export type RejectRequest = (error: Error) => void