Skip to content

Commit 7cce1c7

Browse files
committed
chore(web): add getLocalRounds function to work with the fact that disputeKitDispute is now an array
1 parent 7d42f96 commit 7cce1c7

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

web/src/components/DisputeCard/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useVotingHistory } from "queries/useVotingHistory";
1414
import DisputeInfo from "./DisputeInfo";
1515
import PeriodBanner from "./PeriodBanner";
1616
import { isUndefined } from "utils/index";
17+
import { getLocalRounds } from "utils/getLocalRounds";
1718

1819
const StyledCard = styled(Card)`
1920
width: 100%;
@@ -104,7 +105,7 @@ const DisputeCard: React.FC<IDisputeCard> = ({ id, arbitrated, period, lastPerio
104105
const courtName = courtPolicy?.name;
105106
const category = disputeTemplate ? disputeTemplate.category : undefined;
106107
const { data: votingHistory } = useVotingHistory(id);
107-
const localRounds = votingHistory?.dispute?.disputeKitDispute?.localRounds;
108+
const localRounds = getLocalRounds(votingHistory?.dispute?.disputeKitDispute);
108109
const navigate = useNavigate();
109110
return (
110111
<>

web/src/components/Verdict/DisputeTimeline.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import React, { useMemo } from "react";
22
import { useParams } from "react-router-dom";
33
import styled, { useTheme } from "styled-components";
44
import { _TimelineItem1, CustomTimeline } from "@kleros/ui-components-library";
5+
import CalendarIcon from "assets/svgs/icons/calendar.svg";
6+
import ClosedCaseIcon from "assets/svgs/icons/check-circle-outline.svg";
7+
import AppealedCaseIcon from "assets/svgs/icons/close-circle.svg";
58
import { Periods } from "consts/periods";
69
import { ClassicRound } from "src/graphql/graphql";
7-
import { getVoteChoice } from "pages/Cases/CaseDetails/Voting/VotingHistory";
810
import { DisputeDetailsQuery, useDisputeDetailsQuery } from "queries/useDisputeDetailsQuery";
911
import { useDisputeTemplate } from "queries/useDisputeTemplate";
1012
import { useVotingHistory } from "queries/useVotingHistory";
11-
import CalendarIcon from "assets/svgs/icons/calendar.svg";
12-
import ClosedCaseIcon from "assets/svgs/icons/check-circle-outline.svg";
13-
import AppealedCaseIcon from "assets/svgs/icons/close-circle.svg";
13+
import { getVoteChoice } from "pages/Cases/CaseDetails/Voting/VotingHistory";
14+
import { getLocalRounds } from "utils/getLocalRounds";
1415

1516
const Container = styled.div`
1617
display: flex;
@@ -63,7 +64,7 @@ const useItems = (disputeDetails?: DisputeDetailsQuery, arbitrable?: `0x${string
6364
const { id } = useParams();
6465
const { data: votingHistory } = useVotingHistory(id);
6566
const { data: disputeTemplate } = useDisputeTemplate(id, arbitrable);
66-
const localRounds: ClassicRound[] = votingHistory?.dispute?.disputeKitDispute?.localRounds as ClassicRound[];
67+
const localRounds: ClassicRound[] = getLocalRounds(votingHistory?.dispute?.disputeKitDispute) as ClassicRound[];
6768

6869
const theme = useTheme();
6970

web/src/hooks/queries/useClassicAppealQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const classicAppealQuery = graphql(`
3434
export const useClassicAppealQuery = (id?: string | number) => {
3535
const isEnabled = id !== undefined;
3636

37-
return useQuery({
37+
return useQuery<ClassicAppealQuery>({
3838
queryKey: ["refetchOnBlock", `classicAppealQuery${id}`],
3939
enabled: isEnabled,
4040
queryFn: async () => await graphqlQueryFnHelper(classicAppealQuery, { disputeID: id?.toString() }),

web/src/hooks/useClassicAppealContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useAppealCost } from "queries/useAppealCost";
77
import { useDisputeKitClassicMultipliers } from "queries/useDisputeKitClassicMultipliers";
88
import { useClassicAppealQuery, ClassicAppealQuery } from "queries/useClassicAppealQuery";
99
import { useCountdown } from "hooks/useCountdown";
10+
import { getLocalRounds } from "utils/getLocalRounds";
1011

1112
const LoserSideCountdownContext = createContext<number | undefined>(undefined);
1213

@@ -100,7 +101,7 @@ export const useOptionsContext = () => useContext(OptionsContext);
100101
const getCurrentLocalRound = (dispute?: ClassicAppealQuery["dispute"]) => {
101102
const period = dispute?.period;
102103
const currentLocalRoundIndex = dispute?.disputeKitDispute?.currentLocalRoundIndex;
103-
return dispute?.disputeKitDispute?.localRounds[
104+
return getLocalRounds(dispute?.disputeKitDispute)[
104105
["appeal", "execution"].includes(period ?? "") ? currentLocalRoundIndex : currentLocalRoundIndex - 1
105106
];
106107
};

web/src/pages/Cases/CaseDetails/Overview.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { StyledSkeleton } from "components/StyledSkeleton";
1515
import DisputeInfo from "components/DisputeCard/DisputeInfo";
1616
import Verdict from "components/Verdict/index";
1717
import { useVotingHistory } from "hooks/queries/useVotingHistory";
18+
import { getLocalRounds } from "utils/getLocalRounds";
1819

1920
const Container = styled.div`
2021
width: 100%;
@@ -117,7 +118,7 @@ const Overview: React.FC<IOverview> = ({ arbitrable, courtID, currentPeriodIndex
117118
const { data: disputeDetails } = useDisputeDetailsQuery(id);
118119
const { data: courtPolicy } = useCourtPolicy(courtID);
119120
const { data: votingHistory } = useVotingHistory(id);
120-
const localRounds = votingHistory?.dispute?.disputeKitDispute?.localRounds;
121+
const localRounds = getLocalRounds(votingHistory?.dispute?.disputeKitDispute);
121122
const courtName = courtPolicy?.name;
122123
const court = disputeDetails?.dispute?.court;
123124
const rewards = court ? `≥ ${formatEther(court.feeForJuror)} ETH` : undefined;

web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useVotingHistory } from "queries/useVotingHistory";
99
import { useDisputeTemplate } from "queries/useDisputeTemplate";
1010
import { shortenAddress } from "utils/shortenAddress";
1111
import { isUndefined } from "utils/index";
12+
import { getLocalRounds } from "utils/getLocalRounds";
1213

1314
const Container = styled.div``;
1415

@@ -87,7 +88,7 @@ const AccordionContent: React.FC<{
8788
);
8889
};
8990

90-
export const getVoteChoice = (vote, answers) => {
91+
export const getVoteChoice = (vote: number, answers: { title: string }[]) => {
9192
const selectedAnswer = answers?.[vote - 1]?.title;
9293
if (vote === 0) {
9394
return "Refuse to arbitrate";
@@ -104,7 +105,7 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
104105
const [currentTab, setCurrentTab] = useState(0);
105106
const { data: disputeTemplate } = useDisputeTemplate(id, arbitrable);
106107
const rounds = votingHistory?.dispute?.rounds;
107-
const localRounds = votingHistory?.dispute?.disputeKitDispute?.localRounds;
108+
const localRounds = getLocalRounds(votingHistory?.dispute?.disputeKitDispute);
108109
const answers = disputeTemplate?.answers;
109110

110111
return (
@@ -115,7 +116,7 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
115116
{isQuestion && disputeTemplate.question ? (
116117
<ReactMarkdown>{disputeTemplate.question}</ReactMarkdown>
117118
) : (
118-
<ReactMarkdown>The dispute's template is not correct please vote refuse to arbitrate</ReactMarkdown>
119+
<ReactMarkdown>{"The dispute's template is not correct please vote refuse to arbitrate"}</ReactMarkdown>
119120
)}
120121
<StyledTabs
121122
currentValue={currentTab}

web/src/utils/getLocalRounds.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { VotingHistoryQuery } from "queries/useVotingHistory";
2+
import { ClassicAppealQuery } from "queries/useClassicAppealQuery";
3+
4+
type IVotingHistoryLocalRounds = NonNullable<
5+
NonNullable<VotingHistoryQuery["dispute"]>["disputeKitDispute"]
6+
>["localRounds"];
7+
8+
type IClassicAppealQueryLocalRounds = NonNullable<
9+
NonNullable<ClassicAppealQuery["dispute"]>["disputeKitDispute"]
10+
>["localRounds"];
11+
12+
type ILocalRounds = IClassicAppealQueryLocalRounds | IVotingHistoryLocalRounds;
13+
14+
interface IDisputeKitDisputes {
15+
localRounds: ILocalRounds;
16+
}
17+
18+
export const getLocalRounds = (disputeKitDisputes: IDisputeKitDisputes | undefined | null) => {
19+
return disputeKitDisputes?.reduce<ILocalRounds>((acc: ILocalRounds, { localRounds }) => acc.concat(localRounds), []);
20+
};

0 commit comments

Comments
 (0)