Skip to content
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

Show sum of my vote stakes on CandidateVote (#2985) #3790

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const args: CandidateVoteProps = {
candidateId: '1',
sumOfAllStakes: new BN(5000000),
totalStake: new BN(500000),
ownStake: new BN(32000),
votes: 20,
index: 1,
myStake: new BN(32000),
myVotes: [],
}
Default.args = args
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@ export interface CandidateVoteProps {
member: Member
sumOfAllStakes: BN
totalStake: BN
ownStake?: BN
votes: number
index: number
myVotes: MyCastVote[]
myStake?: BN
}

const AllRevealedButton = (
<ButtonPrimary size="medium" disabled>
Revealed
</ButtonPrimary>
)

export const CandidateVote = ({
candidateId,
member,
sumOfAllStakes,
totalStake,
ownStake,
votes,
index,
myStake,
myVotes,
}: CandidateVoteProps) => {
const { showModal } = useModal()
Expand All @@ -50,9 +56,11 @@ export const CandidateVote = ({
}, [showModal])

const roundedPercentage = totalStake.gt(BN_ZERO) ? sumOfAllStakes.muln(100).divRound(totalStake).toNumber() : 0
const hasOwnStake = ownStake && ownStake.gt(BN_ZERO)
const hasMyVotes = myVotes.length > 0
const userVoted = myVotes.length > 0
const allVotesRevealed = myVotes.every((vote) => vote.voteFor)

const RevealButton = <RevealVoteButton myVotes={myVotes} voteForHandle={member.handle} />

return (
<CandidateVoteWrapper onClick={showCandidate}>
<VoteIndex lighter inter>
Expand All @@ -74,11 +82,11 @@ export const CandidateVote = ({
</StatsValue>
</StakeAndVotesRow>
<StakeAndVotesRow>
{hasOwnStake && (
{myStake?.gt(BN_ZERO) && (
<>
<Subscription>My Stake</Subscription>
<StatsValue>
<TokenValue value={ownStake} />
<TokenValue value={myStake} />
</StatsValue>
</>
)}
Expand All @@ -91,16 +99,7 @@ export const CandidateVote = ({
</StakeAndVotesRow>
</StakeAndVotesGroup>
</VoteIndicatorWrapper>
<ButtonsGroup>
{hasMyVotes &&
(allVotesRevealed ? (
<ButtonPrimary size="medium" disabled>
Revealed
</ButtonPrimary>
) : (
<RevealVoteButton myVotes={myVotes} voteForHandle={member.handle} />
))}
</ButtonsGroup>
<ButtonsGroup>{userVoted && (allVotesRevealed ? AllRevealedButton : RevealButton)}</ButtonsGroup>
<CandidateCardArrow>
<Arrow direction="right" />
</CandidateCardArrow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const RevealingStageVotes = ({ candidateWithVotes, totalStake, onlyMyVote
sumOfAllStakes: candidate.totalStake,
totalStake: totalStake ?? BN_ZERO,
votes: candidate.votesNumber,
ownStake: candidate.ownStake,
myStake: candidate.myStake,
myVotes: candidate.myVotes,
}))}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export const PastElectionTabs = ({ election }: PastElectionTabsProps) => {
revealed: !!myVote,
member: votingResult.candidate.member,
sumOfAllStakes: votingResult.totalStake,
ownStake: myVote ? myVote.stake : undefined,
totalStake: election.totalStake,
votes: votingResult.votes.length,
index: index + 1,
myVotes: [],
myStake: myVote?.stake,
}
})}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const RevealingStage = ({ election, isLoading }: Props) => {
return {
...candidate,
myVotes: myVotesForCandidate,
ownStake: myVotesForCandidate.reduce((prev, next) => prev.add(next.stake), BN_ZERO),
myStake: myVotesForCandidate.reduce((prev, next) => prev.add(next.stake), BN_ZERO),
}
})
.sort(electionVotingResultComparator)
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/council/hooks/useMyCastVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface MyCastVote extends Vote {
}

export interface CandidateWithMyVotes extends ElectionCandidate {
ownStake: BN
myStake: BN
myVotes: MyCastVote[]
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/test/council/components/ElectionVotes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Results = ({ onlyMyVotes }: { onlyMyVotes: boolean }) => {
return {
...candidate,
myVotes: myVotesForCandidate,
ownStake: myVotesForCandidate.reduce((prev, next) => prev.add(next.stake), BN_ZERO),
myStake: myVotesForCandidate.reduce((prev, next) => prev.add(next.stake), BN_ZERO),
}
})
.sort(electionVotingResultComparator)
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('UI: RevealingStageVotes', () => {
expect(voteNumbers[1].nextSibling?.textContent).toEqual('1')
})

it('Own stake', async () => {
it('My stake', async () => {
seedInformations(server.server, {
votes: [{ voteForId: '0', stake: 2000, castBy: bob.address }],
candidate: [{ memberId: '0', votePower: '3000', votesNumber: 2 }],
Expand Down