1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Various improvements to gas input.

This commit is contained in:
Kevin Serrano 2017-03-01 14:37:51 -08:00
parent 5f378d382e
commit 0ac1f749fd
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
3 changed files with 22 additions and 27 deletions

View File

@ -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)
}
}

View File

@ -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 })
},
}),
]),

View File

@ -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'),
]),
])
)