Skip to content

Commit

Permalink
wip 4
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJaroszczak committed Mar 26, 2024
1 parent 28a7998 commit f8b14a2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const VoteActionForm = ({
[confirmVote, areFormErrors, vote, isVoteLoading],
);

const receiveVote = (hash?: string, url: string) => {
const receiveVote = (url: string, hash?: string | null) => {
console.log("RECEIVED");

Check failure on line 129 in govtool/frontend/src/components/molecules/VoteActionForm.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log(hash, url);

Check failure on line 130 in govtool/frontend/src/components/molecules/VoteActionForm.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ import { VoteContextFormValues } from "@/hooks/forms/useVoteContextForm";
type VoteContextModalState = {
onContinue?: () => void;
onCancel?: () => void;
onSubmit?: () => void;
onSubmit?: (url: string, hash: string | null) => void;
};

export const VoteContextModal = () => {
const [step, setStep] = useState(1);
const [savedHash, setSavedHash] = useState<string | null>("");

console.log("savedHash", savedHash);

Check failure on line 24 in govtool/frontend/src/components/organisms/VoteContext/VoteContextModal.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

const { state, closeModal } = useModal<VoteContextModalState>();

Check failure on line 26 in govtool/frontend/src/components/organisms/VoteContext/VoteContextModal.tsx

View workflow job for this annotation

GitHub Actions / lint

'closeModal' is assigned a value but never used

const methods = useForm<VoteContextFormValues>({ mode: "onChange" });

const submitVoteContext = () => {
if (state?.onSubmit) {
console.log("savedHash2222", savedHash);

Check failure on line 32 in govtool/frontend/src/components/organisms/VoteContext/VoteContextModal.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

state.onSubmit(methods.getValues("storingURL"), savedHash);
}
};

return (
<ModalWrapper
dataTestId="vote-context-modal"
Expand All @@ -35,12 +46,15 @@ export const VoteContextModal = () => {
<FormProvider {...methods}>
{step === 1 && <VoteContextText setStep={setStep} />}
{step === 2 && <VoteContextTerms setStep={setStep} />}
{step === 3 && <VoteContextStoringInformation setStep={setStep} />}
{step === 4 && (
<VoteContextSuccess
submitVoteContext={state?.onSubmit ? state?.onSubmit : closeModal}
{step === 3 && (
<VoteContextStoringInformation
setSavedHash={setSavedHash}
setStep={setStep}
/>
)}
{step === 4 && (
<VoteContextSuccess submitVoteContext={submitVoteContext} />
)}
</FormProvider>
</ModalWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import { URL_REGEX, openInNewTab } from "@utils";

type VoteContextStoringInformationProps = {
setStep: Dispatch<SetStateAction<number>>;
setSavedHash: Dispatch<SetStateAction<string | null>>;
};

export const VoteContextStoringInformation = ({
setStep,
setSavedHash,
}: VoteContextStoringInformationProps) => {
const { t } = useTranslation();
const {
Expand All @@ -26,7 +28,7 @@ export const VoteContextStoringInformation = ({
generateMetadata,
onClickDownloadJson,
// isLoading,
} = useVoteContextForm(setStep);
} = useVoteContextForm(setSavedHash, setStep);
const { screenWidth } = useScreenDimension();

// const fileName = getValues("governance_action_type");
Expand All @@ -41,6 +43,8 @@ export const VoteContextStoringInformation = ({
// const onClickBack = () => setStep(5);

useEffect(() => {
console.log("GENERATE");

Check failure on line 46 in govtool/frontend/src/components/organisms/VoteContext/VoteContextStoringInformation.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

generateMetadata();
}, []);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, SetStateAction } from "react";
import { Dispatch, SetStateAction, useState } from "react";

Check failure on line 1 in govtool/frontend/src/components/organisms/VoteContext/VoteContextSuccess.tsx

View workflow job for this annotation

GitHub Actions / lint

'Dispatch' is defined but never used

Check failure on line 1 in govtool/frontend/src/components/organisms/VoteContext/VoteContextSuccess.tsx

View workflow job for this annotation

GitHub Actions / lint

'SetStateAction' is defined but never used

Check failure on line 1 in govtool/frontend/src/components/organisms/VoteContext/VoteContextSuccess.tsx

View workflow job for this annotation

GitHub Actions / lint

'useState' is defined but never used

import { ICONS, IMAGES } from "@consts";

Check failure on line 3 in govtool/frontend/src/components/organisms/VoteContext/VoteContextSuccess.tsx

View workflow job for this annotation

GitHub Actions / lint

'ICONS' is defined but never used
import { Button, Typography } from "@atoms";
Expand All @@ -8,7 +8,7 @@ import { ControlledField } from "..";
import { Box } from "@mui/material";

type VoteContextSuccessProps = {
submitVoteContext: (hash?: string, url: string) => void;
submitVoteContext: () => void;
};

export const VoteContextSuccess = ({
Expand Down Expand Up @@ -55,7 +55,7 @@ export const VoteContextSuccess = ({
console.log("hash", hash);
console.log("getValues", getValues("storingURL"));

submitVoteContext(hash, getValues("storingURL"));
submitVoteContext();
}}
sx={{
borderRadius: 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const useCreateGovernanceActionForm = (

const canonizedJson = await canonizeJSON(jsonld);
const canonizedJsonHash = blake2bHex(canonizedJson, undefined, 32);
console.log("canonizedJsonHash2222", canonizedJsonHash);

// That allows to validate metadata hash
setHash(canonizedJsonHash);
Expand Down
20 changes: 20 additions & 0 deletions govtool/frontend/src/hooks/forms/useVoteContextForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ export type VoteContextFormValues = {
};

export const useVoteContextForm = (
setSavedHash?: Dispatch<SetStateAction<string | null>>,
setStep?: Dispatch<SetStateAction<number>>,
) => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [hash, setHash] = useState<string | null>(null);
const [json, setJson] = useState<NodeObject | null>(null);

console.log("stateHash", hash);
console.log("stateJson", json);

const { openModal, closeModal } = useModal();
const { t } = useTranslation();

Expand Down Expand Up @@ -81,9 +85,16 @@ export const useVoteContextForm = (

const jsonld = await generateJsonld(body, VOTE_TEST_CONTEXT);

console.log("jsonld", jsonld);

const canonizedJson = await canonizeJSON(jsonld);

console.log("canonizedJson", canonizedJson);

const canonizedJsonHash = blake2bHex(canonizedJson, undefined, 32);

console.log("canonizedJsonHash", canonizedJsonHash);

// That allows to validate metadata hash
setHash(canonizedJsonHash);
setJson(jsonld);
Expand Down Expand Up @@ -155,6 +166,8 @@ export const useVoteContextForm = (
try {
setIsLoading(true);

console.log("hash przed validate", hash);

await validateHash(data.storingURL, hash);
// const govActionBuilder = await buildTransaction(data);
// await buildSignSubmitConwayCertTx({
Expand All @@ -170,6 +183,13 @@ export const useVoteContextForm = (
setIsLoading(false);
console.log("weszło");

console.log("hash na koniec", hash);

if (setSavedHash) {
console.log("hash ustawiany", hash);

setSavedHash(hash);
}
if (setStep) setStep(4);
}
},
Expand Down
4 changes: 4 additions & 0 deletions govtool/frontend/src/utils/generateJsonld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const generateJsonld = async <
[`${CIP_100}authors`]: [],
};

console.log("doc", doc);

const json = await jsonld.compact(doc, context);

console.log("json", json);

return json;
};

0 comments on commit f8b14a2

Please sign in to comment.