diff --git a/apps/remix-ide/webpack.config.js b/apps/remix-ide/webpack.config.js index 529fe58d39..57fd709495 100644 --- a/apps/remix-ide/webpack.config.js +++ b/apps/remix-ide/webpack.config.js @@ -16,6 +16,13 @@ module.exports = config => { const nxWebpackConfig = nxWebpack(config) const webpackConfig = { ...nxWebpackConfig, + resolve: { + ...nxWebpackConfig.resolve, + alias: { + path: require.resolve("path-browserify"), + } + }, + node: { fs: 'empty', tls: 'empty', @@ -38,7 +45,7 @@ module.exports = config => { }) ] } - + webpackConfig.output.chunkLoadTimeout = 600000 if (process.env.NODE_ENV === 'production') { diff --git a/libs/remix-ui/workspace/src/lib/actions/events.ts b/libs/remix-ui/workspace/src/lib/actions/events.ts index 74b767cf73..7a9ed8a416 100644 --- a/libs/remix-ui/workspace/src/lib/actions/events.ts +++ b/libs/remix-ui/workspace/src/lib/actions/events.ts @@ -13,7 +13,7 @@ export const listenOnPluginEvents = (filePanelPlugin) => { plugin = filePanelPlugin plugin.on('filePanel', 'createWorkspaceReducerEvent', (name: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb: (err: Error, result?: string | number | boolean | Record) => void) => { - createWorkspace(name, workspaceTemplateName, isEmpty, cb) + createWorkspace(name, workspaceTemplateName, null, isEmpty, cb) }) plugin.on('filePanel', 'renameWorkspaceReducerEvent', (oldName: string, workspaceName: string, cb: (err: Error, result?: string | number | boolean | Record) => void) => { diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 3ef203644e..ab455ee24c 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -43,17 +43,19 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?: return promise } -export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record) => void, isGitRepo: boolean = false) => { +export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, opts = null, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record) => void, isGitRepo: boolean = false) => { await plugin.fileManager.closeAllFiles() const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName) - dispatch(createWorkspaceRequest(promise)) promise.then(async () => { dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo })) await plugin.setWorkspace({ name: workspaceName, isLocalhost: false }) await plugin.setWorkspaces(await getWorkspaces()) await plugin.workspaceCreated(workspaceName) - if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName) + + if (isGitRepo) await plugin.call('dGitProvider', 'init') + if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts) + cb && cb(null, workspaceName) }).catch((error) => { dispatch(createWorkspaceError({ error })) @@ -80,7 +82,7 @@ export type UrlParametersType = { language: string } -export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDefault') => { +export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDefault', opts?) => { const workspaceProvider = plugin.fileProviders.workspace const params = queryParams.get() as UrlParametersType @@ -159,7 +161,7 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe if (!templateList.includes(template)) break _paq.push(['trackEvent', 'workspace', 'template', template]) // @ts-ignore - const files = await templateWithContent[template]() + const files = await templateWithContent[template](opts) for (const file in files) { try { await workspaceProvider.set(file, files[file]) @@ -339,7 +341,7 @@ export const cloneRepository = async (url: string) => { try { const repoName = await getRepositoryTitle(url) - await createWorkspace(repoName, 'blank', true, null, true) + await createWorkspace(repoName, 'blank', null, true, null, true) const promise = plugin.call('dGitProvider', 'clone', repoConfig, repoName, true) dispatch(cloneRepositoryRequest()) diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 1724ca7c29..2fd6a71b46 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -9,7 +9,7 @@ export const FileSystemContext = createContext<{ dispatchFetchDirectory:(path: string) => Promise, dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise, dispatchRemoveInputField:(path: string) => Promise, - dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string) => Promise, + dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, opts?, initGitRepo?: boolean) => Promise, toast: (toasterMsg: string) => void, dispatchFetchWorkspaceDirectory: (path: string) => Promise, dispatchSwitchToWorkspace: (name: string) => Promise, diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index 2d4010ca31..2b1409fe86 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -45,8 +45,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await removeInputField(path) } - const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate) => { - await createWorkspace(workspaceName, workspaceTemplateName) + const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, opts?, initGitRepo?: boolean) => { + await createWorkspace(workspaceName, workspaceTemplateName, opts, null, null, initGitRepo) } const dispatchFetchWorkspaceDirectory = async (path: string) => { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 512fd2ec65..8a4eac301f 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -15,11 +15,14 @@ export function Workspace () { const [currentWorkspace, setCurrentWorkspace] = useState(NO_WORKSPACE) const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean}>(null) const [showDropdown, setShowDropdown] = useState(false) + const displayOzCustomRef = useRef() + const upgradeable = useRef() const global = useContext(FileSystemContext) const workspaceRenameInput = useRef() const workspaceCreateInput = useRef() const workspaceCreateTemplateInput = useRef() const cloneUrlRef = useRef() + const initGitRepoRef = useRef() useEffect(() => { setCurrentWorkspace(localStorage.getItem('currentWorkspace') ? localStorage.getItem('currentWorkspace') : '') @@ -104,9 +107,14 @@ export function Workspace () { const workspaceName = workspaceCreateInput.current.value // @ts-ignore: Object is possibly 'null'. const workspaceTemplateName = workspaceCreateTemplateInput.current.value || 'remixDefault' + const initGitRepo = initGitRepoRef.current.checked + + const opts = { + upgradeable: upgradeable.current + } try { - await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName) + await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName, opts, initGitRepo) } catch (e) { global.modal('Create Workspace', e.message, 'OK', () => {}, '') console.error(e) @@ -138,6 +146,11 @@ export function Workspace () { } const updateWsName = () => { + // @ts-ignore + if (workspaceCreateTemplateInput.current.value.startsWith('oz') && displayOzCustomRef && displayOzCustomRef.current) + displayOzCustomRef.current.style.display = 'block' + else displayOzCustomRef.current.style.display = 'none' + // @ts-ignore workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value || 'remixDefault'}_${Date.now()}` } @@ -156,19 +169,68 @@ export function Workspace () { setShowDropdown(isOpen) } + const handleUpgradeability = (e) => { + // @ts-ignore + upgradeable.current = e.target.value + // @ts-ignore + workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value + '_upgradeable'}_${Date.now()}` + } + const createModalMessage = () => { return ( <> - -
- - + + + + + + + + + + + + +
+ + +
handleUpgradeability(e)}> +
+ + +
+
+ + +
+
+
+ + + + +
+ {}} + /> + +
+ ) } @@ -279,9 +341,9 @@ export function Workspace () { { - createWorkspace() - }} + onClick={() => { + createWorkspace() + }} > { - create a new workspace - diff --git a/libs/remix-ws-templates/src/templates/ozerc20/index.ts b/libs/remix-ws-templates/src/templates/ozerc20/index.ts index f44f812bb2..17ed9113f2 100644 --- a/libs/remix-ws-templates/src/templates/ozerc20/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc20/index.ts @@ -1,8 +1,8 @@ import { erc20 } from '@openzeppelin/wizard'; -export default async () => { +export default async (opts) => { return { - 'contracts/MyToken.sol': erc20.print(), + 'contracts/MyToken.sol': erc20.print({ ...erc20.defaults, upgradeable: opts.upgradeable}), // @ts-ignore 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, // @ts-ignore diff --git a/libs/remix-ws-templates/src/templates/ozerc721/index.ts b/libs/remix-ws-templates/src/templates/ozerc721/index.ts index 26a3acd59b..6505e5f0ef 100644 --- a/libs/remix-ws-templates/src/templates/ozerc721/index.ts +++ b/libs/remix-ws-templates/src/templates/ozerc721/index.ts @@ -1,8 +1,8 @@ import { erc721 } from '@openzeppelin/wizard'; -export default async () => { +export default async (opts) => { return { - 'contracts/MyToken.sol': erc721.print(), + 'contracts/MyToken.sol': erc721.print({ ...erc721.defaults, upgradeable: opts.upgradeable}), // @ts-ignore 'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default, // @ts-ignore diff --git a/package.json b/package.json index 9a6c229781..56fc3c130c 100644 --- a/package.json +++ b/package.json @@ -198,6 +198,7 @@ "merge": "^2.1.1", "monaco-editor": "^0.30.1", "npm-install-version": "^6.0.2", + "path-browserify": "^1.0.1", "prettier": "^2.7.1", "prettier-plugin-solidity": "^1.0.0-beta.24", "raw-loader": "^4.0.2", diff --git a/yarn.lock b/yarn.lock index 1f51deb7ae..62de31106f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18523,6 +18523,11 @@ path-browserify@0.0.1, path-browserify@~0.0.0: resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" integrity sha512-BapA40NHICOS+USX9SN4tyhq+A2RrN/Ws5F0Z5aMHDp98Fl86lX8Oti8B7uN93L4Ifv4fHOEA+pQw87gmMO/lQ== +path-browserify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd" + integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g== + path-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/path-case/-/path-case-3.0.4.tgz#9168645334eb942658375c56f80b4c0cb5f82c6f"