diff --git a/govtool/frontend/src/hooks/forms/index.ts b/govtool/frontend/src/hooks/forms/index.ts index eee66a733..414ec7b4d 100644 --- a/govtool/frontend/src/hooks/forms/index.ts +++ b/govtool/frontend/src/hooks/forms/index.ts @@ -2,7 +2,5 @@ export * from "./useCreateGovernanceActionForm"; export * from "./useDelegateTodRepForm"; export * from "./useEditDRepInfoForm"; export * from "./useRegisterAsdRepForm"; -export * from "./useUpdatedRepMetadataForm"; -export * from "./useUrlAndHashFormController"; export * from "./useVoteActionForm"; export * from "./useVoteContextForm"; diff --git a/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx b/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx deleted file mode 100644 index bd81d6318..000000000 --- a/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx +++ /dev/null @@ -1,64 +0,0 @@ -import { useCallback, useState } from "react"; -import { useNavigate } from "react-router-dom"; - -import { PATHS } from "@consts"; -import { useCardano, useSnackbar } from "@context"; -import { useTranslation } from "@hooks"; -import { - UrlAndHashFormValues, - useUrlAndHashFormController, -} from "./useUrlAndHashFormController"; - -export const useUpdatedRepMetadataForm = () => { - const { buildSignSubmitConwayCertTx, buildDRepUpdateCert } = useCardano(); - const { addSuccessAlert, addErrorAlert } = useSnackbar(); - const [isLoading, setIsLoading] = useState(false); - const navigate = useNavigate(); - const { t } = useTranslation(); - - const { - handleSubmit, - control, - formState: { errors, isValid }, - } = useUrlAndHashFormController(); - - const onSubmit = useCallback( - async (values: UrlAndHashFormValues) => { - const { url, hash } = values; - - // Temporary solution. To modify later. - const urlSubmitValue = !url - ? "https://raw.githubusercontent.com/Thomas-Upfield/test-metadata/main/placeholder.json" - : url; - const hashSubmitValue = !hash - ? "654e483feefc4d208ea02637a981a2046e17c73c09583e9dd0c84c25dab42749" - : hash; - setIsLoading(true); - try { - const certBuilder = await buildDRepUpdateCert( - urlSubmitValue, - hashSubmitValue, - ); - const result = await buildSignSubmitConwayCertTx({ - certBuilder, - type: "updateMetaData", - }); - if (result) addSuccessAlert(t("alerts.updateMetaData.success")); - navigate(PATHS.dashboard); - } catch (e) { - addErrorAlert(t("alerts.updateMetaData.failed")); - } finally { - setIsLoading(false); - } - }, - [buildDRepUpdateCert, buildSignSubmitConwayCertTx], - ); - - return { - submitForm: handleSubmit(onSubmit), - control, - errors, - isValid, - isLoading, - }; -}; diff --git a/govtool/frontend/src/hooks/forms/useUrlAndHashFormController.tsx b/govtool/frontend/src/hooks/forms/useUrlAndHashFormController.tsx deleted file mode 100644 index 53390f2f6..000000000 --- a/govtool/frontend/src/hooks/forms/useUrlAndHashFormController.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { useMemo } from "react"; -import { yupResolver } from "@hookform/resolvers/yup"; -import { useForm } from "react-hook-form"; -import * as Yup from "yup"; -import { HASH_REGEX, URL_REGEX } from "@utils"; -import { useTranslation } from "@hooks"; - -export interface UrlAndHashFormValues { - hash?: string; - storeData?: boolean; - url?: string; -} - -export const useUrlAndHashFormController = () => { - const { t } = useTranslation(); - - const validationSchema = useMemo( - () => - Yup.object().shape({ - url: Yup.string() - .trim() - .max(64, t("forms.errors.urlTooLong")) - .test( - "url-validation", - t("forms.errors.urlInvalidFormat"), - (value) => !value || URL_REGEX.test(value), - ), - hash: Yup.string() - .trim() - .test( - "hash-length-validation", - t("forms.errors.hashInvalidLength"), - (value) => !value || value.length === 64, - ) - .test( - "hash-format-validation", - t("forms.errors.hashInvalidFormat"), - (value) => !value || HASH_REGEX.test(value), - ), - storeData: Yup.boolean(), - }), - [], - ); - - return useForm({ - defaultValues: { url: "", hash: "", storeData: false }, - mode: "onChange", - resolver: yupResolver(validationSchema), - }); -}; diff --git a/govtool/frontend/src/i18n/locales/en.ts b/govtool/frontend/src/i18n/locales/en.ts index dd02c9b16..e129d9083 100644 --- a/govtool/frontend/src/i18n/locales/en.ts +++ b/govtool/frontend/src/i18n/locales/en.ts @@ -351,11 +351,7 @@ export const en = { termOfService: "Term of service", }, forms: { - hashPlaceholder: "The hash of metadata at URL", - howCreateUrlAndHash: "How to create URL and hash?", link: "Link", - urlWithContextPlaceholder: "Your URL with with your context", - urlWithInfoPlaceholder: "Your URL with extra info about you", createGovernanceAction: { typeLabel: "Governance Action Type", typeTip: @@ -373,11 +369,7 @@ export const en = { emailPlaceholder: "john.smith@email.com", }, errors: { - hashInvalidFormat: "Invalid hash format", - hashInvalidLength: "Hash must be exactly 64 characters long", - urlTooLong: "Url must be less than 65 characters", tooLongUrl: "Url must be less than 128 bytes", - urlInvalidFormat: "Invalid URL format", }, registerAsDRep: { bio: "Bio",