This commit is contained in:
counterweight 2025-05-23 23:38:03 +02:00
parent a4efd1fd93
commit 99b7066b83
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -11,40 +11,48 @@ const LoanPanel = () => {
const [loanDuration, setLoanDuration] = useState(12); const [loanDuration, setLoanDuration] = useState(12);
const [loanInterest, setLoanInterest] = useState(5); const [loanInterest, setLoanInterest] = useState(5);
const sanitizeInputToIntWithinRange = ({ value, min, max }) => {
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value });
const inRangeValue = sanitizeInputIntoRange({
value: onlyDigitsValue,
min: min,
max: max,
});
return inRangeValue;
};
const handleLoanPrincipalChange = (event) => { const handleLoanPrincipalChange = (event) => {
setHasBeenInteracted(1); setHasBeenInteracted(1);
const inputValue = event.target.value; const inputValue = event.target.value;
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value: inputValue }); const sanitizedInputValue = sanitizeInputToIntWithinRange({
const inRangeValue = sanitizeInputIntoRange({ value: inputValue,
value: onlyDigitsValue,
min: 0, min: 0,
max: 1_000_000, max: 1_000_000,
}); });
setLoanPrincipal(inRangeValue); setLoanPrincipal(sanitizedInputValue);
}; };
const handleLoanDurationChange = (event) => { const handleLoanDurationChange = (event) => {
setHasBeenInteracted(1); setHasBeenInteracted(1);
const inputValue = event.target.value; const inputValue = event.target.value;
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value: inputValue }); const sanitizedInputValue = sanitizeInputToIntWithinRange({
const inRangeValue = sanitizeInputIntoRange({ value: inputValue,
value: onlyDigitsValue,
min: 1, min: 1,
max: 360, max: 360,
}); });
setLoanDuration(inRangeValue); setLoanDuration(sanitizedInputValue);
}; };
const handleLoanInterestChange = (event) => { const handleLoanInterestChange = (event) => {
setHasBeenInteracted(1); setHasBeenInteracted(1);
const inputValue = event.target.value; const inputValue = event.target.value;
const onlyDigitsValue = sanitizeInputAsOnlyDigits({ value: inputValue }); const sanitizedInputValue = sanitizeInputToIntWithinRange({
const inRangeValue = sanitizeInputIntoRange({ value: inputValue,
value: onlyDigitsValue,
min: 0, min: 0,
max: 50, max: 50,
}); });
setLoanInterest(inRangeValue); setLoanInterest(sanitizedInputValue);
}; };
return ( return (