Skip to content

Commit 955a35d

Browse files
committed
refactor(web): Error handling logic
1 parent 6c8475c commit 955a35d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

web/src/components/NumberInputField.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ interface INumberInputField extends Omit<React.ComponentProps<typeof Field>, "on
3535
onChange?: (value: string) => void;
3636
formatter?: (value: string) => string;
3737
className?: string;
38+
min?: number;
3839
}
3940

4041
export const NumberInputField: React.FC<INumberInputField> = ({
@@ -45,6 +46,7 @@ export const NumberInputField: React.FC<INumberInputField> = ({
4546
formatter,
4647
className,
4748
variant = "info",
49+
min,
4850
}) => {
4951
const [isEditing, setIsEditing] = useState(false);
5052

@@ -61,14 +63,14 @@ export const NumberInputField: React.FC<INumberInputField> = ({
6163
onChange?.(event.target.value);
6264
}}
6365
onBlur={toggleEditing}
64-
{...{ value, placeholder, message, variant }}
66+
{...{ value, placeholder, message, variant, min }}
6567
/>
6668
) : (
6769
<StyledField
6870
type="text"
6971
value={formatter ? formatter(value ?? "0") : value}
7072
onFocus={toggleEditing}
71-
{...{ placeholder, message, variant }}
73+
{...{ placeholder, message, variant, min }}
7274
readOnly
7375
/>
7476
)}

web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ const InputDisplay: React.FC<IInputDisplay> = ({
8989
const isStaking = useMemo(() => action === ActionType.stake, [action]);
9090

9191
useEffect(() => {
92-
if (parsedAmount === 0n) {
93-
setErrorMsg(undefined);
92+
if (parsedAmount === 0n && balance === 0n && isStaking) {
93+
setErrorMsg("You need a non-zero PNK balance to stake");
9494
} else if (isStaking && balance && parsedAmount > balance) {
9595
setErrorMsg("Insufficient balance to stake this amount");
9696
} else if (!isStaking && jurorBalance && parsedAmount > jurorBalance[2]) {
@@ -124,6 +124,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
124124
message={errorMsg ?? undefined}
125125
variant={!isUndefined(errorMsg) ? "error" : "info"}
126126
formatter={(number: string) => commify(roundNumberDown(Number(number)))}
127+
min="0"
127128
/>
128129
<EnsureChainContainer>
129130
<StakeWithdrawButton

0 commit comments

Comments
 (0)