From 8e7e3e1937411c6cfab4f70c71f53c9040a4ae85 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 14 Nov 2023 11:20:18 +0100 Subject: [PATCH] add uniswap template --- .../src/app/tabs/locales/en/filePanel.json | 1 + .../src/lib/components/homeTabGetStarted.tsx | 14 +++++++++----- .../workspace/src/lib/actions/workspace.ts | 11 +++++++++-- .../workspace/src/lib/remix-ui-workspace.tsx | 6 +++++- libs/remix-ui/workspace/src/lib/types/index.ts | 2 +- libs/remix-ui/workspace/src/lib/utils/constants.ts | 10 +++++++++- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/locales/en/filePanel.json b/apps/remix-ide/src/app/tabs/locales/en/filePanel.json index 6b3b8524d0..e2f376d677 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/filePanel.json +++ b/apps/remix-ide/src/app/tabs/locales/en/filePanel.json @@ -105,6 +105,7 @@ "filePanel.pausable": "Pausable", "filePanel.semaphore": "Semaphore", "filePanel.hashchecker": "Hash Checker", + "filePanel.breakthroughLabsUniswapv4Hooks": "Breakthrough-Labs Uniswapv4Hooks", "filePanel.transparent": "Transparent", "filePanel.initGitRepoTitle": "Check option to initialize workspace as a new git repository", "filePanel.switchToBranchTitle1": "Checkout new branch from remote branch", diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx index b97f0faa52..9d6de88e40 100644 --- a/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import React, {useEffect, useRef, useContext} from 'react' import {useIntl, FormattedMessage} from 'react-intl' -import {TEMPLATE_NAMES} from '@remix-ui/workspace' +import {TEMPLATE_NAMES,TEMPLATE_METADATA} from '@remix-ui/workspace' import {ThemeContext} from '../themeContext' import Carousel from 'react-multi-carousel' import WorkspaceTemplate from './workspaceTemplate' @@ -59,12 +59,16 @@ function HomeTabGetStarted({plugin}: HomeTabGetStartedProps) { const createWorkspace = async (templateName) => { await plugin.appManager.activatePlugin('filePanel') - const timeStamp = Date.now() let templateDisplayName = TEMPLATE_NAMES[templateName] templateDisplayName = await plugin.call('filePanel', 'getAvailableWorkspaceName', templateDisplayName) - await plugin.call('filePanel', 'createWorkspace', templateDisplayName, templateName) - await plugin.call('filePanel', 'setWorkspace', templateDisplayName) - plugin.verticalIcons.select('filePanel') + const metadata = TEMPLATE_METADATA['breakthroughLabsUniswapv4Hooks'] + if (metadata) { + plugin.call('dGitProvider', 'clone', {url: metadata.url, branch: metadata.branch}, templateDisplayName, true) + } else { + await plugin.call('filePanel', 'createWorkspace', templateDisplayName, templateName) + await plugin.call('filePanel', 'setWorkspace', templateDisplayName) + plugin.verticalIcons.select('filePanel') + } _paq.push(['trackEvent', 'hometab', 'homeGetStarted', templateName]) } diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index e2d4ed4658..dfc35ed9ee 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -1,6 +1,7 @@ import React from 'react' import { bufferToHex } from '@ethereumjs/util' import { hash } from '@remix-project/remix-lib' +import { TEMPLATE_METADATA, TEMPLATE_NAMES } from '../utils/constants' import axios, { AxiosResponse } from 'axios' import { addInputFieldSuccess, @@ -38,6 +39,7 @@ import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files import { getUncommittedFiles } from '../utils/gitStatusFilter' import { AppModal, ModalTypes } from '@remix-ui/app' import { contractDeployerScripts, etherscanScripts } from '@remix-project/remix-ws-templates' +import { template } from 'lodash' declare global { interface Window { @@ -194,8 +196,13 @@ export const createWorkspaceTemplate = async (workspaceName: string, template: W if (checkSpecialChars(workspaceName) || checkSlash(workspaceName)) throw new Error('special characters are not allowed') if ((await workspaceExists(workspaceName)) && template === 'remixDefault') throw new Error('workspace already exists') else { - const workspaceProvider = plugin.fileProviders.workspace - await workspaceProvider.createWorkspace(workspaceName) + const metadata = TEMPLATE_METADATA[template] + if (metadata) { + plugin.call('dGitProvider', 'clone', {url: metadata.url, branch: metadata.branch}, TEMPLATE_NAMES[template], true) + } else { + const workspaceProvider = plugin.fileProviders.workspace + await workspaceProvider.createWorkspace(workspaceName) + } } } 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 1e203d994d..92e6de20c2 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -754,8 +754,12 @@ export function Workspace() { {intl.formatMessage({id: 'filePanel.hashchecker'})} + + + -