fetch from testnets

pull/2450/head^2
Aniket-Engg 2 years ago committed by Aniket
parent 1c68619d81
commit e5dedfcda5
  1. 2
      libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts
  2. 12
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -10,7 +10,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres
// etherscan api doc https://docs.etherscan.io/api-endpoints/contracts // etherscan api doc https://docs.etherscan.io/api-endpoints/contracts
if (data.message === 'OK' && data.status === "1") { if (data.message === 'OK' && data.status === "1") {
if (data.result.length) { if (data.result.length) {
if (data.result[0].SourceCode === '') throw new Error('contract not verified in Etherscan') if (data.result[0].SourceCode === '') throw new Error(`contract not verified on Etherscan ${network.name} network`)
if (data.result[0].SourceCode.startsWith('{')) { if (data.result[0].SourceCode.startsWith('{')) {
data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}')) data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}'))
} }

@ -63,7 +63,15 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const route = window.location.pathname const route = window.location.pathname
if (route.startsWith('/address/0x') && route.length === 51) { if (route.startsWith('/address/0x') && route.length === 51) {
const contractAddress = route.split('/')[2] const contractAddress = route.split('/')[2]
const network = {id: 1, name: 'main'} const networks = [
{id: 1, name: 'mainnet'},
{id: 3, name: 'ropsten'},
{id: 4, name: 'rinkeby'},
{id: 42, name: 'kovan'},
{id: 5, name: 'goerli'}
]
plugin.call('notification', 'toast', `Looking for contract address ${contractAddress} on different networks`)
for (const network of networks) {
const target = `/${network.name}` const target = `/${network.name}`
try { try {
const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target) const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target)
@ -74,11 +82,11 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content']) await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content'])
plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(filePath)) plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(filePath))
} catch (error) { } catch (error) {
if(error.message.includes('unable to retrieve contract data') || error.message.includes('unable to try fetching the source code'))
plugin.call('notification', 'toast', error.message) plugin.call('notification', 'toast', error.message)
await basicWorkspaceInit(workspaces, workspaceProvider) await basicWorkspaceInit(workspaces, workspaceProvider)
} }
} }
}
} else { } else {
await basicWorkspaceInit(workspaces, workspaceProvider) await basicWorkspaceInit(workspaces, workspaceProvider)
} }

Loading…
Cancel
Save