Skip to content

Commit

Permalink
Fix My stake on CandidateVote (Joystream#2985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joystream Stats committed Nov 17, 2022
1 parent 5cab9bf commit 624d978
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface CandidateVoteProps {
votes: number
index: number
myVotes: MyCastVote[]
myStake?: BN
}

export const CandidateVote = ({
Expand All @@ -40,6 +41,7 @@ export const CandidateVote = ({
votes,
index,
myVotes,
myStake = BN_ZERO,
}: CandidateVoteProps) => {
const { showModal } = useModal()
const showCandidate = useCallback(() => {
Expand All @@ -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 (
<CandidateVoteWrapper onClick={showCandidate}>
<VoteIndex lighter inter>
Expand All @@ -78,7 +81,7 @@ export const CandidateVote = ({
<>
<Subscription>My Stake</Subscription>
<StatsValue>
<TokenValue value={ownStake} />
<TokenValue value={myStake} />
</StatsValue>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Loading />
Expand All @@ -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
),
}))}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const RevealingStage = ({ election, isLoading }: Props) => {
totalStake={totalStake}
votesPerCandidate={sortedVotesPerCandidate}
onlyMyVotes={tab === 'myVotes'}
cycleId={election?.cycleId}
/>
)}
{election && tab === 'candidates' && (
Expand Down

0 comments on commit 624d978

Please sign in to comment.