|
|
@ -63,20 +63,28 @@ 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 = [ |
|
|
|
const target = `/${network.name}` |
|
|
|
{id: 1, name: 'mainnet'}, |
|
|
|
try { |
|
|
|
{id: 3, name: 'ropsten'}, |
|
|
|
const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target) |
|
|
|
{id: 4, name: 'rinkeby'}, |
|
|
|
await createWorkspaceTemplate('etherscan-code-sample', 'code-template') |
|
|
|
{id: 42, name: 'kovan'}, |
|
|
|
plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false }) |
|
|
|
{id: 5, name: 'goerli'} |
|
|
|
dispatch(setCurrentWorkspace('etherscan-code-sample')) |
|
|
|
] |
|
|
|
const filePath = Object.keys(data.compilationTargets)[0] |
|
|
|
plugin.call('notification', 'toast', `Looking for contract address ${contractAddress} on different networks`) |
|
|
|
await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content']) |
|
|
|
for (const network of networks) { |
|
|
|
plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(filePath)) |
|
|
|
const target = `/${network.name}` |
|
|
|
} catch (error) { |
|
|
|
try { |
|
|
|
if(error.message.includes('unable to retrieve contract data') || error.message.includes('unable to try fetching the source code')) |
|
|
|
const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target) |
|
|
|
|
|
|
|
await createWorkspaceTemplate('etherscan-code-sample', 'code-template') |
|
|
|
|
|
|
|
plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false }) |
|
|
|
|
|
|
|
dispatch(setCurrentWorkspace('etherscan-code-sample')) |
|
|
|
|
|
|
|
const filePath = Object.keys(data.compilationTargets)[0] |
|
|
|
|
|
|
|
await workspaceProvider.set(filePath, data.compilationTargets[filePath]['content']) |
|
|
|
|
|
|
|
plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(filePath)) |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
plugin.call('notification', 'toast', error.message) |
|
|
|
plugin.call('notification', 'toast', error.message) |
|
|
|
await basicWorkspaceInit(workspaces, workspaceProvider) |
|
|
|
await basicWorkspaceInit(workspaces, workspaceProvider) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|