Skip to content

Commit

Permalink
feat: last vote column (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrX-SNX authored Sep 18, 2024
1 parent 511e57c commit a62c702
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ export default function CouncilMembers({ activeCouncil }: { activeCouncil: Counc
{sortConfig[1] === 'votingPower' && <SortArrows up={sortConfig[0]} />}
</Th>
)}
{/* {councilPeriod === '0' && (
<Th userSelect="none" textTransform="capitalize" textAlign="center" px="0"></Th>
)}*/}
{councilPeriod === '0' && (
<Th userSelect="none" textTransform="capitalize" textAlign="center" px="0"></Th>
)}
</Tr>
</Thead>
<Tbody>
Expand Down
7 changes: 4 additions & 3 deletions governance/ui/src/components/UserTableView/UserTableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useGetCurrentPeriod } from '../../queries/useGetCurrentPeriod';
import { CouncilSlugs } from '../../utils/councils';
import { ProfilePicture } from '../UserProfileCard/ProfilePicture';
import { prettyString } from '@snx-v3/format';
import { useGetUserBallot } from '../../queries';
import { useGetEpochIndex, useGetUserBallot } from '../../queries';
import { BigNumber, utils } from 'ethers';
import { formatNumber } from '@snx-v3/formatters';
import { renderCorrectBorder } from '../../utils/table-border';
Expand All @@ -28,7 +28,8 @@ export default function UserTableView({
}) {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const { data: ballot } = useGetUserBallot(activeCouncil);
const { data: epochIndex } = useGetEpochIndex(activeCouncil);
const { data: ballot } = useGetUserBallot(activeCouncil, (epochIndex?.toNumber() || 1) - 1);
const { data: councilPeriod } = useGetCurrentPeriod(activeCouncil);
const isSelected = searchParams.get('view') === user.address;
const councilIsInAdminOrVotinOrEval =
Expand Down Expand Up @@ -129,7 +130,7 @@ export default function UserTableView({
</Text>
</Td>
)}
{councilPeriod === '2' && (
{(councilPeriod === '2' || councilPeriod === '0') && (
<Td
borderTop="1px solid"
borderBottom={renderCorrectBorder('badge', 'bottom', councilPeriod, isSelected)}
Expand Down
16 changes: 10 additions & 6 deletions governance/ui/src/queries/useGetUserBallot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ import { getCouncilContract } from '../utils/contracts';
import { useNetwork, useSigner } from './useWallet';
import { motherShipProvider } from '../utils/providers';

export function useGetUserBallot<T extends CouncilSlugs | CouncilSlugs[]>(council: T) {
export function useGetUserBallot<T extends CouncilSlugs | CouncilSlugs[]>(
council: T,
epochIndex?: number
) {
const { network } = useNetwork();
const signer = useSigner();

return useQuery({
queryFn: async () => {
if (signer && network?.id) {
const address = await signer.getAddress();
return await getBallot(council, address, network.id);
return await getBallot(council, address, network.id, epochIndex);
}
},
enabled: !!signer,
queryKey: ['userBallot', council.toString(), network?.id],
queryKey: ['userBallot', council.toString(), network?.id, epochIndex],
staleTime: 900000,
});
}

async function getBallot<T extends CouncilSlugs | CouncilSlugs[]>(
council: T,
address: string,
chainId: number
chainId: number,
epochIndex?: number
): Promise<
T extends CouncilSlugs
? {
Expand All @@ -47,14 +51,14 @@ async function getBallot<T extends CouncilSlugs | CouncilSlugs[]>(
ballot = (await Promise.all(
council.map(async (c) => {
const electionModule = getCouncilContract(c).connect(provider);
const electionId = await electionModule.getEpochIndex();
const electionId = epochIndex ?? (await electionModule.getEpochIndex());
const temp = await electionModule.getBallot(address, chainId, electionId);
return { ...temp, council: c };
})
)) as { votingPower: BigNumber; votedCandidates: string[]; amounts: BigNumber[] }[];
} else {
const electionModule = getCouncilContract(council).connect(provider);
const electionId = electionModule.getEpochIndex();
const electionId = epochIndex ?? (await electionModule.getEpochIndex());
const temp = (await electionModule.getBallot(address, chainId, electionId)) as {
votingPower: BigNumber;
votedCandidates: string[];
Expand Down

0 comments on commit a62c702

Please sign in to comment.