From 6682f39eb320d245bf67d90795e988e3dbcc1d1b Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 2 Mar 2022 11:33:52 +0100 Subject: [PATCH] small fixes --- apps/remix-ide/src/app/plugins/config.ts | 3 +-- .../src/lib/helpers/fetch-etherscan.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/config.ts b/apps/remix-ide/src/app/plugins/config.ts index a9ecc48e57..3102d555df 100644 --- a/apps/remix-ide/src/app/plugins/config.ts +++ b/apps/remix-ide/src/app/plugins/config.ts @@ -18,8 +18,7 @@ export class ConfigPlugin extends Plugin { const queryParams = new QueryParams() const params = queryParams.get() const config = Registry.getInstance().get('config').api - let param = params[name] ? params[name] : config.get(name) - param = param ? param : config.get('settings/' + name) + let param = params[name] || config.get(name) || config.get('settings/' + name) if (param === 'true') return true if (param === 'false') return false return param diff --git a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts index 78b750b15c..f5f1c71f1b 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts @@ -7,13 +7,15 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres const endpoint = network.id == 1 ? 'api.etherscan.io' : 'api-' + network.name + '.etherscan.io' data = await fetch('https://' + endpoint + '/api?module=contract&action=getsourcecode&address=' + contractAddress + '&apikey=' + etherscanKey) data = await data.json() - if (data.message !== 'OK') throw new Error('unable to retrieve contract data ' + data.message) - if (data.result.length) { - if (data.result[0].SourceCode === '') throw new Error('contract not verified') - if (data.result[0].SourceCode.startsWith('{')) { - data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}')) - } - } + // etherscan api doc https://docs.etherscan.io/api-endpoints/contracts + if (data.message === 'OK' && data.status === "1") { + if (data.result.length) { + if (data.result[0].SourceCode === '') throw new Error('contract not verified') + if (data.result[0].SourceCode.startsWith('{')) { + data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}')) + } + } + } else throw new Error('unable to retrieve contract data ' + data.message) } if (!data || !data.result) { @@ -24,7 +26,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres const fileName = `${targetPath}/${network.id}/${contractAddress}/${data.result[0].ContractName}.sol` await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode) compilationTargets[fileName] = { content: data.result[0].SourceCode } - } else if (typeof data.result[0].SourceCode == 'object') { + } else if (data.result[0].SourceCode && typeof data.result[0].SourceCode == 'object') { const sources = data.result[0].SourceCode.sources for (let [file, source] of Object.entries(sources)) { // eslint-disable-line file = file.replace('browser/', '') // should be fixed in the remix IDE end.