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 1 commit
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
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
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,21 @@ export const useRegisterAsdRepFormContext = () => {
async (values: UrlAndHashFormValues) => {
const { url, hash } = values;

const urlSubmitValue = url ?? "";
const hashSubmitValue = hash ?? "";
// Temporary solution. To modify later.
const urlSubmitValue =
!url || url === ""
Copy link
Contributor

Choose a reason for hiding this comment

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

!undefined === true, !null === true, !"" === true, !'' === true
Conclusion: OR operator here makes no sense in my opinion

? "https://raw.githubusercontent.com/Thomas-Upfield/test-metadata/main/placeholder.json"
: url;
const hashSubmitValue =
!hash || 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
11 changes: 9 additions & 2 deletions govtool/frontend/src/hooks/forms/useUpdatedRepMetadataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ export const useUpdatedRepMetadataForm = () => {
async (values: UrlAndHashFormValues) => {
const { url, hash } = values;

const urlSubmitValue = url ?? "";
const hashSubmitValue = hash ?? "";
// Temporary solution. To modify later.
const urlSubmitValue =
!url || url === ""
? "https://raw.githubusercontent.com/Thomas-Upfield/test-metadata/main/placeholder.json"
: url;
const hashSubmitValue =
!hash || hash === ""
? "654e483feefc4d208ea02637a981a2046e17c73c09583e9dd0c84c25dab42749"
: hash;
setIsLoading(true);
try {
const certBuilder = await buildDRepUpdateCert(
Expand Down
3 changes: 2 additions & 1 deletion govtool/frontend/src/hooks/queries/useGetDRepInfoQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { useCardano } from "@context";
import { getDRepInfo } from "@services";

export const useGetDRepInfo = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

then change this on useGetVoterInfo connected with voter data

const { dRepID, registerTransaction } = useCardano();
const { dRepID, registerTransaction, soleVoterTransaction } = useCardano();

const { data, isLoading } = useQuery({
queryKey: [
QUERY_KEYS.useGetDRepInfoKey,
registerTransaction?.transactionHash,
soleVoterTransaction?.transactionHash,
],
enabled: !!dRepID,
queryFn: async () => await getDRepInfo(dRepID),
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ 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.",
Expand Down