Skip to content

Commit d0d09ae

Browse files
committed
move custom cors-proxy to settings
1 parent bc12e43 commit d0d09ae

File tree

7 files changed

+123
-49
lines changed

7 files changed

+123
-49
lines changed

apps/remix-ide/src/app/tabs/locales/en/filePanel.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727
"filePanel.workspace.clone": "Clone Git Repository",
2828
"filePanel.workspace.cloneMessage": "Please provide a valid git repository url.",
2929
"filePanel.workspace.enterGitUrl": "Enter git repository url",
30-
"filePanel.workspace.enterCorsproxyUrl": "Enter cors proxy url, default to be https://corsproxy.remixproject.org/",
31-
"filePanel.workspace.gitRepoUrl": "Git Repo Url:",
32-
"filePanel.workspace.corsProxyUrl": "Cors Proxy Url (Optional):",
33-
"filePanel.workspace.corsproxyText1": "Note: To run CorsProxy on your system, run:",
34-
"filePanel.workspace.corsproxyText2": "Note: Cors Proxy Url must be end with /, such as http://127.0.0.1:9999/",
35-
"filePanel.workspace.corsproxyText3": "For more info, visit: <a>CorsProxy Documentation</a>",
3630
"filePanel.workspace.switch": "Switch To Workspace",
3731
"filePanel.workspace.solghaction": "Adds a preset yml file to run solidity unit tests on github actions CI.",
3832
"filePanel.solghaction": "Solidity Test Workflow",

apps/remix-ide/src/app/tabs/locales/en/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
"settings.email": "EMAIL",
3434
"settings.deleteGithubCredentials": "Delete Github Credentials",
3535
"settings.deleteGitlabCredentials": "Delete Gitlab Credentials",
36+
"settings.url": "URL",
37+
"settings.deleteCorsproxy": "Delete Cors Proxy",
38+
"settings.corsproxyTitle": "Cors Proxy for Git",
39+
"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:",
40+
"settings.corsproxyText2": "Cors Proxy Url must be end with /, default to be https://corsproxy.remixproject.org/",
41+
"settings.corsproxyText3": "For more info, visit: <a>CorsProxy Documentation</a>",
3642
"settings.privateBeeAddress": "PRIVATE BEE ADDRESS",
3743
"settings.postageStampID": "POSTAGE STAMP ID",
3844
"settings.host": "HOST",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import {CopyToClipboard} from '@remix-ui/clipboard'
2+
import {CustomTooltip} from '@remix-ui/helper'
3+
import React, {useEffect, useState} from 'react'
4+
import {FormattedMessage, useIntl} from 'react-intl'
5+
import {CorsproxySettingsProps} from '../types'
6+
7+
export function CorsproxySettings(props: CorsproxySettingsProps) {
8+
const [url, setUrl] = useState<string>('')
9+
const intl = useIntl()
10+
11+
useEffect(() => {
12+
if (props.config) {
13+
const url = props.config.get('settings/corsproxy-url') || 'https://corsproxy.remixproject.org/'
14+
15+
setUrl(url)
16+
}
17+
}, [props.config])
18+
19+
const handleChangeUrlState = (event) => {
20+
setUrl(event.target.value)
21+
}
22+
23+
const saveCorsproxy = () => {
24+
props.saveCorsproxy(url)
25+
}
26+
27+
const removeToken = () => {
28+
setUrl('')
29+
props.removeCorsproxy()
30+
}
31+
32+
return (
33+
<div className="border-top">
34+
<div className="card-body pt-3 pb-2">
35+
<h6 className="card-title">
36+
<FormattedMessage id="settings.corsproxyTitle" />
37+
</h6>
38+
<FormattedMessage id="settings.corsproxyText" />
39+
<div className="p-1 pl-3">
40+
<b>npm install -g @drafish/cors-proxy</b>
41+
</div>
42+
<div className="p-1 pl-3">
43+
<b>cors-proxy start</b>
44+
</div>
45+
<div className="pt-2">
46+
<FormattedMessage
47+
id="settings.corsproxyText2"
48+
/>
49+
</div>
50+
<div className="pt-2">
51+
<FormattedMessage
52+
id="settings.corsproxyText3"
53+
values={{
54+
a: (chunks) => (
55+
<a href="https://github.com/drafish/cors-proxy" target="_blank">
56+
{chunks}
57+
</a>
58+
)
59+
}}
60+
/>
61+
</div>
62+
63+
<div>
64+
<label className="pt-2 mb-0 pb-0">
65+
<FormattedMessage id="settings.url" />:
66+
</label>
67+
<div className="text-secondary mb-0 h6">
68+
<input id="corsproxy" data-id="settingsTabCorsproxy" type="text" className="form-control" onChange={(e) => handleChangeUrlState(e)} value={url} />
69+
<div className="d-flex justify-content-end pt-2">
70+
<input className="btn btn-sm btn-primary ml-2" id="savecorsproxy" data-id="settingsTabSaveCorsproxy" onClick={saveCorsproxy} value={intl.formatMessage({id: 'settings.save'})} type="button"></input>
71+
<CustomTooltip tooltipText={<FormattedMessage id="settings.deleteCorsproxy" />} tooltipClasses="text-nowrap" tooltipId="removecorsproxyTooltip" placement="top-start">
72+
<button className="btn btn-sm btn-secondary ml-2" id="removecorsproxy" data-id="settingsTabRemoveCorsproxy" onClick={removeToken}>
73+
<FormattedMessage id="settings.remove" />
74+
</button>
75+
</CustomTooltip>
76+
</div>
77+
</div>
78+
</div>
79+
</div>
80+
</div>
81+
)
82+
}

