Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading