Skip to content

Commit

Permalink
Merge pull request #1685 from IntersectMBO/fix/1675-blank-edit-drep-w…
Browse files Browse the repository at this point in the history
…hen-invalid-data

[#1675] blank edit drep when invalid data
  • Loading branch information
jdyczka authored Aug 8, 2024
2 parents 7492ac3 + 71afc12 commit 11db089
Show file tree
Hide file tree
Showing 20 changed files with 177 additions and 191 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ changes.
- Remove incorrect @value property to fix validating the metadata body [Issue 1687](https://github.com/IntersectMBO/govtool/issues/1687)
- Fix PDF not enabled in default deployments
- Fix displaying incorrect connected to Voltaire GovTool network
- Runtime error at /edit_drep when metadata incorrect [Issue 1675](https://github.com/IntersectMBO/govtool/issues/1675)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {

import { useScreenDimension, useTranslation } from "@hooks";
import {
formatDisplayDate,
getFullGovActionId,
getProposalTypeLabel,
getProposalTypeNoEmptySpaces,
Expand Down Expand Up @@ -104,8 +103,8 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({ ...props }) => {
isSliderCard
/>
<GovernanceActionsDatesBox
createdDate={formatDisplayDate(createdDate)}
expiryDate={formatDisplayDate(expiryDate)}
createdDate={createdDate}
expiryDate={expiryDate}
expiryEpochNo={expiryEpochNo}
createdEpochNo={createdEpochNo}
isSliderCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Trans } from "react-i18next";

import { Tooltip, Typography } from "@atoms";
import { useScreenDimension, useTranslation } from "@hooks";
import { formatDisplayDate } from "@/utils";

type GovernanceActionsDatesBoxProps = {
createdDate: string;
expiryDate: string;
expiryEpochNo: number;
expiryDate: string | undefined;
expiryEpochNo: number | undefined;
createdEpochNo: number;
isSliderCard?: boolean;
};
Expand Down Expand Up @@ -58,7 +59,10 @@ export const GovernanceActionsDatesBox = ({
>
<Trans
i18nKey="govActions.submittedDateWithEpoch"
values={{ date: createdDate, epoch: createdEpochNo }}
values={{
date: formatDisplayDate(createdDate),
epoch: createdEpochNo,
}}
components={[
<span style={{ fontWeight: 600 }} key="0" />,
<span style={{ fontWeight: 400 }} key="1" />,
Expand Down Expand Up @@ -100,7 +104,10 @@ export const GovernanceActionsDatesBox = ({
>
<Trans
i18nKey="govActions.expiresDateWithEpoch"
values={{ date: expiryDate, epoch: expiryEpochNo }}
values={{
date: expiryDate ? formatDisplayDate(expiryDate) : "-",
epoch: expiryEpochNo ?? "-",
}}
components={[
<span style={{ fontWeight: 600 }} key="0" />,
<span style={{ fontWeight: 400 }} key="1" />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Button } from "@atoms";
import { PATHS } from "@consts";
import { useScreenDimension, useTranslation } from "@hooks";
import {
formatDisplayDate,
getFullGovActionId,
getProposalTypeLabel,
getProposalTypeNoEmptySpaces,
Expand Down Expand Up @@ -94,8 +93,8 @@ export const GovernanceVotedOnCard = ({ votedProposal, inProgress }: Props) => {
isSliderCard
/>
<GovernanceActionsDatesBox
createdDate={formatDisplayDate(createdDate)}
expiryDate={formatDisplayDate(expiryDate)}
createdDate={createdDate}
expiryDate={expiryDate}
expiryEpochNo={expiryEpochNo}
createdEpochNo={createdEpochNo}
isSliderCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import {
useScreenDimension,
useTranslation,
} from "@hooks";
import {
formatDisplayDate,
getShortenedGovActionId,
getProposalTypeLabel,
} from "@utils";
import { getShortenedGovActionId, getProposalTypeLabel } from "@utils";
import { GovernanceActionDetailsCard } from "@organisms";
import { Breadcrumbs } from "@molecules";

Expand Down Expand Up @@ -104,22 +100,14 @@ export const DashboardGovernanceActionDetails = () => {
abstainVotes={
state ? state.abstainVotes : data.proposal.abstainVotes
}
createdDate={
state
? formatDisplayDate(state.createdDate)
: formatDisplayDate(data.proposal.createdDate)
}
createdDate={state ? state.createdDate : data.proposal.createdDate}
createdEpochNo={
state ? state.createdEpochNo : data.proposal.createdEpochNo
}
isDataMissing={
state ? state.metadataStatus : data?.proposal.metadataStatus
}
expiryDate={
state
? formatDisplayDate(state.expiryDate)
: formatDisplayDate(data?.proposal.expiryDate)
}
expiryDate={state ? state.expiryDate : data?.proposal.expiryDate}
expiryEpochNo={
state ? state.expiryEpochNo : data.proposal.expiryEpochNo
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { postValidate } from "@services";
import { MUTATION_KEYS } from "@consts";
import { MetadataValidationDTO } from "@models";

export const useValidateMutation = () => {
export const useValidateMutation = <MetadataType>() => {
const { data, isLoading, mutateAsync } = useMutation({
mutationFn: (body: MetadataValidationDTO) => postValidate(body),
mutationFn: (body: MetadataValidationDTO) => postValidate<MetadataType>(body),
mutationKey: [MUTATION_KEYS.postValidateKey],
});

Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/src/hooks/queries/useGetDRepListQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UseInfiniteQueryOptions, useInfiniteQuery } from "react-query";
import { QUERY_KEYS } from "@consts";
import { useCardano } from "@context";
import { GetDRepListArguments, getDRepList } from "@services";
import { InfinityDRepData } from "@/models";
import { DRepData, Infinite } from "@/models";

export const useGetDRepListInfiniteQuery = (
{
Expand All @@ -13,7 +13,7 @@ export const useGetDRepListInfiniteQuery = (
sorting,
status,
}: GetDRepListArguments,
options?: UseInfiniteQueryOptions<InfinityDRepData>,
options?: UseInfiniteQueryOptions<Infinite<DRepData>>,
) => {
const { pendingTransaction } = useCardano();

Expand Down
64 changes: 36 additions & 28 deletions govtool/frontend/src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,30 @@ export enum DRepListSort {
Status = "Status",
}

export interface DRepData {
drepId: string;
view: string;
url: string;
metadataHash: string;
export interface DrepDataDTO {
deposit: number;
votingPower: number;
drepId: string;
latestRegistrationDate: string;
latestTxHash?: string;
metadataHash?: string;
status: DRepStatus;
type: "DRep" | "SoleVoter";
url?: string;
view: string;
votingPower?: number;
}

export interface DRepData extends DrepDataDTO {
bio: string | null;
dRepName: string | null;
email: string | null;
references: string[];
metadataStatus: MetadataValidationStatus | null;
metadataValid: boolean;
}
export type InfinityDRepData = {
elements: DRepData[];
page: number;
pageSize: number;
total: number;
};

export type Vote = "yes" | "no" | "abstain";

export type InfinityProposals = {
elements: ProposalData[];
page: number;
pageSize: number;
total: number;
};

type ProposalVote = {
date: string;
drepId: string;
Expand All @@ -82,30 +74,39 @@ type ProposalVote = {
vote: Vote;
};

export type ProposalData = {
export type ProposalDataDTO = {
abstainVotes: number;
createdDate: string;
createdEpochNo: number;
expiryDate: string;
expiryEpochNo: number;
details?: ActionDetailsType;
expiryDate?: string;
expiryEpochNo?: number;
id: string;
index: number;
metadataValid: boolean;
metadataHash: string;
noVotes: number;
txHash: string;
type: string;
url: string;
yesVotes: number;
abstract?: string;
details?: ActionDetailsType;
metadataHash?: string;
metadataStatus: MetadataValidationStatus | null;
motivation?: string;
rationale?: string;
references?: string[];
title?: string;
url?: string;
};
export interface VotedProposal {

export type ProposalData = ProposalDataDTO & {
metadataStatus: MetadataValidationStatus | null;
metadataValid: boolean;
}

export type VotedProposalDTO = {
vote: ProposalVote;
proposal: ProposalDataDTO;
}

export type VotedProposal = {
vote: ProposalVote;
proposal: ProposalData;
}
Expand All @@ -115,3 +116,10 @@ export type CurrentDelegation = {
dRepView: string | null;
txHash: string | null;
} | null;

export type Infinite<T> = {
elements: T[];
page: number;
pageSize: number;
total: number;
}
20 changes: 17 additions & 3 deletions govtool/frontend/src/models/metadataValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,29 @@ export enum MetadataStandard {
CIPQQQ = "CIPQQQ",
}

export type ValidateMetadataResult = {
export type ValidateMetadataResult<MetadataType> = {
status?: MetadataValidationStatus;
valid: boolean;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metadata?: any;
metadata?: MetadataType;
};

export type MetadataValidationDTO = {
url: string;
hash: string;
standard?: MetadataStandard;
};

export type DRepMetadata = {
bio?: string;
dRepName?: string;
email?: string;
references?: string[];
};

export type ProposalMetadata = {
abstract?: string;
motivation?: string;
rationale?: string;
references?: string[];
title?: string;
}
9 changes: 2 additions & 7 deletions govtool/frontend/src/pages/GovernanceActionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from "@hooks";
import { Footer, TopNav, GovernanceActionDetailsCard } from "@organisms";
import {
formatDisplayDate,
getProposalTypeLabel,
WALLET_LS_KEY,
getItemFromLocalStorage,
Expand Down Expand Up @@ -131,9 +130,7 @@ export const GovernanceActionDetails = () => {
state ? state.abstainVotes : data.proposal.abstainVotes
}
createdDate={
state
? formatDisplayDate(state.createdDate)
: formatDisplayDate(data.proposal.createdDate)
state ? state.createdDate : data.proposal.createdDate
}
createdEpochNo={
state ? state.createdEpochNo : data.proposal.createdEpochNo
Expand All @@ -142,9 +139,7 @@ export const GovernanceActionDetails = () => {
state ? state.metadataStatus : data?.proposal.metadataStatus
}
expiryDate={
state
? formatDisplayDate(state.expiryDate)
: formatDisplayDate(data.proposal.expiryDate)
state ? state.expiryDate : data.proposal.expiryDate
}
expiryEpochNo={
state ? state.expiryEpochNo : data.proposal.expiryEpochNo
Expand Down
34 changes: 7 additions & 27 deletions govtool/frontend/src/services/requests/getDRepList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
type InfinityDRepData,
type Infinite,
type DRepStatus,
type DRepListSort,
MetadataStandard,
DRepData,
DrepDataDTO,
} from "@models";
import { API } from "../API";
import { postValidate } from "./metadataValidation";
import { mapDtoToDrep } from "@/utils";

export type GetDRepListArguments = {
filters?: string[];
Expand All @@ -23,8 +24,8 @@ export const getDRepList = async ({
pageSize = 10,
searchPhrase = "",
status = [],
}: GetDRepListArguments): Promise<InfinityDRepData> => {
const response = await API.get<InfinityDRepData>("/drep/list", {
}: GetDRepListArguments): Promise<Infinite<DRepData>> => {
const response = await API.get<Infinite<DrepDataDTO>>("/drep/list", {
params: {
page,
pageSize,
Expand All @@ -38,28 +39,7 @@ export const getDRepList = async ({
const validatedResponse = {
...response.data,
elements: await Promise.all(
response.data.elements.map(async (drep) => {
if (drep.metadataStatus || drep.metadataValid) {
return drep;
}
if (drep.url && drep.metadataHash) {
const validationResponse = await postValidate({
url: drep.url,
hash: drep.metadataHash,
standard: MetadataStandard.CIPQQQ,
});
return {
...drep,
bio: validationResponse.metadata?.bio,
dRepName: validationResponse.metadata?.dRepName,
email: validationResponse.metadata?.email,
references: validationResponse.metadata?.references,
metadataStatus: validationResponse.status || null,
metadataValid: validationResponse.valid,
};
}
return drep;
}),
response.data.elements.map(async (drep) => mapDtoToDrep(drep)),
),
};

Expand Down
Loading

0 comments on commit 11db089

Please sign in to comment.