aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan Finlay <flyswatter@users.noreply.github.com>2016-12-22 04:04:05 +0800
committerGitHub <noreply@github.com>2016-12-22 04:04:05 +0800
commit73cdf0bfd49470bad1f0da4d0d894278c87af54e (patch)
treecf6d02769508e734336f388f6b2a1d7d5230e27f /ui
parent674b2689826c770092a3dfee7fe76fb83c0b444a (diff)
parent91105474655a3e17eefbc3663928f6ca5bb6b71c (diff)
downloadtangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.tar
tangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.tar.gz
tangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.tar.bz2
tangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.tar.lz
tangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.tar.xz
tangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.tar.zst
tangerine-wallet-browser-73cdf0bfd49470bad1f0da4d0d894278c87af54e.zip
Merge pull request #944 from MetaMask/i938-uri-validation
I938 uri validation
Diffstat (limited to 'ui')
-rw-r--r--ui/app/config.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/ui/app/config.js b/ui/app/config.js
index 3730baf6b..65b1ed712 100644
--- a/ui/app/config.js
+++ b/ui/app/config.js
@@ -4,11 +4,13 @@ const h = require('react-hyperscript')
const connect = require('react-redux').connect
const actions = require('./actions')
const currencies = require('./conversion.json').rows
+const validUrl = require('valid-url')
module.exports = connect(mapStateToProps)(ConfigScreen)
function mapStateToProps (state) {
return {
metamask: state.metamask,
+ warning: state.appState.warning,
}
}
@@ -20,6 +22,7 @@ function ConfigScreen () {
ConfigScreen.prototype.render = function () {
var state = this.props
var metamaskState = state.metamask
+ var warning = state.warning
return (
h('.flex-column.flex-grow', [
@@ -34,6 +37,14 @@ ConfigScreen.prototype.render = function () {
h('h2.page-subtitle', 'Settings'),
]),
+ h('.error', {
+ style: {
+ display: warning ? 'block' : 'none',
+ padding: '0 20px',
+ textAlign: 'center',
+ },
+ }, warning),
+
// conf view
h('.flex-column.flex-justify-center.flex-grow.select-none', [
h('.flex-space-around', {
@@ -57,7 +68,7 @@ ConfigScreen.prototype.render = function () {
if (event.key === 'Enter') {
var element = event.target
var newRpc = element.value
- state.dispatch(actions.setRpcTarget(newRpc))
+ rpcValidation(newRpc, state)
}
},
}),
@@ -69,7 +80,7 @@ ConfigScreen.prototype.render = function () {
event.preventDefault()
var element = document.querySelector('input#new_rpc')
var newRpc = element.value
- state.dispatch(actions.setRpcTarget(newRpc))
+ rpcValidation(newRpc, state)
},
}, 'Save'),
]),
@@ -99,6 +110,19 @@ ConfigScreen.prototype.render = function () {
)
}
+function rpcValidation (newRpc, state) {
+ if (validUrl.isWebUri(newRpc)) {
+ state.dispatch(actions.setRpcTarget(newRpc))
+ } else {
+ var appendedRpc = `http://${newRpc}`
+ if (validUrl.isWebUri(appendedRpc)) {
+ state.dispatch(actions.displayWarning('URIs require the appropriate HTTP/HTTPS prefix.'))
+ } else {
+ state.dispatch(actions.displayWarning('Invalid RPC URI'))
+ }
+ }
+}
+
function currentConversionInformation (metamaskState, state) {
var currentFiat = metamaskState.currentFiat
var conversionDate = metamaskState.conversionDate