fetch contract feom GitHub

pull/2450/head^2
Aniket-Engg 3 years ago committed by Aniket
parent b31589da16
commit 1c3039c4b7
  1. 2
      apps/remix-ide/src/app/tabs/theme-module.js
  2. 17
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -37,7 +37,7 @@ export class ThemeModule extends Plugin {
themes.map((theme) => {
this.themes[theme.name.toLocaleLowerCase()] = {
...theme,
url: window.location.origin + ( window.location.pathname.startsWith('/address/') ? '/' : window.location.pathname ) + theme.url
url: window.location.origin + ( window.location.pathname.startsWith('/address/') || window.location.pathname.endsWith('.sol') ? '/' : 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 axios, { AxiosResponse } from 'axios'
export * from './events'
export * from './workspace'
@ -60,7 +61,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
const filePath = await loadWorkspacePreset('code-template')
plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(filePath))
} else if (window.location.pathname && window.location.pathname !== '/') {
const route = window.location.pathname
let route = window.location.pathname
if (route.startsWith('/address/0x') && route.length === 51) {
const contractAddress = route.split('/')[2]
plugin.call('notification', 'toast', `Looking for contract address ${contractAddress} on different networks`)
@ -100,7 +101,19 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
} catch (error) {
await basicWorkspaceInit(workspaces, workspaceProvider)
}
}
} else if (route.endsWith('.sol')) {
if (route.includes('blob')) route = route.replace('/blob', '')
const response: AxiosResponse = await axios.get(`https://raw.githubusercontent.com${route}`)
let content
if (response.status === 200) {
content = response.data
await createWorkspaceTemplate('github-code-sample', 'code-template')
plugin.setWorkspace({ name: 'github-code-sample', isLocalhost: false })
dispatch(setCurrentWorkspace('github-code-sample'))
await workspaceProvider.set(route, content)
plugin.on('editor', 'editorMounted', async () => await plugin.fileManager.openFile(route))
} else await basicWorkspaceInit(workspaces, workspaceProvider)
} else await basicWorkspaceInit(workspaces, workspaceProvider)
} else {
await basicWorkspaceInit(workspaces, workspaceProvider)
}

Loading…
Cancel
Save