Skip to content

Commit

Permalink
Revert changes to progress bar, fix displaying voting results
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrila committed Oct 18, 2023
1 parent b9c27cf commit 2a8b947
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default function SnapshotProposalVoteItem({ proposal, vote }: ISnapshotPr
</Flex>
) : (
<StatusBox>
<Text textStyle="text-sm-mono-semibold">{vote.choice as string}</Text>
<Text textStyle="text-sm-mono-semibold">
{proposal.choices[(vote.choice as number) - 1]}
</Text>
</StatusBox>
)}
</GridItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function SnapshotProposalVotes({ proposal }: ISnapshotProposalVot
<VotesPercentage
key={choice}
label={choice}
percentage={Number(choicePercentageFromTotal.toFixed(2))}
percentage={Number(choicePercentageFromTotal.toFixed(1))}
>
<Text>
{proposal.privacy === 'shutter' &&
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/utils/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ProgressBar({
height="100%"
position="absolute"
top="0"
left={value > 50 ? `calc(${Math.min(value - 5, 90)}% - 20px)` : `${value / 2}%`}
left={value > 50 ? `calc(${Math.min(value - 5, 90)}% - 20px)` : value / 2}
>
{valueLabel || Math.min(value, 100)}
{unit}
Expand Down
30 changes: 20 additions & 10 deletions src/hooks/DAO/loaders/snapshot/useSnapshotProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,21 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u

const { choices, type, privacy } = proposalQueryResult;

Object.keys(choices).forEach(choice => {
votesBreakdown[choice] = {
votes: [],
total: 0,
};
});
if (type === 'weighted') {
Object.keys(choices).forEach((choice: string) => {
votesBreakdown[choice] = {
votes: [],
total: 0,
};
});
} else {
choices.forEach((choice: string) => {
votesBreakdown[choice] = {
votes: [],
total: 0,
};
});
}

const isShielded = privacy === 'shutter';
const isClosed = snapshotProposal.state === FractalProposalState.CLOSED;
Expand All @@ -141,16 +150,17 @@ export default function useSnapshotProposal(proposal: FractalProposal | null | u
}
});
} else {
const voteChoice = vote.choice as string;
const existingChoiceType = votesBreakdown[voteChoice];
const voteChoice = vote.choice as number;
const choiceKey = choices[voteChoice - 1];
const existingChoiceType = votesBreakdown[choiceKey];

if (existingChoiceType) {
votesBreakdown[voteChoice] = {
votesBreakdown[choiceKey] = {
total: existingChoiceType.total + getVoteWeight(vote),
votes: [...existingChoiceType.votes, vote],
};
} else {
votesBreakdown[voteChoice] = {
votesBreakdown[choiceKey] = {
total: getVoteWeight(vote),
votes: [vote],
};
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/DAO/proposal/useCastVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const useCastVote = ({
);

const castSnapshotVote = useCallback(
async (choice: string) => {
async (choice: number) => {
if (signer && signer?.provider && address && daoSnapshotURL && extendedSnapshotProposal) {
let toastId;
try {
Expand All @@ -114,7 +114,7 @@ const useCastVote = ({
});
if (extendedSnapshotProposal.privacy === 'shutter') {
const encryptedChoice = await encryptWithShutter(
choice,
JSON.stringify(choice),
extendedSnapshotProposal.proposalId
);
await client.vote(signer.provider as ethers.providers.Web3Provider, address, {
Expand Down
2 changes: 1 addition & 1 deletion src/types/daoProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export interface SnapshotVote {
votingWeightByStrategy: number[];
votingState: string;
created: number;
choice: string | SnapshotWeightedVotingChoice;
choice: number | SnapshotWeightedVotingChoice;
}

export interface SnapshotVoteBreakdown {
Expand Down

0 comments on commit 2a8b947

Please sign in to comment.