From 459ce5a4488054ade0651b5a7f52c53fd1c8bd90 Mon Sep 17 00:00:00 2001 From: MrX-SNX Date: Fri, 6 Sep 2024 13:23:19 +0100 Subject: [PATCH] Voting issues (#442) * fix: counting * feat: total votes --- .../components/CouncilCard/CouncilCard.tsx | 5 ++-- .../MyVotesSummary/MyVotesSummary.tsx | 2 +- governance/ui/src/mutations/useCastVotes.ts | 5 ++-- governance/ui/src/pages/App.tsx | 25 +++++++++++++++++-- .../ui/src/queries/useGetHistoricalVotes.ts | 12 +++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/governance/ui/src/components/CouncilCard/CouncilCard.tsx b/governance/ui/src/components/CouncilCard/CouncilCard.tsx index 1bb22efe0..d8c9470a4 100644 --- a/governance/ui/src/components/CouncilCard/CouncilCard.tsx +++ b/governance/ui/src/components/CouncilCard/CouncilCard.tsx @@ -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(); @@ -121,7 +122,7 @@ export function CouncilCard({ council }: CouncilCardProps) { - 0000 + {votesReceived} diff --git a/governance/ui/src/components/MyVotesSummary/MyVotesSummary.tsx b/governance/ui/src/components/MyVotesSummary/MyVotesSummary.tsx index 5d7bfd3a1..aed2eed0a 100644 --- a/governance/ui/src/components/MyVotesSummary/MyVotesSummary.tsx +++ b/governance/ui/src/components/MyVotesSummary/MyVotesSummary.tsx @@ -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; diff --git a/governance/ui/src/mutations/useCastVotes.ts b/governance/ui/src/mutations/useCastVotes.ts index fb25febe0..f721eb49e 100644 --- a/governance/ui/src/mutations/useCastVotes.ts +++ b/governance/ui/src/mutations/useCastVotes.ts @@ -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); @@ -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, }); diff --git a/governance/ui/src/pages/App.tsx b/governance/ui/src/pages/App.tsx index b482c0520..051592e92 100644 --- a/governance/ui/src/pages/App.tsx +++ b/governance/ui/src/pages/App.tsx @@ -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 ( <> @@ -39,7 +41,15 @@ function App() { {councils.map((council) => ( - + ))} @@ -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'; + } +} diff --git a/governance/ui/src/queries/useGetHistoricalVotes.ts b/governance/ui/src/queries/useGetHistoricalVotes.ts index ed74c6d79..f2f0c1fd1 100644 --- a/governance/ui/src/queries/useGetHistoricalVotes.ts +++ b/governance/ui/src/queries/useGetHistoricalVotes.ts @@ -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,