diff --git a/hooks/useRealm.tsx b/hooks/useRealm.tsx index 62348a8..8570b89 100644 --- a/hooks/useRealm.tsx +++ b/hooks/useRealm.tsx @@ -16,14 +16,9 @@ export default function useRealm(symbol: string) { const connected = useWalletStore((s) => s.connected) const wallet = useWalletStore((s) => s.current) const tokenAccounts = useWalletStore((s) => s.tokenAccounts) - const { - realm, - mint, - governances, - proposals, - tokenRecords, - votes, - } = useWalletStore((s) => s.selectedRealm) + const { realm, mint, governances, proposals, tokenRecords } = useWalletStore( + (s) => s.selectedRealm + ) const realmInfo = useMemo(() => REALMS.find((r) => r.symbol === symbol), [ symbol, @@ -60,7 +55,6 @@ export default function useRealm(symbol: string) { governances, proposals, tokenRecords, - votes, realmTokenAccount, ownTokenRecord, } diff --git a/pages/dao/[symbol].tsx b/pages/dao/[symbol].tsx index 2604cee..40f85fe 100644 --- a/pages/dao/[symbol].tsx +++ b/pages/dao/[symbol].tsx @@ -3,6 +3,7 @@ import Link from 'next/link' import useWalletStore from '../../stores/useWalletStore' import moment from 'moment' import useRealm from '../../hooks/useRealm' +import BN from 'bn.js' export const ProposalStateLabels = { 0: 'Draft', @@ -22,13 +23,20 @@ const DAO = () => { const wallet = useWalletStore((s) => s.current) const { + mint, governances, proposals, - votes, realmTokenAccount, ownTokenRecord, } = useRealm(symbol as string) + const votePrecision = 10000 + const formatVoteCount = (c: BN) => + `${ + c.mul(new BN(votePrecision)).div(mint.supply).toNumber() * + (100 / votePrecision) + }%` + // DEBUG print remove console.log( 'governance page tokenAccount', @@ -89,7 +97,10 @@ const DAO = () => {
)}{ProposalStateLabels[v.info.state]}
-Votes {JSON.stringify(votes[k])}
++ Votes Yes: {formatVoteCount(v.info.yesVotesCount)} No:{' '} + {formatVoteCount(v.info.noVotesCount)} +
{`Yes Threshold: ${
governances[v.info.governance.toBase58()]?.info.config
diff --git a/stores/useWalletStore.tsx b/stores/useWalletStore.tsx
index 46fe8c4..a532171 100644
--- a/stores/useWalletStore.tsx
+++ b/stores/useWalletStore.tsx
@@ -16,11 +16,9 @@ import {
Proposal,
Realm,
TokenOwnerRecord,
- VoteRecord,
} from '../models/accounts'
import { DEFAULT_PROVIDER } from '../utils/wallet-adapters'
import { ParsedAccount } from '../models/serialisation'
-import { BN } from '@project-serum/anchor'
export const ENDPOINTS: EndpointInfo[] = [
{
@@ -52,7 +50,6 @@ interface WalletStore extends State {
governances: { [governance: string]: ParsedAccount