Skip to content

Commit e97ae56

Browse files
committed
feat(#3277): handle drep voting power list on frontend
1 parent d99f342 commit e97ae56

File tree

10 files changed

+68
-2
lines changed

10 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ changes.
2525
- Add redirection to outcomes when proposal is not found [Issue 3230](https://github.com/IntersectMBO/govtool/issues/3230)
2626
- Add DRep voting power list endpoint [Issue 3263](https://github.com/IntersectMBO/govtool/issues/3263)
2727
- Add DRep given name to the voting power list endpoint [Issue 3273](https://github.com/IntersectMBO/govtool/issues/3273)
28+
- Add DRep voting power list query to PDF Pillar [Issue 3277](https://github.com/IntersectMBO/govtool/issues/3277)
2829

2930
### Fixed
3031

govtool/frontend/src/consts/queryKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const QUERY_KEYS = {
1313
useGetProposalsInfiniteKey: "useGetProposalsInfiniteKey",
1414
useGetProposalsKey: "useGetProposalsKey",
1515
useGetVoteContextFromFile: "useGetVoteContextFromFile",
16+
useGetDRepVotingPowerListKey: "useGetDRepVotingPowerListKey",
1617
};
1718

1819
export const MUTATION_KEYS = {

govtool/frontend/src/hooks/queries/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from "./useGetProposalsInfiniteQuery";
1313
export * from "./useGetProposalsQuery";
1414
export * from "./useGetVoteContextTextFromFile";
1515
export * from "./useGetVoterInfoQuery";
16+
export * from "./useGetDRepVotingPowerList";
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useQuery, useQueryClient } from "react-query";
2+
import { getDRepVotingPowerList } from "@/services";
3+
import { QUERY_KEYS } from "@/consts";
4+
5+
export const useGetDRepVotingPowerList = () => {
6+
const queryClient = useQueryClient();
7+
8+
const queryResult = useQuery({
9+
queryKey: [QUERY_KEYS.useGetDRepVotingPowerListKey],
10+
queryFn: () => getDRepVotingPowerList([]),
11+
enabled: false,
12+
});
13+
14+
const { data: dRepVotingPowerList, isError, error, isLoading } = queryResult;
15+
16+
const fetchDRepVotingPowerList = async (identifiers: string[]) =>
17+
queryClient.fetchQuery({
18+
queryKey: [QUERY_KEYS.useGetDRepVotingPowerListKey],
19+
queryFn: () => getDRepVotingPowerList(identifiers),
20+
});
21+
22+
return {
23+
dRepVotingPowerList,
24+
fetchDRepVotingPowerList,
25+
isError,
26+
error,
27+
isLoading,
28+
};
29+
};

govtool/frontend/src/models/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,12 @@ export type Infinite<T> = {
265265
pageSize: number;
266266
total: number;
267267
};
268+
269+
export type DRepVotingPower = {
270+
view: string;
271+
hashRaw: string;
272+
votingPower: number;
273+
givenName: string | null;
274+
};
275+
276+
export type DRepVotingPowerListResponse = DRepVotingPower[];

govtool/frontend/src/pages/ProposalDiscussion.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useCardano, useGovernanceActions } from "@/context";
55
import { useValidateMutation } from "@/hooks/mutations";
66
import { useScreenDimension } from "@/hooks/useScreenDimension";
77
import { Footer, TopNav } from "@/components/organisms";
8-
import { useGetVoterInfo } from "@/hooks";
8+
import { useGetDRepVotingPowerList, useGetVoterInfo } from "@/hooks";
99

1010
const ProposalDiscussion = React.lazy(
1111
() => import("@intersect.mbo/pdf-ui/cjs"),
@@ -17,6 +17,7 @@ export const ProposalDiscussionPillar = () => {
1717
const { walletApi, ...context } = useCardano();
1818
const { voter } = useGetVoterInfo();
1919
const { createGovernanceActionJsonLD, createHash } = useGovernanceActions();
20+
const { fetchDRepVotingPowerList } = useGetDRepVotingPowerList();
2021

2122
return (
2223
<Box
@@ -65,6 +66,11 @@ export const ProposalDiscussionPillar = () => {
6566
typeof ProposalDiscussion
6667
>["validateMetadata"]
6768
}
69+
fetchDRepVotingPowerList={
70+
fetchDRepVotingPowerList as ComponentProps<
71+
typeof ProposalDiscussion
72+
>["fetchDRepVotingPowerList"]
73+
}
6874
/>
6975
</Suspense>
7076
</Box>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from "./API";
22

3-
export * from "./requests/index";
3+
export * from "./requests";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { DRepVotingPowerListResponse } from "@/models";
2+
import { API } from "../API";
3+
4+
export const getDRepVotingPowerList = async (
5+
identifiers: string[],
6+
): Promise<DRepVotingPowerListResponse> => {
7+
const params = new URLSearchParams();
8+
identifiers.forEach((id: string) => params.append("identifiers", id));
9+
10+
const response = await API.get<DRepVotingPowerListResponse>(
11+
`/drep/voting-power-list?${params.toString()}`,
12+
);
13+
14+
return response.data;
15+
};

govtool/frontend/src/services/requests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export * from "./postDRepRegister";
2121
export * from "./postDRepRemoveVote";
2222
export * from "./postDRepRetire";
2323
export * from "./postDRepVote";
24+
export * from "./getDRepVotingPowerList";

govtool/frontend/src/types/@intersect.mbo.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ type ProposalDiscussionProps = {
2424
| { status?: MetadataValidationStatus; metadata?: any; valid: boolean }
2525
| undefined
2626
>;
27+
fetchDRepVotingPowerList: (
28+
identifiers: string[],
29+
) => Promise<DRepVotingPowerListResponse>;
2730
};
2831

2932
type GovernanceActionsOutcomesProps = {

0 commit comments

Comments
 (0)