Skip to content

feat: new overview design #2022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2025
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
11 changes: 11 additions & 0 deletions web/src/assets/svgs/icons/gavel-executed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 57 additions & 6 deletions web/src/components/DisputePreview/DisputeContext.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import React from "react";
import React, { useMemo } from "react";
import styled from "styled-components";

import { DisputeDetails } from "@kleros/kleros-sdk/src/dataMappings/utils/disputeDetailsTypes";
import { useAccount } from "wagmi";

import { INVALID_DISPUTE_DATA_ERROR, RPC_ERROR } from "consts/index";
import { Answer as IAnswer } from "context/NewDisputeContext";
import { isUndefined } from "utils/index";

import { responsiveSize } from "styles/responsiveSize";

import { DisputeDetailsQuery, VotingHistoryQuery } from "src/graphql/graphql";

import ReactMarkdown from "components/ReactMarkdown";
import { StyledSkeleton } from "components/StyledSkeleton";

import { Divider } from "../Divider";
import { ExternalLink } from "../ExternalLink";

import AliasDisplay from "./Alias";
import RulingAndRewardsIndicators from "../Verdict/RulingAndRewardsIndicators";
import CardLabel from "../DisputeView/CardLabels";

const StyledH1 = styled.h1`
margin: 0;
word-wrap: break-word;
font-size: ${responsiveSize(18, 24)};
font-size: ${responsiveSize(20, 26)};
line-height: 24px;
`;

const TitleSection = styled.div`
display: flex;
flex-direction: column;
gap: 12px;
`;

const ReactMarkdownWrapper = styled.div`
& p:first-of-type {
margin: 0;
@@ -66,19 +77,59 @@ const AliasesContainer = styled.div`
gap: ${responsiveSize(8, 20)};
`;

const RulingAndRewardsAndLabels = styled.div`
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 8px;
`;

interface IDisputeContext {
disputeDetails?: DisputeDetails;
isRpcError?: boolean;
dispute?: DisputeDetailsQuery | undefined;

disputeId?: string;
votingHistory?: VotingHistoryQuery | undefined;
}

export const DisputeContext: React.FC<IDisputeContext> = ({ disputeDetails, isRpcError = false }) => {
export const DisputeContext: React.FC<IDisputeContext> = ({
disputeDetails,
isRpcError = false,
dispute,
disputeId,
votingHistory,
}) => {
const { isDisconnected } = useAccount();
const errMsg = isRpcError ? RPC_ERROR : INVALID_DISPUTE_DATA_ERROR;
const rounds = votingHistory?.dispute?.rounds;
const jurorRewardsDispersed = useMemo(() => Boolean(rounds?.every((round) => round.jurorRewardsDispersed)), [rounds]);
console.log({ jurorRewardsDispersed }, disputeDetails);

return (
<>
<StyledH1 dir="auto">
{isUndefined(disputeDetails) ? <StyledSkeleton /> : (disputeDetails?.title ?? errMsg)}
</StyledH1>
<TitleSection>
<StyledH1 dir="auto">
{isUndefined(disputeDetails) ? <StyledSkeleton /> : (disputeDetails?.title ?? errMsg)}
</StyledH1>
{!isUndefined(disputeDetails) &&
!isUndefined(dispute) &&
!isUndefined(disputeId) &&
!isUndefined(votingHistory) ? (
<RulingAndRewardsAndLabels>
{!isUndefined(Boolean(dispute?.dispute?.ruled)) || jurorRewardsDispersed ? (
<RulingAndRewardsIndicators
ruled={Boolean(dispute?.dispute?.ruled)}
jurorRewardsDispersed={jurorRewardsDispersed}
/>
) : null}
{!isDisconnected ? (
<CardLabel {...{ disputeId }} round={rounds?.length - 1} isList={false} isOverview={true} />
) : null}
</RulingAndRewardsAndLabels>
) : null}
<Divider />
</TitleSection>
{disputeDetails?.question?.trim() || disputeDetails?.description?.trim() ? (
<div>
{disputeDetails?.question?.trim() ? (
17 changes: 14 additions & 3 deletions web/src/components/DisputeView/CardLabels/index.tsx
Original file line number Diff line number Diff line change
@@ -22,11 +22,12 @@ import { ClassicContribution } from "src/graphql/graphql";
import Label, { IColors } from "./Label";
import RewardsAndFundLabel from "./RewardsAndFundLabel";

const Container = styled.div<{ isList: boolean }>`
const Container = styled.div<{ isList: boolean; isOverview: boolean }>`
display: flex;
gap: 8px;
flex-direction: column;
align-items: end;
${({ isList }) =>
!isList &&
css`
@@ -36,7 +37,16 @@ const Container = styled.div<{ isList: boolean }>`
flex-direction: row;
align-items: center;
`}
${({ isOverview }) =>
isOverview &&
css`
margin-top: 0;
flex-direction: row;
width: auto;
`}
`;

const RewardsContainer = styled.div`
display: flex;
gap: 4px 8px;
@@ -47,6 +57,7 @@ interface ICardLabels {
disputeId: string;
round: number;
isList: boolean;
isOverview?: boolean;
}

