Skip to content

Commit 9e597b2

Browse files
authored
fix: staking project input (#68)
* fix: staking project input * added changeset
1 parent 6fe8a50 commit 9e597b2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.changeset/five-stingrays-turn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitcoin/ui": patch
3+
---
4+
5+
fixes staking project input

packages/ui/src/features/project/components/StakeProjectCard/components/StakeInput.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const StakeInput = ({
2020
}: StakeInputProps) => {
2121
const [value, setValue] = useState(stakeAmount);
2222
const inputRef = useRef<HTMLInputElement>(null);
23+
const [isFocused, setIsFocused] = useState(false);
2324

2425
// Immediate value clamping with cleanup
2526
const handleValueChange = useCallback(
@@ -56,6 +57,7 @@ export const StakeInput = ({
5657

5758
useEffect(() => {
5859
const input = inputRef.current;
60+
if (!isFocused) return;
5961
input?.addEventListener("wheel", handleWheel, { passive: false });
6062
return () => input?.removeEventListener("wheel", handleWheel);
6163
}, [handleWheel]);
@@ -64,9 +66,19 @@ export const StakeInput = ({
6466
<div className="flex items-center justify-between">
6567
<NumericFormat
6668
getInputRef={inputRef}
67-
value={value}
69+
value={Number(value.toFixed(5))}
6870
onValueChange={({ floatValue = 0 }) => handleValueChange(floatValue)}
6971
isAllowed={({ floatValue = 0 }) => floatValue >= 0 && floatValue <= maxAmount}
72+
onWheel={(e: React.WheelEvent<HTMLInputElement>) => {
73+
if (!isFocused) return;
74+
e.preventDefault();
75+
const stepSize = Math.floor((maxAmount / 10) * 100000) / 100000; // 5 decimal precision
76+
const delta = e.deltaY < 0 ? stepSize : -stepSize;
77+
const newValue = Math.min(Math.max(value + delta, 0), maxAmount);
78+
handleValueChange(newValue);
79+
}}
80+
onFocus={() => setIsFocused(true)}
81+
onBlur={() => setIsFocused(false)}
7082
allowNegative={false}
7183
decimalScale={100}
7284
max={maxAmount}

0 commit comments

Comments
 (0)