mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Use hex values only in send.js to handle limit and price; GasTooltip accepts and returns values as hex (allows user to enter floats)
This commit is contained in:
parent
cd351e8aef
commit
cd5861541c
@ -22,7 +22,10 @@ function GasTooltip () {
|
|||||||
GasTooltip.prototype.componentWillMount = function () {
|
GasTooltip.prototype.componentWillMount = function () {
|
||||||
const { gasPrice = 0, gasLimit = 0} = this.props
|
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) {
|
GasTooltip.prototype.updateGasPrice = function (newPrice) {
|
||||||
@ -30,7 +33,10 @@ GasTooltip.prototype.updateGasPrice = function (newPrice) {
|
|||||||
const { gasLimit } = this.state
|
const { gasLimit } = this.state
|
||||||
|
|
||||||
this.setState({ gasPrice: newPrice })
|
this.setState({ gasPrice: newPrice })
|
||||||
onFeeChange({ gasLimit, gasPrice: newPrice })
|
onFeeChange({
|
||||||
|
gasLimit: gasLimit.toString(16),
|
||||||
|
gasPrice: (newPrice * 1000000000).toString(16)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
GasTooltip.prototype.updateGasLimit = function (newLimit) {
|
GasTooltip.prototype.updateGasLimit = function (newLimit) {
|
||||||
@ -38,7 +44,10 @@ GasTooltip.prototype.updateGasLimit = function (newLimit) {
|
|||||||
const { gasPrice } = this.state
|
const { gasPrice } = this.state
|
||||||
|
|
||||||
this.setState({ gasLimit: newLimit })
|
this.setState({ gasLimit: newLimit })
|
||||||
onFeeChange({ gasLimit: newLimit, gasPrice })
|
onFeeChange({
|
||||||
|
gasLimit: newLimit.toString(16),
|
||||||
|
gasPrice: (gasPrice * 1000000000).toString(16)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
GasTooltip.prototype.onClose = function (e) {
|
GasTooltip.prototype.onClose = function (e) {
|
||||||
@ -63,10 +72,9 @@ GasTooltip.prototype.render = function () {
|
|||||||
]),
|
]),
|
||||||
h(InputNumber, {
|
h(InputNumber, {
|
||||||
unitLabel: 'GWEI',
|
unitLabel: 'GWEI',
|
||||||
step: 0.0001,
|
step: 1,
|
||||||
min: 0.0000,
|
min: 0,
|
||||||
placeholder: '0.0000',
|
placeholder: '0',
|
||||||
fixed: 4,
|
|
||||||
initValue: gasPrice,
|
initValue: gasPrice,
|
||||||
onChange: (newPrice) => this.updateGasPrice(newPrice),
|
onChange: (newPrice) => this.updateGasPrice(newPrice),
|
||||||
}),
|
}),
|
||||||
|
@ -58,7 +58,7 @@ function SendTransactionScreen () {
|
|||||||
to: '',
|
to: '',
|
||||||
// these values are hardcoded, so "Next" can be clicked
|
// these values are hardcoded, so "Next" can be clicked
|
||||||
amount: '0.0001', // see L544
|
amount: '0.0001', // see L544
|
||||||
gasPrice: '0x19',
|
gasPrice: '0x5d21dba00',
|
||||||
gas: '0x7b0d',
|
gas: '0x7b0d',
|
||||||
txData: null,
|
txData: null,
|
||||||
memo: '',
|
memo: '',
|
||||||
@ -92,7 +92,8 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
} = props
|
} = props
|
||||||
const { blockGasLimit } = this.state
|
const { blockGasLimit, newTx } = this.state
|
||||||
|
const { gas, gasPrice } = newTx
|
||||||
|
|
||||||
console.log({ selectedIdentity, identities })
|
console.log({ selectedIdentity, identities })
|
||||||
console.log("SendTransactionScreen state:", this.state)
|
console.log("SendTransactionScreen state:", this.state)
|
||||||
@ -245,7 +246,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
h('div.large-input.send-screen-gas-input', {}, [
|
h('div.large-input.send-screen-gas-input', {}, [
|
||||||
currentCurrency === 'USD'
|
currentCurrency === 'USD'
|
||||||
? h(FiatValue, {
|
? 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,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
style: {
|
style: {
|
||||||
@ -256,7 +257,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
: h(EthBalance, {
|
: 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,
|
currentCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
showFiat: false,
|
showFiat: false,
|
||||||
@ -277,8 +278,8 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
|
|
||||||
this.state.tooltipIsOpen && h(GasTooltip, {
|
this.state.tooltipIsOpen && h(GasTooltip, {
|
||||||
className: 'send-tooltip',
|
className: 'send-tooltip',
|
||||||
gasPrice: parseInt(this.state.newTx.gasPrice, 16),
|
gasPrice,
|
||||||
gasLimit: parseInt(this.state.newTx.gas, 16),
|
gasLimit: gas,
|
||||||
onClose: this.closeTooltip,
|
onClose: this.closeTooltip,
|
||||||
onFeeChange: ({gasLimit, gasPrice}) => {
|
onFeeChange: ({gasLimit, gasPrice}) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -233,6 +233,7 @@ function bnMultiplyByFraction (targetBN, numerator, denominator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimit) {
|
function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimit) {
|
||||||
|
// Gas Limit
|
||||||
const gasBn = hexToBn(gas)
|
const gasBn = hexToBn(gas)
|
||||||
const gasLimit = new ethUtil.BN(parseInt(blockGasLimit))
|
const gasLimit = new ethUtil.BN(parseInt(blockGasLimit))
|
||||||
const safeGasLimit = bnMultiplyByFraction(gasLimit, 19, 20).toString(10)
|
const safeGasLimit = bnMultiplyByFraction(gasLimit, 19, 20).toString(10)
|
||||||
@ -241,8 +242,5 @@ function getTxFeeBn (gas, gasPrice = MIN_GAS_PRICE_BN.toString(16), blockGasLimi
|
|||||||
const gasPriceBn = hexToBn(gasPrice)
|
const gasPriceBn = hexToBn(gasPrice)
|
||||||
const txFeeBn = gasBn.mul(gasPriceBn)
|
const txFeeBn = gasBn.mul(gasPriceBn)
|
||||||
|
|
||||||
const fiatMultiplier = hexToBn((1000000000).toString(16))
|
return txFeeBn.toString(16);
|
||||||
const txFeeAsFiatBn = txFeeBn.mul(fiatMultiplier)
|
|
||||||
|
|
||||||
return txFeeAsFiatBn;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user