Merge pull request #1161 from MetaMask/Debugging

Tune up master
feature/default_network_editable
Dan Finlay 8 years ago committed by GitHub
commit f9b2c12dc3
  1. 14
      ui/app/components/hex-as-decimal-input.js
  2. 29
      ui/app/components/pending-tx-details.js
  3. 34
      ui/app/components/pending-tx.js

@ -39,15 +39,17 @@ HexAsDecimalInput.prototype.render = function () {
}, },
}, [ }, [
h('input.ether-balance.ether-balance-amount', { h('input.ether-balance.ether-balance-amount', {
type: 'number',
style: extend({ style: extend({
display: 'block', display: 'block',
textAlign: 'right', textAlign: 'right',
backgroundColor: 'transparent', backgroundColor: 'transparent',
border: '1px solid #bdbdbd', border: '1px solid #bdbdbd',
}, style), }, style),
value: decimalValue, value: decimalValue,
onChange: (event) => { onChange: (event) => {
const hexString = hexify(event.target.value) const hexString = (event.target.value === '') ? '' : hexify(event.target.value)
onChange(hexString) onChange(hexString)
}, },
}), }),
@ -70,7 +72,11 @@ function hexify (decimalString) {
} }
function decimalize (input, toEth) { function decimalize (input, toEth) {
const strippedInput = ethUtil.stripHexPrefix(input) if (input === '') {
const inputBN = new BN(strippedInput, 'hex') return ''
return inputBN.toString(10) } else {
const strippedInput = ethUtil.stripHexPrefix(input)
const inputBN = new BN(strippedInput, 'hex')
return inputBN.toString(10)
}
} }

@ -32,10 +32,8 @@ PTXP.render = function () {
var account = props.accounts[address] var account = props.accounts[address]
var balance = account ? account.balance : '0x0' var balance = account ? account.balance : '0x0'
const gas = state.gas || txParams.gas const gas = (state.gas === undefined) ? txParams.gas : state.gas
const gasPrice = state.gasPrice || txData.gasPrice const gasPrice = (state.gasPrice === undefined) ? txData.gasPrice : state.gasPrice
const gasDefault = txParams.gas
const gasPriceDefault = txData.gasPrice
var txFee = state.txFee || txData.txFee || '' var txFee = state.txFee || txData.txFee || ''
var maxCost = state.maxCost || txData.maxCost || '' var maxCost = state.maxCost || txData.maxCost || ''
@ -131,11 +129,7 @@ PTXP.render = function () {
}, },
onChange: (newHex) => { onChange: (newHex) => {
log.info(`Gas limit changed to ${newHex}`) log.info(`Gas limit changed to ${newHex}`)
if (newHex === '0x0') { this.setState({ gas: newHex })
this.setState({gas: gasDefault})
} else {
this.setState({ gas: newHex })
}
}, },
}), }),
]), ]),
@ -155,11 +149,7 @@ PTXP.render = function () {
}, },
onChange: (newHex) => { onChange: (newHex) => {
log.info(`Gas price changed to: ${newHex}`) log.info(`Gas price changed to: ${newHex}`)
if (newHex === '0x0') { this.setState({ gasPrice: newHex })
this.setState({gasPrice: gasPriceDefault})
} else {
this.setState({ gasPrice: newHex })
}
}, },
}), }),
]), ]),
@ -316,7 +306,6 @@ PTXP.gatherParams = function () {
const state = this.state || {} const state = this.state || {}
const txData = state.txData || props.txData const txData = state.txData || props.txData
const txParams = txData.txParams const txParams = txData.txParams
const gas = state.gas || txParams.gas const gas = state.gas || txParams.gas
const gasPrice = state.gasPrice || txParams.gasPrice const gasPrice = state.gasPrice || txParams.gasPrice
const resultTx = extend(txParams, { const resultTx = extend(txParams, {
@ -330,6 +319,16 @@ PTXP.gatherParams = function () {
return resultTxMeta 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 () { function forwardCarrat () {
return ( return (

@ -1,10 +1,18 @@
const Component = require('react').Component const Component = require('react').Component
const connect = require('react-redux').connect
const h = require('react-hyperscript') const h = require('react-hyperscript')
const inherits = require('util').inherits const inherits = require('util').inherits
const PendingTxDetails = require('./pending-tx-details') const PendingTxDetails = require('./pending-tx-details')
const extend = require('xtend') const extend = require('xtend')
const actions = require('../actions')
module.exports = PendingTx module.exports = connect(mapStateToProps)(PendingTx)
function mapStateToProps (state) {
return {
}
}
inherits(PendingTx, Component) inherits(PendingTx, Component)
function PendingTx () { function PendingTx () {
@ -60,25 +68,31 @@ PendingTx.prototype.render = function () {
}, [ }, [
props.insufficientBalance ? props.insufficientBalance ?
h('button.btn-green', { h('button', {
onClick: props.buyEth, onClick: props.buyEth,
}, 'Buy Ether') }, 'Buy Ether')
: null, : null,
h('button.confirm', { h('button', {
onClick: () => {
this.refs.details.resetGasFields()
},
}, 'Reset'),
h('button.confirm.btn-green', {
disabled: props.insufficientBalance, 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'), }, 'Accept'),
h('button.cancel.btn-red', { h('button.cancel.btn-red', {
onClick: props.cancelTransaction, onClick: props.cancelTransaction,
}, 'Reject'), }, 'Reject'),
h('button', {
onClick: () => {
this.refs.details.resetGasFields()
},
}, 'Reset'),
]), ]),
]) ])
) )

Loading…
Cancel
Save