Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-shift token haver power #2318

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TokenHaverPlugin/TokenHaverClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class TokenHaverClient extends Client<TokenHaver> {
})
)
).reduce((acc, curr) => acc + curr, 0)
return new BN(countOfTokensUserHas)
return new BN(countOfTokensUserHas).muln(10 ** 6)
}

async updateVoterWeightRecord(
Expand Down
17 changes: 16 additions & 1 deletion components/ProposalVotingPower/TokenHaverVotingPower.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import classNames from 'classnames'
import useDepositStore from 'VoteStakeRegistry/stores/useDepositStore'

import { getMintMetadata } from '@components/instructions/programs/splToken'
import { useMintInfoByPubkeyQuery } from '@hooks/queries/mintInfo'
import { useRealmQuery } from '@hooks/queries/realm'
import { useDelegatorAwareVoterWeight } from '@hooks/useDelegatorAwareVoterWeight'
import { useRealmVoterWeightPlugins } from '@hooks/useRealmVoterWeightPlugins'
import { BigNumber } from 'bignumber.js'
import clsx from 'clsx'
import { useMemo } from 'react'

interface Props {
className?: string
Expand All @@ -17,6 +20,9 @@ export default function TokenHaverVotingPower({ role, className }: Props) {
const realm = useRealmQuery().data?.result
const voterWeight = useDelegatorAwareVoterWeight(role)

const mintInfo = useMintInfoByPubkeyQuery(realm?.account.communityMint).data
?.result

const isLoading = useDepositStore((s) => s.state.isLoading)
const { isReady } = useRealmVoterWeightPlugins(role)

Expand All @@ -28,7 +34,16 @@ export default function TokenHaverVotingPower({ role, className }: Props) {
const tokenName =
getMintMetadata(relevantMint)?.name ?? realm?.account.name ?? ''

const formattedTotal = voterWeight?.value?.toString() ?? 0
const formattedTotal = useMemo(
() =>
mintInfo && voterWeight?.value
? new BigNumber(voterWeight?.value.toString())
.shiftedBy(-mintInfo.decimals)
.toFixed(0)
.toString()
: undefined,
[mintInfo, voterWeight?.value]
)

if (isLoading || !isReady) {
return (
Expand Down
Loading