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

feat(#1703): make voting on governance actions dependent on the protocol version #1716

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ changes.
- Unsancho GovTool [Issue 1637](https://github.com/IntersectMBO/govtool/issues/1637)
- Add network metrics model to frontend service
- Added workflows to add labels to issues
- Make voting on governance actions enabled based on protocol version [Issue 1703](https://github.com/IntersectMBO/govtool/issues/1703)

### Fixed

Expand Down
51 changes: 27 additions & 24 deletions govtool/frontend/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { I18nextProvider } from "react-i18next";
import { QueryClient, QueryClientProvider } from "react-query";
import { MemoryRouter, Route, Routes } from "react-router-dom";

import { FeatureFlagProvider } from "../src/context/featureFlag";
import { AppContextProvider } from "../src/context/appContext";
import { ModalProvider } from "../src/context/modal";
import i18n from "../src/i18n";
Expand All @@ -26,30 +27,32 @@ const preview: Preview = {
(Story) => (
<QueryClientProvider client={queryClient}>
<AppContextProvider>
<ThemeProvider theme={theme}>
<ModalProvider>
<I18nextProvider i18n={i18n}>
<MemoryRouter>
<Routes>
<Route
path="/*"
element={
<div
style={{
margin: "0px",
padding: "0px",
position: "relative",
}}
>
<Story />
</div>
}
/>
</Routes>
</MemoryRouter>
</I18nextProvider>
</ModalProvider>
</ThemeProvider>
<FeatureFlagProvider>
<ThemeProvider theme={theme}>
<ModalProvider>
<I18nextProvider i18n={i18n}>
<MemoryRouter>
<Routes>
<Route
path="/*"
element={
<div
style={{
margin: "0px",
padding: "0px",
position: "relative",
}}
>
<Story />
</div>
}
/>
</Routes>
</MemoryRouter>
</I18nextProvider>
</ModalProvider>
</ThemeProvider>
</FeatureFlagProvider>
</AppContextProvider>
</QueryClientProvider>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Box } from "@mui/material";

import { useScreenDimension } from "@hooks";
import { VoteActionForm, VotesSubmitted } from "@molecules";
import { useFeatureFlag } from "@/context";
import { GovernanceActionType } from "@/types/governanceAction";

type GovernanceActionCardVotesProps = {
setIsVoteSubmitted: Dispatch<SetStateAction<boolean>>;
Expand All @@ -19,6 +21,7 @@ type GovernanceActionCardVotesProps = {
voteEpochNoFromEP?: number;
isDashboard?: boolean;
isInProgress?: boolean;
type: GovernanceActionType;
};

export const GovernanceActionDetailsCardVotes = ({
Expand All @@ -36,7 +39,9 @@ export const GovernanceActionDetailsCardVotes = ({
voteEpochNoFromEP,
isDashboard,
isInProgress,
type,
}: GovernanceActionCardVotesProps) => {
const { isVotingOnGovernanceActionEnabled } = useFeatureFlag();
const { screenWidth } = useScreenDimension();

const isModifiedPadding =
Expand All @@ -50,7 +55,7 @@ export const GovernanceActionDetailsCardVotes = ({
p: `40px ${isModifiedPadding ? "24px" : "80px"}`,
}}
>
{isVoter ? (
{isVoter && isVotingOnGovernanceActionEnabled(type) ? (
<VoteActionForm
setIsVoteSubmitted={setIsVoteSubmitted}
expiryDate={expiryDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const AutomatedVotingOptions = ({
txHash,
}: AutomatedVotingOptionsProps) => {
const { t } = useTranslation();
// TODO: Get network metrics from useAppContext
const { networkMetrics, fetchNetworkMetrics } = useGetNetworkMetrics();

const [isOpen, setIsOpen] = useState<boolean>(false);

const { networkMetrics } = useGetNetworkMetrics();

const isDelegatedToAbstain =
currentDelegation ===
AutomatedVotingOptionCurrentDelegation.drep_always_abstain;
Expand All @@ -55,6 +55,10 @@ export const AutomatedVotingOptions = ({
const isDelegationToNoConfidenceInProgress =
delegationInProgress === AutomatedVotingOptionDelegationId.no_confidence;

useEffect(() => {
fetchNetworkMetrics();
}, []);

useEffect(() => {
const shouldBeSetOpen =
isDelegatedToAbstain ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Dispatch, SetStateAction } from "react";
import { ActionRadio, Spacer, Typography } from "@atoms";
import { GovernanceActionTootlip } from "@consts";
import { GovernanceActionTooltip } from "@consts";
import {
useCreateGovernanceActionForm,
useScreenDimension,
Expand Down Expand Up @@ -49,7 +49,9 @@ export const ChooseGovernanceActionType = ({
value={type}
tooltipTitle={type}
tooltipText={
GovernanceActionTootlip[type as GovernanceActionType]
GovernanceActionTooltip[
type as keyof typeof GovernanceActionTooltip
]
}
/>
{index + 1 < governanceActionTypes.length ? <Spacer y={2} /> : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { GOVERNANCE_ACTION_FIELDS, Placeholders } from "@consts";
import { useCreateGovernanceActionForm, useTranslation } from "@hooks";
import { Field } from "@molecules";
import { URL_REGEX, testIdFromLabel } from "@/utils";
import { GovernanceActionField } from "@/types/governanceAction";
import {
GovernanceActionField,
GovernanceActionType,
} from "@/types/governanceAction";

import { BgCard } from "../BgCard";
import { ControlledField } from "../ControlledField";
Expand Down Expand Up @@ -40,7 +43,13 @@ export const CreateGovernanceActionForm = ({
const isContinueButtonDisabled =
// TODO: Provide better typing for GOVERNANCE_ACTION_FIELDS
// to get rid of explicit type assertion
Object.keys(GOVERNANCE_ACTION_FIELDS[type!]).some(
Object.keys(
GOVERNANCE_ACTION_FIELDS[
type! as
| GovernanceActionType.InfoAction
| GovernanceActionType.TreasuryWithdrawals
],
).some(
(field) => !watch(field as unknown as Parameters<typeof watch>[0]),
) || isError;

Expand All @@ -54,7 +63,13 @@ export const CreateGovernanceActionForm = ({
};

const renderGovernanceActionField = () =>
Object.entries(GOVERNANCE_ACTION_FIELDS[type!]).map(([key, field]) => {
Object.entries(
GOVERNANCE_ACTION_FIELDS[
type! as
| GovernanceActionType.InfoAction
| GovernanceActionType.TreasuryWithdrawals
],
).map(([key, field]) => {
const fieldProps = {
helpfulText: field.tipI18nKey ? t(field.tipI18nKey) : undefined,
key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { getShortenedGovActionId, getProposalTypeLabel } from "@utils";
import { GovernanceActionDetailsCard } from "@organisms";
import { Breadcrumbs } from "@molecules";

// TODO: Refactor: GovernanceActionDetals and DashboardGovernanceActionDetails are almost identical
// and should be unified
export const DashboardGovernanceActionDetails = () => {
const { voter } = useGetVoterInfo();
const { pendingTransaction, isEnableLoading } = useCardano();
Expand All @@ -33,7 +35,13 @@ export const DashboardGovernanceActionDetails = () => {
state ? state.txHash : data?.proposal.txHash ?? "",
state ? state.index : data?.proposal.index ?? "",
);

// TODO: Refactor me
const title = state ? state?.title : data?.proposal?.title;
const label = state
? getProposalTypeLabel(state.type)
: getProposalTypeLabel(data.proposal.type);
const type = state ? state.type : data.proposal.type;

return (
<Box
Expand Down Expand Up @@ -115,14 +123,11 @@ export const DashboardGovernanceActionDetails = () => {
voter?.isRegisteredAsDRep || voter?.isRegisteredAsSoleVoter
}
noVotes={state ? state.noVotes : data.proposal.noVotes}
type={
state
? getProposalTypeLabel(state.type)
: getProposalTypeLabel(data.proposal.type)
}
type={type}
label={label}
title={title}
details={state ? state.details : data.proposal.details}
url={state ? state.url : data.proposal.url}
title={title}
links={state ? state?.references : data.proposal?.references}
abstract={state ? state?.abstract : data.proposal?.abstract}
motivation={state ? state?.motivation : data.proposal?.motivation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@molecules";
import { GovernanceActionDetailsCardData } from "@organisms";
import { MetadataValidationStatus } from "@models";
import { GovernanceActionType } from "@/types/governanceAction";

type GovernanceActionDetailsCardProps = {
abstainVotes: number;
Expand All @@ -16,7 +17,8 @@ type GovernanceActionDetailsCardProps = {
expiryDate: string;
expiryEpochNo: number;
noVotes: number;
type: string;
type: GovernanceActionType;
label: string;
details?: ActionDetailsType;
url: string;
title?: string;
Expand All @@ -43,9 +45,10 @@ export const GovernanceActionDetailsCard = ({
expiryDate,
expiryEpochNo,
noVotes,
type,
details,
url,
type,
label,
title,
links,
abstract,
Expand Down Expand Up @@ -109,7 +112,7 @@ export const GovernanceActionDetailsCard = ({
motivation={motivation}
rationale={rationale}
title={title}
type={type}
label={label}
url={url}
/>
<GovernanceActionDetailsCardVotes
Expand All @@ -127,6 +130,7 @@ export const GovernanceActionDetailsCard = ({
isDashboard={isDashboard}
isOneColumn={isOneColumn}
isInProgress={isInProgress}
type={type}
/>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GovernanceActionDetailsCardDataProps = {
motivation?: string;
rationale?: string;
title?: string;
type: string;
label: string;
url: string;
};

Expand All @@ -51,7 +51,7 @@ export const GovernanceActionDetailsCardData = ({
motivation,
rationale,
title,
type,
label,
url,
}: GovernanceActionDetailsCardDataProps) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -89,9 +89,9 @@ export const GovernanceActionDetailsCardData = ({
/>
<GovernanceActionCardElement
label={t("govActions.governanceActionType")}
text={type}
text={label}
textVariant="pill"
dataTestId={`${getProposalTypeNoEmptySpaces(type)}-type`}
dataTestId={`${getProposalTypeNoEmptySpaces(label)}-type`}
/>
<GovernanceActionsDatesBox
createdDate={createdDate}
Expand Down Expand Up @@ -134,12 +134,12 @@ export const GovernanceActionDetailsCardData = ({
/>
{details &&
Object.keys(details).length !== 0 &&
Object.entries(details).map(([label, content]) => (
Object.entries(details).map(([detailLabel, content]) => (
<GovernanceActionCardElement
isCopyButton={label.toLowerCase().includes("address")}
label={label}
isCopyButton={detailLabel.toLowerCase().includes("address")}
label={detailLabel}
text={content}
dataTestId={testIdFromLabel(label)}
dataTestId={testIdFromLabel(detailLabel)}
/>
))}
<GovernanceActionDetailsCardLinks links={links} />
Expand Down
10 changes: 5 additions & 5 deletions govtool/frontend/src/consts/governanceAction/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
SharedGovernanceActionFieldSchema,
} from "@/types/governanceAction";

export const GovernanceActionTootlip = {
Info: I18n.t("govActions.tooltips.info"),
Treasury: I18n.t("govActions.tooltips.treasury"),
export const GovernanceActionTooltip = {
InfoAction: I18n.t("govActions.tooltips.info"),
TreasuryWithdrawals: I18n.t("govActions.tooltips.treasury"),
};

export const CIP_100 =
Expand Down Expand Up @@ -96,8 +96,8 @@ export const sharedGovernanceActionFields: SharedGovernanceActionFieldSchema = {
};

export const GOVERNANCE_ACTION_FIELDS: GovernanceActionFields = {
[GovernanceActionType.Info]: sharedGovernanceActionFields,
[GovernanceActionType.Treasury]: {
[GovernanceActionType.InfoAction]: sharedGovernanceActionFields,
[GovernanceActionType.TreasuryWithdrawals]: {
...sharedGovernanceActionFields,
receivingAddress: {
component: GovernanceActionField.Input,
Expand Down
5 changes: 3 additions & 2 deletions govtool/frontend/src/consts/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
export const QUERY_KEYS = {
getAdaHolderCurrentDelegationKey: "getAdaHolderCurrentDelegationKey",
getAdaHolderVotingPowerKey: "getAdaHolderVotingPowerKey",
useGetDRepInfoKey: "useGetDRepInfoKey",
useGetDRepListInfiniteKey: "useGetDRepListInfiniteKey",
useGetDRepVotesKey: "useGetDRepVotesKey",
useGetDRepVotingPowerKey: "useGetDRepVotingPowerKey",
useGetEpochParamsKey: "useGetEpochParamsKey",
useGetNetworkMetricsKey: "useGetNetworkMetricsKey",
useGetProposalKey: "useGetProposalKey",
useGetProposalsKey: "useGetProposalsKey",
useGetProposalsInfiniteKey: "useGetProposalsInfiniteKey",
useGetDRepInfoKey: "useGetDRepInfoKey",
useGetProposalsKey: "useGetProposalsKey",
useGetVoteContextFromFile: "useGetVoteContextFromFile",
};

Expand Down
Loading
Loading