From 572980402d9c9f0cf92554ef616707554236c728 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 20 Dec 2016 16:41:04 -0800 Subject: [PATCH 1/3] Validate URIs before entering them in. --- package.json | 1 + ui/app/config.js | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a4b0ad676..4c33ad9ab 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "textarea-caret": "^3.0.1", "three.js": "^0.73.2", "through2": "^2.0.1", + "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "0.17.0-beta", "web3-provider-engine": "^8.1.14", diff --git a/ui/app/config.js b/ui/app/config.js index 3730baf6b..bd828b3d5 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 From aea263a80d373841f89cd1ef895b80781d2f78f7 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 20 Dec 2016 16:45:22 -0800 Subject: [PATCH 2/3] Lint. --- app/scripts/notice-controller.js | 22 +++++++++++----------- ui/app/config.js | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index 438f5c27e..00c87c670 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -9,7 +9,7 @@ module.exports = class NoticeController extends EventEmitter { this.noticePoller = null } - getState() { + getState () { var lastUnreadNotice = this.getLatestUnreadNotice() return { @@ -18,7 +18,7 @@ module.exports = class NoticeController extends EventEmitter { } } - getNoticesList() { + getNoticesList () { var data = this.configManager.getData() if ('noticesList' in data) { return data.noticesList @@ -27,28 +27,28 @@ module.exports = class NoticeController extends EventEmitter { } } - setNoticesList(list) { + setNoticesList (list) { var data = this.configManager.getData() data.noticesList = list this.configManager.setData(data) return Promise.resolve(true) } - markNoticeRead(notice, cb) { - cb = cb || function(err){ if (err) throw err } + markNoticeRead (notice, cb) { + cb = cb || function (err) { if (err) throw err } try { var notices = this.getNoticesList() var id = notice.id notices[id].read = true this.setNoticesList(notices) - let latestNotice = this.getLatestUnreadNotice() + const latestNotice = this.getLatestUnreadNotice() cb(null, latestNotice) } catch (err) { cb(err) } } - updateNoticesList() { + updateNoticesList () { return this._retrieveNoticeData().then((newNotices) => { var oldNotices = this.getNoticesList() var combinedNotices = this._mergeNotices(oldNotices, newNotices) @@ -56,7 +56,7 @@ module.exports = class NoticeController extends EventEmitter { }) } - getLatestUnreadNotice() { + getLatestUnreadNotice () { var notices = this.getNoticesList() var filteredNotices = notices.filter((notice) => { return notice.read === false @@ -73,7 +73,7 @@ module.exports = class NoticeController extends EventEmitter { }, 300000) } - _mergeNotices(oldNotices, newNotices) { + _mergeNotices (oldNotices, newNotices) { var noticeMap = this._mapNoticeIds(oldNotices) newNotices.forEach((notice) => { if (noticeMap.indexOf(notice.id) === -1) { @@ -83,11 +83,11 @@ module.exports = class NoticeController extends EventEmitter { return oldNotices } - _mapNoticeIds(notices) { + _mapNoticeIds (notices) { return notices.map((notice) => notice.id) } - _retrieveNoticeData() { + _retrieveNoticeData () { // Placeholder for the API. return Promise.resolve(hardCodedNotices) } diff --git a/ui/app/config.js b/ui/app/config.js index bd828b3d5..65b1ed712 100644 --- a/ui/app/config.js +++ b/ui/app/config.js @@ -10,7 +10,7 @@ module.exports = connect(mapStateToProps)(ConfigScreen) function mapStateToProps (state) { return { metamask: state.metamask, - warning: state.appState.warning + warning: state.appState.warning, } } From 91105474655a3e17eefbc3663928f6ca5bb6b71c Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 20 Dec 2016 16:45:30 -0800 Subject: [PATCH 3/3] Add to changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0f22779c..cf478a8a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## 2.14.1 2016-12-20 - Temporarily disable extension reload detection causing infinite reload bug. +- Implemented basic checking for valid RPC URIs. ## 2.14.0 2016-12-16