1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

Fix network-form block explorer URL validation (#7137)

This commit is contained in:
Sunghee Lee 2019-09-10 11:51:05 +09:00 committed by Mark Stacey
parent 7af902e500
commit 869c83fd2c

View File

@ -222,6 +222,17 @@ export default class NetworkForm extends PureComponent {
}
}
validateBlockExplorerUrl = (url, stateKey) => {
if (url === '' || validUrl.isWebUri(url)) {
this.setErrorTo(stateKey, '')
} else {
const appendedRpc = `http://${url}`
const validWhenAppended = validUrl.isWebUri(appendedRpc) && !url.match(/^https?:\/\/$/)
this.setErrorTo(stateKey, this.context.t(validWhenAppended ? 'uriErrorMsg' : 'invalidRPC'))
}
}
render () {
const { t } = this.context
const {
@ -272,7 +283,7 @@ export default class NetworkForm extends PureComponent {
{this.renderFormTextField(
'blockExplorerUrl',
'block-explorer-url',
this.setStateWithValue('blockExplorerUrl', this.validateUrl),
this.setStateWithValue('blockExplorerUrl', this.validateBlockExplorerUrl),
blockExplorerUrl,
'optionalBlockExplorerUrl',
)}