Skip to content

Commit

Permalink
feat: pass govtool metadata validator to pdf pillar
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Jun 20, 2024
1 parent bfa66c6 commit ad41e12
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
43 changes: 43 additions & 0 deletions docs/GOVERNANCE_ACTION_SUBMISSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,46 @@ await buildSignSubmitConwayCertTx({
### Step 6: Verify the Governance Action

`buildSignSubmitConwayCertTx` logs the transaction CBOR making it able to be tracked on the transactions tools such as cexplorer.

## Additional steps for using the GovTool metadata validation on the imported Pillar component

```tsx
enum MetadataValidationStatus {
URL_NOT_FOUND = "URL_NOT_FOUND",
INVALID_JSONLD = "INVALID_JSONLD",
INVALID_HASH = "INVALID_HASH",
INCORRECT_FORMAT = "INCORRECT_FORMAT",
}
// Using the props passed to the component
type Props = {
validateMetadata: ({
url,
hash,
standard,
}: {
url: string;
hash: string;
standard: "CIP108";
}) => Promise<{
metadata?: any;
status?: MetadataValidationStatus;
valid: boolean;
}>;
};

import React, { Suspense } from "react";

const SomeImportedPillar: React.FC<Props> = React.lazy(
() => import("path/to/SomeImportedPillar")
);

const SomeWrapperComponent = () => {
const { validateMetadata } = useValidateMutation();

return (
<Suspense fallback={<div>I am lazy loading...</div>}>
<SomeImportedPillar validateMetadata={validateMetadata} />
</Suspense>
);
};
```
15 changes: 12 additions & 3 deletions govtool/frontend/src/components/organisms/PDFWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, { Suspense } from "react";
import React, { ComponentProps, Suspense } from "react";
import { Box, CircularProgress } from "@mui/material";
import "@intersect.mbo/pdf-ui/style";
import { useCardano, useGovernanceActions } from "@/context";
import { useValidateMutation } from "@/hooks/mutations";

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

export const PDFWrapper = () => {
const { validateMetadata } = useValidateMutation();
const { walletApi, ...context } = useCardano();
const { createGovernanceActionJsonLD, createHash } = useGovernanceActions();

Expand Down Expand Up @@ -33,14 +37,19 @@ export const PDFWrapper = () => {
</Box>
}
>
<PDF
<ProposalDiscussion
walletAPI={{
...context,
...walletApi,
createGovernanceActionJsonLD,
createHash,
}}
pathname={window.location.pathname}
validateMetadata={
validateMetadata as ComponentProps<
typeof ProposalDiscussion
>["validateMetadata"]
}
/>
</Suspense>
</Box>
Expand Down
26 changes: 24 additions & 2 deletions govtool/frontend/src/types/@intersect.mbo.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
type PDFProps = {
enum MetadataValidationStatus {
URL_NOT_FOUND = "URL_NOT_FOUND",
INVALID_JSONLD = "INVALID_JSONLD",
INVALID_HASH = "INVALID_HASH",
INCORRECT_FORMAT = "INCORRECT_FORMAT",
}

type ProposalDiscussionProps = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
walletAPI: any;
pathname: string;
locale?: string;
validateMetadata: ({
url,
hash,
standard,
}: {
url: string;
hash: string;
standard: "CIP108";
}) => Promise<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| { status?: MetadataValidationStatus; metadata?: any; valid: boolean }
| undefined
>;
};

declare module "@intersect.mbo/pdf-ui/cjs" {
export default function PDF(props: PDFProps): JSX.Element;
export default function ProposalDiscussion(
props: ProposalDiscussionProps,
): JSX.Element;
}

0 comments on commit ad41e12

Please sign in to comment.