From 624d978bf8f805e6d081dda3ab582156675e1944 Mon Sep 17 00:00:00 2001 From: Joystream Stats Date: Mon, 31 Oct 2022 19:41:59 +0000 Subject: [PATCH] Fix `My stake` on `CandidateVote` (#2985) --- .../components/election/CandidateVote/CandidateVote.tsx | 5 ++++- .../election/CandidateVote/RevealingStageVotes.tsx | 9 ++++++++- .../components/election/revealing/RevealingStage.tsx | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/council/components/election/CandidateVote/CandidateVote.tsx b/packages/ui/src/council/components/election/CandidateVote/CandidateVote.tsx index 864f534315..37758e9268 100644 --- a/packages/ui/src/council/components/election/CandidateVote/CandidateVote.tsx +++ b/packages/ui/src/council/components/election/CandidateVote/CandidateVote.tsx @@ -29,6 +29,7 @@ export interface CandidateVoteProps { votes: number index: number myVotes: MyCastVote[] + myStake?: BN } export const CandidateVote = ({ @@ -40,6 +41,7 @@ export const CandidateVote = ({ votes, index, myVotes, + myStake = BN_ZERO, }: CandidateVoteProps) => { const { showModal } = useModal() const showCandidate = useCallback(() => { @@ -53,6 +55,7 @@ export const CandidateVote = ({ const hasOwnStake = ownStake && ownStake.gt(BN_ZERO) const hasMyVotes = myVotes.length > 0 const allVotesRevealed = myVotes.every((vote) => vote.voteFor) + return ( @@ -78,7 +81,7 @@ export const CandidateVote = ({ <> My Stake - + )} diff --git a/packages/ui/src/council/components/election/CandidateVote/RevealingStageVotes.tsx b/packages/ui/src/council/components/election/CandidateVote/RevealingStageVotes.tsx index ea4cfdf4b5..6ac28ba76a 100644 --- a/packages/ui/src/council/components/election/CandidateVote/RevealingStageVotes.tsx +++ b/packages/ui/src/council/components/election/CandidateVote/RevealingStageVotes.tsx @@ -5,18 +5,21 @@ import { Loading } from '@/common/components/Loading' import { NoData } from '@/common/components/NoData' import { BN_ZERO } from '@/common/constants' import { CandidateStats } from '@/council/hooks/useElectionVotes' +import { useMyCastVotes } from '@/council/hooks/useMyCastVotes' import { CandidateVoteList } from './CandidateVoteList' interface Props { + cycleId: number onlyMyVotes?: boolean votesPerCandidate: CandidateStats[] totalStake?: BN isLoading: boolean } -export const RevealingStageVotes = ({ votesPerCandidate, totalStake, onlyMyVotes, isLoading }: Props) => { +export const RevealingStageVotes = ({ cycleId, votesPerCandidate, totalStake, onlyMyVotes, isLoading }: Props) => { const votesToDisplay = onlyMyVotes ? votesPerCandidate.filter((vote) => vote.myVotes.length) : votesPerCandidate + const myStakes = useMyCastVotes(cycleId ?? undefined).votes?.map(({ stake, voteFor }) => ({ stake, voteFor })) ?? [] if (isLoading) { return @@ -41,6 +44,10 @@ export const RevealingStageVotes = ({ votesPerCandidate, totalStake, onlyMyVotes votes: candidateStats.votesNumber, ownStake: candidateStats.ownStake, myVotes: candidateStats.myVotes, + myStake: myStakes.reduce( + (sum, { voteFor, stake }) => (voteFor?.id === candidateStats.candidate.id ? sum.add(stake) : sum), + BN_ZERO + ), }))} /> ) diff --git a/packages/ui/src/council/components/election/revealing/RevealingStage.tsx b/packages/ui/src/council/components/election/revealing/RevealingStage.tsx index 01b8d914f0..c077b73ec5 100644 --- a/packages/ui/src/council/components/election/revealing/RevealingStage.tsx +++ b/packages/ui/src/council/components/election/revealing/RevealingStage.tsx @@ -44,6 +44,7 @@ export const RevealingStage = ({ election, isLoading }: Props) => { totalStake={totalStake} votesPerCandidate={sortedVotesPerCandidate} onlyMyVotes={tab === 'myVotes'} + cycleId={election?.cycleId} /> )} {election && tab === 'candidates' && (