diff --git a/ui/app/pages/settings/networks-tab/network-form/network-form.component.js b/ui/app/pages/settings/networks-tab/network-form/network-form.component.js index 0349aa14f..ad199a701 100644 --- a/ui/app/pages/settings/networks-tab/network-form/network-form.component.js +++ b/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', )}