From 5fb1e492fb32e664364603c34044c3e573501781 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 14:33:30 -0700 Subject: Add valdations to txData param --- ui/app/send.js | 6 ++++++ ui/app/util.js | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'ui') diff --git a/ui/app/send.js b/ui/app/send.js index 97ed29e4a..d28a6433b 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -7,6 +7,7 @@ const actions = require('./actions') const util = require('./util') const numericBalance = require('./util').numericBalance const addressSummary = require('./util').addressSummary +const isHex = require('./util').isHex const EthBalance = require('./components/eth-balance') const ethUtil = require('ethereumjs-util') const RangeSlider = require('./components/range-slider') @@ -312,6 +313,11 @@ SendTransactionScreen.prototype.onSubmit = function (gasPrice) { return this.props.dispatch(actions.displayWarning(message)) } + if (!isHex(ethUtil.stripHexPrefix(txData)) && txData) { + message = 'Transaction data must be hex string.' + return this.props.dispatch(actions.displayWarning(message)) + } + this.props.dispatch(actions.hideWarning()) var txParams = { diff --git a/ui/app/util.js b/ui/app/util.js index e4b77e2bc..facaef3ee 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -35,6 +35,7 @@ module.exports = { normalizeNumberToWei: normalizeNumberToWei, valueTable: valueTable, bnTable: bnTable, + isHex: isHex, } function valuesFor (obj) { @@ -209,3 +210,8 @@ function readableDate (ms) { var time = `${hours}:${minutes.substr(-2)}:${seconds.substr(-2)}` return `${dateStr} ${time}` } + +function isHex (str) { + if (str.match(/[g-zG-Z]/) || str.match(/\W/)) return false + return true +} -- cgit v1.2.3 From ac7dca22c3a630d4623e44abe1e86d1cc51f3acc Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 17:39:41 -0700 Subject: Fix up wording --- ui/app/send.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/app/send.js b/ui/app/send.js index d28a6433b..b8af19028 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -191,7 +191,7 @@ SendTransactionScreen.prototype.render = function () { marginBottom: '16px', }, }, [ - 'Transactional Data (optional)', + 'Transaction Data (optional)', ]), // 'data' field -- cgit v1.2.3 From aa4746f4c723857710d61482a73960d863a8a098 Mon Sep 17 00:00:00 2001 From: Frankie Date: Wed, 19 Oct 2016 19:35:44 -0700 Subject: Add test and ability for isHex to handle hex strings with hex-prefix --- ui/app/util.js | 1 + 1 file changed, 1 insertion(+) (limited to 'ui') diff --git a/ui/app/util.js b/ui/app/util.js index facaef3ee..a519ab5b4 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -212,6 +212,7 @@ function readableDate (ms) { } function isHex (str) { + if (str.startsWith('0x')) str = str.replace('0x', '') if (str.match(/[g-zG-Z]/) || str.match(/\W/)) return false return true } -- cgit v1.2.3 From d79424e9c04fb409843c3a08b8f6eabc1036b7b6 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 21 Oct 2016 16:05:39 -0700 Subject: clean up the isHex function --- ui/app/util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/app/util.js b/ui/app/util.js index a519ab5b4..72b3af465 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -212,7 +212,8 @@ function readableDate (ms) { } function isHex (str) { - if (str.startsWith('0x')) str = str.replace('0x', '') - if (str.match(/[g-zG-Z]/) || str.match(/\W/)) return false - return true + if (str.startsWith('0x')) { + return !str.substring(2).match(/([g-zG-Z]|\W)/) + } + return !str.match(/([g-zG-Z]|\W)/) } -- cgit v1.2.3 From 7d9e295b759ccd1ca77e286651c3da71284631e3 Mon Sep 17 00:00:00 2001 From: Frankie Date: Fri, 21 Oct 2016 16:39:14 -0700 Subject: Change regex in isHex function --- ui/app/util.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/app/util.js b/ui/app/util.js index 72b3af465..7a56bf6a0 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -212,8 +212,5 @@ function readableDate (ms) { } function isHex (str) { - if (str.startsWith('0x')) { - return !str.substring(2).match(/([g-zG-Z]|\W)/) - } - return !str.match(/([g-zG-Z]|\W)/) + return Boolean(str.match(/^(0x)?[0-9a-fA-F]+$/)) } -- cgit v1.2.3