Skip to content

Commit 6c8475c

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

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
6868
setAmount,
6969
}) => {
7070
const [debouncedAmount, setDebouncedAmount] = useState("");
71-
const [hasInteracted, setHasInteracted] = useState(false);
7271
const [errorMsg, setErrorMsg] = useState<string | undefined>();
7372
useDebounce(() => setDebouncedAmount(amount), 500, [amount]);
7473
const parsedAmount = useParsedAmount(uncommify(debouncedAmount) as `${number}`);
@@ -90,7 +89,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
9089
const isStaking = useMemo(() => action === ActionType.stake, [action]);
9190

9291
useEffect(() => {
93-
if (!hasInteracted || parsedAmount === 0n) {
92+
if (parsedAmount === 0n) {
9493
setErrorMsg(undefined);
9594
} else if (isStaking && balance && parsedAmount > balance) {
9695
setErrorMsg("Insufficient balance to stake this amount");
@@ -99,7 +98,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
9998
} else {
10099
setErrorMsg(undefined);
101100
}
102-
}, [hasInteracted, parsedAmount, isStaking, balance, jurorBalance]);
101+
}, [parsedAmount, isStaking, balance, jurorBalance]);
103102

104103
return (
105104
<>
@@ -109,7 +108,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
109108
onClick={() => {
110109
const amount = isStaking ? parsedBalance : parsedStake;
111110
setAmount(amount);
112-
setHasInteracted(true);
113111
}}
114112
>
115113
{isStaking ? "Stake" : "Withdraw"} all
@@ -121,7 +119,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
121119
value={uncommify(amount)}
122120
onChange={(e) => {
123121
setAmount(e);
124-
setHasInteracted(true);
125122
}}
126123
placeholder={isStaking ? "Amount to stake" : "Amount to withdraw"}
127124
message={errorMsg ?? undefined}
@@ -137,9 +134,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
137134
isSending,
138135
setIsSending,
139136
setIsPopupOpen,
140-
setErrorMsg,
141-
hasInteracted,
142-
setHasInteracted,
143137
}}
144138
/>
145139
</EnsureChainContainer>

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ interface IActionButton {
3434
setIsSending: (arg0: boolean) => void;
3535
setAmount: (arg0: string) => void;
3636
setIsPopupOpen: (arg0: boolean) => void;
37-
setErrorMsg: (arg0: string | undefined) => void;
38-
hasInteracted: boolean;
39-
setHasInteracted: (arg0: boolean) => void;
4037
}
4138

4239
const StakeWithdrawButton: React.FC<IActionButton> = ({
@@ -45,7 +42,6 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
4542
isSending,
4643
setIsSending,
4744
setIsPopupOpen,
48-
setHasInteracted,
4945
}) => {
5046
const { id } = useParams();
5147
const { address } = useAccount();
@@ -149,10 +145,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
149145
(targetStake !== 0n && targetStake < BigInt(courtDetails.court?.minStake)) ||
150146
(isStaking && !isAllowance && isUndefined(setStakeConfig.request))
151147
}
152-
onClick={() => {
153-
setHasInteracted(true);
154-
onClick();
155-
}}
148+
onClick={onClick}
156149
/>
157150
</EnsureChain>
158151
);

0 commit comments

Comments
 (0)