diff --git a/govtool/frontend/src/App.tsx b/govtool/frontend/src/App.tsx index a282b9e74..13bc34a7d 100644 --- a/govtool/frontend/src/App.tsx +++ b/govtool/frontend/src/App.tsx @@ -30,13 +30,13 @@ import { removeItemFromLocalStorage, } from "@utils"; import { SetupInterceptors } from "./services"; -import { useGetDRepInfo, useWalletConnectionListener } from "./hooks"; +import { useGetVoterInfo, useWalletConnectionListener } from "./hooks"; import { RegisterAsSoleVoter } from "./pages/RegisterAsSoleVoter"; export default function App() { const { enable, setVoter, setIsDrepLoading } = useCardano(); const navigate = useNavigate(); - const { data } = useGetDRepInfo(); + const { data } = useGetVoterInfo(); const { modal, openModal, modals } = useModal(); useWalletConnectionListener(); diff --git a/govtool/frontend/src/components/organisms/DashboardCards.tsx b/govtool/frontend/src/components/organisms/DashboardCards.tsx index 34018f07a..73208b3cb 100644 --- a/govtool/frontend/src/components/organisms/DashboardCards.tsx +++ b/govtool/frontend/src/components/organisms/DashboardCards.tsx @@ -246,7 +246,7 @@ export const DashboardCards = () => { } } else if (voter?.isRegisteredAsSoleVoter) { return "dashboard.soleVoter.isRegisteredDescription"; - } else if (voter?.wasRegisteredAsSoleVoter && !voter?.isRegisteredAsDRep) { + } else if (voter?.wasRegisteredAsSoleVoter) { return "dashboard.soleVoter.wasRegisteredDescription"; } else { return "dashboard.soleVoter.registerDescription"; @@ -292,8 +292,8 @@ export const DashboardCards = () => { } } else if (voter?.isRegisteredAsSoleVoter) { return t("dashboard.soleVoter.youAreSoleVoterTitle"); - } else if (voter?.wasRegisteredAsSoleVoter && !voter?.isRegisteredAsDRep) { - return t("dashboard.soleVoter.retireTitle"); + } else if (voter?.wasRegisteredAsSoleVoter) { + return t("dashboard.soleVoter.wasSoleVoterTitle"); } else { return t("dashboard.soleVoter.registerTitle"); } @@ -473,8 +473,7 @@ export const DashboardCards = () => { : t( voter?.isRegisteredAsSoleVoter ? "dashboard.soleVoter.retire" - : voter?.wasRegisteredAsSoleVoter && - !voter?.isRegisteredAsDRep + : voter?.wasRegisteredAsSoleVoter ? "dashboard.soleVoter.reRegister" : "dashboard.soleVoter.register" ) diff --git a/govtool/frontend/src/components/organisms/RegisterAsSoleVoterBox.tsx b/govtool/frontend/src/components/organisms/RegisterAsSoleVoterBox.tsx index 1794a7042..f55acb106 100644 --- a/govtool/frontend/src/components/organisms/RegisterAsSoleVoterBox.tsx +++ b/govtool/frontend/src/components/organisms/RegisterAsSoleVoterBox.tsx @@ -10,7 +10,12 @@ import { useCardano, useModal } from "@context"; export const RegisterAsSoleVoterBox = () => { const [isLoading, setIsLoading] = useState(false); - const { buildSignSubmitConwayCertTx, buildDRepRegCert } = useCardano(); + const { + buildSignSubmitConwayCertTx, + buildDRepRegCert, + buildDRepUpdateCert, + voter, + } = useCardano(); const navigate = useNavigate(); const { openModal, closeModal } = useModal(); const { t } = useTranslation(); @@ -19,7 +24,9 @@ export const RegisterAsSoleVoterBox = () => { setIsLoading(true); try { - const certBuilder = await buildDRepRegCert(); + const certBuilder = voter?.isRegisteredAsDRep + ? await buildDRepUpdateCert() + : await buildDRepRegCert(); const result = await buildSignSubmitConwayCertTx({ certBuilder, type: "soleVoterRegistration", diff --git a/govtool/frontend/src/context/walletUtils.ts b/govtool/frontend/src/context/walletUtils.ts index d68d8e7cf..ef6a8a00b 100644 --- a/govtool/frontend/src/context/walletUtils.ts +++ b/govtool/frontend/src/context/walletUtils.ts @@ -1,4 +1,4 @@ -import { getAdaHolderCurrentDelegation, getDRepInfo } from "@services"; +import { getAdaHolderCurrentDelegation, getVoterInfo } from "@services"; import { DRepActionType } from "./wallet"; import { VoterInfo } from "@models"; @@ -18,7 +18,7 @@ export const setLimitedRegistrationInterval = ( count++; try { - const data = await getDRepInfo(dRepID); + const data = await getVoterInfo(dRepID); if ( data.isRegisteredAsDRep === desiredResult || diff --git a/govtool/frontend/src/hooks/forms/useRegisterAsdRepFormContext.tsx b/govtool/frontend/src/hooks/forms/useRegisterAsdRepFormContext.tsx index 27a9fc6a5..28cc2a557 100644 --- a/govtool/frontend/src/hooks/forms/useRegisterAsdRepFormContext.tsx +++ b/govtool/frontend/src/hooks/forms/useRegisterAsdRepFormContext.tsx @@ -7,7 +7,12 @@ import { useCardano, useModal } from "@context"; import { UrlAndHashFormValues, useTranslation } from "@hooks"; export const useRegisterAsdRepFormContext = () => { - const { buildSignSubmitConwayCertTx, buildDRepRegCert } = useCardano(); + const { + buildSignSubmitConwayCertTx, + buildDRepRegCert, + buildDRepUpdateCert, + voter, + } = useCardano(); const { openModal, closeModal } = useModal(); const [isLoading, setIsLoading] = useState(false); const navigate = useNavigate(); @@ -31,15 +36,19 @@ export const useRegisterAsdRepFormContext = () => { async (values: UrlAndHashFormValues) => { const { url, hash } = values; - const urlSubmitValue = url ?? ""; - const hashSubmitValue = hash ?? ""; + // 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 buildDRepRegCert( - urlSubmitValue, - hashSubmitValue - ); + const certBuilder = voter?.isRegisteredAsSoleVoter + ? await buildDRepUpdateCert(urlSubmitValue, hashSubmitValue) + : await buildDRepRegCert(urlSubmitValue, hashSubmitValue); const result = await buildSignSubmitConwayCertTx({ certBuilder, type: "registration", diff --git a/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx b/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx index da48b2250..fd35f8474 100644 --- a/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx +++ b/govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx @@ -26,8 +26,13 @@ export const useUpdatedRepMetadataForm = () => { async (values: UrlAndHashFormValues) => { const { url, hash } = values; - const urlSubmitValue = url ?? ""; - const hashSubmitValue = hash ?? ""; + // 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( diff --git a/govtool/frontend/src/hooks/queries/index.ts b/govtool/frontend/src/hooks/queries/index.ts index 7733019b0..192e18b0d 100644 --- a/govtool/frontend/src/hooks/queries/index.ts +++ b/govtool/frontend/src/hooks/queries/index.ts @@ -1,6 +1,6 @@ export * from "./useGetAdaHolderCurrentDelegationQuery"; export * from "./useGetAdaHolderVotingPowerQuery"; -export * from "./useGetDRepInfoQuery"; +export * from "./useGetVoterInfoQuery"; export * from "./useGetDRepListQuery"; export * from "./useGetDRepVotesQuery"; export * from "./useGetDRepVotingPowerQuery"; diff --git a/govtool/frontend/src/hooks/queries/useGetDRepInfoQuery.ts b/govtool/frontend/src/hooks/queries/useGetVoterInfoQuery.ts similarity index 55% rename from govtool/frontend/src/hooks/queries/useGetDRepInfoQuery.ts rename to govtool/frontend/src/hooks/queries/useGetVoterInfoQuery.ts index 217aecde8..63f8f97c8 100644 --- a/govtool/frontend/src/hooks/queries/useGetDRepInfoQuery.ts +++ b/govtool/frontend/src/hooks/queries/useGetVoterInfoQuery.ts @@ -2,18 +2,19 @@ import { useQuery } from "react-query"; import { QUERY_KEYS } from "@consts"; import { useCardano } from "@context"; -import { getDRepInfo } from "@services"; +import { getVoterInfo } from "@services"; -export const useGetDRepInfo = () => { - const { dRepID, registerTransaction } = useCardano(); +export const useGetVoterInfo = () => { + const { dRepID, registerTransaction, soleVoterTransaction } = useCardano(); const { data, isLoading } = useQuery({ queryKey: [ QUERY_KEYS.useGetDRepInfoKey, registerTransaction?.transactionHash, + soleVoterTransaction?.transactionHash, ], enabled: !!dRepID, - queryFn: async () => await getDRepInfo(dRepID), + queryFn: async () => await getVoterInfo(dRepID), }); return { data, isLoading }; diff --git a/govtool/frontend/src/i18n/locales/en.ts b/govtool/frontend/src/i18n/locales/en.ts index edf57f75d..967863ecf 100644 --- a/govtool/frontend/src/i18n/locales/en.ts +++ b/govtool/frontend/src/i18n/locales/en.ts @@ -112,12 +112,12 @@ export const en = { registrationInProgress: "The registration process is ongoing. This may take several minutes.", retire: "Retire", - retireTitle: "You Have Retired as a Sole Voter", + wasSoleVoterTitle: "You Have Retired as a Sole Voter", retirement: "Sole Voter Retirement", - wasRegisteredDescription: - "You cannot vote on Governance Actions using your own voting power of ₳{{votingPower}}. until you re-register.", retirementInProgress: "The retirement process is ongoing. This may take several minutes.", + wasRegisteredDescription: + "You cannot vote on Governance Actions using your own voting power of ₳{{votingPower}}. until you re-register.", youAreSoleVoterTitle: "You are a Sole Voter", }, }, diff --git a/govtool/frontend/src/services/requests/getDRepInfo.ts b/govtool/frontend/src/services/requests/getVoterInfo.ts similarity index 75% rename from govtool/frontend/src/services/requests/getDRepInfo.ts rename to govtool/frontend/src/services/requests/getVoterInfo.ts index 869fcd337..8233aa7c8 100644 --- a/govtool/frontend/src/services/requests/getDRepInfo.ts +++ b/govtool/frontend/src/services/requests/getVoterInfo.ts @@ -2,7 +2,7 @@ import { API } from "../API"; import type { VoterInfo } from "@models"; -export const getDRepInfo = async (dRepID: string) => { +export const getVoterInfo = async (dRepID: string) => { const response = await API.get(`/drep/info/${dRepID}`); return response.data; diff --git a/govtool/frontend/src/services/requests/index.ts b/govtool/frontend/src/services/requests/index.ts index f5809f815..16f5cb743 100644 --- a/govtool/frontend/src/services/requests/index.ts +++ b/govtool/frontend/src/services/requests/index.ts @@ -1,6 +1,6 @@ export * from "./getAdaHolderCurrentDelegation"; export * from "./getAdaHolderVotingPower"; -export * from "./getDRepInfo"; +export * from "./getVoterInfo"; export * from "./getDRepList"; export * from "./getDRepVotes"; export * from "./getDRepVotingPower";