const LabelArgs: Record<string, { text: string; icon: React.FC<React.SVGAttributes<SVGElement>>; color: IColors }> = {
@@ -73,7 +84,7 @@ const getFundingRewards = (contributions: ClassicContribution[], closed: boolean
return Number(formatUnits(BigInt(contribution), 18));
};

const CardLabel: React.FC<ICardLabels> = ({ disputeId, round, isList }) => {
const CardLabel: React.FC<ICardLabels> = ({ disputeId, round, isList, isOverview = false }) => {
const { address } = useAccount();
const { data: labelInfo, isLoading } = useLabelInfoQuery(address?.toLowerCase(), disputeId);
const localRounds = getLocalRounds(labelInfo?.dispute?.disputeKitDispute);
@@ -139,7 +150,7 @@ const CardLabel: React.FC<ICardLabels> = ({ disputeId, round, isList }) => {
}, [contributionRewards, shifts]);

return (
<Container {...{ isList }}>
<Container {...{ isList, isOverview }}>
{isLoading ? (
<Skeleton width={130} height={14} />
) : (
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ const DisputeInfoCard: React.FC<IDisputeInfoCard> = ({ isOverview, showLabels, f
item.display ? <StyledField key={item.name} {...(item as IField)} {...{ isOverview }} /> : null
)}
</RestOfFieldsContainer>
{showLabels ? <CardLabel disputeId={disputeID} round={round - 1} /> : null}
{showLabels ? <CardLabel disputeId={disputeID} round={round - 1} isList={false} /> : null}
</Container>
);
};
194 changes: 85 additions & 109 deletions web/src/components/Verdict/DisputeTimeline.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import React, { useMemo } from "react";
import styled, { useTheme } from "styled-components";

import Skeleton from "react-loading-skeleton";
import { useParams } from "react-router-dom";

import { _TimelineItem1, CustomTimeline } from "@kleros/ui-components-library";

import CalendarIcon from "svgs/icons/calendar.svg";
import ClosedCaseIcon from "svgs/icons/check-circle-outline.svg";
import NewTabIcon from "svgs/icons/new-tab.svg";
import GavelExecutedIcon from "svgs/icons/gavel-executed.svg";

import { Periods } from "consts/periods";
import { usePopulatedDisputeData } from "hooks/queries/usePopulatedDisputeData";
@@ -21,8 +20,6 @@ import { useVotingHistory } from "queries/useVotingHistory";
import { ClassicRound } from "src/graphql/graphql";
import { getTxnExplorerLink } from "src/utils";

import { responsiveSize } from "styles/responsiveSize";

import { StyledClosedCircle } from "components/StyledIcons/ClosedCircleIcon";

import { ExternalLink } from "../ExternalLink";
@@ -37,24 +34,6 @@ const StyledTimeline = styled(CustomTimeline)`
width: 100%;
`;

const EnforcementContainer = styled.div`
display: flex;
gap: 8px;
margin-top: ${responsiveSize(12, 24)};
fill: ${({ theme }) => theme.secondaryText};
small {
font-weight: 400;
line-height: 19px;
color: ${({ theme }) => theme.secondaryText};
}
`;

const StyledCalendarIcon = styled(CalendarIcon)`
width: 14px;
height: 14px;
`;

const StyledNewTabIcon = styled(NewTabIcon)`
margin-bottom: 2px;
path {
@@ -84,73 +63,95 @@ const useItems = (disputeDetails?: DisputeDetailsQuery, arbitrable?: `0x${string
const localRounds: ClassicRound[] = getLocalRounds(votingHistory?.dispute?.disputeKitDispute) as ClassicRound[];
const rounds = votingHistory?.dispute?.rounds;
const theme = useTheme();
const txnExplorerLink = useMemo(() => {
const txnDisputeCreatedLink = useMemo(() => {
return getTxnExplorerLink(votingHistory?.dispute?.transactionHash ?? "");
}, [votingHistory]);
const txnEnforcementLink = useMemo(() => {
return getTxnExplorerLink(disputeDetails?.dispute?.rulingTransactionHash ?? "");
}, [disputeDetails]);

return useMemo<TimelineItems | undefined>(() => {
const dispute = disputeDetails?.dispute;
if (dispute) {
const rulingOverride = dispute.overridden;
const currentPeriodIndex = Periods[dispute.period];

return localRounds?.reduce<TimelineItems>(
(acc, { winningChoice }, index) => {
const isOngoing = index === localRounds.length - 1 && currentPeriodIndex < 3;
const roundTimeline = rounds?.[index].timeline;

const icon = dispute.ruled && !rulingOverride && index === localRounds.length - 1 ? ClosedCaseIcon : "";
const answers = disputeData?.answers;
acc.push({
title: `Jury Decision - Round ${index + 1}`,
party: isOngoing ? "Voting is ongoing" : getVoteChoice(winningChoice, answers),
subtitle: isOngoing
? ""
: `${formatDate(roundTimeline?.[Periods.vote])} / ${
votingHistory?.dispute?.rounds.at(index)?.court.name
}`,
rightSided: true,
variant: theme.secondaryPurple,
Icon: icon !== "" ? icon : undefined,
});

if (index < localRounds.length - 1) {
acc.push({
title: "Appealed",
party: "",
subtitle: formatDate(roundTimeline?.[Periods.appeal]),
rightSided: true,
Icon: StyledClosedCircle,
});
} else if (rulingOverride && dispute.currentRuling !== winningChoice) {
acc.push({
title: "Won by Appeal",
party: getVoteChoice(dispute.currentRuling, answers),
subtitle: formatDate(roundTimeline?.[Periods.appeal]),
rightSided: true,
Icon: ClosedCaseIcon,
});
}

return acc;
},
[
{
title: "Dispute created",
party: (
<ExternalLink to={txnExplorerLink} rel="noopener noreferrer" target="_blank">
<StyledNewTabIcon />
</ExternalLink>
),
subtitle: formatDate(votingHistory?.dispute?.createdAt),
rightSided: true,
variant: theme.secondaryPurple,
},
]
);
if (!dispute) return;

const rulingOverride = dispute.overridden;
const currentPeriodIndex = Periods[dispute.period];

const base: TimelineItems = [
{
title: "Dispute created",
party: (
<ExternalLink to={txnDisputeCreatedLink} rel="noopener noreferrer" target="_blank">
<StyledNewTabIcon />
</ExternalLink>
),
subtitle: formatDate(votingHistory?.dispute?.createdAt),
rightSided: true,
variant: theme.secondaryPurple,
},
];

const items = localRounds?.reduce<_TimelineItem1[]>((acc, { winningChoice }, index) => {
const isOngoing = index === localRounds.length - 1 && currentPeriodIndex < 3;
const roundTimeline = rounds?.[index].timeline;
const icon = dispute.ruled && !rulingOverride && index === localRounds.length - 1 ? ClosedCaseIcon : undefined;
const answers = disputeData?.answers;

acc.push({
title: `Jury Decision - Round ${index + 1}`,
party: isOngoing ? "Voting is ongoing" : getVoteChoice(winningChoice, answers),
subtitle: isOngoing ? "" : `${formatDate(roundTimeline?.[Periods.vote])} / ${rounds?.[index]?.court.name}`,
rightSided: true,
variant: theme.secondaryPurple,
Icon: icon,
});

if (index < localRounds.length - 1) {
acc.push({
title: "Appealed",
party: "",
subtitle: formatDate(roundTimeline?.[Periods.appeal]),
rightSided: true,
Icon: StyledClosedCircle,
});
} else if (rulingOverride && dispute.currentRuling !== winningChoice) {
acc.push({
title: "Won by Appeal",
party: getVoteChoice(dispute.currentRuling, answers),
subtitle: formatDate(roundTimeline?.[Periods.appeal]),
rightSided: true,
Icon: ClosedCaseIcon,
});
}

return acc;
}, []);

if (dispute.ruled) {
items.push({
title: "Enforcement",
party: (
<ExternalLink to={txnEnforcementLink} rel="noopener noreferrer" target="_blank">
<StyledNewTabIcon />
</ExternalLink>
),
subtitle: `${formatDate(dispute.rulingTimestamp)} / ${rounds?.at(-1)?.court.name}`,
rightSided: true,
Icon: GavelExecutedIcon,
});
}
return;
}, [disputeDetails, disputeData, localRounds, theme, rounds, votingHistory, txnExplorerLink]);

return [...base, ...items] as TimelineItems;
}, [
disputeDetails,
disputeData,
localRounds,
theme,
rounds,
votingHistory,
txnDisputeCreatedLink,
txnEnforcementLink,
]);
};

interface IDisputeTimeline {
@@ -160,33 +161,8 @@ interface IDisputeTimeline {
const DisputeTimeline: React.FC<IDisputeTimeline> = ({ arbitrable }) => {
const { id } = useParams();
const { data: disputeDetails } = useDisputeDetailsQuery(id);
const { data: votingHistory } = useVotingHistory(id);
const items = useItems(disputeDetails, arbitrable);

const transactionExplorerLink = useMemo(() => {
return getTxnExplorerLink(disputeDetails?.dispute?.rulingTransactionHash ?? "");
}, [disputeDetails]);

return (
<Container>
{items && <StyledTimeline {...{ items }} />}
{disputeDetails?.dispute?.ruled && (
<EnforcementContainer>
<StyledCalendarIcon />
<small>
Enforcement:{" "}
{disputeDetails.dispute.rulingTimestamp ? (
<ExternalLink to={transactionExplorerLink} rel="noopener noreferrer" target="_blank">
{formatDate(disputeDetails.dispute.rulingTimestamp)}
</ExternalLink>
) : (
<Skeleton height={16} width={56} />
)}{" "}
/ {votingHistory?.dispute?.rounds.at(-1)?.court.name}
</small>
</EnforcementContainer>
)}
</Container>
);
return <Container>{items && <StyledTimeline {...{ items }} />}</Container>;
};
export default DisputeTimeline;
38 changes: 14 additions & 24 deletions web/src/components/Verdict/FinalDecision.tsx
Original file line number Diff line number Diff line change
@@ -12,10 +12,9 @@ import { REFETCH_INTERVAL } from "consts/index";
import { Periods } from "consts/periods";
import { useReadKlerosCoreCurrentRuling } from "hooks/contracts/generated";
import { usePopulatedDisputeData } from "hooks/queries/usePopulatedDisputeData";
import { useVotingHistory } from "hooks/queries/useVotingHistory";
import { VotingHistoryQuery } from "hooks/queries/useVotingHistory";
import { useVotingContext } from "hooks/useVotingContext";
import { getLocalRounds } from "utils/getLocalRounds";
import { isUndefined } from "utils/index";

import { useDisputeDetailsQuery } from "queries/useDisputeDetailsQuery";

@@ -25,7 +24,6 @@ import { Divider } from "../Divider";
import { StyledArrowLink } from "../StyledArrowLink";

import AnswerDisplay from "./Answer";
import RulingAndRewardsIndicators from "./RulingAndRewardsIndicators";

const Container = styled.div`
width: 100%;
@@ -61,11 +59,11 @@ const JuryDecisionTag = styled.small`
`;

const StyledDivider = styled(Divider)`
margin: 16px 0px;
margin: 16px 0 0;
${landscapeStyle(
() => css`
margin: 24px 0px;
margin: 24px 0 0;
`
)}
`;
@@ -81,15 +79,15 @@ const ReStyledArrowLink = styled(StyledArrowLink)`

interface IFinalDecision {
arbitrable?: `0x${string}`;
votingHistory: VotingHistoryQuery | undefined;
}

const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable }) => {
const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable, votingHistory }) => {
const { id } = useParams();
const { isDisconnected } = useAccount();
const { data: populatedDisputeData } = usePopulatedDisputeData(id, arbitrable);
const { data: disputeDetails } = useDisputeDetailsQuery(id);
const { wasDrawn, hasVoted, isLoading, isCommitPeriod, isVotingPeriod, commited, isHiddenVotes } = useVotingContext();
const { data: votingHistory } = useVotingHistory(id);
const localRounds = getLocalRounds(votingHistory?.dispute?.disputeKitDispute);
const ruled = disputeDetails?.dispute?.ruled ?? false;
const periodIndex = Periods[disputeDetails?.dispute?.period ?? "evidence"];
@@ -101,25 +99,17 @@ const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable }) => {
const currentRuling = Number(currentRulingArray?.[0] ?? 0);

const answer = populatedDisputeData?.answers?.find((answer) => BigInt(answer.id) === BigInt(currentRuling));
const rounds = votingHistory?.dispute?.rounds;
const jurorRewardsDispersed = useMemo(() => Boolean(rounds?.every((round) => round.jurorRewardsDispersed)), [rounds]);
const buttonText = useMemo(() => {
if (!wasDrawn || isDisconnected) return "Check how the jury voted";
if (!wasDrawn || isDisconnected) return "Check votes";
if (isCommitPeriod && !commited) return "Commit your vote";
if (isVotingPeriod && isHiddenVotes && commited && !hasVoted) return "Reveal your vote";
if (isVotingPeriod && !isHiddenVotes && !hasVoted) return "Cast your vote";
return "Check how the jury voted";
return "Check votes";
}, [wasDrawn, hasVoted, isCommitPeriod, isVotingPeriod, commited, isHiddenVotes, isDisconnected]);

return (
<Container>
<VerdictContainer>
{!isUndefined(Boolean(disputeDetails?.dispute?.ruled)) || jurorRewardsDispersed ? (
<RulingAndRewardsIndicators
ruled={Boolean(disputeDetails?.dispute?.ruled)}
jurorRewardsDispersed={jurorRewardsDispersed}
/>
) : null}
{ruled && (
<JuryContainer>
<JuryDecisionTag>The jury decided in favor of:</JuryDecisionTag>
@@ -140,15 +130,15 @@ const FinalDecision: React.FC<IFinalDecision> = ({ arbitrable }) => {
)}
</JuryContainer>
)}
{isLoading && !isDisconnected ? (
<Skeleton width={250} height={20} />
) : (
<ReStyledArrowLink to={`/cases/${id?.toString()}/voting`}>
{buttonText} <ArrowIcon />
</ReStyledArrowLink>
)}
</VerdictContainer>
<StyledDivider />
{isLoading && !isDisconnected ? (
<Skeleton width={250} height={20} />
) : (
<ReStyledArrowLink to={`/cases/${id?.toString()}/voting`}>
{buttonText} <ArrowIcon />
</ReStyledArrowLink>
)}
</Container>
);
};
9 changes: 6 additions & 3 deletions web/src/components/Verdict/index.tsx
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import styled from "styled-components";

import { responsiveSize } from "styles/responsiveSize";

import { VotingHistoryQuery } from "src/graphql/graphql";

import DisputeTimeline from "./DisputeTimeline";
import FinalDecision from "./FinalDecision";

@@ -14,13 +16,14 @@ const Container = styled.div`

interface IVerdict {
arbitrable?: `0x${string}`;
votingHistory: VotingHistoryQuery | undefined;
}

const Verdict: React.FC<IVerdict> = ({ arbitrable }) => {
const Verdict: React.FC<IVerdict> = ({ arbitrable, votingHistory }) => {
return (
<Container>
<FinalDecision arbitrable={arbitrable} />
<DisputeTimeline arbitrable={arbitrable} />
<FinalDecision {...{ votingHistory, arbitrable }} />
<DisputeTimeline {...{ arbitrable }} />
</Container>
);
};
4 changes: 2 additions & 2 deletions web/src/pages/Cases/CaseDetails/Overview/index.tsx
Original file line number Diff line number Diff line change
@@ -56,10 +56,10 @@ const Overview: React.FC<IOverview> = ({ arbitrable, courtID, currentPeriodIndex
return (
<>
<Container>
<DisputeContext disputeDetails={disputeDetails} isRpcError={isError} />
<DisputeContext isRpcError={isError} disputeId={id} {...{ votingHistory, disputeDetails, dispute }} />
<Divider />

<Verdict arbitrable={arbitrable} />
<Verdict {...{ arbitrable, votingHistory }} />
<Divider />

<DisputeInfo