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

feature/default_network_editable
Sunghee Lee 5 years ago committed by Mark Stacey
parent 7af902e500
commit 869c83fd2c
  1. 13
      ui/app/pages/settings/networks-tab/network-form/network-form.component.js

@ -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',
)}

Loading…
Cancel
Save