From ced40d5aeced41b02f44cab7e8329d6d39ca3345 Mon Sep 17 00:00:00 2001 From: Harman-singh-waraich Date: Wed, 7 Aug 2024 19:59:52 +0530 Subject: [PATCH 1/2] refactor(web): improve-draw-maintenance-button --- .../MaintenanceButtons/DrawButton.tsx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx b/web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx index f4a23a654..67b4a77e0 100644 --- a/web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx +++ b/web/src/pages/Cases/CaseDetails/MaintenanceButtons/DrawButton.tsx @@ -6,6 +6,7 @@ import { usePublicClient } from "wagmi"; import { Button } from "@kleros/ui-components-library"; import { useSimulateKlerosCoreDraw, useWriteKlerosCoreDraw } from "hooks/contracts/generated"; +import { useSortitionModulePhase } from "hooks/useSortitionModulePhase"; import { wrapWithToast } from "utils/wrapWithToast"; import useDisputeMaintenanceQuery from "queries/useDisputeMaintenanceQuery"; @@ -13,6 +14,8 @@ import useDisputeMaintenanceQuery from "queries/useDisputeMaintenanceQuery"; import { Period } from "src/graphql/graphql"; import { isUndefined } from "src/utils"; +import { Phases } from "components/Phase"; + import { IBaseMaintenanceButton } from "."; const StyledButton = styled(Button)` @@ -28,21 +31,22 @@ const DrawButton: React.FC = ({ id, numberOfVotes, setIsOpen, perio const [isSending, setIsSending] = useState(false); const publicClient = usePublicClient(); const { data: maintenanceData } = useDisputeMaintenanceQuery(id); + const { data: phase } = useSortitionModulePhase(); const isDrawn = useMemo(() => maintenanceData?.dispute?.currentRound.jurorsDrawn, [maintenanceData]); + const canDraw = useMemo( + () => !isUndefined(maintenanceData) && !isDrawn && period === Period.Evidence && phase === Phases.drawing, + [maintenanceData, isDrawn, phase, period] + ); + const { data: drawConfig, isLoading: isLoadingConfig, isError, } = useSimulateKlerosCoreDraw({ query: { - enabled: - !isUndefined(id) && - !isUndefined(numberOfVotes) && - !isUndefined(period) && - period === Period.Evidence && - !isDrawn, + enabled: !isUndefined(id) && !isUndefined(numberOfVotes) && !isUndefined(period) && canDraw, }, args: [BigInt(id ?? 0), BigInt(numberOfVotes ?? 0)], }); @@ -51,9 +55,8 @@ const DrawButton: React.FC = ({ id, numberOfVotes, setIsOpen, perio const isLoading = useMemo(() => isLoadingConfig || isSending, [isLoadingConfig, isSending]); const isDisabled = useMemo( - () => - isUndefined(id) || isUndefined(numberOfVotes) || isError || isLoading || period !== Period.Evidence || isDrawn, - [id, numberOfVotes, isError, isLoading, period, isDrawn] + () => isUndefined(id) || isUndefined(numberOfVotes) || isError || isLoading || !canDraw, + [id, numberOfVotes, isError, isLoading, canDraw] ); const handleClick = () => { if (!drawConfig || !publicClient) return; From 740193d4a5a1e048dea8076dd4064c3cf23a7180 Mon Sep 17 00:00:00 2001 From: jaybuidl Date: Fri, 9 Aug 2024 11:14:37 +0100 Subject: [PATCH 2/2] fix: ruler --- .../devtools/DisputeResolverRuler.sol | 2 +- .../arbitration/devtools/KlerosCoreRuler.sol | 31 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/contracts/src/arbitration/devtools/DisputeResolverRuler.sol b/contracts/src/arbitration/devtools/DisputeResolverRuler.sol index 51a4620f7..c450abe01 100644 --- a/contracts/src/arbitration/devtools/DisputeResolverRuler.sol +++ b/contracts/src/arbitration/devtools/DisputeResolverRuler.sol @@ -7,7 +7,7 @@ import {DisputeResolver, IArbitratorV2, IDisputeTemplateRegistry} from "../arbitrables/DisputeResolver.sol"; -pragma solidity 0.8.18; +pragma solidity 0.8.24; interface IKlerosCoreRulerFragment { function getNextDisputeID() external view returns (uint256); diff --git a/contracts/src/arbitration/devtools/KlerosCoreRuler.sol b/contracts/src/arbitration/devtools/KlerosCoreRuler.sol index 8c5a6a95e..bd3bf0816 100644 --- a/contracts/src/arbitration/devtools/KlerosCoreRuler.sol +++ b/contracts/src/arbitration/devtools/KlerosCoreRuler.sol @@ -1,13 +1,12 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.18; +pragma solidity 0.8.24; import {IArbitrableV2, IArbitratorV2} from "../interfaces/IArbitratorV2.sol"; import {SafeERC20, IERC20} from "../../libraries/SafeERC20.sol"; -import {Constants} from "../../libraries/Constants.sol"; -import {OnError} from "../../libraries/Types.sol"; import {UUPSProxiable} from "../../proxy/UUPSProxiable.sol"; import {Initializable} from "../../proxy/Initializable.sol"; +import "../../libraries/Constants.sol"; /// @title KlerosCoreRuler /// Core arbitrator contract for development and testing purposes. @@ -188,7 +187,7 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { // GENERAL_COURT Court storage court = courts.push(); - court.parent = Constants.FORKING_COURT; + court.parent = FORKING_COURT; court.children = new uint256[](0); court.hiddenVotes = false; court.minStake = _courtParameters[0]; @@ -262,7 +261,7 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { uint256 _jurorsForCourtJump, uint256[4] memory _timesPerPeriod ) external onlyByGovernor { - if (_parent == Constants.FORKING_COURT) revert InvalidForkingCourtAsParent(); + if (_parent == FORKING_COURT) revert InvalidForkingCourtAsParent(); uint256 courtID = courts.length; Court storage court = courts.push(); @@ -387,7 +386,7 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { ) external payable override returns (uint256 disputeID) { if (msg.value < arbitrationCost(_extraData)) revert ArbitrationFeesNotEnough(); - return _createDispute(_numberOfChoices, _extraData, Constants.NATIVE_CURRENCY, msg.value); + return _createDispute(_numberOfChoices, _extraData, NATIVE_CURRENCY, msg.value); } /// @inheritdoc IArbitratorV2 @@ -516,7 +515,7 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { Round storage round = dispute.rounds[_round]; uint256 feeReward = round.totalFeesForJurors; round.sumFeeRewardPaid += feeReward; - if (round.feeToken == Constants.NATIVE_CURRENCY) { + if (round.feeToken == NATIVE_CURRENCY) { // The dispute fees were paid in ETH payable(account).send(feeReward); } else { @@ -573,7 +572,7 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { uint256 nbVotes = round.totalFeesForJurors / court.feeForJuror; if (_jump) { // Jump to parent court. - if (dispute.courtID == Constants.GENERAL_COURT) { + if (dispute.courtID == GENERAL_COURT) { // TODO: Handle the forking when appealed in General court. cost = NON_PAYABLE_AMOUNT; // Get the cost of the parent court. } else { @@ -648,19 +647,19 @@ contract KlerosCoreRuler is IArbitratorV2, UUPSProxiable, Initializable { minJurors := mload(add(_extraData, 0x40)) disputeKitID := mload(add(_extraData, 0x60)) } - if (courtID == Constants.FORKING_COURT || courtID >= courts.length) { - courtID = Constants.GENERAL_COURT; + if (courtID == FORKING_COURT || courtID >= courts.length) { + courtID = GENERAL_COURT; } if (minJurors == 0) { - minJurors = Constants.DEFAULT_NB_OF_JURORS; + minJurors = DEFAULT_NB_OF_JURORS; } - if (disputeKitID == Constants.NULL_DISPUTE_KIT) { - disputeKitID = Constants.DISPUTE_KIT_CLASSIC; // 0 index is not used. + if (disputeKitID == NULL_DISPUTE_KIT) { + disputeKitID = DISPUTE_KIT_CLASSIC; // 0 index is not used. } } else { - courtID = Constants.GENERAL_COURT; - minJurors = Constants.DEFAULT_NB_OF_JURORS; - disputeKitID = Constants.DISPUTE_KIT_CLASSIC; + courtID = GENERAL_COURT; + minJurors = DEFAULT_NB_OF_JURORS; + disputeKitID = DISPUTE_KIT_CLASSIC; } }