Skip to content

Commit

Permalink
Voting issues (#442)
Browse files Browse the repository at this point in the history
* fix: counting

* feat: total votes
  • Loading branch information
MrX-SNX authored Sep 6, 2024
1 parent cf13fa3 commit 459ce5a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
5 changes: 3 additions & 2 deletions governance/ui/src/components/CouncilCard/CouncilCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { useWallet } from '../../queries/useWallet';

interface CouncilCardProps {
council: Council;
votesReceived?: number;
}

export function CouncilCard({ council }: CouncilCardProps) {
export function CouncilCard({ council, votesReceived }: CouncilCardProps) {
const navigate = useNavigate();
const { activeWallet } = useWallet();

Expand Down Expand Up @@ -121,7 +122,7 @@ export function CouncilCard({ council }: CouncilCardProps) {
<Skeleton isLoaded={!isLoading} height="24px" mt={1} placeholder="0000">
<Fade in>
<Text fontSize="24px" lineHeight="32px" fontWeight={700} textAlign="end">
0000
{votesReceived}
</Text>
</Fade>
</Skeleton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const MyVotesSummary = ({
const { network } = useNetwork();
const { data: epochId } = useGetEpochIndex('spartan');
const { state } = useVoteContext();
const networkForState = getVoteSelectionState(state, epochId, network?.id.toString(), 'spartan');
const networkForState = getVoteSelectionState(state, epochId, network?.id.toString());
const stateFromCouncils = (
typeof networkForState !== 'string' ? networkForState : { spartan: networkForState }
) as VoteStateForNetwork;
Expand Down
5 changes: 3 additions & 2 deletions governance/ui/src/mutations/useCastVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function useCastVotes(
await multicall
.connect(signer)
[isMC ? 'aggregate' : 'aggregate3Value']([...prepareBallotData, ...castData], {
value: isMC ? 0 : quote.add(quote.mul(25).div(100)),
value: isMC ? 0 : quote.add(quote.mul(25).div(100)).mul(councils.length),
});
} catch (error: any) {
console.error(error);
Expand All @@ -143,9 +143,10 @@ export function useCastVotes(
}
},
onError: (error) => {
console.error(error);
toast({
title: 'Could not cast votes.',
description: error.message,
description: 'Check the browser console for more information',
status: 'error',
isClosable: true,
});
Expand Down
25 changes: 23 additions & 2 deletions governance/ui/src/pages/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Container, Flex, Heading, Text } from '@chakra-ui/react';
import councils from '../utils/councils';
import councils, { CouncilSlugs } from '../utils/councils';
import { CouncilCard } from '../components/CouncilCard';
import Head from 'react-helmet';
import { useGetHistoricalVotes } from '../queries';

function App() {
const { data: votes } = useGetHistoricalVotes();
return (
<>
<Head>
Expand Down Expand Up @@ -39,7 +41,15 @@ function App() {
</Flex>
<Flex wrap={{ base: 'wrap', lg: 'nowrap' }} w="100%" gap={{ base: 4, lg: 6 }} mt="8">
{councils.map((council) => (
<CouncilCard council={council} key={council.address.concat('council-card')} />
<CouncilCard
council={council}
votesReceived={
votes && votes[totalVotesForCouncil(council.slug)]
? votes[totalVotesForCouncil(council.slug)].toNumber()
: 0
}
key={council.address.concat('council-card')}
/>
))}
</Flex>
</Container>
Expand All @@ -49,3 +59,14 @@ function App() {
}

export default App;

function totalVotesForCouncil(council: CouncilSlugs) {
switch (council) {
case 'spartan':
return 'totalVotesSpartan';
case 'ambassador':
return 'totalVotesAmbassador';
case 'treasury':
return 'totalVotesTreasury';
}
}
12 changes: 12 additions & 0 deletions governance/ui/src/queries/useGetHistoricalVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ export function useGetHistoricalVotes() {
(cur, candidate) => cur.add(treasury[candidate].votePower),
BigNumber.from(0)
),
totalVotesSpartan: Object.keys(spartan).reduce(
(cur, candidate) => cur.add(spartan[candidate].votesReceived),
BigNumber.from(0)
),
totalVotesAmbassador: Object.keys(ambassador).reduce(
(cur, candidate) => cur.add(ambassador[candidate].votesReceived),
BigNumber.from(0)
),
totalVotesTreasury: Object.keys(treasury).reduce(
(cur, candidate) => cur.add(treasury[candidate].votesReceived),
BigNumber.from(0)
),
};
},
staleTime: 900000,
Expand Down

0 comments on commit 459ce5a

Please sign in to comment.