Skip to content

Commit

Permalink
refactor(web): Error handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ShubhamParkhi committed May 20, 2024
1 parent b03bc44 commit 6c8475c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
10 changes: 2 additions & 8 deletions web/src/pages/Courts/CourtDetails/StakePanel/InputDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
setAmount,
}) => {
const [debouncedAmount, setDebouncedAmount] = useState("");
const [hasInteracted, setHasInteracted] = useState(false);
const [errorMsg, setErrorMsg] = useState<string | undefined>();
useDebounce(() => setDebouncedAmount(amount), 500, [amount]);
const parsedAmount = useParsedAmount(uncommify(debouncedAmount) as `${number}`);
Expand All @@ -90,7 +89,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
const isStaking = useMemo(() => action === ActionType.stake, [action]);

useEffect(() => {
if (!hasInteracted || parsedAmount === 0n) {
if (parsedAmount === 0n) {
setErrorMsg(undefined);
} else if (isStaking && balance && parsedAmount > balance) {
setErrorMsg("Insufficient balance to stake this amount");
Expand All @@ -99,7 +98,7 @@ const InputDisplay: React.FC<IInputDisplay> = ({
} else {
setErrorMsg(undefined);
}
}, [hasInteracted, parsedAmount, isStaking, balance, jurorBalance]);
}, [parsedAmount, isStaking, balance, jurorBalance]);

return (
<>
Expand All @@ -109,7 +108,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
onClick={() => {
const amount = isStaking ? parsedBalance : parsedStake;
setAmount(amount);
setHasInteracted(true);
}}
>
{isStaking ? "Stake" : "Withdraw"} all
Expand All @@ -121,7 +119,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
value={uncommify(amount)}
onChange={(e) => {
setAmount(e);
setHasInteracted(true);
}}
placeholder={isStaking ? "Amount to stake" : "Amount to withdraw"}
message={errorMsg ?? undefined}
Expand All @@ -137,9 +134,6 @@ const InputDisplay: React.FC<IInputDisplay> = ({
isSending,
setIsSending,
setIsPopupOpen,
setErrorMsg,
hasInteracted,
setHasInteracted,
}}
/>
</EnsureChainContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ interface IActionButton {
setIsSending: (arg0: boolean) => void;
setAmount: (arg0: string) => void;
setIsPopupOpen: (arg0: boolean) => void;
setErrorMsg: (arg0: string | undefined) => void;
hasInteracted: boolean;
setHasInteracted: (arg0: boolean) => void;
}

const StakeWithdrawButton: React.FC<IActionButton> = ({
Expand All @@ -45,7 +42,6 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
isSending,
setIsSending,
setIsPopupOpen,
setHasInteracted,
}) => {
const { id } = useParams();
const { address } = useAccount();
Expand Down Expand Up @@ -149,10 +145,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({
(targetStake !== 0n && targetStake < BigInt(courtDetails.court?.minStake)) ||
(isStaking && !isAllowance && isUndefined(setStakeConfig.request))
}
onClick={() => {
setHasInteracted(true);
onClick();
}}
onClick={onClick}
/>
</EnsureChain>
);
Expand Down

0 comments on commit 6c8475c

Please sign in to comment.