Skip to content

Commit

Permalink
Merge pull request #1676 from kleros/feat/rewards-and-execution-indic…
Browse files Browse the repository at this point in the history
…ators

feat(web): ruling-and-rewards-indicators
  • Loading branch information
alcercu authored Aug 23, 2024
2 parents cc4ccc5 + 4029771 commit dc91d63
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
3 changes: 3 additions & 0 deletions web/src/hooks/queries/useVotingHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const votingHistoryQuery = graphql(`
dispute(id: $disputeID) {
id
createdAt
ruled
rounds {
nbVotes
jurorRewardsDispersed
court {
id
name
Expand All @@ -25,6 +27,7 @@ const votingHistoryQuery = graphql(`
}
vote {
... on ClassicVote {
commited
justification {
choice
reference
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import styled from "styled-components";

import CheckCircle from "svgs/icons/check-circle-outline.svg";
import Coins from "svgs/icons/pile-coins.svg";

import Label from "components/DisputeView/CardLabels/Label";

const Container = styled.div`
display: flex;
gap: 8px;
flex-wrap: wrap;
`;

interface IRulingAndRewardsIndicators {
jurorRewardsDispersed: boolean;
ruled: boolean;
}

const RulingAndRewardsIndicators: React.FC<IRulingAndRewardsIndicators> = ({ jurorRewardsDispersed, ruled }) => (
<Container>
{ruled ? <Label icon={CheckCircle} text="Ruling executed" color="green" /> : null}
{jurorRewardsDispersed ? <Label icon={Coins} text="Juror rewards distributed" color="green" /> : null}
</Container>
);

export default RulingAndRewardsIndicators;
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,22 @@ const VoteStatus: React.FC<{
choice?: string;
period: string;
answers: Answer[];
commited: boolean;
isActiveRound: boolean;
}> = ({ choice, period, answers, isActiveRound }) => {
hiddenVotes: boolean;
}> = ({ choice, period, answers, isActiveRound, commited, hiddenVotes }) => {
if (hiddenVotes) {
if (!commited && (isActiveRound ? ["vote", "appeal", "execution"].includes(period) : true))
return <StyledLabel>Did not commit vote </StyledLabel>;

if (["evidence", "commit"].includes(period))
return <StyledLabel>{commited ? "Vote committed" : "Pending vote commitment"}</StyledLabel>;
}

// not voted
if (isUndefined(choice) && (isActiveRound ? ["appeal", "execution"].includes(period) : true))
return <StyledLabel>Did not vote</StyledLabel>;

return (
<StyledLabel>
{isUndefined(choice) ? "Pending Vote" : <StyledSmall>{getVoteChoice(parseInt(choice), answers)}</StyledSmall>}
Expand All @@ -60,14 +72,16 @@ const AccordionTitle: React.FC<{
period: string;
answers: Answer[];
isActiveRound: boolean;
}> = ({ juror, choice, voteCount, period, answers, isActiveRound }) => {
commited: boolean;
hiddenVotes: boolean;
}> = ({ juror, choice, voteCount, period, answers, isActiveRound, commited, hiddenVotes }) => {
return (
<TitleContainer>
<AddressContainer>
<Identicon size="20" string={juror} />
<StyledLabel variant="secondaryText">{shortenAddress(juror)}</StyledLabel>
</AddressContainer>
<VoteStatus {...{ choice, period, answers, isActiveRound }} />
<VoteStatus {...{ choice, period, answers, isActiveRound, commited, hiddenVotes }} />
<StyledLabel variant="secondaryPurple">
{voteCount} vote{voteCount > 1 && "s"}
</StyledLabel>
Expand Down
9 changes: 7 additions & 2 deletions web/src/pages/Cases/CaseDetails/Voting/VotesDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ interface IVotesAccordion {
period: string;
answers: Answer[];
isActiveRound: boolean;
hiddenVotes: boolean;
}

const VotesAccordion: React.FC<IVotesAccordion> = ({ drawnJurors, period, answers, isActiveRound }) => {
const VotesAccordion: React.FC<IVotesAccordion> = ({ drawnJurors, period, answers, isActiveRound, hiddenVotes }) => {
const accordionItems = useMemo(() => {
return drawnJurors
.map((drawnJuror) =>
Expand All @@ -111,6 +112,8 @@ const VotesAccordion: React.FC<IVotesAccordion> = ({ drawnJurors, period, answer
period={period}
answers={answers}
isActiveRound={isActiveRound}
commited={Boolean(drawnJuror.vote.commited)}
hiddenVotes={hiddenVotes}
/>
),
body: (
Expand All @@ -124,7 +127,7 @@ const VotesAccordion: React.FC<IVotesAccordion> = ({ drawnJurors, period, answer
: null
)
.filter((item) => item !== null);
}, [drawnJurors, period, answers, isActiveRound]);
}, [drawnJurors, period, answers, isActiveRound, hiddenVotes]);

return (
<>
Expand All @@ -146,6 +149,8 @@ const VotesAccordion: React.FC<IVotesAccordion> = ({ drawnJurors, period, answer
period={period}
answers={answers}
isActiveRound={isActiveRound}
hiddenVotes={hiddenVotes}
commited={Boolean(drawnJuror.vote?.commited)}
/>
</StyledCard>
)
Expand Down
9 changes: 9 additions & 0 deletions web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import HowItWorks from "components/HowItWorks";
import BinaryVoting from "components/Popup/MiniGuides/BinaryVoting";

import PendingVotesBox from "./PendingVotesBox";
import RulingAndRewardsIndicators from "./RulingAndRewardsIndicators";
import VotesAccordion from "./VotesDetails";

const Container = styled.div``;

const StyledTabs = styled(Tabs)`
width: 100%;
margin-bottom: 16px;
margin-top: 48px;
`;

const Header = styled.div`
Expand Down Expand Up @@ -69,6 +71,8 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
[votingHistory, currentTab]
);

const jurorRewardsDispersed = useMemo(() => Boolean(rounds?.every((round) => round.jurorRewardsDispersed)), [rounds]);

return (
<Container>
<Header>
Expand All @@ -90,6 +94,10 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
)}
</>
)}
<RulingAndRewardsIndicators
ruled={Boolean(disputeData?.dispute?.ruled)}
jurorRewardsDispersed={jurorRewardsDispersed}
/>
<StyledTabs
currentValue={currentTab}
items={rounds.map((_, i) => ({
Expand All @@ -108,6 +116,7 @@ const VotingHistory: React.FC<{ arbitrable?: `0x${string}`; isQuestion: boolean
period={disputeData?.dispute?.period}
answers={answers}
isActiveRound={localRounds?.length - 1 === currentTab}
hiddenVotes={Boolean(disputeData?.dispute?.court.hiddenVotes)}
/>
</>
) : (
Expand Down

0 comments on commit dc91d63

Please sign in to comment.