Skip to content

Commit 9918f00

Browse files
authored
Merge pull request #3433 from IntersectMBO/develop
GovTool - v2.0.20-rc1
2 parents cac53b6 + 18e1726 commit 9918f00

File tree

10 files changed

+152
-52
lines changed

10 files changed

+152
-52
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ changes.
1212

1313
### Added
1414

15+
- Add Proposal discussion context that manages username [Issue 3341](https://github.com/IntersectMBO/govtool/issues/3341)
16+
- Add epochParams and ada holder balance to Proposal Discussion Pillar [Issue 2243](https://github.com/IntersectMBO/govtool/issues/2243)
17+
1518
### Fixed
1619

1720
- Fix scroll on a drawer on smaller resolution

govtool/frontend/src/context/contextProviders.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DataActionsBarProvider } from "./dataActionsBar";
66
import { FeatureFlagProvider } from "./featureFlag";
77
import { GovernanceActionProvider } from "./governanceAction";
88
import { AdaHandleProvider } from "./adaHandle";
9+
import { ProposalDiscussionProvider } from "./proposalDiscussion";
910

1011
interface Props {
1112
children: React.ReactNode;
@@ -14,17 +15,19 @@ interface Props {
1415
const ContextProviders = ({ children }: Props) => (
1516
<AppContextProvider>
1617
<GovernanceActionProvider>
17-
<FeatureFlagProvider>
18-
<AdaHandleProvider>
19-
<ModalProvider>
20-
<SnackbarProvider>
21-
<DataActionsBarProvider>
22-
<CardanoProvider>{children}</CardanoProvider>
23-
</DataActionsBarProvider>
24-
</SnackbarProvider>
25-
</ModalProvider>
26-
</AdaHandleProvider>
27-
</FeatureFlagProvider>
18+
<ProposalDiscussionProvider>
19+
<FeatureFlagProvider>
20+
<AdaHandleProvider>
21+
<ModalProvider>
22+
<SnackbarProvider>
23+
<DataActionsBarProvider>
24+
<CardanoProvider>{children}</CardanoProvider>
25+
</DataActionsBarProvider>
26+
</SnackbarProvider>
27+
</ModalProvider>
28+
</AdaHandleProvider>
29+
</FeatureFlagProvider>
30+
</ProposalDiscussionProvider>
2831
</GovernanceActionProvider>
2932
</AppContextProvider>
3033
);

govtool/frontend/src/context/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from "./usersnapContext";
88
export * from "./wallet";
99
export * from "./featureFlag";
1010
export * from "./governanceAction";
11+
export * from "./proposalDiscussion";
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
PropsWithChildren,
3+
useMemo,
4+
createContext,
5+
useContext,
6+
useState,
7+
} from "react";
8+
9+
type ProposalDiscussionContextType = {
10+
username: string;
11+
setUsername: (username: string) => void;
12+
} | null;
13+
14+
const ProposalDiscussionContext =
15+
createContext<ProposalDiscussionContextType>(null);
16+
17+
/**
18+
* Provides proposal discussion context to its children components.
19+
*
20+
* @param children - The child components to render.
21+
*/
22+
const ProposalDiscussionProvider = ({ children }: PropsWithChildren) => {
23+
const [username, setUsername] = useState<string>("");
24+
25+
const value = useMemo(
26+
() => ({
27+
username,
28+
setUsername,
29+
}),
30+
[username],
31+
);
32+
33+
return (
34+
<ProposalDiscussionContext.Provider value={value}>
35+
{children}
36+
</ProposalDiscussionContext.Provider>
37+
);
38+
};
39+
40+
/**
41+
* Custom hook to use the ProposalDiscussionContext.
42+
* @returns The context value.
43+
*/
44+
const useProposalDiscussion = () => {
45+
const context = useContext(ProposalDiscussionContext);
46+
if (!context) {
47+
throw new Error(
48+
"useProposalDiscussion must be used within a ProposalDiscussionProvider",
49+
);
50+
}
51+
return context;
52+
};
53+
54+
export { ProposalDiscussionProvider, useProposalDiscussion };

govtool/frontend/src/pages/GovernanceActionOutComes.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Box, CircularProgress } from "@mui/material";
22
import React, { Suspense } from "react";
33
import { Footer, TopNav } from "@/components/organisms";
44
import { useCardano } from "@/context";
5-
import { useScreenDimension } from "@/hooks";
5+
import { useScreenDimension, useTranslation } from "@/hooks";
66
import { Background } from "@/components/atoms";
77

88
const GovernanceActionsOutcomes = React.lazy(
@@ -12,6 +12,8 @@ const GovernanceActionsOutcomes = React.lazy(
1212
export const GovernanceActionOutComesPillar = () => {
1313
const { pagePadding } = useScreenDimension();
1414
const { walletApi, ...context } = useCardano();
15+
const { i18n } = useTranslation();
16+
1517
return (
1618
<Background>
1719
<Box
@@ -49,6 +51,7 @@ export const GovernanceActionOutComesPillar = () => {
4951
apiUrl={import.meta.env.VITE_OUTCOMES_API_URL}
5052
ipfsGateway={import.meta.env.VITE_IPFS_GATEWAY}
5153
walletAPI={{ ...context, ...walletApi }}
54+
i18n={i18n}
5255
/>
5356
</Suspense>
5457
</Box>

govtool/frontend/src/pages/ProposalDiscussion.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
import React, { ComponentProps, Suspense } from "react";
22
import { Box, CircularProgress } from "@mui/material";
33
import "@intersect.mbo/pdf-ui/style";
4-
import { useCardano, useGovernanceActions } from "@/context";
4+
import {
5+
useAppContext,
6+
useCardano,
7+
useGovernanceActions,
8+
useProposalDiscussion,
9+
} from "@/context";
510
import { useValidateMutation } from "@/hooks/mutations";
611
import { useScreenDimension } from "@/hooks/useScreenDimension";
712
import { Footer, TopNav } from "@/components/organisms";
8-
import { useGetDRepVotingPowerList, useGetVoterInfo } from "@/hooks";
13+
import {
14+
useGetAdaHolderVotingPowerQuery,
15+
useGetDRepVotingPowerList,
16+
useGetVoterInfo,
17+
} from "@/hooks";
918

1019
const ProposalDiscussion = React.lazy(
1120
() => import("@intersect.mbo/pdf-ui/cjs"),
1221
);
1322

1423
export const ProposalDiscussionPillar = () => {
24+
const { epochParams } = useAppContext();
1525
const { pagePadding } = useScreenDimension();
1626
const { validateMetadata } = useValidateMutation();
1727
const { walletApi, ...context } = useCardano();
1828
const { voter } = useGetVoterInfo();
1929
const { createGovernanceActionJsonLD, createHash } = useGovernanceActions();
2030
const { fetchDRepVotingPowerList } = useGetDRepVotingPowerList();
31+
const { username, setUsername } = useProposalDiscussion();
32+
const { votingPower } = useGetAdaHolderVotingPowerQuery(context.stakeKey);
2133

2234
return (
2335
<Box
@@ -67,6 +79,10 @@ export const ProposalDiscussionPillar = () => {
6779
>["validateMetadata"]
6880
}
6981
fetchDRepVotingPowerList={fetchDRepVotingPowerList}
82+
username={username}
83+
setUsername={setUsername}
84+
epochParams={epochParams}
85+
votingPower={votingPower}
7086
/>
7187
</Suspense>
7288
</Box>

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

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,46 @@ enum MetadataValidationStatus {
44
INVALID_HASH = "INVALID_HASH",
55
INCORRECT_FORMAT = "INCORRECT_FORMAT",
66
}
7+
declare module "@intersect.mbo/pdf-ui/cjs" {
8+
import { EpochParams } from "@/models";
79

8-
type ProposalDiscussionProps = {
9-
pdfApiUrl: string;
10-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11-
walletAPI: any;
12-
pathname: string;
13-
locale?: string;
14-
validateMetadata: ({
15-
url,
16-
hash,
17-
standard,
18-
}: {
19-
url: string;
20-
hash: string;
21-
standard: "CIP108";
22-
}) => Promise<
10+
type ProposalDiscussionProps = {
11+
pdfApiUrl: string;
2312
// eslint-disable-next-line @typescript-eslint/no-explicit-any
24-
| { status?: MetadataValidationStatus; metadata?: any; valid: boolean }
25-
| undefined
26-
>;
27-
fetchDRepVotingPowerList: (
28-
identifiers: string[],
29-
) => Promise<DRepVotingPowerListResponse>;
30-
};
13+
walletAPI: any;
14+
pathname: string;
15+
locale?: string;
16+
validateMetadata: ({
17+
url,
18+
hash,
19+
standard,
20+
}: {
21+
url: string;
22+
hash: string;
23+
standard: "CIP108";
24+
}) => Promise<
25+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26+
| { status?: MetadataValidationStatus; metadata?: any; valid: boolean }
27+
| undefined
28+
>;
29+
fetchDRepVotingPowerList: (
30+
identifiers: string[],
31+
) => Promise<DRepVotingPowerListResponse>;
32+
epochParams?: EpochParams;
33+
votingPower: number;
34+
username: string;
35+
setUsername: (username: string) => void;
36+
};
3137

32-
type GovernanceActionsOutcomesProps = {
33-
apiUrl?: string;
34-
ipfsGateway?: string;
35-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
36-
walletAPI?: any;
37-
};
38+
type GovernanceActionsOutcomesProps = {
39+
apiUrl?: string;
40+
ipfsGateway?: string;
41+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
42+
walletAPI?: any;
43+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44+
i18n?: any;
45+
};
3846

39-
declare module "@intersect.mbo/pdf-ui/cjs" {
4047
export default function ProposalDiscussion(
4148
props: ProposalDiscussionProps,
4249
): JSX.Element;

tests/govtool-frontend/playwright/lib/services/kuberService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ const kuberService = {
211211
},
212212

213213
multipleDRepRegistration: (metadataAndWallets: WalletAndAnchorType[]) => {
214-
const kuber = new Kuber(faucetWallet.address, faucetWallet.payment.private);
214+
const kuber = new Kuber(
215+
proposalFaucetWallet.address,
216+
proposalFaucetWallet.payment.private
217+
);
215218
const req = {
216219
certificates: metadataAndWallets.map((metadataAndWallet) =>
217220
Kuber.generateCert(

tests/govtool-frontend/playwright/tests/11-proposal-budget/proposalBudget.loggedin.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test.describe("Budget proposal logged in state", () => {
4949
});
5050

5151
test("11I. Should comments on any proposal", async ({}) => {
52-
const comment = faker.lorem.paragraph(2);
52+
const comment = faker.lorem.paragraph(1);
5353
await budgetDiscussionDetailsPage.addComment(comment);
5454
await expect(
5555
budgetDiscussionDetailsPage.currentPage
@@ -59,7 +59,7 @@ test.describe("Budget proposal logged in state", () => {
5959
});
6060

6161
test("11J. Should reply to any comments", async ({}) => {
62-
const randComment = faker.lorem.paragraph(2);
62+
const randComment = faker.lorem.paragraph(1);
6363
const randReply = faker.lorem.words(5);
6464

6565
await budgetDiscussionDetailsPage.addComment(randComment);

tests/govtool-frontend/playwright/tests/11-proposal-budget/proposalBudget.spec.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ test("11E. Should view comments with count indications on a budget proposal", as
187187
page,
188188
}) => {
189189
let responsePromise = page.waitForResponse((response) =>
190-
response.url().includes(`/api/comments`)
190+
response.url().includes(`/api/bds/`)
191191
);
192192

193193
const budgetDiscussionPage = new BudgetDiscussionPage(page);
@@ -197,13 +197,23 @@ test("11E. Should view comments with count indications on a budget proposal", as
197197
await budgetDiscussionPage.viewFirstProposal();
198198
const response = await responsePromise;
199199

200-
const comments: CommentResponse[] = (await response.json()).data;
200+
const proposalResponse = await response.json();
201201

202-
await responsePromise;
202+
const actualTotalComments =
203+
await budgetDiscussionDetailsPage.totalComments.textContent();
204+
const expectedTotalComments =
205+
proposalResponse.data.attributes.prop_comments_number.toString();
206+
const isEqual = actualTotalComments === expectedTotalComments;
203207

204-
await expect(budgetDiscussionDetailsPage.totalComments).toHaveText(
205-
comments.length.toString()
206-
);
208+
const currentPageUrl = budgetDiscussionDetailsPage.currentPage.url();
209+
210+
const proposalId = extractProposalIdFromUrl(currentPageUrl);
211+
212+
await expect(
213+
budgetDiscussionDetailsPage.totalComments,
214+
!isEqual &&
215+
`Total comments do not match in ${environments.frontendUrl}/budget_discussion/${proposalId}`
216+
).toHaveText(expectedTotalComments);
207217
});
208218

209219
test.describe("Restricted access to interact budget proposal", () => {

0 commit comments

Comments
 (0)