Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional rpcUrl verification #7436

Merged
merged 9 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1468,8 +1468,11 @@
"updatedWithDate": {
"message": "Updated $1"
},
"uriErrorMsg": {
"message": "URIs require the appropriate HTTP/HTTPS prefix."
"urlErrorMsg": {
"message": "URLs require the appropriate HTTP/HTTPS prefix."
},
"urlExistsErrorMsg": {
"message": "URL is already present in existing list of networks"
},
"usedByClients": {
"message": "Used by a variety of different clients"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class NetworkForm extends PureComponent {
isCurrentRpcTarget: PropTypes.bool,
blockExplorerUrl: PropTypes.string,
rpcPrefs: PropTypes.object,
rpcUrls: PropTypes.array,
}

state = {
Expand Down Expand Up @@ -212,6 +213,7 @@ export default class NetworkForm extends PureComponent {
}

validateUrl = (url, stateKey) => {
const { rpcUrls } = this.props
const invalidUrlErrorMsg = stateKey === 'rpcUrl' ? 'invalidRPC' : 'invalidBlockExplorerURL'

if (validUrl.isWebUri(url) || (stateKey === 'blockExplorerUrl' && url === '')) {
Expand All @@ -220,7 +222,11 @@ export default class NetworkForm extends PureComponent {
const appendedRpc = `http://${url}`
const validWhenAppended = validUrl.isWebUri(appendedRpc) && !url.match(/^https?:\/\/$/)

this.setErrorTo(stateKey, this.context.t(validWhenAppended ? 'uriErrorMsg' : invalidUrlErrorMsg))
this.setErrorTo(stateKey, this.context.t(validWhenAppended ? 'urlErrorMsg' : invalidUrlErrorMsg))
}

if (rpcUrls.includes(url)) {
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
this.setErrorTo(stateKey, this.context.t('urlExistsErrorMsg'))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class NetworksTab extends PureComponent {
location: PropTypes.object.isRequired,
networkIsSelected: PropTypes.bool,
networksTabIsInAddMode: PropTypes.bool,
networksToRender: PropTypes.array.isRequired,
networksToRender: PropTypes.arrayOf(PropTypes.object).isRequired,
selectedNetwork: PropTypes.object,
setNetworksTabAddMode: PropTypes.func.isRequired,
setRpcTarget: PropTypes.func.isRequired,
Expand Down Expand Up @@ -177,6 +177,7 @@ export default class NetworksTab extends PureComponent {
editRpc,
networkDefaultedToProvider,
providerUrl,
networksToRender,
} = this.props

const envIsPopup = getEnvironmentType() === ENVIRONMENT_TYPE_POPUP
Expand All @@ -189,6 +190,7 @@ export default class NetworksTab extends PureComponent {
shouldRenderNetworkForm
? (
<NetworkForm
rpcUrls={networksToRender.map(network => network.rpcUrl)}
setRpcTarget={setRpcTarget}
editRpc={editRpc}
networkName={label || labelKey && t(labelKey) || ''}
Expand Down