From d15c6160e6cb010b01c4a854016bcf3f31187e91 Mon Sep 17 00:00:00 2001 From: Sem <931684+sembrestels@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:56:21 +0100 Subject: [PATCH] Use units instead of ratios when voting --- apps/web/src/app/page.tsx | 3 ++- apps/web/src/components/VotingButton.tsx | 3 +-- apps/web/src/components/VotingCard.tsx | 34 +++++++++++++----------- apps/web/src/hooks/useAllocation.ts | 9 ++++++- apps/web/src/hooks/useWriteAllocation.ts | 22 +++------------ 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index a8501cd..c234b9f 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -30,7 +30,7 @@ export default function Page() { // Fetch data when the council is available const { address } = useAccount(); const { data: councilData, isLoading } = useCouncil(council); - const { data: myAllocation } = useAllocation(council, address); + const { data: myAllocation, votingPower } = useAllocation(council, address); const grantees = councilData?.grantees; return ( @@ -46,6 +46,7 @@ export default function Page() { initialAllocation={myAllocation} maxVotedProjects={3} isLoading={isLoading || !council} + votingPower={votingPower} /> ); diff --git a/apps/web/src/components/VotingButton.tsx b/apps/web/src/components/VotingButton.tsx index a4176df..7f6e261 100644 --- a/apps/web/src/components/VotingButton.tsx +++ b/apps/web/src/components/VotingButton.tsx @@ -22,7 +22,6 @@ const VotingButton = ({ }: VotingButtonProps) => { const { address } = useAccount(); const vote = useWriteAllocation(council); - const totalVotes = Object.values(votes).reduce((a, b) => a + b, 0); const [isLoading, setIsLoading] = useState(false); const toast = useToast(); @@ -37,7 +36,7 @@ const VotingButton = ({ .filter(([, voteCount]) => voteCount > 0) .map(([grantee, voteCount]) => ({ account: grantee as `0x${string}`, - ratio: (BigInt(voteCount) * 2n ** 128n) / BigInt(totalVotes), + amount: BigInt(voteCount), })), ) .then(() => { diff --git a/apps/web/src/components/VotingCard.tsx b/apps/web/src/components/VotingCard.tsx index 5173f6f..852480f 100644 --- a/apps/web/src/components/VotingCard.tsx +++ b/apps/web/src/components/VotingCard.tsx @@ -21,24 +21,18 @@ const VotingCard = ({ council, projects, initialAllocation, + votingPower, maxVotedProjects = 3, isLoading = false, }: { className: string; council: `0x${string}` | undefined; projects: Project[]; - maxVotedProjects?: number; initialAllocation: Allocation | undefined; + votingPower: number; + maxVotedProjects?: number; isLoading: boolean; }) => { - console.log( - initialAllocation, - projects.map((project) => [ - project.account, - initialAllocation?.[project.account] ?? 0, - ]), - ); - const [votes, setVotes] = useState( Object.fromEntries( projects.map((project) => [ @@ -86,11 +80,17 @@ const VotingCard = ({
No projects to vote on
) : ( <> -

- Cast Your Vote ({votedProjects.length} / {maxVotedProjects}{" "} - projects) -

+
+

+ Cast Your Vote ({votedProjects.length} / {maxVotedProjects}{" "} + projects) +

+
+ Used {totalVotes} / {votingPower} +
+
{projects.map((project) => { + console.log(totalVotes, votingPower); const voteCount = votes[project.account] || 0; return (