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 : '';
|
||||
}
|
||||
|
||||
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()}
|
||||
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user