pull/5370/head
Aniket-Engg 3 years ago committed by Aniket
parent 1cc352b0c3
commit 3b92a1b7e8
  1. 3
      apps/remix-ide/src/app/tabs/theme-module.js
  2. 56
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -37,8 +37,7 @@ export class ThemeModule extends Plugin {
themes.map((theme) => {
this.themes[theme.name.toLocaleLowerCase()] = {
...theme,
// url: window.location.origin + window.location.pathname + theme.url
url: window.location.origin + '/' + theme.url
url: window.location.origin + ( window.location.pathname.startsWith('/address/') ? '/' : window.location.pathname ) + theme.url
}
})
this._paq = _paq

@ -8,6 +8,7 @@ import { createWorkspaceTemplate, getWorkspaces, loadWorkspacePreset, setPlugin
import { QueryParams } from '@remix-project/remix-lib'
import { fetchContractFromEtherscan } from '@remix-project/core-plugin' // eslint-disable-line
import JSZip from 'jszip'
import { networkInterfaces } from 'os'
export * from './events'
export * from './workspace'
@ -63,30 +64,45 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const route = window.location.pathname
if (route.startsWith('/address/0x') && route.length === 51) {
const contractAddress = route.split('/')[2]
let data
try {
const etherscanKey = await plugin.call('config', 'getAppParameter', 'etherscan-access-token')
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.')
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 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))
if (!etherscanKey) {
plugin.call('notification', 'toast', `Cannot look for contract address ${contractAddress}. Etherscan access token not found. Go to Remix settings page and save an access token.`)
await basicWorkspaceInit(workspaces, workspaceProvider)
} else {
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`)
let found = false
for (const network of networks) {
const target = `/${network.name}`
try{
data = await fetchContractFromEtherscan(plugin, network, contractAddress, target)
} catch (error) {
if ((error.message.startsWith('contract not verified on Etherscan') || error.message.startsWith('unable to retrieve contract data')) && network.id !== 5)
continue
else {
if (!found) await basicWorkspaceInit(workspaces, workspaceProvider)
break
}
}
found = true
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)
await basicWorkspaceInit(workspaces, workspaceProvider)
await basicWorkspaceInit(workspaces, workspaceProvider)
}
}
} else {

Loading…
Cancel
Save