libs/remix-ui/settings/src/lib/remix-ui-settings.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
useMatomoAnalytics,
1616
saveTokenToast,
1717
removeTokenToast,
18+
saveCorsproxyToast,
19+
removeCorsproxyToast,
1820
saveSwarmSettingsToast,
1921
saveIpfsSettingsToast,
2022
useAutoCompletion,
@@ -28,6 +30,7 @@ import {RemixUiLocaleModule, LocaleModule} from '@remix-ui/locale-module'
2830
import {FormattedMessage, useIntl} from 'react-intl'
2931
import {GithubSettings} from './github-settings'
3032
import {GitlabSettings} from './gitlab-settings'
33+
import {CorsproxySettings} from './corsproxy-settings'
3134
import {EtherscanSettings} from './etherscan-settings'
3235

3336
/* eslint-disable-next-line */
@@ -604,6 +607,15 @@ export const RemixUiSettings = (props: RemixUiSettingsProps) => {
604607
}}
605608
config={props.config}
606609
/>
610+
<CorsproxySettings
611+
saveCorsproxy={(url: string) => {
612+
saveCorsproxyToast(props.config, dispatchToast, url, 'corsproxy-url')
613+
}}
614+
removeCorsproxy={() => {
615+
removeCorsproxyToast(props.config, dispatchToast, 'corsproxy-url')
616+
}}
617+
config={props.config}
618+
/>
607619
<EtherscanSettings
608620
saveToken={(etherscanToken: string) => {
609621
saveTokenToast(props.config, dispatchToast, etherscanToken, 'etherscan-access-token')

libs/remix-ui/settings/src/lib/settingsAction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ export const removeTokenToast = (config, dispatch, key) => {
7676
dispatch({ type: 'removed', payload: { message: 'Credentials removed' } })
7777
}
7878

79+
export const saveCorsproxyToast = (config, dispatch, value, key) => {
80+
config.set('settings/' + key, value)
81+
dispatch({ type: 'save', payload: { message: 'Corsproxy updated' } })
82+
}
83+
84+
export const removeCorsproxyToast = (config, dispatch, key) => {
85+
config.set('settings/' + key, '')
86+
dispatch({ type: 'removed', payload: { message: 'Corsproxy removed' } })
87+
}
88+
7989
export const saveSwarmSettingsToast = (config, dispatch, privateBeeAddress, postageStampId) => {
8090
config.set('settings/swarm-private-bee-address', privateBeeAddress)
8191
config.set('settings/swarm-postage-stamp-id', postageStampId)

libs/remix-ui/settings/src/types/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ export interface GithubSettingsProps {
1111
}
1212
}
1313

14+
export interface CorsproxySettingsProps {
15+
saveCorsproxy: (url: string) => void,
16+
removeCorsproxy: () => void,
17+
config: {
18+
exists: (key: string) => boolean,
19+
get: (key: string) => string,
20+
set: (key: string, content: string) => void,
21+
clear: () => void,
22+
getUnpersistedProperty: (key: string) => void,
23+
setUnpersistedProperty: (key: string, value: string) => void
24+
}
25+
}
26+
1427
export interface EtherscanSettingsProps {
1528
saveToken: (etherscanToken: string) => void,
1629
removeToken: () => void,

libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ export function Workspace() {
4949
const workspaceCreateTemplateInput = useRef()
5050
const intl = useIntl()
5151
const cloneUrlRef = useRef<HTMLInputElement>()
52-
const config = global.plugin.registry.get('config').api
53-
const corsproxyUrlRef = useRef<HTMLInputElement>()
5452
const initGitRepoRef = useRef<HTMLInputElement>()
5553
const filteredBranches = selectedWorkspace ? (selectedWorkspace.branches || []).filter((branch) => branch.name.includes(branchFilter) && branch.name !== 'HEAD').slice(0, 20) : []
5654
const currentBranch = selectedWorkspace ? selectedWorkspace.currentBranch : null
@@ -426,9 +424,6 @@ export function Workspace() {
426424
const handleTypingUrl = () => {
427425
const url = cloneUrlRef.current.value
428426

429-
const corsproxy = corsproxyUrlRef.current.value
430-
config.set('corsproxy', corsproxy)
431-
432427
if (url) {
433428
global.dispatchCloneRepository(url)
434429
} else {
@@ -910,7 +905,6 @@ export function Workspace() {
910905
const cloneModalMessage = () => {
911906
return (
912907
<>
913-
<div><FormattedMessage id="filePanel.workspace.gitRepoUrl" /></div>
914908
<input
915909
type="text"
916910
data-id="modalDialogCustomPromptTextClone"
@@ -920,43 +914,6 @@ export function Workspace() {
920914
ref={cloneUrlRef}
921915
className="form-control"
922916
/>
923-
<div className="pt-4"><FormattedMessage id="filePanel.workspace.corsProxyUrl" /></div>
924-
<input
925-
type="text"
926-
data-id="modalDialogCustomPromptTextCorsproxy"
927-
placeholder={intl.formatMessage({
928-
id: 'filePanel.workspace.enterCorsproxyUrl'
929-
})}
930-
ref={corsproxyUrlRef}
931-
defaultValue={config.get('corsproxy')}
932-
className="form-control"
933-
/>
934-
<div className="pt-2">
935-
<FormattedMessage id="filePanel.workspace.corsproxyText1" />
936-
<div className="p-1 pl-3">
937-
<b>npm install -g @drafish/cors-proxy</b>
938-
</div>
939-
<div className="p-1 pl-3">
940-
<b>cors-proxy start</b>
941-
</div>
942-
<div className="pt-2">
943-
<FormattedMessage
944-
id="filePanel.workspace.corsproxyText2"
945-
/>
946-
</div>
947-
<div className="pt-2">
948-
<FormattedMessage
949-
id="filePanel.workspace.corsproxyText3"
950-
values={{
951-
a: (chunks) => (
952-
<a href="https://github.com/drafish/cors-proxy" target="_blank">
953-
{chunks}
954-
</a>
955-
)
956-
}}
957-
/>
958-
</div>
959-
</div>
960917
</>
961918
)
962919
}

0 commit comments

Comments
 (0)