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

Feat/210 sole voter wallet logic for registration and retirement #307

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
6 changes: 3 additions & 3 deletions govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { useGetDRepInfo, useWalletConnectionListener } from "./hooks";
import { RegisterAsSoleVoter } from "./pages/RegisterAsSoleVoter";

export default function App() {
const { enable, setDRep, setIsDrepLoading } = useCardano();
const { enable, setVoter, setIsDrepLoading } = useCardano();
const navigate = useNavigate();
const { data } = useGetDRepInfo();
const { modal, openModal, modals } = useModal();
Expand All @@ -47,11 +47,11 @@ export default function App() {

useEffect(() => {
setIsDrepLoading(true);
setDRep(data);
setVoter(data);
const timer = setTimeout(() => setIsDrepLoading(false), 1000);

return () => clearTimeout(timer);
}, [data?.isRegistered]);
}, [data?.isRegisteredAsDRep, data?.isRegisteredAsSoleVoter]);

const checkTheWalletIsActive = useCallback(() => {
const hrefCondition =
Expand Down
10 changes: 5 additions & 5 deletions govtool/frontend/src/components/atoms/VotingPowerChips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { correctAdaFormat } from "@utils";
import { Tooltip } from "@atoms";

export const VotingPowerChips = () => {
const { dRep, stakeKey, isDrepLoading } = useCardano();
const { voter, stakeKey, isDrepLoading } = useCardano();
const { dRepVotingPower, isDRepVotingPowerLoading } =
useGetDRepVotingPowerQuery();
const { votingPower, powerIsLoading } =
Expand All @@ -33,7 +33,7 @@ export const VotingPowerChips = () => {
alignItems="center"
maxHeight={isMobile ? undefined : 48}
>
{dRep?.isRegistered && (
{voter?.isRegisteredAsDRep && (
<Tooltip
heading={t("tooltips.votingPower.heading")}
paragraphOne={t("tooltips.votingPower.paragraphOne")}
Expand All @@ -55,8 +55,8 @@ export const VotingPowerChips = () => {
{t("votingPower")}
</Typography>
)}
{(dRep?.isRegistered && isDRepVotingPowerLoading) ||
(!dRep?.isRegistered && powerIsLoading) ||
{(voter?.isRegisteredAsDRep && isDRepVotingPowerLoading) ||
(!voter?.isRegisteredAsDRep && powerIsLoading) ||
isDrepLoading ? (
<CircularProgress size={20} color="primary" />
) : (
Expand All @@ -67,7 +67,7 @@ export const VotingPowerChips = () => {
sx={{ whiteSpace: "nowrap" }}
>
₳{" "}
{dRep?.isRegistered
{voter?.isRegisteredAsDRep
? correctAdaFormat(dRepVotingPower) ?? 0
: correctAdaFormat(votingPower) ?? 0}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
) : null}
{inProgress && !isLoading ? (
<Typography variant="title2" fontWeight={700}>
in progress
In Progress
</Typography>
) : null}
{description ? (
Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/src/components/molecules/VoteActionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const VoteActionForm = ({
const [isContext, setIsContext] = useState<boolean>(false);
const { isMobile, screenWidth } = useScreenDimension();
const { openModal } = useModal();
const { dRep } = useCardano();
const { voter } = useCardano();
const { t } = useTranslation();

const {
Expand Down Expand Up @@ -142,7 +142,7 @@ export const VoteActionForm = ({
/>
</Box>
</Box>
{dRep?.isRegistered && (
{voter?.isRegisteredAsDRep && (
<Button
data-testid="show-votes-button"
variant="text"
Expand Down
150 changes: 98 additions & 52 deletions govtool/frontend/src/components/organisms/DashboardCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ export const DashboardCards = () => {
buildSignSubmitConwayCertTx,
delegateTo,
delegateTransaction,
dRep,
voter,
dRepID,
dRepIDBech32,
isDrepLoading,
isPendingTransaction,
registerTransaction,
soleVoterTransaction,
stakeKey,
soleVoter,
} = useCardano();
const navigate = useNavigate();
const { currentDelegation, isCurrentDelegationLoading } =
Expand Down Expand Up @@ -225,16 +224,38 @@ export const DashboardCards = () => {
default:
return t("dashboard.registration.metadataUpdateInProgress");
}
} else if (dRep?.isRegistered || dRep?.wasRegistered) {
} else if (voter?.isRegisteredAsDRep || voter?.wasRegisteredAsDRep) {
return t("dashboard.registration.holdersCanDelegate");
} else {
return t("dashboard.registration.ifYouWant");
}
}, [
registerTransaction.transactionHash,
registerTransaction.type,
dRep?.isRegistered,
dRep?.wasRegistered,
voter?.isRegisteredAsDRep,
voter?.wasRegisteredAsDRep,
]);

const soleVoterCardDescription = useMemo(() => {
if (soleVoterTransaction.transactionHash) {
switch (soleVoterTransaction.type) {
case "retirement":
return "dashboard.soleVoter.retirementInProgress";
default:
return "dashboard.soleVoter.registrationInProgress";
}
} else if (voter?.isRegisteredAsSoleVoter) {
return "dashboard.soleVoter.isRegisteredDescription";
} else if (voter?.wasRegisteredAsSoleVoter && !voter?.isRegisteredAsDRep) {
return "dashboard.soleVoter.wasRegisteredDescription";
} else {
return "dashboard.soleVoter.registerDescription";
}
}, [
soleVoterTransaction.transactionHash,
soleVoterTransaction.type,
voter?.isRegisteredAsSoleVoter,
voter?.wasRegisteredAsSoleVoter,
]);

const registrationCardTitle = useMemo(() => {
Expand All @@ -247,18 +268,40 @@ export const DashboardCards = () => {
default:
return t("dashboard.registration.dRepUpdate");
}
} else if (dRep?.isRegistered) {
} else if (voter?.isRegisteredAsDRep) {
return t("dashboard.registration.youAreRegistered");
} else if (dRep?.wasRegistered) {
} else if (voter?.wasRegisteredAsDRep) {
return t("dashboard.registration.registerAgain");
} else {
return t("dashboard.registration.registerAsDRep");
}
}, [
registerTransaction?.transactionHash,
registerTransaction.type,
dRep?.isRegistered,
dRep?.wasRegistered,
voter?.isRegisteredAsDRep,
voter?.wasRegisteredAsDRep,
]);

const soleVoterCardTitle = useMemo(() => {
if (soleVoterTransaction?.transactionHash) {
switch (soleVoterTransaction.type) {
case "retirement":
return t("dashboard.soleVoter.retirement");
default:
return t("dashboard.soleVoter.registration");
}
} else if (voter?.isRegisteredAsSoleVoter) {
return t("dashboard.soleVoter.youAreSoleVoterTitle");
} else if (voter?.wasRegisteredAsSoleVoter && !voter?.isRegisteredAsDRep) {
return t("dashboard.soleVoter.retireTitle");
} else {
return t("dashboard.soleVoter.registerTitle");
}
}, [
soleVoterTransaction?.transactionHash,
soleVoterTransaction.type,
voter?.isRegisteredAsSoleVoter,
voter?.isRegisteredAsSoleVoter,
]);

return isDrepLoading ? (
Expand Down Expand Up @@ -340,25 +383,27 @@ export const DashboardCards = () => {
{/* REGISTARTION AS DREP CARD */}
<DashboardActionCard
dataTestidFirstButton={
dRep?.isRegistered ? "retire-button" : "register-button"
voter?.isRegisteredAsDRep ? "retire-button" : "register-button"
}
dataTestidDrepIdBox="my-drep-id"
firstButtonVariant={dRep?.isRegistered ? "outlined" : "contained"}
firstButtonVariant={
voter?.isRegisteredAsDRep ? "outlined" : "contained"
}
secondButtonVariant={
registerTransaction?.transactionHash
? "outlined"
: dRep?.isRegistered
: voter?.isRegisteredAsDRep
? "text"
: "outlined"
}
dataTestidSecondButton={
dRep?.isRegistered
voter?.isRegisteredAsDRep
? "change-metadata-button"
: "register-learn-more-button"
}
description={registrationCardDescription}
firstButtonAction={
dRep?.isRegistered
voter?.isRegisteredAsDRep
? retireAsDrep
: () => navigateTo(PATHS.registerAsdRep)
}
Expand All @@ -368,7 +413,7 @@ export const DashboardCards = () => {
? ""
: t(
`dashboard.registration.${
dRep?.isRegistered ? "retire" : "register"
voter?.isRegisteredAsDRep ? "retire" : "register"
}`
)
}
Expand All @@ -377,7 +422,7 @@ export const DashboardCards = () => {
secondButtonAction={
registerTransaction?.transactionHash
? () => openInNewTab("https://adanordic.com/latest_transactions")
: dRep?.isRegistered
: voter?.isRegisteredAsDRep
? () => {
navigateTo(PATHS.updateMetadata);
}
Expand All @@ -389,68 +434,69 @@ export const DashboardCards = () => {
secondButtonLabel={
registerTransaction?.transactionHash
? t("seeTransaction")
: dRep?.isRegistered
: voter?.isRegisteredAsDRep
? t("dashboard.registration.changeMetadata")
: t("learnMore")
}
cardId={dRep?.isRegistered || dRep?.wasRegistered ? dRepIDBech32 : ""}
cardId={
voter?.isRegisteredAsDRep || voter?.wasRegisteredAsDRep
? dRepIDBech32
: ""
}
cardTitle={
dRep?.isRegistered || dRep?.wasRegistered ? t("myDRepId") : ""
voter?.isRegisteredAsDRep || voter?.wasRegisteredAsDRep
? t("myDRepId")
: ""
}
title={registrationCardTitle}
/>
{/* DREP CARD END*/}
{/* SOLE VOTER CARD */}
<DashboardActionCard
dataTestidFirstButton={
soleVoter?.isRegistered
? "retire-as-sole-voter-button"
: "register-as-sole-voter-button"
}
dataTestidSecondButton="learn-more-button"
title={soleVoterCardTitle}
inProgress={!!soleVoterTransaction?.transactionHash}
description={
<Trans
i18nKey={
soleVoter?.isRegistered
? "dashboard.soleVoter.youAreSoleVoterDescription"
: "dashboard.soleVoter.registerAsSoleVoterDescription"
}
i18nKey={soleVoterCardDescription}
values={{ votingPower: correctAdaFormat(votingPower) }}
/>
}
firstButtonLabel={
soleVoterTransaction?.transactionHash
? ""
: t(
voter?.isRegisteredAsSoleVoter
? "dashboard.soleVoter.retire"
: voter?.wasRegisteredAsSoleVoter &&
!voter?.isRegisteredAsDRep
? "dashboard.soleVoter.reRegister"
: "dashboard.soleVoter.register"
)
}
firstButtonAction={() =>
navigateTo(
soleVoter?.isRegistered
voter?.isRegisteredAsSoleVoter
? PATHS.retireAsSoleVoter
: PATHS.registerAsSoleVoter
)
}
firstButtonLabel={t(
soleVoter?.isRegistered
? "dashboard.soleVoter.retire"
: "dashboard.soleVoter.register"
)}
firstButtonVariant={soleVoter?.isRegistered ? "outlined" : "contained"}
secondButtonVariant={
soleVoterTransaction?.transactionHash
? "outlined"
: soleVoter?.isRegistered
? "text"
: "outlined"
firstButtonVariant={
voter?.isRegisteredAsSoleVoter ? "outlined" : "contained"
}
inProgress={!!soleVoterTransaction?.transactionHash}
imageURL={IMAGES.soleVoterImage}
secondButtonLabel={t("learnMore")}
secondButtonAction={() =>
openInNewTab(
"https://docs.sanchogov.tools/faqs/what-does-it-mean-to-register-as-a-drep"
)
}
secondButtonLabel={t("learnMore")}
title={t(
soleVoter?.isRegistered
? "dashboard.soleVoter.youAreSoleVoterTitle"
: "dashboard.soleVoter.registerAsSoleVoterTitle"
)}
secondButtonVariant={"outlined"}
dataTestidFirstButton={
voter?.isRegisteredAsSoleVoter
? "retire-as-sole-voter-button"
: "register-as-sole-voter-button"
}
dataTestidSecondButton="learn-more-button"
imageURL={IMAGES.soleVoterImage}
/>
{/* REGISTARTION AS SOLE VOTER CARD END*/}
{/* GOV ACTIONS LIST CARD */}
Expand All @@ -460,7 +506,7 @@ export const DashboardCards = () => {
firstButtonAction={() => navigate(PATHS.dashboard_governance_actions)}
firstButtonLabel={t(
`dashboard.govActions.${
dRep?.isRegistered ? "reviewAndVote" : "view"
voter?.isRegisteredAsDRep ? "reviewAndVote" : "view"
}`
)}
imageURL={IMAGES.govActionListImage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from "@utils";

export const DashboardGovernanceActionDetails = () => {
const { dRep } = useCardano();
const { voter } = useCardano();
const { state, hash } = useLocation();
const navigate = useNavigate();
const { isMobile, screenWidth } = useScreenDimension();
Expand Down Expand Up @@ -134,7 +134,7 @@ export const DashboardGovernanceActionDetails = () => {
? formatDisplayDate(state.expiryDate)
: formatDisplayDate(data.proposal.expiryDate)
}
isDRep={dRep?.isRegistered}
isDRep={voter?.isRegisteredAsDRep}
noVotes={state ? state.noVotes : data.proposal.noVotes}
type={
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const DashboardGovernanceActions = () => {
state && state.isVotedListOnLoad ? 1 : 0
);

const { dRep, isDrepLoading } = useCardano();
const { voter, isDrepLoading } = useCardano();
const { isMobile } = useScreenDimension();
const { t } = useTranslation();

Expand Down Expand Up @@ -121,7 +121,7 @@ export const DashboardGovernanceActions = () => {
sortingActive={Boolean(chosenSorting)}
sortOpen={sortOpen}
/>
{dRep?.isRegistered && (
{voter?.isRegisteredAsDRep && (
<Tabs
sx={{
marginTop: 3,
Expand Down
Loading