diff --git a/ui/components/ui/token-input/token-input.component.js b/ui/components/ui/token-input/token-input.component.js index 60665ac20..763bc5824 100644 --- a/ui/components/ui/token-input/token-input.component.js +++ b/ui/components/ui/token-input/token-input.component.js @@ -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()} diff --git a/ui/components/ui/unit-input/unit-input.component.js b/ui/components/ui/unit-input/unit-input.component.js index 8802519fb..10e14b12f 100644 --- a/ui/components/ui/unit-input/unit-input.component.js +++ b/ui/components/ui/unit-input/unit-input.component.js @@ -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) => {