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 4bea2e1c6f7..6932ae3e048 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/filePanel.json +++ b/apps/remix-ide/src/app/tabs/locales/en/filePanel.json @@ -27,12 +27,6 @@ "filePanel.workspace.clone": "Clone Git Repository", "filePanel.workspace.cloneMessage": "Please provide a valid git repository url.", "filePanel.workspace.enterGitUrl": "Enter git repository url", - "filePanel.workspace.enterCorsproxyUrl": "Enter cors proxy url, default to be https://corsproxy.remixproject.org/", - "filePanel.workspace.gitRepoUrl": "Git Repo Url:", - "filePanel.workspace.corsProxyUrl": "Cors Proxy Url (Optional):", - "filePanel.workspace.corsproxyText1": "Note: To run CorsProxy on your system, run:", - "filePanel.workspace.corsproxyText2": "Note: Cors Proxy Url must be end with /, such as http://127.0.0.1:9999/", - "filePanel.workspace.corsproxyText3": "For more info, visit: CorsProxy Documentation", "filePanel.workspace.switch": "Switch To Workspace", "filePanel.workspace.solghaction": "Adds a preset yml file to run solidity unit tests on github actions CI.", "filePanel.solghaction": "Solidity Test Workflow", diff --git a/apps/remix-ide/src/app/tabs/locales/en/settings.json b/apps/remix-ide/src/app/tabs/locales/en/settings.json index 7cad9c14120..83465e2d25a 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/settings.json +++ b/apps/remix-ide/src/app/tabs/locales/en/settings.json @@ -36,6 +36,12 @@ "settings.email": "EMAIL", "settings.deleteGithubCredentials": "Delete Github Credentials", "settings.deleteGitlabCredentials": "Delete Gitlab Credentials", + "settings.url": "URL", + "settings.deleteCorsproxy": "Delete Cors Proxy", + "settings.corsproxyTitle": "Cors Proxy for Git", + "settings.corsproxyText": "Cors Proxy is used to proxy git requests, such as clone, push, pull etc. Follow the commands below to start your own service:", + "settings.corsproxyText2": "Cors Proxy Url must be end with /, default to be https://corsproxy.remixproject.org/", + "settings.corsproxyText3": "For more info, visit: CorsProxy Documentation", "settings.privateBeeAddress": "PRIVATE BEE ADDRESS", "settings.postageStampID": "POSTAGE STAMP ID", "settings.host": "HOST", diff --git a/libs/remix-ui/settings/src/lib/corsproxy-settings.tsx b/libs/remix-ui/settings/src/lib/corsproxy-settings.tsx new file mode 100644 index 00000000000..b64d6a86aba --- /dev/null +++ b/libs/remix-ui/settings/src/lib/corsproxy-settings.tsx @@ -0,0 +1,82 @@ +import {CopyToClipboard} from '@remix-ui/clipboard' +import {CustomTooltip} from '@remix-ui/helper' +import React, {useEffect, useState} from 'react' +import {FormattedMessage, useIntl} from 'react-intl' +import {CorsproxySettingsProps} from '../types' + +export function CorsproxySettings(props: CorsproxySettingsProps) { + const [url, setUrl] = useState('') + const intl = useIntl() + + useEffect(() => { + if (props.config) { + const url = props.config.get('settings/corsproxy-url') || 'https://corsproxy.remixproject.org/' + + setUrl(url) + } + }, [props.config]) + + const handleChangeUrlState = (event) => { + setUrl(event.target.value) + } + + const saveCorsproxy = () => { + props.saveCorsproxy(url) + } + + const removeToken = () => { + setUrl('') + props.removeCorsproxy() + } + + return ( +
+
+
+ +
+ +
+ npm install -g @drafish/cors-proxy +
+
+ cors-proxy start +
+
+ +
+
+ ( + + {chunks} + + ) + }} + /> +
+ +
+ +
+ handleChangeUrlState(e)} value={url} /> +
+ + } tooltipClasses="text-nowrap" tooltipId="removecorsproxyTooltip" placement="top-start"> + + +
+
+
+
+
+ ) +} diff --git a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx index 6d04f71fcfc..95ba9286b32 100644 --- a/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx +++ b/libs/remix-ui/settings/src/lib/remix-ui-settings.tsx @@ -17,6 +17,8 @@ import { useMatomoAnalytics, saveTokenToast, removeTokenToast, + saveCorsproxyToast, + removeCorsproxyToast, saveSwarmSettingsToast, saveIpfsSettingsToast, useAutoCompletion, @@ -31,6 +33,7 @@ import { RemixUiLocaleModule, LocaleModule } from '@remix-ui/locale-module' import { FormattedMessage, useIntl } from 'react-intl' import { GithubSettings } from './github-settings' import { GitlabSettings } from './gitlab-settings' +import { CorsproxySettings } from './corsproxy-settings' import { EtherscanSettings } from './etherscan-settings' import { SindriSettings } from './sindri-settings' @@ -605,6 +608,15 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => { }} config={props.config} /> + { + saveCorsproxyToast(props.config, dispatchToast, url, 'corsproxy-url') + }} + removeCorsproxy={() => { + removeCorsproxyToast(props.config, dispatchToast, 'corsproxy-url') + }} + config={props.config} + /> { saveTokenToast(props.config, dispatchToast, etherscanToken, 'etherscan-access-token') diff --git a/libs/remix-ui/settings/src/lib/settingsAction.ts b/libs/remix-ui/settings/src/lib/settingsAction.ts index 22110f8cb9a..c277df26152 100644 --- a/libs/remix-ui/settings/src/lib/settingsAction.ts +++ b/libs/remix-ui/settings/src/lib/settingsAction.ts @@ -76,6 +76,16 @@ export const removeTokenToast = (config, dispatch, key) => { dispatch({ type: 'removed', payload: { message: 'Credentials removed' } }) } +export const saveCorsproxyToast = (config, dispatch, value, key) => { + config.set('settings/' + key, value) + dispatch({ type: 'save', payload: { message: 'Corsproxy updated' } }) +} + +export const removeCorsproxyToast = (config, dispatch, key) => { + config.set('settings/' + key, '') + dispatch({ type: 'removed', payload: { message: 'Corsproxy removed' } }) +} + export const saveSwarmSettingsToast = (config, dispatch, privateBeeAddress, postageStampId) => { config.set('settings/swarm-private-bee-address', privateBeeAddress) config.set('settings/swarm-postage-stamp-id', postageStampId) diff --git a/libs/remix-ui/settings/src/types/index.ts b/libs/remix-ui/settings/src/types/index.ts index 3b25907d202..8b5f355347d 100644 --- a/libs/remix-ui/settings/src/types/index.ts +++ b/libs/remix-ui/settings/src/types/index.ts @@ -11,6 +11,19 @@ export interface GithubSettingsProps { } } +export interface CorsproxySettingsProps { + saveCorsproxy: (url: string) => void, + removeCorsproxy: () => void, + config: { + exists: (key: string) => boolean, + get: (key: string) => string, + set: (key: string, content: string) => void, + clear: () => void, + getUnpersistedProperty: (key: string) => void, + setUnpersistedProperty: (key: string, value: string) => void + } +} + export interface EtherscanSettingsProps { saveToken: (etherscanToken: string) => void, removeToken: () => void, 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 51c19f8019c..03d807808a0 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -46,8 +46,6 @@ export function Workspace() { const workspaceCreateTemplateInput = useRef() const intl = useIntl() const cloneUrlRef = useRef() - const config = global.plugin.registry.get('config').api - const corsproxyUrlRef = useRef() const initGitRepoRef = useRef() const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter((branch) => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : [] const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null @@ -557,9 +555,6 @@ export function Workspace() { const handleTypingUrl = () => { const url = cloneUrlRef.current.value - const corsproxy = corsproxyUrlRef.current.value - config.set('corsproxy', corsproxy) - if (url) { global.dispatchCloneRepository(url) } else { @@ -1046,7 +1041,6 @@ export function Workspace() { const cloneModalMessage = () => { return ( <> -
-
- -
- -
- npm install -g @drafish/cors-proxy -
-
- cors-proxy start -
-
- -
-
- ( - - {chunks} - - ) - }} - /> -
-
) }