Skip to content

Commit

Permalink
Merge pull request #1787 from kleros/fix/stake-button-disabling
Browse files Browse the repository at this point in the history
fix(web): stake-button-disabling
  • Loading branch information
alcercu authored Dec 12, 2024
2 parents e8e48f4 + ba21ef1 commit 6abacc8
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
error: allowanceError,
} = useSimulatePnkIncreaseAllowance({
query: {
enabled: isAllowance && !isUndefined(targetStake) && !isUndefined(allowance) && !isUndefined(balance),
enabled:
isAllowance &&
!isUndefined(targetStake) &&
!isUndefined(allowance) &&
!isUndefined(balance) &&
parsedAmount <= balance,
},
args: [klerosCoreAddress[DEFAULT_CHAIN], BigInt(targetStake ?? 0) - BigInt(allowance ?? 0)],
});
Expand All @@ -103,7 +108,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
parsedAmount !== 0n &&
targetStake >= 0n &&
!isAllowance &&
(isStaking ? true : jurorBalance && parsedAmount <= jurorBalance[2]),
Boolean(isStaking ? balance && parsedAmount <= balance : jurorBalance && parsedAmount <= jurorBalance[2]),
},
args: [BigInt(id ?? 0), targetStake],
});
Expand Down Expand Up @@ -231,30 +236,26 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac

useEffect(() => {
if (isPopupOpen) return;
if (setStakeError || allowanceError) {
setErrorMsg(parseWagmiError(setStakeError || allowanceError));
} else if (targetStake !== 0n && courtDetails && targetStake < BigInt(courtDetails.court?.minStake)) {
if (
action === ActionType.stake &&
targetStake !== 0n &&
courtDetails &&
targetStake < BigInt(courtDetails.court?.minStake)
) {
setErrorMsg(`Min Stake in court is: ${formatETH(courtDetails?.court?.minStake)}`);
} else if (setStakeError || allowanceError) {
setErrorMsg(parseWagmiError(setStakeError || allowanceError));
}
}, [setStakeError, setErrorMsg, targetStake, courtDetails, allowanceError, isPopupOpen]);
}, [setStakeError, setErrorMsg, targetStake, courtDetails, allowanceError, isPopupOpen, action]);

const isDisabled = useMemo(() => {
if (
parsedAmount == 0n ||
isUndefined(targetStake) ||
isUndefined(courtDetails) ||
(targetStake !== 0n && targetStake < BigInt(courtDetails.court?.minStake))
)
return true;
if (parsedAmount == 0n) return true;
if (isAllowance) {
return isUndefined(increaseAllowanceConfig) || isSimulatingAllowance || !isUndefined(allowanceError);
}

return isUndefined(setStakeConfig) || isSimulatingSetStake || !isUndefined(setStakeError);
}, [
parsedAmount,
targetStake,
courtDetails,
increaseAllowanceConfig,
isSimulatingAllowance,
setStakeConfig,
Expand Down

0 comments on commit 6abacc8

Please sign in to comment.