aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/input-number.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/components/input-number.js')
-rw-r--r--ui/app/components/input-number.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/ui/app/components/input-number.js b/ui/app/components/input-number.js
index 16347fd5e..e28807c13 100644
--- a/ui/app/components/input-number.js
+++ b/ui/app/components/input-number.js
@@ -1,7 +1,12 @@
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
-const { addCurrencies } = require('../conversion-util')
+const {
+ addCurrencies,
+ conversionGTE,
+ conversionLTE,
+ toNegative,
+} = require('../conversion-util')
module.exports = InputNumber
@@ -17,8 +22,21 @@ InputNumber.prototype.setValue = function (newValue) {
newValue = Number(fixed ? newValue.toFixed(4) : newValue)
- if (newValue >= min && newValue <= max) {
+ const newValueGreaterThanMin = conversionGTE(
+ { value: newValue, fromNumericBase: 'dec' },
+ { value: min, fromNumericBase: 'hex' },
+ )
+
+ const newValueLessThanMax = conversionLTE(
+ { value: newValue, fromNumericBase: 'dec' },
+ { value: max, fromNumericBase: 'hex' },
+ )
+ if (newValueGreaterThanMin && newValueLessThanMax) {
onChange(newValue)
+ } else if (!newValueGreaterThanMin) {
+ onChange(min)
+ } else if (!newValueLessThanMax) {
+ onChange(max)
}
}
@@ -29,7 +47,7 @@ InputNumber.prototype.render = function () {
h('input.customize-gas-input', {
placeholder,
type: 'number',
- value: value,
+ value,
onChange: (e) => this.setValue(e.target.value),
}),
h('span.gas-tooltip-input-detail', {}, [unitLabel]),
@@ -39,7 +57,7 @@ InputNumber.prototype.render = function () {
}),
h('i.fa.fa-angle-down', {
style: { cursor: 'pointer' },
- onClick: () => this.setValue(addCurrencies(value, step * -1)),
+ onClick: () => this.setValue(addCurrencies(value, toNegative(step))),
}),
]),
])