mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-02-04 07:14:03 +00:00
Improve readability and add a condition to invalidity for Input
This commit is contained in:
parent
9004cee42c
commit
2e0dd57d8b
@ -50,7 +50,7 @@ class Input extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
// Show an error with no value only after blurring.
|
||||
if (!hasValue && showInvalidWithoutValue && !validDueToBlur) {
|
||||
if (!isStateless && !validDueToBlur && !hasValue && showInvalidWithoutValue) {
|
||||
validClass = 'invalid';
|
||||
}
|
||||
|
||||
|
@ -130,20 +130,21 @@ export const validNumber = (num: number) => isFinite(num) && num >= 0;
|
||||
export const validPositiveNumber = (num: number) => validNumber(num) && num !== 0;
|
||||
|
||||
export const validDecimal = (input: string, decimal: number) => {
|
||||
const decimals: RegExpMatchArray | null = input.match(/\./g);
|
||||
const arr = input.split('.');
|
||||
|
||||
// Only a single decimal can exist.
|
||||
if (decimals && decimals.length > 1) {
|
||||
if (arr.length > 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const arr = input.split('.');
|
||||
const fractionPortion = arr[1];
|
||||
|
||||
if (!fractionPortion || fractionPortion.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const decimalLength = fractionPortion.length;
|
||||
|
||||
return decimalLength <= decimal;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user