Skip to content

Commit

Permalink
Increment and decrement votes by 10% in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
sembrestels committed Sep 23, 2024
1 parent d94383e commit 0d14d2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 17 additions & 4 deletions apps/web/src/components/VotingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ const VotingCard = ({
</div>
</div>
{projects.map((project) => {
console.log(totalVotes, votingPower);
const voteCount = votes[project.account] || 0;
return (
<div
Expand All @@ -101,7 +100,12 @@ const VotingCard = ({
<div className="flex items-center">
<Button
disabled={voteCount <= 0}
onClick={() => handleVote(project.account, voteCount - 1)}
onClick={() =>
handleVote(
project.account,
Math.max(0, voteCount - Math.floor(votingPower / 10)),
)
}
className="bg-gray-700 w-8 py-1 text-white hover:bg-gray-500 rounded-r-none"
>
-
Expand All @@ -123,14 +127,23 @@ const VotingCard = ({
!votes[project.account]) ||
totalVotes >= votingPower
}
onClick={() => handleVote(project.account, voteCount + 1)}
onClick={() =>
handleVote(
project.account,
voteCount +
Math.min(
votingPower - totalVotes,
Math.floor(votingPower / 10),
),
)
}
className="bg-gray-700 w-8 py-1 text-white hover:bg-gray-500 rounded-l-none"
>
+
</Button>
<span className="w-12 text-right">
{totalVotes > 0
? Math.round((voteCount / totalVotes) * 100)
? Math.round((voteCount / votingPower) * 100)
: 0}
%
</span>
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/hooks/useAllocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export const useAllocation = (
});
const allocation = data?.allocations?.[0];
if (!allocation) {
return { data: undefined, isLoading, votingPower: 0 };
return {
data: undefined,
isLoading,
votingPower: data?.councilMember?.votingPower ?? 0,
};
}
const formattedAllocation: { [grantee: `0x${string}`]: number } =
Object.fromEntries(
Expand Down

0 comments on commit 0d14d2f

Please sign in to comment.