1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02: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:
Olusegun Akintayo 2021-11-11 22:16:28 +04:00 committed by Dan Miller
parent c06935b8b8
commit bed7c787e9
2 changed files with 11 additions and 2 deletions

View File

@ -75,11 +75,12 @@ export default class TokenInput extends PureComponent {
return Number(decimalValueString) ? decimalValueString : '';
}
handleChange = (decimalValue) => {
handleChange = (decimalValue, applyDecimals = false) => {
const { token: { decimals } = {}, onChange } = this.props;
let newDecimalValue = decimalValue;
if (decimals) {
if (decimals && applyDecimals) {
newDecimalValue = parseFloat(decimalValue).toFixed(decimals);
}
@ -94,6 +95,10 @@ export default class TokenInput extends PureComponent {
onChange(hexValue);
};
handleBlur = (decimalValue) => {
this.handleChange(decimalValue, true);
};
renderConversionComponent() {
const {
tokenExchangeRates,
@ -155,6 +160,7 @@ export default class TokenInput extends PureComponent {
{...restProps}
suffix={token.symbol}
onChange={this.handleChange}
onBlur={this.handleBlur}
value={decimalValue}
>
{this.renderConversionComponent()}

View File

@ -17,6 +17,7 @@ export default class UnitInput extends PureComponent {
actionComponent: PropTypes.node,
error: PropTypes.bool,
onChange: PropTypes.func,
onBlur: PropTypes.func,
placeholder: PropTypes.string,
suffix: PropTypes.string,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
@ -55,6 +56,8 @@ export default class UnitInput extends PureComponent {
if (value === '') {
this.setState({ value: '0' });
}
this.props.onBlur && this.props.onBlur(value);
};
handleChange = (event) => {