From 1638dc3eefe19bc21e710922142b7a96f99b23e0 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 21 Feb 2023 15:12:48 +0100 Subject: [PATCH 1/5] refactor --- apps/etherscan/src/app/RemixPlugin.tsx | 7 ++++--- apps/etherscan/src/app/utils/utilities.ts | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/etherscan/src/app/RemixPlugin.tsx b/apps/etherscan/src/app/RemixPlugin.tsx index f9c6a4e18a..e4879ef6ce 100644 --- a/apps/etherscan/src/app/RemixPlugin.tsx +++ b/apps/etherscan/src/app/RemixPlugin.tsx @@ -23,9 +23,10 @@ export class RemixClient extends PluginClient { const etherscanApi = getEtherScanApi(network) const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi) return { - status: receiptStatus, - message: receiptStatus, - succeed: true + status: receiptStatus.status, + message: receiptStatus.message, + result: receiptStatus.result, + succeed: receiptStatus.status === '0' ? false : true } } catch (e: any){ return { diff --git a/apps/etherscan/src/app/utils/utilities.ts b/apps/etherscan/src/app/utils/utilities.ts index d7300806a3..11cc6bd8e7 100644 --- a/apps/etherscan/src/app/utils/utilities.ts +++ b/apps/etherscan/src/app/utils/utilities.ts @@ -2,6 +2,12 @@ import { PluginClient } from "@remixproject/plugin" import axios from 'axios' type RemixClient = PluginClient +export type receiptStatus = { + result: string + message: string + status: string +} + export const getEtherScanApi = (network: string) => { return network === "main" ? `https://api.etherscan.io/api` @@ -20,12 +26,16 @@ export const getReceiptStatus = async ( receiptGuid: string, apiKey: string, etherscanApi: string -) => { +): Promise => { const params = `guid=${receiptGuid}&module=contract&action=checkverifystatus&apiKey=${apiKey}` try { const response = await axios.get(`${etherscanApi}?${params}`) - const { result } = response.data - return result + const { result, message, status } = response.data + return { + result, + message, + status, + } } catch (error) { console.error(error) } From 2fd680644f8b02f37a67698dc355a06c12acc22f Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 21 Feb 2023 15:30:29 +0100 Subject: [PATCH 2/5] fix build --- apps/etherscan/.babelrc | 18 ++- apps/etherscan/src/app/RemixPlugin.tsx | 4 +- apps/etherscan/src/app/app.tsx | 4 +- apps/etherscan/src/app/utils/utilities.ts | 5 + apps/etherscan/src/app/utils/verify.ts | 4 +- apps/etherscan/src/app/views/ReceiptsView.tsx | 2 +- apps/etherscan/webpack.config.js | 104 +++++++++++++----- 7 files changed, 98 insertions(+), 43 deletions(-) diff --git a/apps/etherscan/.babelrc b/apps/etherscan/.babelrc index b1fc975456..e37036ce66 100644 --- a/apps/etherscan/.babelrc +++ b/apps/etherscan/.babelrc @@ -1,13 +1,9 @@ { - "presets": [ - [ - "@nrwl/react/babel", { - "runtime": "automatic" - - } - ] - ], - "plugins": [ - + "presets": ["@babel/preset-env", ["@babel/preset-react", + {"runtime": "automatic"} + ]], + "plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime", "@babel/plugin-proposal-nullish-coalescing-operator"], + "ignore": [ + "**/node_modules/**" ] -} +} \ No newline at end of file diff --git a/apps/etherscan/src/app/RemixPlugin.tsx b/apps/etherscan/src/app/RemixPlugin.tsx index e4879ef6ce..601e523920 100644 --- a/apps/etherscan/src/app/RemixPlugin.tsx +++ b/apps/etherscan/src/app/RemixPlugin.tsx @@ -23,9 +23,7 @@ export class RemixClient extends PluginClient { const etherscanApi = getEtherScanApi(network) const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi) return { - status: receiptStatus.status, - message: receiptStatus.message, - result: receiptStatus.result, + message: receiptStatus.result, succeed: receiptStatus.status === '0' ? false : true } } catch (e: any){ diff --git a/apps/etherscan/src/app/app.tsx b/apps/etherscan/src/app/app.tsx index 5a141e239d..9b5450cb0a 100644 --- a/apps/etherscan/src/app/app.tsx +++ b/apps/etherscan/src/app/app.tsx @@ -89,7 +89,7 @@ const App = () => { }) if (receiptsNotVerified.length > 0) { - let timer1 = setInterval(() => { + const timer1 = setInterval(() => { for (const item in receiptsNotVerified) { } @@ -106,7 +106,7 @@ const App = () => { apiKey, getEtherScanApi(network) ) - if (status === "Pass - Verified") { + if (status.result === "Pass - Verified") { const newReceipts = receipts.map((currentReceipt: Receipt) => { if (currentReceipt.guid === item.guid) { return { diff --git a/apps/etherscan/src/app/utils/utilities.ts b/apps/etherscan/src/app/utils/utilities.ts index 11cc6bd8e7..b7db856364 100644 --- a/apps/etherscan/src/app/utils/utilities.ts +++ b/apps/etherscan/src/app/utils/utilities.ts @@ -2,6 +2,11 @@ import { PluginClient } from "@remixproject/plugin" import axios from 'axios' type RemixClient = PluginClient +/* + status: 0=Error, 1=Pass + message: OK, NOTOK + result: explanation +*/ export type receiptStatus = { result: string message: string diff --git a/apps/etherscan/src/app/utils/verify.ts b/apps/etherscan/src/app/utils/verify.ts index e3cfabd9d9..305c926fca 100644 --- a/apps/etherscan/src/app/utils/verify.ts +++ b/apps/etherscan/src/app/utils/verify.ts @@ -90,6 +90,8 @@ export const verify = async ( const response = await axios.post(etherscanApi, body) const { message, result, status } = await response.data + console.log("response", response.data) + if (message === "OK" && status === "1") { resetAfter10Seconds(client, setResults) const receiptStatus = await getReceiptStatus( @@ -100,7 +102,7 @@ export const verify = async ( const returnValue = { guid: result, - status: receiptStatus, + status: receiptStatus.result, message: `Verification process started correctly. Receipt GUID ${result}`, succeed: true } diff --git a/apps/etherscan/src/app/views/ReceiptsView.tsx b/apps/etherscan/src/app/views/ReceiptsView.tsx index ad13fbee33..4d07953a38 100644 --- a/apps/etherscan/src/app/views/ReceiptsView.tsx +++ b/apps/etherscan/src/app/views/ReceiptsView.tsx @@ -30,7 +30,7 @@ export const ReceiptsView: React.FC = () => { apiKey, etherscanApi ) - setResults(result) + setResults(result.result) } catch (error: any) { setResults(error.message) } diff --git a/apps/etherscan/webpack.config.js b/apps/etherscan/webpack.config.js index 68ea64e4a1..8fda923d20 100644 --- a/apps/etherscan/webpack.config.js +++ b/apps/etherscan/webpack.config.js @@ -1,28 +1,82 @@ -const nxWebpack = require('@nrwl/react/plugins/webpack') - -module.exports = config => { - const nxWebpackConfig = nxWebpack(config) - const webpackConfig = { - ...nxWebpackConfig, - resolve : { - ...nxWebpackConfig.resolve, - fallback: { - ...nxWebpackConfig.resolve.fallback, - "http": require.resolve("stream-http"), - "https": require.resolve("https-browserify"), - "stream": require.resolve("stream-browserify"), - "zlib": require.resolve("browserify-zlib"), - }, - } +const { composePlugins, withNx } = require('@nrwl/webpack') +const webpack = require('webpack') +const TerserPlugin = require("terser-webpack-plugin") +const CssMinimizerPlugin = require("css-minimizer-webpack-plugin") + +// Nx plugins for webpack. +module.exports = composePlugins(withNx(), (config) => { + // Update the webpack config as needed here. + // e.g. `config.plugins.push(new MyPlugin())` + + // add fallback for node modules + config.resolve.fallback = { + ...config.resolve.fallback, + "crypto": require.resolve("crypto-browserify"), + "stream": require.resolve("stream-browserify"), + "path": require.resolve("path-browserify"), + "http": require.resolve("stream-http"), + "https": require.resolve("https-browserify"), + "constants": require.resolve("constants-browserify"), + "os": false, //require.resolve("os-browserify/browser"), + "timers": false, // require.resolve("timers-browserify"), + "zlib": require.resolve("browserify-zlib"), + "fs": false, + "module": false, + "tls": false, + "net": false, + "readline": false, + "child_process": false, + "buffer": require.resolve("buffer/"), + "vm": require.resolve('vm-browserify'), } - if (process.env.NODE_ENV === 'production') { - return { - ...webpackConfig, - mode: 'production', - devtool: 'source-map', - } - } else { - return webpackConfig + + // add externals + config.externals = { + ...config.externals, + solc: 'solc', } -} + + // add public path + config.output.publicPath = '/' + + + + // add copy & provide plugin + config.plugins.push( + new webpack.ProvidePlugin({ + Buffer: ['buffer', 'Buffer'], + url: ['url', 'URL'], + process: 'process/browser', + }) + ) + + // souce-map loader + config.module.rules.push({ + test: /\.js$/, + use: ["source-map-loader"], + enforce: "pre" + }) + + config.ignoreWarnings = [/Failed to parse source map/] // ignore source-map-loader warnings + + + // set minimizer + config.optimization.minimizer = [ + new TerserPlugin({ + parallel: true, + terserOptions: { + ecma: 2015, + compress: false, + mangle: false, + format: { + comments: false, + }, + }, + extractComments: false, + }), + new CssMinimizerPlugin(), + ]; + + return config; +}); \ No newline at end of file From 1a76c6f7b4f07a626bea71a6e65ad49296caf0ae Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 21 Feb 2023 15:40:58 +0100 Subject: [PATCH 3/5] fix the test --- apps/remix-ide-e2e/src/tests/etherscan_api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/etherscan_api.ts b/apps/remix-ide-e2e/src/tests/etherscan_api.ts index f951942f0d..15a3fa62e7 100644 --- a/apps/remix-ide-e2e/src/tests/etherscan_api.ts +++ b/apps/remix-ide-e2e/src/tests/etherscan_api.ts @@ -54,7 +54,7 @@ module.exports = { .clickLaunchIcon('filePanel') .addFile('receiptStatusScript.ts', { content: receiptStatusScript }) .click('*[data-id="play-editor"]') // run the script - .waitForElementContainsText('*[data-id="terminalJournal"]', 'Pass - Verified', 60000) + .waitForElementContainsText('*[data-id="terminalJournal"]', 'Already Verified', 60000) } } @@ -119,7 +119,7 @@ const receiptStatusScript = ` const receiptStatus = async () => { try { const apikey = '2HKUX5ZVASZIKWJM8MIQVCRUVZ6JAWT531' - const ret = await remix.call('etherscan' as any, 'receiptStatus', 'n1qtqfn8jggwqv9uvni5zzectnztqbxqqvizznvl4vg1pndb9v', apikey) + const ret = await remix.call('etherscan' as any, 'receiptStatus', 'tsrrzmayenrslvixnvhdv7fbbp6kk1xuqkg667aqlesblpkimt', apikey) console.log(ret) } catch (e) { console.log(e.message) From c9925d5eb11f7541d73d51d5cc0f2ab7266ae189 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Tue, 21 Feb 2023 17:36:18 +0100 Subject: [PATCH 4/5] Update verify.ts --- apps/etherscan/src/app/utils/verify.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/etherscan/src/app/utils/verify.ts b/apps/etherscan/src/app/utils/verify.ts index 305c926fca..f20ce3fa9b 100644 --- a/apps/etherscan/src/app/utils/verify.ts +++ b/apps/etherscan/src/app/utils/verify.ts @@ -90,8 +90,6 @@ export const verify = async ( const response = await axios.post(etherscanApi, body) const { message, result, status } = await response.data - console.log("response", response.data) - if (message === "OK" && status === "1") { resetAfter10Seconds(client, setResults) const receiptStatus = await getReceiptStatus( @@ -171,4 +169,4 @@ export const verify = async ( } } return contractMetadata - } \ No newline at end of file + } From 72220cff6c9d05cc4888a03bebb263ed2c1155e0 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Tue, 21 Feb 2023 16:09:22 +0100 Subject: [PATCH 5/5] fix test --- .../src/tests/solidityImport.test.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/solidityImport.test.ts b/apps/remix-ide-e2e/src/tests/solidityImport.test.ts index 2cdd6894f6..2b75395e2a 100644 --- a/apps/remix-ide-e2e/src/tests/solidityImport.test.ts +++ b/apps/remix-ide-e2e/src/tests/solidityImport.test.ts @@ -34,19 +34,6 @@ module.exports = { timeout: 120000, suppressNotFoundErrors: true }) - .click('[data-id="compilerContainerCompileBtn"]') - .isVisible({ - selector: "//span[contains(.,'not found Untitled11')]", - locateStrategy: 'xpath', - timeout: 120000, - suppressNotFoundErrors: true - }) - .click('[data-id="compilerContainerCompileBtn"]') - .waitForElementVisible({ - selector: "//span[contains(.,'not found Untitled11')]", - locateStrategy: 'xpath', - timeout: 120000, - }) }, @@ -135,11 +122,11 @@ const sources = [ 'Untitled.sol': { content: 'contract test1 {} contract test2 {}' } }, { - 'Untitled1.sol': { content: 'import "./Untitled2.sol"; contract test6 {}' }, + 'Untitled1.sol': { content: 'import "/Untitled2.sol"; contract test6 {}' }, 'Untitled2.sol': { content: 'contract test4 {} contract test5 {}' } }, { - 'Untitled3.sol': { content: 'import "./Untitled11.sol"; contract test6 {}' } + 'Untitled3.sol': { content: 'import "/Untitled11.sol"; contract test6 {}' } }, { 'Untitled4.sol': { content: 'import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"; contract test7 {}' }