Skip to content

Commit

Permalink
Fix: voting OutcomeStep display correct side winnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rdig committed Nov 28, 2023
1 parent 0742f8c commit 73fbbf9
Showing 1 changed file with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,41 +1,67 @@
import React, { FC } from 'react';
import { formatText } from '~utils/intl';

import CardWithSections from '~v5/shared/CardWithSections';
import { UserAvatarsItem } from '~v5/shared/UserAvatars/types';

import { formatText } from '~utils/intl';
import { MotionState, MotionVote } from '~utils/colonyMotions';
import { useAppContext } from '~hooks';

import { OutcomeStepProps } from './types';
import { useOutcomeStep } from './hooks';
import VoteStatuses from './partials/VoteStatuses';
import { MotionState } from '~utils/colonyMotions';
import { UserAvatarsItem } from '~v5/shared/UserAvatars/types';

const displayName =
'v5.common.ActionSidebar.partials.motions.Motion.steps.OutcomeStep';

const OutcomeStep: FC<OutcomeStepProps> = ({ motionData, motionState }) => {
const { wallet, user } = useAppContext();
const { voteStatuses } = useOutcomeStep(motionData);

const canInteract = !!wallet && !!user;

const voters: UserAvatarsItem[] =
motionData?.voterRecord.map((voter) => ({
address: voter.address,
voteCount: voter.voteCount,
vote: voter.vote ?? undefined,
})) || [];

const currentUserVote = voters.find(
({ address }) => address === wallet?.address,
);
const currentUserVoted = !!currentUserVote;

let outcome = false;
if (
currentUserVote?.vote === MotionVote.Yay &&
motionState === MotionState.Passed
) {
outcome = true;
}
if (
currentUserVote?.vote === MotionVote.Nay &&
motionState === MotionState.Failed
) {
outcome = true;
}

return (
<CardWithSections
sections={[
{
key: '1',
content: (
<div className="flex flex-col gap-4">
<h3 className="text-center text-1 mb-2">
{formatText({
id:
motionState === MotionState.Passed
{canInteract && currentUserVoted && (
<h3 className="text-center text-1 mb-2">
{formatText({
id: outcome
? 'motion.outcomeStep.win.title'
: 'motion.outcomeStep.lost.title',
})}
</h3>
})}
</h3>
)}
<VoteStatuses items={voteStatuses} voters={voters} />
</div>
),
Expand Down

0 comments on commit 73fbbf9

Please sign in to comment.