access content from etherscan mail

pull/2450/head^2
Aniket-Engg 3 years ago committed by Aniket
parent cb94a6b81e
commit 209b890db0
  1. 14
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -47,10 +47,18 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
} else if (window.location.pathname && window.location.pathname !== '/') { } else if (window.location.pathname && window.location.pathname !== '/') {
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) {
console.log('this is an etherscan url') const contractAddress = route.split('/')[2]
const network = {id: 1, name: 'main'}
const target = `/${network.name}`
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))
} }
} } else {
else {
if (workspaces.length === 0) { if (workspaces.length === 0) {
await createWorkspaceTemplate('default_workspace', 'remixDefault') await createWorkspaceTemplate('default_workspace', 'remixDefault')
plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false }) plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false })

Loading…
Cancel
Save