From 209b890db0f1abf2256ad1bd18948fccfdf472e1 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Wed, 15 Jun 2022 18:58:02 +0530 Subject: [PATCH] access content from etherscan mail --- libs/remix-ui/workspace/src/lib/actions/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 5b6cba7e62..5c220be345 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/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 !== '/') { const route = window.location.pathname 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) { await createWorkspaceTemplate('default_workspace', 'remixDefault') plugin.setWorkspace({ name: 'default_workspace', isLocalhost: false })