From 5f378d382e008ef577223055c9674c25e2e6bba4 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 1 Mar 2017 13:01:23 -0800 Subject: Only allow numbers in gas inputs --- ui/app/components/hex-as-decimal-input.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/app/components/hex-as-decimal-input.js b/ui/app/components/hex-as-decimal-input.js index 523c1264b..ecf232640 100644 --- a/ui/app/components/hex-as-decimal-input.js +++ b/ui/app/components/hex-as-decimal-input.js @@ -44,6 +44,7 @@ HexAsDecimalInput.prototype.render = function () { textAlign: 'right', backgroundColor: 'transparent', border: '1px solid #bdbdbd', + type: 'number', }, style), value: decimalValue, onChange: (event) => { -- cgit v1.2.3 From 0ac1f749fd68244682d0f2c763028cdf6aa29486 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 1 Mar 2017 14:37:51 -0800 Subject: Various improvements to gas input. --- ui/app/components/hex-as-decimal-input.js | 15 ++++++++++----- ui/app/components/pending-tx-details.js | 18 ++++-------------- ui/app/components/pending-tx.js | 16 ++++++++-------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/ui/app/components/hex-as-decimal-input.js b/ui/app/components/hex-as-decimal-input.js index ecf232640..c89ed0416 100644 --- a/ui/app/components/hex-as-decimal-input.js +++ b/ui/app/components/hex-as-decimal-input.js @@ -39,16 +39,17 @@ HexAsDecimalInput.prototype.render = function () { }, }, [ h('input.ether-balance.ether-balance-amount', { + type: 'number', style: extend({ display: 'block', textAlign: 'right', backgroundColor: 'transparent', border: '1px solid #bdbdbd', - type: 'number', + }, style), value: decimalValue, onChange: (event) => { - const hexString = hexify(event.target.value) + const hexString = (event.target.value === '') ? '' : hexify(event.target.value) onChange(hexString) }, }), @@ -71,7 +72,11 @@ function hexify (decimalString) { } function decimalize (input, toEth) { - const strippedInput = ethUtil.stripHexPrefix(input) - const inputBN = new BN(strippedInput, 'hex') - return inputBN.toString(10) + if (input === '') { + return '' + } else { + const strippedInput = ethUtil.stripHexPrefix(input) + const inputBN = new BN(strippedInput, 'hex') + return inputBN.toString(10) + } } diff --git a/ui/app/components/pending-tx-details.js b/ui/app/components/pending-tx-details.js index b1ab9576b..fc8d65454 100644 --- a/ui/app/components/pending-tx-details.js +++ b/ui/app/components/pending-tx-details.js @@ -32,10 +32,8 @@ PTXP.render = function () { var account = props.accounts[address] var balance = account ? account.balance : '0x0' - const gas = state.gas || txParams.gas - const gasPrice = state.gasPrice || txData.gasPrice - const gasDefault = txParams.gas - const gasPriceDefault = txData.gasPrice + const gas = (state.gas === undefined) ? txParams.gas : state.gas + const gasPrice = (state.gasPrice === undefined) ? txData.gasPrice : state.gasPrice var txFee = state.txFee || txData.txFee || '' var maxCost = state.maxCost || txData.maxCost || '' @@ -131,11 +129,7 @@ PTXP.render = function () { }, onChange: (newHex) => { log.info(`Gas limit changed to ${newHex}`) - if (newHex === '0x0') { - this.setState({gas: gasDefault}) - } else { - this.setState({ gas: newHex }) - } + this.setState({ gas: newHex }) }, }), ]), @@ -155,11 +149,7 @@ PTXP.render = function () { }, onChange: (newHex) => { log.info(`Gas price changed to: ${newHex}`) - if (newHex === '0x0') { - this.setState({gasPrice: gasPriceDefault}) - } else { - this.setState({ gasPrice: newHex }) - } + this.setState({ gasPrice: newHex }) }, }), ]), diff --git a/ui/app/components/pending-tx.js b/ui/app/components/pending-tx.js index d39cbc0f8..ed366aa45 100644 --- a/ui/app/components/pending-tx.js +++ b/ui/app/components/pending-tx.js @@ -60,12 +60,18 @@ PendingTx.prototype.render = function () { }, [ props.insufficientBalance ? - h('button.btn-green', { + h('button', { onClick: props.buyEth, }, 'Buy Ether') : null, - h('button.confirm', { + h('button', { + onClick: () => { + this.refs.details.resetGasFields() + }, + }, 'Reset'), + + h('button.confirm.btn-green', { disabled: props.insufficientBalance, onClick: props.sendTransaction, }, 'Accept'), @@ -73,12 +79,6 @@ PendingTx.prototype.render = function () { h('button.cancel.btn-red', { onClick: props.cancelTransaction, }, 'Reject'), - - h('button', { - onClick: () => { - this.refs.details.resetGasFields() - }, - }, 'Reset'), ]), ]) ) -- cgit v1.2.3 From 72932bdcba10bd9d47724f271d0c14f84d12b759 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 1 Mar 2017 17:03:55 -0800 Subject: Prevent submission of invalid gas parameters. --- ui/app/components/pending-tx-details.js | 11 ++++++++++- ui/app/components/pending-tx.js | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ui/app/components/pending-tx-details.js b/ui/app/components/pending-tx-details.js index fc8d65454..e92ce575f 100644 --- a/ui/app/components/pending-tx-details.js +++ b/ui/app/components/pending-tx-details.js @@ -306,7 +306,6 @@ PTXP.gatherParams = function () { const state = this.state || {} const txData = state.txData || props.txData const txParams = txData.txParams - const gas = state.gas || txParams.gas const gasPrice = state.gasPrice || txParams.gasPrice const resultTx = extend(txParams, { @@ -320,6 +319,16 @@ PTXP.gatherParams = function () { return resultTxMeta } +PTXP.verifyGasParams = function () { + // We call this in case the gas has not been modified at all + if (!this.state) { return true } + return this._notZeroOrEmptyString(this.state.gas) && this._notZeroOrEmptyString(this.state.gasPrice) +} + +PTXP._notZeroOrEmptyString = function (obj) { + return obj !== '' && obj !== '0x0' +} + function forwardCarrat () { return ( diff --git a/ui/app/components/pending-tx.js b/ui/app/components/pending-tx.js index ed366aa45..2ab6f25a9 100644 --- a/ui/app/components/pending-tx.js +++ b/ui/app/components/pending-tx.js @@ -1,10 +1,18 @@ const Component = require('react').Component +const connect = require('react-redux').connect const h = require('react-hyperscript') const inherits = require('util').inherits const PendingTxDetails = require('./pending-tx-details') const extend = require('xtend') +const actions = require('../actions') -module.exports = PendingTx +module.exports = connect(mapStateToProps)(PendingTx) + +function mapStateToProps (state) { + return { + + } +} inherits(PendingTx, Component) function PendingTx () { @@ -73,7 +81,13 @@ PendingTx.prototype.render = function () { h('button.confirm.btn-green', { disabled: props.insufficientBalance, - onClick: props.sendTransaction, + onClick: (txData, event) => { + if (this.refs.details.verifyGasParams()) { + props.sendTransaction(txData, event) + } else { + this.props.dispatch(actions.displayWarning('Invalid Gas Parameters')) + } + }, }, 'Accept'), h('button.cancel.btn-red', { -- cgit v1.2.3 From 7d2019eac9706bc208c6aa5ea0ef3c4b4ee66e4b Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 6 Mar 2017 13:45:19 -0800 Subject: Fix personal sign for loose accounts Fix was written, but not published to npm. Now fixing semver at the correct version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1542853ad..0c4ca9096 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "eth-lightwallet": "^2.3.3", "eth-query": "^1.0.3", "eth-sig-util": "^1.1.1", - "eth-simple-keyring": "^1.1.0", + "eth-simple-keyring": "^1.1.1", "ethereumjs-tx": "^1.0.0", "ethereumjs-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9", "ethereumjs-wallet": "^0.6.0", -- cgit v1.2.3 From 9bd8c5f723abef25b8864457df7207eb361be8e3 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 6 Mar 2017 15:03:49 -0800 Subject: Render personal_sign messages as utf-8 text Calls to `personal_sign` are now: - When hex encoded, preserved as hex encoded, but displayed as utf-8 text. - When not hex encoded, decoded as utf-8 text as hex for signing. - The messages proposed for signing are displayed as UTF-8 text. - When the message cannot be rendered as UTF-8 text, it is displayed as hexadecimal. Fixes #1173 --- app/scripts/lib/personal-message-manager.js | 22 +++++++----- test/unit/components/binary-renderer-test.js | 25 +++++++++++++ test/unit/personal-message-manager-test.js | 23 +++++++++++- ui/app/components/binary-renderer.js | 43 +++++++++++++++++++++++ ui/app/components/pending-personal-msg-details.js | 15 ++------ 5 files changed, 107 insertions(+), 21 deletions(-) create mode 100644 test/unit/components/binary-renderer-test.js create mode 100644 ui/app/components/binary-renderer.js diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js index 3b8510767..04dba4a90 100644 --- a/app/scripts/lib/personal-message-manager.js +++ b/app/scripts/lib/personal-message-manager.js @@ -2,6 +2,7 @@ const EventEmitter = require('events') const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const createId = require('./random-id') +const hexRe = /^[0-9A-Fa-f]+$/g module.exports = class PersonalMessageManager extends EventEmitter{ @@ -24,7 +25,8 @@ module.exports = class PersonalMessageManager extends EventEmitter{ } addUnapprovedMessage (msgParams) { - msgParams.data = normalizeMsgData(msgParams.data) + log.debug(`PersonalMessageManager addUnapprovedMessage: ${JSON.stringify(msgParams)}`) + msgParams.data = this.normalizeMsgData(msgParams.data) // create txData obj with parameters and meta data var time = (new Date()).getTime() var msgId = createId() @@ -106,14 +108,18 @@ module.exports = class PersonalMessageManager extends EventEmitter{ this.emit('updateBadge') } -} + normalizeMsgData(data) { + try { + const stripped = ethUtil.stripHexPrefix(data) + if (stripped.match(hexRe)) { + return stripped + } + } catch (e) { + log.debug(`Message was not hex encoded, interpreting as utf8.`) + } -function normalizeMsgData(data) { - if (data.slice(0, 2) === '0x') { - // data is already hex - return data - } else { - // data is unicode, convert to hex return ethUtil.bufferToHex(new Buffer(data, 'utf8')) } + } + diff --git a/test/unit/components/binary-renderer-test.js b/test/unit/components/binary-renderer-test.js new file mode 100644 index 000000000..3264faddc --- /dev/null +++ b/test/unit/components/binary-renderer-test.js @@ -0,0 +1,25 @@ +var assert = require('assert') +var BinaryRenderer = require('../../../ui/app/components/binary-renderer') + +describe('BinaryRenderer', function() { + + let binaryRenderer + const message = 'Hello, world!' + const buffer = new Buffer(message, 'utf8') + const hex = buffer.toString('hex') + + beforeEach(function() { + binaryRenderer = new BinaryRenderer() + }) + + it('recovers message', function() { + const result = binaryRenderer.hexToText(hex) + assert.equal(result, message) + }) + + + it('recovers message with hex prefix', function() { + const result = binaryRenderer.hexToText('0x' + hex) + assert.equal(result, message) + }) +}) diff --git a/test/unit/personal-message-manager-test.js b/test/unit/personal-message-manager-test.js index 657d5e675..69d373ed3 100644 --- a/test/unit/personal-message-manager-test.js +++ b/test/unit/personal-message-manager-test.js @@ -4,7 +4,7 @@ const EventEmitter = require('events') const PersonalMessageManager = require('../../app/scripts/lib/personal-message-manager') -describe('Transaction Manager', function() { +describe('Personal Message Manager', function() { let messageManager beforeEach(function() { @@ -86,4 +86,25 @@ describe('Transaction Manager', function() { assert.equal(messageManager.getMsg('2').status, 'approved') }) }) + + describe('#normalizeMsgData', function() { + it('converts text to a utf8 buffer', function() { + var input = 'hello' + var output = messageManager.normalizeMsgdata(input) + assert.equal(output, '68656c6c6f', 'predictably hex encoded') + }) + + it('tolerates a hex prefix', function() { + var input = '0x12' + var output = messageManager.normalizeMsgdata(input) + assert.equal(output, '12', 'prefix stripped') + }) + + it('tolerates normal hex', function() { + var input = '12' + var output = messageManager.normalizeMsgdata(input) + assert.equal(output, '12', 'not modified') + }) + }) + }) diff --git a/ui/app/components/binary-renderer.js b/ui/app/components/binary-renderer.js new file mode 100644 index 000000000..a9d49b128 --- /dev/null +++ b/ui/app/components/binary-renderer.js @@ -0,0 +1,43 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits +const ethUtil = require('ethereumjs-util') + +module.exports = BinaryRenderer + +inherits(BinaryRenderer, Component) +function BinaryRenderer () { + Component.call(this) +} + +BinaryRenderer.prototype.render = function () { + const props = this.props + const { value } = props + const text = this.hexToText(value) + + return ( + h('textarea.font-small', { + readOnly: true, + style: { + width: '315px', + maxHeight: '210px', + resize: 'none', + border: 'none', + background: 'white', + padding: '3px', + }, + defaultValue: text, + }) + ) +} + +BinaryRenderer.prototype.hexToText = function (hex) { + try { + const stripped = ethUtil.stripHexPrefix(hex) + const buff = Buffer.from(stripped, 'hex') + return buff.toString('utf8') + } catch (e) { + return hex + } +} + diff --git a/ui/app/components/pending-personal-msg-details.js b/ui/app/components/pending-personal-msg-details.js index ffd11ca0b..afd04fc51 100644 --- a/ui/app/components/pending-personal-msg-details.js +++ b/ui/app/components/pending-personal-msg-details.js @@ -3,6 +3,7 @@ const h = require('react-hyperscript') const inherits = require('util').inherits const AccountPanel = require('./account-panel') +const BinaryRenderer = require('./binary-renderer') module.exports = PendingMsgDetails @@ -21,6 +22,7 @@ PendingMsgDetails.prototype.render = function () { var account = state.accounts[address] || { address: address } var { data } = msgParams + console.dir({ msgParams }) return ( h('div', { @@ -41,18 +43,7 @@ PendingMsgDetails.prototype.render = function () { // message data h('div', [ h('label.font-small', { style: { display: 'block' } }, 'MESSAGE'), - h('textarea.font-small', { - readOnly: true, - style: { - width: '315px', - maxHeight: '210px', - resize: 'none', - border: 'none', - background: 'white', - padding: '3px', - }, - defaultValue: data, - }), + h(BinaryRenderer, { value: data }), ]), ]) -- cgit v1.2.3 From af337dfae556cc3ac8739dc8337970147d74bb69 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 6 Mar 2017 15:17:45 -0800 Subject: Fix function names --- test/unit/personal-message-manager-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/personal-message-manager-test.js b/test/unit/personal-message-manager-test.js index 69d373ed3..5ee03726f 100644 --- a/test/unit/personal-message-manager-test.js +++ b/test/unit/personal-message-manager-test.js @@ -90,20 +90,20 @@ describe('Personal Message Manager', function() { describe('#normalizeMsgData', function() { it('converts text to a utf8 buffer', function() { var input = 'hello' - var output = messageManager.normalizeMsgdata(input) - assert.equal(output, '68656c6c6f', 'predictably hex encoded') + var output = messageManager.normalizeMsgData(input) + assert.equal(output, '0x68656c6c6f', 'predictably hex encoded') }) it('tolerates a hex prefix', function() { var input = '0x12' - var output = messageManager.normalizeMsgdata(input) - assert.equal(output, '12', 'prefix stripped') + var output = messageManager.normalizeMsgData(input) + assert.equal(output, '12', 'un modified') }) it('tolerates normal hex', function() { var input = '12' - var output = messageManager.normalizeMsgdata(input) - assert.equal(output, '12', 'not modified') + var output = messageManager.normalizeMsgData(input) + assert.equal(output, '12', 'adds prefix') }) }) -- cgit v1.2.3 From 26ea5993a9dffa687b50446bbffd0d2310a796bc Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 6 Mar 2017 15:36:16 -0800 Subject: Remove log --- ui/app/components/pending-personal-msg-details.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/app/components/pending-personal-msg-details.js b/ui/app/components/pending-personal-msg-details.js index afd04fc51..fa2c6416c 100644 --- a/ui/app/components/pending-personal-msg-details.js +++ b/ui/app/components/pending-personal-msg-details.js @@ -22,7 +22,6 @@ PendingMsgDetails.prototype.render = function () { var account = state.accounts[address] || { address: address } var { data } = msgParams - console.dir({ msgParams }) return ( h('div', { -- cgit v1.2.3 From b84f1b053265fdabc0aaec4fa8aa3145b6fb7f51 Mon Sep 17 00:00:00 2001 From: Frankie Date: Mon, 6 Mar 2017 15:41:11 -0800 Subject: Fix issue where old txMeta object was being used to pass the txHash to the cb --- app/scripts/metamask-controller.js | 8 ++++---- app/scripts/transaction-manager.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index bd01a260d..3dddf7065 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -414,14 +414,14 @@ module.exports = class MetamaskController extends EventEmitter { self.sendUpdate() self.opts.showUnapprovedTx(txMeta) // listen for tx completion (success, fail) - self.txManager.once(`${txMeta.id}:finished`, (status) => { - switch (status) { + self.txManager.once(`${txMeta.id}:finished`, (completedTx) => { + switch (completedTx.status) { case 'submitted': - return cb(null, txMeta.hash) + return cb(null, completedTx.hash) case 'rejected': return cb(new Error('MetaMask Tx Signature: User denied transaction signature.')) default: - return cb(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(txMeta.txParams)}`)) + return cb(new Error(`MetaMask Tx Signature: Unknown problem: ${JSON.stringify(completedTx.txParams)}`)) } }) }) diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js index 07c90af7e..c6cfdf11d 100644 --- a/app/scripts/transaction-manager.js +++ b/app/scripts/transaction-manager.js @@ -353,7 +353,7 @@ module.exports = class TransactionManager extends EventEmitter { txMeta.status = status this.emit(`${txMeta.id}:${status}`, txId) if (status === 'submitted' || status === 'rejected') { - this.emit(`${txMeta.id}:finished`, status) + this.emit(`${txMeta.id}:finished`, txMeta) } this.updateTx(txMeta) this.emit('updateBadge') -- cgit v1.2.3 From e66e755766ef318c38277c184d2670cc2179d37a Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 6 Mar 2017 16:33:33 -0800 Subject: Fix normalizeMsgData function to always return hex prefixed --- app/scripts/lib/personal-message-manager.js | 2 +- test/unit/personal-message-manager-test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js index 04dba4a90..bbc978446 100644 --- a/app/scripts/lib/personal-message-manager.js +++ b/app/scripts/lib/personal-message-manager.js @@ -112,7 +112,7 @@ module.exports = class PersonalMessageManager extends EventEmitter{ try { const stripped = ethUtil.stripHexPrefix(data) if (stripped.match(hexRe)) { - return stripped + return ethUtil.addHexPrefix(stripped) } } catch (e) { log.debug(`Message was not hex encoded, interpreting as utf8.`) diff --git a/test/unit/personal-message-manager-test.js b/test/unit/personal-message-manager-test.js index 5ee03726f..77e1656c5 100644 --- a/test/unit/personal-message-manager-test.js +++ b/test/unit/personal-message-manager-test.js @@ -97,13 +97,13 @@ describe('Personal Message Manager', function() { it('tolerates a hex prefix', function() { var input = '0x12' var output = messageManager.normalizeMsgData(input) - assert.equal(output, '12', 'un modified') + assert.equal(output, '0x12', 'un modified') }) it('tolerates normal hex', function() { var input = '12' var output = messageManager.normalizeMsgData(input) - assert.equal(output, '12', 'adds prefix') + assert.equal(output, '0x12', 'adds prefix') }) }) -- cgit v1.2.3