diff --git a/apps/remix-ide/src/app/tabs/theme-module.js b/apps/remix-ide/src/app/tabs/theme-module.js index 842a39422f..ceb7192317 100644 --- a/apps/remix-ide/src/app/tabs/theme-module.js +++ b/apps/remix-ide/src/app/tabs/theme-module.js @@ -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 diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 5d67f99182..208ebd139f 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -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) }