Skip to content

Commit

Permalink
feat(web): vote-commited-indicator-in-voting-history
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed Aug 21, 2024
1 parent 60cb52c commit 4029771
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions web/src/hooks/queries/useVotingHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,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
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
1 change: 1 addition & 0 deletions web/src/pages/Cases/CaseDetails/Voting/VotingHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,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 4029771

Please sign in to comment.