check api key

pull/2450/head^2
Aniket-Engg 3 years ago committed by Aniket
parent e5dedfcda5
commit 8fbad4d33e
  1. 28
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -63,17 +63,19 @@ 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 networks = [ try {
{id: 1, name: 'mainnet'}, const etherscanKey = await plugin.call('config', 'getAppParameter', 'etherscan-access-token')
{id: 3, name: 'ropsten'}, if (!etherscanKey) throw new Error('unable to try fetching the source code from etherscan: etherscan access token not found. please go to the Remix settings page and provide an access token.')
{id: 4, name: 'rinkeby'}, const networks = [
{id: 42, name: 'kovan'}, {id: 1, name: 'mainnet'},
{id: 5, name: 'goerli'} {id: 3, name: 'ropsten'},
] {id: 4, name: 'rinkeby'},
plugin.call('notification', 'toast', `Looking for contract address ${contractAddress} on different networks`) {id: 42, name: 'kovan'},
for (const network of networks) { {id: 5, name: 'goerli'}
const target = `/${network.name}` ]
try { plugin.call('notification', 'toast', `Looking for contract address ${contractAddress} on different networks`)
for (const network of networks) {
const target = `/${network.name}`
const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target) const data = await fetchContractFromEtherscan(plugin, network, contractAddress, target)
await createWorkspaceTemplate('etherscan-code-sample', 'code-template') await createWorkspaceTemplate('etherscan-code-sample', 'code-template')
plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false }) plugin.setWorkspace({ name: 'etherscan-code-sample', isLocalhost: false })
@ -81,10 +83,10 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const filePath = Object.keys(data.compilationTargets)[0] const filePath = Object.keys(data.compilationTargets)[0]
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) {
plugin.call('notification', 'toast', error.message) plugin.call('notification', 'toast', error.message)
await basicWorkspaceInit(workspaces, workspaceProvider) await basicWorkspaceInit(workspaces, workspaceProvider)
}
} }
} }
} else { } else {

Loading…
Cancel
Save