mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Set gas price allows for WEI precision.
This commit is contained in:
parent
b16946723f
commit
716bbf67d7
@ -73,6 +73,8 @@ function getOriginalState (props) {
|
|||||||
gasLimit,
|
gasLimit,
|
||||||
gasTotal,
|
gasTotal,
|
||||||
error: null,
|
error: null,
|
||||||
|
priceSigZeros: '',
|
||||||
|
priceSigDec: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +169,15 @@ CustomizeGasModal.prototype.convertAndSetGasLimit = function (newGasLimit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CustomizeGasModal.prototype.convertAndSetGasPrice = function (newGasPrice) {
|
CustomizeGasModal.prototype.convertAndSetGasPrice = function (newGasPrice) {
|
||||||
const { gasLimit } = this.state
|
const { gasLimit, priceSigZeros } = this.state
|
||||||
|
const priceStrLength = newGasPrice.length
|
||||||
|
const sigZeros = String(newGasPrice).match(/^\d+[.]\d*?(0+)$/)
|
||||||
|
const sigDec = String(newGasPrice).match(/^\d+([.])0*$/)
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
priceSigZeros: sigZeros && sigZeros[1] || '',
|
||||||
|
priceSigDec: sigDec && sigDec[1] || '',
|
||||||
|
})
|
||||||
|
|
||||||
const gasPrice = conversionUtil(newGasPrice, {
|
const gasPrice = conversionUtil(newGasPrice, {
|
||||||
fromNumericBase: 'dec',
|
fromNumericBase: 'dec',
|
||||||
@ -189,15 +199,17 @@ CustomizeGasModal.prototype.convertAndSetGasPrice = function (newGasPrice) {
|
|||||||
|
|
||||||
CustomizeGasModal.prototype.render = function () {
|
CustomizeGasModal.prototype.render = function () {
|
||||||
const { hideModal } = this.props
|
const { hideModal } = this.props
|
||||||
const { gasPrice, gasLimit, gasTotal, error } = this.state
|
const { gasPrice, gasLimit, gasTotal, error, priceSigZeros, priceSigDec } = this.state
|
||||||
|
|
||||||
const convertedGasPrice = conversionUtil(gasPrice, {
|
let convertedGasPrice = conversionUtil(gasPrice, {
|
||||||
fromNumericBase: 'hex',
|
fromNumericBase: 'hex',
|
||||||
toNumericBase: 'dec',
|
toNumericBase: 'dec',
|
||||||
fromDenomination: 'WEI',
|
fromDenomination: 'WEI',
|
||||||
toDenomination: 'GWEI',
|
toDenomination: 'GWEI',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
convertedGasPrice += convertedGasPrice.match(/[.]/) ? priceSigZeros : `${priceSigDec}${priceSigZeros}`
|
||||||
|
|
||||||
const convertedGasLimit = conversionUtil(gasLimit, {
|
const convertedGasLimit = conversionUtil(gasLimit, {
|
||||||
fromNumericBase: 'hex',
|
fromNumericBase: 'hex',
|
||||||
toNumericBase: 'dec',
|
toNumericBase: 'dec',
|
||||||
@ -222,7 +234,7 @@ CustomizeGasModal.prototype.render = function () {
|
|||||||
value: convertedGasPrice,
|
value: convertedGasPrice,
|
||||||
min: MIN_GAS_PRICE_GWEI,
|
min: MIN_GAS_PRICE_GWEI,
|
||||||
// max: 1000,
|
// max: 1000,
|
||||||
step: MIN_GAS_PRICE_GWEI,
|
step: multiplyCurrencies(MIN_GAS_PRICE_GWEI, 10),
|
||||||
onChange: value => this.convertAndSetGasPrice(value),
|
onChange: value => this.convertAndSetGasPrice(value),
|
||||||
title: 'Gas Price (GWEI)',
|
title: 'Gas Price (GWEI)',
|
||||||
copy: 'We calculate the suggested gas prices based on network success rates.',
|
copy: 'We calculate the suggested gas prices based on network success rates.',
|
||||||
|
@ -5,6 +5,7 @@ const {
|
|||||||
addCurrencies,
|
addCurrencies,
|
||||||
conversionGTE,
|
conversionGTE,
|
||||||
conversionLTE,
|
conversionLTE,
|
||||||
|
subtractCurrencies,
|
||||||
toNegative,
|
toNegative,
|
||||||
} = require('../conversion-util')
|
} = require('../conversion-util')
|
||||||
|
|
||||||
@ -17,18 +18,24 @@ function InputNumber () {
|
|||||||
this.setValue = this.setValue.bind(this)
|
this.setValue = this.setValue.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidInput (text) {
|
||||||
|
const re = /^([1-9]\d*|0)(\.|\.\d*)?$/
|
||||||
|
return re.test(text)
|
||||||
|
}
|
||||||
|
|
||||||
InputNumber.prototype.setValue = function (newValue) {
|
InputNumber.prototype.setValue = function (newValue) {
|
||||||
|
if (newValue && !isValidInput(newValue)) return
|
||||||
const { fixed, min = -1, max = Infinity, onChange } = this.props
|
const { fixed, min = -1, max = Infinity, onChange } = this.props
|
||||||
|
|
||||||
newValue = Number(fixed ? newValue.toFixed(4) : newValue)
|
newValue = fixed ? newValue.toFixed(4) : newValue
|
||||||
|
|
||||||
const newValueGreaterThanMin = conversionGTE(
|
const newValueGreaterThanMin = conversionGTE(
|
||||||
{ value: newValue, fromNumericBase: 'dec' },
|
{ value: newValue || '0', fromNumericBase: 'dec' },
|
||||||
{ value: min, fromNumericBase: 'hex' },
|
{ value: min, fromNumericBase: 'hex' },
|
||||||
)
|
)
|
||||||
|
|
||||||
const newValueLessThanMax = conversionLTE(
|
const newValueLessThanMax = conversionLTE(
|
||||||
{ value: newValue, fromNumericBase: 'dec' },
|
{ value: newValue || '0', fromNumericBase: 'dec' },
|
||||||
{ value: max, fromNumericBase: 'hex' },
|
{ value: max, fromNumericBase: 'hex' },
|
||||||
)
|
)
|
||||||
if (newValueGreaterThanMin && newValueLessThanMax) {
|
if (newValueGreaterThanMin && newValueLessThanMax) {
|
||||||
@ -46,8 +53,8 @@ InputNumber.prototype.render = function () {
|
|||||||
return h('div.customize-gas-input-wrapper', {}, [
|
return h('div.customize-gas-input-wrapper', {}, [
|
||||||
h('input.customize-gas-input', {
|
h('input.customize-gas-input', {
|
||||||
placeholder,
|
placeholder,
|
||||||
type: 'number',
|
|
||||||
value,
|
value,
|
||||||
|
step,
|
||||||
onChange: (e) => this.setValue(e.target.value),
|
onChange: (e) => this.setValue(e.target.value),
|
||||||
}),
|
}),
|
||||||
h('span.gas-tooltip-input-detail', {}, [unitLabel]),
|
h('span.gas-tooltip-input-detail', {}, [unitLabel]),
|
||||||
@ -57,7 +64,7 @@ InputNumber.prototype.render = function () {
|
|||||||
}),
|
}),
|
||||||
h('i.fa.fa-angle-down', {
|
h('i.fa.fa-angle-down', {
|
||||||
style: { cursor: 'pointer' },
|
style: { cursor: 'pointer' },
|
||||||
onClick: () => this.setValue(addCurrencies(value, toNegative(step))),
|
onClick: () => this.setValue(subtractCurrencies(value, step)),
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
|
@ -11,6 +11,7 @@ const MIN_GAS_PRICE_GWEI = ethUtil.addHexPrefix(conversionUtil(MIN_GAS_PRICE_HEX
|
|||||||
toDenomination: 'GWEI',
|
toDenomination: 'GWEI',
|
||||||
fromNumericBase: 'hex',
|
fromNumericBase: 'hex',
|
||||||
toNumericBase: 'hex',
|
toNumericBase: 'hex',
|
||||||
|
numberOfDecimals: 1,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const MIN_GAS_TOTAL = multiplyCurrencies(MIN_GAS_LIMIT_HEX, MIN_GAS_PRICE_HEX, {
|
const MIN_GAS_TOTAL = multiplyCurrencies(MIN_GAS_LIMIT_HEX, MIN_GAS_PRICE_HEX, {
|
||||||
|
@ -53,7 +53,7 @@ const toNormalizedDenomination = {
|
|||||||
}
|
}
|
||||||
const toSpecifiedDenomination = {
|
const toSpecifiedDenomination = {
|
||||||
WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round(),
|
WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).round(),
|
||||||
GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(1),
|
GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).round(9),
|
||||||
}
|
}
|
||||||
const baseChange = {
|
const baseChange = {
|
||||||
hex: n => n.toString(16),
|
hex: n => n.toString(16),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user