Skip to content

Commit

Permalink
feat: use getVotes from governor to display user's voting power on pr…
Browse files Browse the repository at this point in the history
…oposals page (#382)

* feat: use getVotes from governor to display user's voting power on proposals page

* feat: use correct stRIF contract for getVotes method

* feat: use correct stRIF contract for getVotes method
  • Loading branch information
LordCheta authored and shenshin committed Nov 20, 2024
1 parent 44ea629 commit ed5e66f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/app/proposals/hooks/useVotingPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export const useVotingPower = () => {
functionName: 'decimals',
},
{ abi: GovernorAbi, address: GovernorAddress, functionName: 'proposalThreshold' },
{
abi: StRIFTokenAbi,
address: tokenContracts.stRIF,
functionName: 'getVotes',
args: [address!],
},
],
})

Expand All @@ -34,11 +40,12 @@ export const useVotingPower = () => {
}
}

const [balance, decimals, threshold] = data as [bigint, number, bigint]
const [balance, decimals, threshold, totalVotingPower] = data as [bigint, number, bigint, bigint]
return {
isLoading: false,
votingPower: formatUnits(balance, decimals),
canCreateProposal: balance >= threshold,
threshold: formatUnits(threshold, decimals),
totalVotingPower: formatUnits(totalVotingPower, decimals),
}
}
4 changes: 2 additions & 2 deletions src/app/proposals/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useVotingPower } from './hooks/useVotingPower'
import { useMemo } from 'react'

export default function Proposals() {
const { votingPower, canCreateProposal, threshold } = useVotingPower()
const { canCreateProposal, threshold, totalVotingPower } = useVotingPower()
const { latestProposals } = useFetchAllProposals()

const memoizedProposals = useMemo(() => latestProposals, [latestProposals])
Expand All @@ -26,7 +26,7 @@ export default function Proposals() {
<div>
<VotingPowerPopover />
<Paragraph className="text-[48px] text-primary tracking-[-0.96px]" fontFamily="kk-topo">
{toFixed(votingPower)}
{totalVotingPower}
</Paragraph>
</div>
<div className="flex flex-row gap-x-6">
Expand Down

0 comments on commit ed5e66f

Please sign in to comment.