aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-03-08 02:37:31 +0800
committerKevin Serrano <kevgagser@gmail.com>2017-03-08 02:37:31 +0800
commit08ca7dac5a15e104084c6da3eb6015136b316809 (patch)
tree3e0b1a61f3be3aa1e01824512b4df0a793dc6a17
parent01f2ec4823e83d986e7ecfd268f6b293f38a13e8 (diff)
parent2acf991b67bc42fb904ff77af6ff6a7ca3a683fd (diff)
downloadtangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.tar
tangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.tar.gz
tangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.tar.bz2
tangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.tar.lz
tangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.tar.xz
tangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.tar.zst
tangerine-wallet-browser-08ca7dac5a15e104084c6da3eb6015136b316809.zip
Merge branch 'master' into i1144-moarrpc
-rw-r--r--app/scripts/lib/personal-message-manager.js22
-rw-r--r--app/scripts/metamask-controller.js8
-rw-r--r--app/scripts/transaction-manager.js2
-rw-r--r--package.json2
-rw-r--r--test/unit/components/binary-renderer-test.js25
-rw-r--r--test/unit/personal-message-manager-test.js23
-rw-r--r--ui/app/components/binary-renderer.js43
-rw-r--r--ui/app/components/hex-as-decimal-input.js14
-rw-r--r--ui/app/components/pending-personal-msg-details.js14
-rw-r--r--ui/app/components/pending-tx-details.js29
-rw-r--r--ui/app/components/pending-tx.js34
11 files changed, 160 insertions, 56 deletions
diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js
index 3b8510767..bbc978446 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 ethUtil.addHexPrefix(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/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index ab55ed697..f6dbf899d 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -415,14 +415,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')
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",
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..77e1656c5 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, '0x68656c6c6f', 'predictably hex encoded')
+ })
+
+ it('tolerates a hex prefix', function() {
+ var input = '0x12'
+ var output = messageManager.normalizeMsgData(input)
+ assert.equal(output, '0x12', 'un modified')
+ })
+
+ it('tolerates normal hex', function() {
+ var input = '12'
+ var output = messageManager.normalizeMsgData(input)
+ assert.equal(output, '0x12', 'adds prefix')
+ })
+ })
+
})
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/hex-as-decimal-input.js b/ui/app/components/hex-as-decimal-input.js
index 523c1264b..c89ed0416 100644
--- a/ui/app/components/hex-as-decimal-input.js
+++ b/ui/app/components/hex-as-decimal-input.js
@@ -39,15 +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',
+
}, style),
value: decimalValue,
onChange: (event) => {
- const hexString = hexify(event.target.value)
+ const hexString = (event.target.value === '') ? '' : hexify(event.target.value)
onChange(hexString)
},
}),
@@ -70,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-personal-msg-details.js b/ui/app/components/pending-personal-msg-details.js
index ffd11ca0b..fa2c6416c 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
@@ -41,18 +42,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 }),
]),
])
diff --git a/ui/app/components/pending-tx-details.js b/ui/app/components/pending-tx-details.js
index b1ab9576b..e92ce575f 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 })
},
}),
]),
@@ -316,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, {
@@ -330,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 d39cbc0f8..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 () {
@@ -60,25 +68,31 @@ 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,
+ 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', {
onClick: props.cancelTransaction,
}, 'Reject'),
-
- h('button', {
- onClick: () => {
- this.refs.details.resetGasFields()
- },
- }, 'Reset'),
]),
])
)