Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#239 #240 #338] DRep can become Sole Voter, Sole Voter can become DRep #342

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { useCardano, useModal } from "@context";
export const RegisterAsSoleVoterBox = () => {
const [isLoading, setIsLoading] = useState<boolean>(false);

const { buildSignSubmitConwayCertTx, buildDRepRegCert } = useCardano();
const {
buildSignSubmitConwayCertTx,
buildDRepRegCert,
buildDRepUpdateCert,
voter,
} = useCardano();
const navigate = useNavigate();
const { openModal, closeModal } = useModal();
const { t } = useTranslation();
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/src/context/walletUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAdaHolderCurrentDelegation, getDRepInfo } from "@services";
import { getAdaHolderCurrentDelegation, getVoterInfo } from "@services";
import { DRepActionType } from "./wallet";
import { VoterInfo } from "@models";

Expand All @@ -18,7 +18,7 @@ export const setLimitedRegistrationInterval = (
count++;

try {
const data = await getDRepInfo(dRepID);
const data = await getVoterInfo(dRepID);

if (
data.isRegisteredAsDRep === desiredResult ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(false);
const navigate = useNavigate();
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/hooks/queries/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
6 changes: 3 additions & 3 deletions govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort

retirement: "Sole Voter Retirement",
wasRegisteredDescription:
"You cannot vote on Governance Actions using your own voting power of ₳<strong>{{votingPower}}</strong>. 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 ₳<strong>{{votingPower}}</strong>. until you re-register.",
youAreSoleVoterTitle: "You are a Sole Voter",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VoterInfo>(`/drep/info/${dRepID}`);

return response.data;
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/services/requests/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down