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 16f6b284b8..f81914d8a4 100644 --- a/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts +++ b/libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.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 const compilationTargets = {} let etherscanKey @@ -27,7 +27,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres if (typeof data.result[0].SourceCode === 'string') { 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 } } else if (data.result[0].SourceCode && typeof data.result[0].SourceCode == 'object') { const sources = data.result[0].SourceCode.sources @@ -39,7 +39,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres } else { const path = `${targetPath}/${file}` 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 } } } diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index fce393a7c8..7c3615c10c 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -80,12 +80,13 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. {id: 5, name: 'goerli'} ] let found = false + let workspaceName = 'etherscan-code-sample' let filePath const foundOnNetworks = [] for (const network of networks) { const target = `/${network.name}/${contractAddress}` try { - data = await fetchContractFromEtherscan(plugin, network, contractAddress, target, etherscanKey) + data = await fetchContractFromEtherscan(plugin, network, contractAddress, target, false, etherscanKey) } catch (error) { if ((error.message.startsWith('contract not verified on Etherscan') || error.message.startsWith('unable to retrieve contract data')) && network.id !== 5) continue @@ -96,10 +97,10 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. } found = true foundOnNetworks.push(network.name) - if (await workspaceExists('etherscan-code-sample')) workspaceProvider.setWorkspace('etherscan-code-sample') - else await createWorkspaceTemplate('etherscan-code-sample', 'code-template') - plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false }) - dispatch(setCurrentWorkspace({ name: 'etherscan-code-sample', isGitRepo: false })) + if (await workspaceExists(workspaceName)) workspaceProvider.setWorkspace(workspaceName) + else await createWorkspaceTemplate(workspaceName, 'code-template') + plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) + dispatch(setCurrentWorkspace({ name: workspaceName, isGitRepo: false })) count = count + (Object.keys(data.compilationTargets)).length for (filePath in data.compilationTargets) await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content'])