diff --git a/apps/remix-ide/src/app/plugins/templates-selection.tsx b/apps/remix-ide/src/app/plugins/templates-selection.tsx new file mode 100644 index 0000000000..2d1d1a97ab --- /dev/null +++ b/apps/remix-ide/src/app/plugins/templates-selection.tsx @@ -0,0 +1,462 @@ + +import React from 'react' +import { FormattedMessage, useIntl } from 'react-intl' +const isElectron = require('is-electron') +import { AppModal } from '@remix-ui/app' +import { ViewPlugin } from '@remixproject/engine-web' +import { PluginViewWrapper } from '@remix-ui/helper' +import { RemixUIGridView } from '@remix-ui/remix-ui-grid-view' +import { RemixUIGridSection } from '@remix-ui/remix-ui-grid-section' +import { RemixUIGridCell } from '@remix-ui/remix-ui-grid-cell' +import type { TemplateGroup } from '@remix-ui/workspace' + +//@ts-ignore +const _paq = (window._paq = window._paq || []) + +const profile = { + name: 'templateSelection', + displayName: 'Template Selection', + description: 'templateSelection', + location: 'mainPanel', + methods: [], + events: [] +} + +export class TemplatesSelection extends ViewPlugin { + templates: Array + dispatch: React.Dispatch = () => { } + constructor() { + super(profile) + } + + async onActivation() { + this.handleThemeChange() + await this.call('tabs', 'focus', 'remixGuide') + this.renderComponent() + _paq.push(['trackEvent', 'plugin', 'activated', 'remixGuide']) + } + + onDeactivation(): void { + } + + private handleThemeChange() { + this.on('theme', 'themeChanged', (theme: any) => { + this.renderComponent() + }) + } + + setDispatch(dispatch: React.Dispatch): void { + this.dispatch = dispatch + this.renderComponent() + } + + render() { + return ( +
+ +
+ ) + } + + renderComponent() { + this.dispatch({ + ...this, + }) + } + + updateComponent() { + /* + const opts = { + // @ts-ignore: Object is possibly 'null'. + mintable: mintableCheckboxRef.current.checked, + // @ts-ignore: Object is possibly 'null'. + burnable: burnableCheckboxRef.current.checked, + // @ts-ignore: Object is possibly 'null'. + pausable: pausableCheckboxRef.current.checked, + // @ts-ignore: Object is possibly 'null'. + upgradeable: transparentRadioRef.current.checked ? transparentRadioRef.current.value : uupsRadioRef.current.checked ? uupsRadioRef.current.value : false + } + */ + this.templates = [ + { + name: "Generic", + items: [ + { value: "remixDefault", displayName: window._intl.formatMessage({id: 'filePanel.basic'}) }, + { value: "blank", displayName: window._intl.formatMessage({id: 'filePanel.blank'}) } + ] + }, + { + name: "OpenZeppelin", + items: [ + { + value: "ozerc20", + displayName: "ERC20" + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)" + }, + { + value: "ozerc1155", + displayName: "ERC1155" + }, + { + value: "ozerc20", + displayName: "ERC20", + opts: { + mintable: true + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + mintable: true + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + mintable: true + } + }, + { + value: "ozerc20", + displayName: "ERC20", + opts: { + mintable: true, + burnable: true + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + mintable: true, + burnable: true + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + mintable: true, + burnable: true + } + }, + { + value: "ozerc20", + displayName: "ERC20", + opts: { + mintable: true, + pausable: true + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + mintable: true, + pausable: true + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + mintable: true, + pausable: true + } + } + ] + }, + { + name: "OpenZeppelin Proxy", + items: [ + { + value: "ozerc20", + displayName: "ERC20", + opts: { + upgradeable: 'uups' + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + upgradeable: 'uups' + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + upgradeable: 'uups' + } + }, + { + value: "ozerc20", + displayName: "ERC20", + opts: { + upgradeable: 'uups', + mintable: true + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + upgradeable: 'uups', + mintable: true + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + upgradeable: 'uups', + mintable: true + } + }, + { + value: "ozerc20", + displayName: "ERC20", + opts: { + upgradeable: 'uups', + mintable: true, + burnable: true + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + upgradeable: 'uups', + mintable: true, + burnable: true + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + upgradeable: 'uups', + mintable: true, + burnable: true + } + }, + { + value: "ozerc20", + displayName: "ERC20", + opts: { + upgradeable: 'uups', + mintable: true, + pausable: true + } + }, + { + value: "ozerc721", + displayName: "ERC721 (NFT)", + opts: { + upgradeable: 'uups', + mintable: true, + pausable: true + } + }, + { + value: "ozerc1155", + displayName: "ERC1155", + opts: { + upgradeable: 'uups', + mintable: true, + pausable: true + } + } + ] + }, + { + name: "OxProject", + items: [ + { value: "zeroxErc20", displayName: "ERC20" } + ] + }, + { + name: "Gnosis Safe", + items: [ + { value: "gnosisSafeMultisig", displayName: window._intl.formatMessage({id: 'filePanel.multiSigWallet'}) } + ] + }, + { + name: "Circom ZKP", + items: [ + { value: "semaphore", displayName: window._intl.formatMessage({id: 'filePanel.semaphore'}) }, + { value: "hashchecker", displayName: window._intl.formatMessage({id: 'filePanel.hashchecker'}) }, + { value: "rln", displayName: window._intl.formatMessage({id: 'filePanel.rln'}) } + ] + }, + { + name: "Generic ZKP", + items: [ + { value: "sindriScripts", displayName: window._intl.formatMessage({id: 'filePanel.addscriptsindri'}) }, + ] + }, + { + name: "Uniswap V4", + items: [ + { value: "uniswapV4Template", displayName: window._intl.formatMessage({id: 'filePanel.uniswapV4Template'}) }, + { value: "breakthroughLabsUniswapv4Hooks", displayName: window._intl.formatMessage({id: 'filePanel.breakthroughLabsUniswapv4Hooks'}) }, + { value: "uniswapV4HookBookMultiSigSwapHook", displayName: window._intl.formatMessage({id: 'filePanel.uniswapV4HookBookMultiSigSwapHook'}) } + ] + }, + { + name: "Solidity CREATE2", + items: [ + { value: "contractCreate2Factory", displayName: window._intl.formatMessage({id: 'filePanel.addcreate2solidityfactory'}) }, + { value: "contractDeployerScripts", displayName: window._intl.formatMessage({id: 'filePanel.addscriptdeployer'}) } + ] + }, + { + name: "Contract Verification", + items: [ + { value: "etherscanScripts", displayName: window._intl.formatMessage({id: 'filePanel.addscriptetherscan'}) }, + ] + } + ] + + const createWorkspace = async (item) => { + const defaultName = await this.call('filePanel', 'getAvailableWorkspaceName', item.displayName) + + const username = await this.call('settings', 'get', 'settings/github-user-name') + const email = await this.call('settings', 'get', 'settings/github-email') + const gitNotSet = !username || !email + let workspaceName = defaultName + let initGit = true + const modal: AppModal = { + id: 'TemplatesSelection', + title: window._intl.formatMessage({id: !isElectron() ? 'filePanel.workspace.create': 'filePanel.workspace.create.desktop'}), + message: await createModalMessage(defaultName, gitNotSet, (value) => workspaceName = value, (value) => initGit = !!value), + okLabel: window._intl.formatMessage({id: !isElectron() ? 'filePanel.ok':'filePanel.selectFolder'}), + } + const modalResult = await this.call('notification', 'modal', modal) + if (!modalResult) return + this.emit('createWorkspaceReducerEvent', workspaceName, item.value, item.opts, false, (e, data) => { + if (e) { + const modal: AppModal = { + id: 'TemplatesSelection', + title: window._intl.formatMessage({id: !isElectron() ? 'filePanel.workspace.create': 'filePanel.workspace.create.desktop'}), + message: e.message, + okLabel: window._intl.formatMessage({id: 'filePanel.ok'}), + cancelLabel: window._intl.formatMessage({id: 'filePanel.cancel'}) + } + this.call('notification', 'modal', modal) + console.error(e) + } + + }, initGit) + } + + const addToExistingWorkspace = async (item) => { + this.emit('addTemplateToWorkspaceReducerEvent', item.value, item.opts, false, (e, data) => { + if (e) { + const modal: AppModal = { + id: 'TemplatesSelection', + title: window._intl.formatMessage({id: !isElectron() ? 'filePanel.workspace.create': 'filePanel.workspace.create.desktop'}), + message: e.message, + okLabel: window._intl.formatMessage({id: 'filePanel.ok'}), + cancelLabel: window._intl.formatMessage({id: 'filePanel.cancel'}) + } + this.call('notification', 'modal', modal) + console.error(e) + } + + }) + } + + return ( + + { + + this.templates.map(template => { + return + {template.items.map(item => { + return +
+ {item.displayName} + {JSON.stringify(item.opts)} +
+
+
+ })} +
+ })} +
+ ) + } + +} + +const createModalMessage = async ( + defaultName: string, + gitConfigNotSet: boolean, + onChangeTemplateName: (name: string) => void, + onChangeInitGit: (name: string) => void) => { + + return ( + <> + + onChangeTemplateName(e.target.value)} + /> +
+ onChangeInitGit(e.target.value)} + /> + +
+ {gitConfigNotSet ? ( +
+ +
+ ) : ( + <> + )} + + ) +} + diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index c9fe57ea97..c9ec33522d 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -155,6 +155,7 @@ export const createWorkspace = async ( await plugin.workspaceCreated(workspaceName) if (isGitRepo && createCommit) { + console.log('CREATE COMMIT') const name = await plugin.call('settings', 'get', 'settings/github-user-name') const email = await plugin.call('settings', 'get', 'settings/github-email') const currentBranch: branch = await dgitPlugin.call('dgitApi', 'currentbranch')