Skip to content

Commit 6abacc8

Browse files
authored
Merge pull request #1787 from kleros/fix/stake-button-disabling
fix(web): stake-button-disabling
2 parents e8e48f4 + ba21ef1 commit 6abacc8

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

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

+17-16
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
8383
error: allowanceError,
8484
} = useSimulatePnkIncreaseAllowance({
8585
query: {
86-
enabled: isAllowance && !isUndefined(targetStake) && !isUndefined(allowance) && !isUndefined(balance),
86+
enabled:
87+
isAllowance &&
88+
!isUndefined(targetStake) &&
89+
!isUndefined(allowance) &&
90+
!isUndefined(balance) &&
91+
parsedAmount <= balance,
8792
},
8893
args: [klerosCoreAddress[DEFAULT_CHAIN], BigInt(targetStake ?? 0) - BigInt(allowance ?? 0)],
8994
});
@@ -103,7 +108,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
103108
parsedAmount !== 0n &&
104109
targetStake >= 0n &&
105110
!isAllowance &&
106-
(isStaking ? true : jurorBalance && parsedAmount <= jurorBalance[2]),
111+
Boolean(isStaking ? balance && parsedAmount <= balance : jurorBalance && parsedAmount <= jurorBalance[2]),
107112
},
108113
args: [BigInt(id ?? 0), targetStake],
109114
});
@@ -231,30 +236,26 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
231236

232237
useEffect(() => {
233238
if (isPopupOpen) return;
234-
if (setStakeError || allowanceError) {
235-
setErrorMsg(parseWagmiError(setStakeError || allowanceError));
236-
} else if (targetStake !== 0n && courtDetails && targetStake < BigInt(courtDetails.court?.minStake)) {
239+
if (
240+
action === ActionType.stake &&
241+
targetStake !== 0n &&
242+
courtDetails &&
243+
targetStake < BigInt(courtDetails.court?.minStake)
244+
) {
237245
setErrorMsg(`Min Stake in court is: ${formatETH(courtDetails?.court?.minStake)}`);
246+
} else if (setStakeError || allowanceError) {
247+
setErrorMsg(parseWagmiError(setStakeError || allowanceError));
238248
}
239-
}, [setStakeError, setErrorMsg, targetStake, courtDetails, allowanceError, isPopupOpen]);
249+
}, [setStakeError, setErrorMsg, targetStake, courtDetails, allowanceError, isPopupOpen, action]);
240250

241251
const isDisabled = useMemo(() => {
242-
if (
243-
parsedAmount == 0n ||
244-
isUndefined(targetStake) ||
245-
isUndefined(courtDetails) ||
246-
(targetStake !== 0n && targetStake < BigInt(courtDetails.court?.minStake))
247-
)
248-
return true;
252+
if (parsedAmount == 0n) return true;
249253
if (isAllowance) {
250254
return isUndefined(increaseAllowanceConfig) || isSimulatingAllowance || !isUndefined(allowanceError);
251255
}
252-
253256
return isUndefined(setStakeConfig) || isSimulatingSetStake || !isUndefined(setStakeError);
254257
}, [
255258
parsedAmount,
256-
targetStake,
257-
courtDetails,
258259
increaseAllowanceConfig,
259260
isSimulatingAllowance,
260261
setStakeConfig,

0 commit comments

Comments
 (0)