From cd5861541c1cb871d5e3b606501931f2aee0d048 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 29 Aug 2017 10:21:31 -0230 Subject: [PATCH] Use hex values only in send.js to handle limit and price; GasTooltip accepts and returns values as hex (allows user to enter floats) --- ui/app/components/gas-tooltip.js | 22 +++++++++++++++------- ui/app/send.js | 13 +++++++------ ui/app/util.js | 6 ++---- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/ui/app/components/gas-tooltip.js b/ui/app/components/gas-tooltip.js index 76edb9214..4b6472b44 100644 --- a/ui/app/components/gas-tooltip.js +++ b/ui/app/components/gas-tooltip.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), }), diff --git a/ui/app/send.js b/ui/app/send.js index f50af386c..23216d54c 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -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({ diff --git a/ui/app/util.js b/ui/app/util.js index 4b48db0ca..a624726e2 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -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); }