2022-01-06 14:30:34 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-04-08 13:47:19 +00:00
|
|
|
import type { NumberFormatValues } from 'react-number-format';
|
2022-01-06 14:30:34 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-08 13:47:19 +00:00
|
|
|
Check if that the value is minor than the max price and greater than 0.
|
2022-01-06 14:30:34 +00:00
|
|
|
*/
|
|
|
|
export const isValidMaxValue = ( {
|
|
|
|
maxConstraint,
|
|
|
|
minorUnit,
|
|
|
|
}: {
|
|
|
|
maxConstraint: number;
|
|
|
|
minorUnit: number;
|
|
|
|
} ) => ( { floatValue }: NumberFormatValues ): boolean => {
|
|
|
|
const maxPrice = maxConstraint / 10 ** minorUnit;
|
|
|
|
|
|
|
|
return floatValue !== undefined && floatValue <= maxPrice && floatValue > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2022-04-08 13:47:19 +00:00
|
|
|
Check if that the value is minor than the max price and greater than 0.
|
2022-01-06 14:30:34 +00:00
|
|
|
*/
|
|
|
|
export const isValidMinValue = ( {
|
|
|
|
minConstraint,
|
|
|
|
currentMaxValue,
|
|
|
|
minorUnit,
|
|
|
|
}: {
|
|
|
|
minConstraint: number;
|
|
|
|
currentMaxValue: number;
|
|
|
|
minorUnit: number;
|
|
|
|
} ) => ( { floatValue }: NumberFormatValues ): boolean => {
|
|
|
|
const minPrice = minConstraint / 10 ** minorUnit;
|
|
|
|
const currentMaxPrice = currentMaxValue / 10 ** minorUnit;
|
|
|
|
|
|
|
|
return (
|
|
|
|
floatValue !== undefined &&
|
|
|
|
floatValue >= minPrice &&
|
|
|
|
floatValue < currentMaxPrice
|
|
|
|
);
|
|
|
|
};
|