removed errors in console

pull/5370/head
Aniket-Engg 2 years ago committed by Aniket
parent 6ce083752d
commit 6fae2a6c9b
  1. 6
      libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts
  2. 11
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -1,4 +1,4 @@
export const fetchContractFromEtherscan = async (plugin, network, contractAddress, targetPath, key?) => { export const fetchContractFromEtherscan = async (plugin, network, contractAddress, targetPath, shouldSetFile = true, key?) => {
let data let data
const compilationTargets = {} const compilationTargets = {}
let etherscanKey let etherscanKey
@ -27,7 +27,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres
if (typeof data.result[0].SourceCode === 'string') { if (typeof data.result[0].SourceCode === 'string') {
const fileName = `${targetPath}/${data.result[0].ContractName}.sol` const fileName = `${targetPath}/${data.result[0].ContractName}.sol`
await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode) if (shouldSetFile) await plugin.call('fileManager', 'setFile', fileName , data.result[0].SourceCode)
compilationTargets[fileName] = { content: data.result[0].SourceCode } compilationTargets[fileName] = { content: data.result[0].SourceCode }
} else if (data.result[0].SourceCode && 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 const sources = data.result[0].SourceCode.sources
@ -39,7 +39,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres
} else { } else {
const path = `${targetPath}/${file}` const path = `${targetPath}/${file}`
const content = (source as any).content const content = (source as any).content
await plugin.call('fileManager', 'setFile', path, content) if (shouldSetFile) await plugin.call('fileManager', 'setFile', path, content)
compilationTargets[path] = { content } compilationTargets[path] = { content }
} }
} }

@ -80,12 +80,13 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
{id: 5, name: 'goerli'} {id: 5, name: 'goerli'}
] ]
let found = false let found = false
let workspaceName = 'etherscan-code-sample'
let filePath let filePath
const foundOnNetworks = [] const foundOnNetworks = []
for (const network of networks) { for (const network of networks) {
const target = `/${network.name}/${contractAddress}` const target = `/${network.name}/${contractAddress}`
try { try {
data = await fetchContractFromEtherscan(plugin, network, contractAddress, target, etherscanKey) data = await fetchContractFromEtherscan(plugin, network, contractAddress, target, false, etherscanKey)
} catch (error) { } catch (error) {
if ((error.message.startsWith('contract not verified on Etherscan') || error.message.startsWith('unable to retrieve contract data')) && network.id !== 5) if ((error.message.startsWith('contract not verified on Etherscan') || error.message.startsWith('unable to retrieve contract data')) && network.id !== 5)
continue continue
@ -96,10 +97,10 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
} }
found = true found = true
foundOnNetworks.push(network.name) foundOnNetworks.push(network.name)
if (await workspaceExists('etherscan-code-sample')) workspaceProvider.setWorkspace('etherscan-code-sample') if (await workspaceExists(workspaceName)) workspaceProvider.setWorkspace(workspaceName)
else await createWorkspaceTemplate('etherscan-code-sample', 'code-template') else await createWorkspaceTemplate(workspaceName, 'code-template')
plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false }) plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
dispatch(setCurrentWorkspace({ name: 'etherscan-code-sample', isGitRepo: false })) dispatch(setCurrentWorkspace({ name: workspaceName, isGitRepo: false }))
count = count + (Object.keys(data.compilationTargets)).length count = count + (Object.keys(data.compilationTargets)).length
for (filePath in data.compilationTargets) for (filePath in data.compilationTargets)
await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content']) await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content'])

Loading…
Cancel
Save