Use hex values only in send.js to handle limit and price; GasTooltip accepts and returns values as hex (allows user to enter floats)

feature/default_network_editable
Dan 7 years ago
parent cd351e8aef
commit cd5861541c
  1. 22
      ui/app/components/gas-tooltip.js
  2. 13
      ui/app/send.js
  3. 6
      ui/app/util.js

@ -22,7 +22,10 @@ function GasTooltip () {
GasTooltip.prototype.componentWillMount = function () {
const { gasPrice = 0, gasLimit = 0} = this.props
this.setState({ gasPrice, gasLimit })
this.setState({
gasPrice: parseInt(gasPrice, 16) / 1000000000,
gasLimit: parseInt(gasLimit, 16),
})
}
GasTooltip.prototype.updateGasPrice = function (newPrice) {
@ -30,7 +33,10 @@ GasTooltip.prototype.updateGasPrice = function (newPrice) {
const { gasLimit } = this.state
this.setState({ gasPrice: newPrice })
onFeeChange({ gasLimit, gasPrice: newPrice })
onFeeChange({
gasLimit: gasLimit.toString(16),
gasPrice: (newPrice * 1000000000).toString(16)
})
}
GasTooltip.prototype.updateGasLimit = function (newLimit) {
@ -38,7 +44,10 @@ GasTooltip.prototype.updateGasLimit = function (newLimit) {
const { gasPrice } = this.state
this.setState({ gasLimit: newLimit })
onFeeChange({ gasLimit: newLimit, gasPrice })
onFeeChange({
gasLimit: newLimit.toString(16),
gasPrice: (gasPrice * 1000000000).toString(16)
})
}
GasTooltip.prototype.onClose = function (e) {
@ -63,10 +72,9 @@ GasTooltip.prototype.render = function () {
]),
h(InputNumber, {
unitLabel: 'GWEI',
step: 0.0001,
min: 0.0000,
placeholder: '0.0000',
fixed: 4,
step: 1,
min: 0,
placeholder: '0',
initValue: gasPrice,
onChange: (newPrice) => this.updateGasPrice(newPrice),
}),

@ -58,7 +58,7 @@ function SendTransactionScreen () {
to: '',
// these values are hardcoded, so "Next" can be clicked
amount: '0.0001', // see L544
gasPrice: '0x19',
gasPrice: '0x5d21dba00',
gas: '0x7b0d',
txData: null,
memo: '',
@ -92,7 +92,8 @@ SendTransactionScreen.prototype.render = function () {
conversionRate,
currentCurrency,
} = props
const { blockGasLimit } = this.state
const { blockGasLimit, newTx } = this.state
const { gas, gasPrice } = newTx
console.log({ selectedIdentity, identities })
console.log("SendTransactionScreen state:", this.state)
@ -245,7 +246,7 @@ SendTransactionScreen.prototype.render = function () {
h('div.large-input.send-screen-gas-input', {}, [
currentCurrency === 'USD'
? h(FiatValue, {
value: getTxFeeBn(this.state.newTx.gas.toString(16), this.state.newTx.gasPrice.toString(16), blockGasLimit).toString(16),
value: getTxFeeBn(gas, gasPrice, blockGasLimit),
conversionRate,
currentCurrency,
style: {
@ -256,7 +257,7 @@ SendTransactionScreen.prototype.render = function () {
}
})
: h(EthBalance, {
value: getTxFeeBn(this.state.newTx.gas.toString(16), this.state.newTx.gasPrice.toString(16), blockGasLimit).toString(16),
value: getTxFeeBn(gas, gasPrice, blockGasLimit),
currentCurrency,
conversionRate,
showFiat: false,
@ -277,8 +278,8 @@ SendTransactionScreen.prototype.render = function () {
this.state.tooltipIsOpen && h(GasTooltip, {
className: 'send-tooltip',
gasPrice: parseInt(this.state.newTx.gasPrice, 16),
gasLimit: parseInt(this.state.newTx.gas, 16),
gasPrice,
gasLimit: gas,
onClose: this.closeTooltip,
onFeeChange: ({gasLimit, gasPrice}) => {
this.setState({

@ -233,6 +233,7 @@ function bnMultiplyByFraction (targetBN, numerator, denominator) {
}
function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimit) {
// Gas Limit
const gasBn = hexToBn(gas)
const gasLimit = new ethUtil.BN(parseInt(blockGasLimit))
const safeGasLimit = bnMultiplyByFraction(gasLimit, 19, 20).toString(10)
@ -240,9 +241,6 @@ function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimi
// Gas Price
const gasPriceBn = hexToBn(gasPrice)
const txFeeBn = gasBn.mul(gasPriceBn)
const fiatMultiplier = hexToBn((1000000000).toString(16))
const txFeeAsFiatBn = txFeeBn.mul(fiatMultiplier)
return txFeeAsFiatBn;
return txFeeBn.toString(16);
}

Loading…
Cancel
Save