mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
We shouldn't be changing decimal places as user type, we should do that on blur. (#12631)
* We shouldn't be changing decimal places as user type, we should do that on blur. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Lint fixes. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Refactor code. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com> * Linter fixes. Signed-off-by: Akintayo A. Olusegun <akintayo.segun@gmail.com>
This commit is contained in:
parent
c06935b8b8
commit
bed7c787e9
@ -75,11 +75,12 @@ export default class TokenInput extends PureComponent {
|
|||||||
return Number(decimalValueString) ? decimalValueString : '';
|
return Number(decimalValueString) ? decimalValueString : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange = (decimalValue) => {
|
handleChange = (decimalValue, applyDecimals = false) => {
|
||||||
const { token: { decimals } = {}, onChange } = this.props;
|
const { token: { decimals } = {}, onChange } = this.props;
|
||||||
|
|
||||||
let newDecimalValue = decimalValue;
|
let newDecimalValue = decimalValue;
|
||||||
if (decimals) {
|
|
||||||
|
if (decimals && applyDecimals) {
|
||||||
newDecimalValue = parseFloat(decimalValue).toFixed(decimals);
|
newDecimalValue = parseFloat(decimalValue).toFixed(decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +95,10 @@ export default class TokenInput extends PureComponent {
|
|||||||
onChange(hexValue);
|
onChange(hexValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleBlur = (decimalValue) => {
|
||||||
|
this.handleChange(decimalValue, true);
|
||||||
|
};
|
||||||
|
|
||||||
renderConversionComponent() {
|
renderConversionComponent() {
|
||||||
const {
|
const {
|
||||||
tokenExchangeRates,
|
tokenExchangeRates,
|
||||||
@ -155,6 +160,7 @@ export default class TokenInput extends PureComponent {
|
|||||||
{...restProps}
|
{...restProps}
|
||||||
suffix={token.symbol}
|
suffix={token.symbol}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
onBlur={this.handleBlur}
|
||||||
value={decimalValue}
|
value={decimalValue}
|
||||||
>
|
>
|
||||||
{this.renderConversionComponent()}
|
{this.renderConversionComponent()}
|
||||||
|
@ -17,6 +17,7 @@ export default class UnitInput extends PureComponent {
|
|||||||
actionComponent: PropTypes.node,
|
actionComponent: PropTypes.node,
|
||||||
error: PropTypes.bool,
|
error: PropTypes.bool,
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
|
onBlur: PropTypes.func,
|
||||||
placeholder: PropTypes.string,
|
placeholder: PropTypes.string,
|
||||||
suffix: PropTypes.string,
|
suffix: PropTypes.string,
|
||||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
@ -55,6 +56,8 @@ export default class UnitInput extends PureComponent {
|
|||||||
if (value === '') {
|
if (value === '') {
|
||||||
this.setState({ value: '0' });
|
this.setState({ value: '0' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.props.onBlur && this.props.onBlur(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleChange = (event) => {
|
handleChange = (event) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user