Skip to content

Commit

Permalink
[#280] Fix get drep voting power request
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Feb 23, 2024
1 parent da200b0 commit b3fd480
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ changes.
- Fixed vote calculation problems related to NoConfidence DRep [Issue 59](https://github.com/IntersectMBO/govtool/issues/59)
- Fixed ada-holder/get-current-delegation error when delegated to NoConfidence or AlwaysAbstain dreps. [Issue 82](https://github.com/IntersectMBO/govtool/issues/82)
- Fixed deployment scripts to address [Issue 171](https://github.com/IntersectMBO/govtool/issues/171).
- Fixed get drep voting power incorrectly executed endpoint [Issue 280](https://github.com/IntersectMBO/govtool/issues/280)

### Changed
- Update Cardano-Serialization-Lib to 12.0.0-alpha.16 [Issue 156](https://github.com/IntersectMBO/govtool/issues/156)
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function App() {
const timer = setTimeout(() => setIsDrepLoading(false), 1000);

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

const checkTheWalletIsActive = useCallback(() => {
const hrefCondition =
Expand Down
8 changes: 4 additions & 4 deletions govtool/frontend/src/components/atoms/VotingPowerChips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const VotingPowerChips = () => {
alignItems="center"
maxHeight={isMobile ? undefined : 48}
>
{dRep?.isRegistered && (
{dRep?.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) ||
{(dRep?.isRegisteredAsDRep && isDRepVotingPowerLoading) ||
(!dRep?.isRegisteredAsDRep && powerIsLoading) ||
isDrepLoading ? (
<CircularProgress size={20} color="primary" />
) : (
Expand All @@ -67,7 +67,7 @@ export const VotingPowerChips = () => {
sx={{ whiteSpace: "nowrap" }}
>
{" "}
{dRep?.isRegistered
{dRep?.isRegisteredAsDRep
? correctAdaFormat(dRepVotingPower) ?? 0
: correctAdaFormat(votingPower) ?? 0}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const VoteActionForm = ({
/>
</Box>
</Box>
{dRep?.isRegistered && (
{dRep?.isRegisteredAsDRep && (
<Button
data-testid="show-votes-button"
variant="text"
Expand Down
50 changes: 29 additions & 21 deletions govtool/frontend/src/components/organisms/DashboardCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,16 @@ export const DashboardCards = () => {
default:
return t("dashboard.registration.metadataUpdateInProgress");
}
} else if (dRep?.isRegistered || dRep?.wasRegistered) {
} else if (dRep?.isRegisteredAsDRep || dRep?.wasRegisteredAsDRep) {
return t("dashboard.registration.holdersCanDelegate");
} else {
return t("dashboard.registration.ifYouWant");
}
}, [
registerTransaction.transactionHash,
registerTransaction.type,
dRep?.isRegistered,
dRep?.wasRegistered,
dRep?.isRegisteredAsDRep,
dRep?.wasRegisteredAsDRep,
]);

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

const renderGovActionSection = useCallback(() => {
Expand All @@ -274,7 +274,7 @@ export const DashboardCards = () => {
}
firstButtonLabel={t(
`dashboard.govActions.${
dRep?.isRegistered ? "reviewAndVote" : "view"
dRep?.isRegisteredAsDRep ? "reviewAndVote" : "view"
}`
)}
imageURL={IMAGES.govActionListImage}
Expand All @@ -289,7 +289,7 @@ export const DashboardCards = () => {
</Box>
</>
);
}, [screenWidth, isMobile, dRep?.isRegistered]);
}, [screenWidth, isMobile, dRep?.isRegisteredAsDRep]);

return isDrepLoading ? (
<Box
Expand All @@ -306,7 +306,7 @@ export const DashboardCards = () => {
pl={screenWidth < 1024 ? 2 : screenWidth < 1440 ? 4 : 4}
pr={screenWidth < 1024 ? 2 : screenWidth < 1440 ? 8 : 29.5}
>
{dRep?.isRegistered && renderGovActionSection()}
{dRep?.isRegisteredAsDRep && renderGovActionSection()}
<Typography fontSize={16} fontWeight={600} lineHeight={"24px"} my={3}>
{t("dashboard.headingOne")}
</Typography>
Expand Down Expand Up @@ -374,25 +374,27 @@ export const DashboardCards = () => {
<Box width={24} />
<DashboardActionCard
dataTestidFirstButton={
dRep?.isRegistered ? "retire-button" : "register-button"
dRep?.isRegisteredAsDRep ? "retire-button" : "register-button"
}
dataTestidDrepIdBox="my-drep-id"
firstButtonVariant={dRep?.isRegistered ? "outlined" : "contained"}
firstButtonVariant={
dRep?.isRegisteredAsDRep ? "outlined" : "contained"
}
secondButtonVariant={
registerTransaction?.transactionHash
? "outlined"
: dRep?.isRegistered
: dRep?.isRegisteredAsDRep
? "text"
: "outlined"
}
dataTestidSecondButton={
dRep?.isRegistered
dRep?.isRegisteredAsDRep
? "change-metadata-button"
: "register-learn-more-button"
}
description={registrationCardDescription}
firstButtonAction={
dRep?.isRegistered
dRep?.isRegisteredAsDRep
? retireAsDrep
: () => navigateTo(PATHS.registerAsdRep)
}
Expand All @@ -402,7 +404,7 @@ export const DashboardCards = () => {
? ""
: t(
`dashboard.registration.${
dRep?.isRegistered ? "retire" : "register"
dRep?.isRegisteredAsDRep ? "retire" : "register"
}`
)
}
Expand All @@ -411,7 +413,7 @@ export const DashboardCards = () => {
secondButtonAction={
registerTransaction?.transactionHash
? () => openInNewTab("https://adanordic.com/latest_transactions")
: dRep?.isRegistered
: dRep?.isRegisteredAsDRep
? () => {
navigateTo(PATHS.updateMetadata);
}
Expand All @@ -423,18 +425,24 @@ export const DashboardCards = () => {
secondButtonLabel={
registerTransaction?.transactionHash
? t("seeTransaction")
: dRep?.isRegistered
: dRep?.isRegisteredAsDRep
? t("dashboard.registration.changeMetadata")
: t("learnMore")
}
cardId={dRep?.isRegistered || dRep?.wasRegistered ? dRepIDBech32 : ""}
cardId={
dRep?.isRegisteredAsDRep || dRep?.wasRegisteredAsDRep
? dRepIDBech32
: ""
}
cardTitle={
dRep?.isRegistered || dRep?.wasRegistered ? t("myDRepId") : ""
dRep?.isRegisteredAsDRep || dRep?.wasRegisteredAsDRep
? t("myDRepId")
: ""
}
title={registrationCardTitle}
/>
</Box>
{!dRep?.isRegistered && renderGovActionSection()}
{!dRep?.isRegisteredAsDRep && renderGovActionSection()}
</Box>
);
};
2 changes: 1 addition & 1 deletion govtool/frontend/src/components/organisms/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const Drawer = () => {
))}
</Grid>
<Box px={2}>
{dRep?.isRegistered && <DRepInfoCard />}
{dRep?.isRegisteredAsDRep && <DRepInfoCard />}
<Box py={2} />
<WalletInfoCard />
<Box my={1}>
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/context/walletUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const setLimitedRegistrationInterval = (
try {
const data = await getDRepInfo(dRepID);

if (data.isRegistered === desiredResult) {
if (data.isRegisteredAsDRep === desiredResult) {
setDRep(data);
clearInterval(interval);
resolve(desiredResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const useDRepRegisterMutation = () => {

const { mutateAsync, isLoading } = useMutation(postDRepRegister, {
onSuccess: () => {
setDRep({ deposit: 100, isRegistered: true, wasRegistered: false });
setDRep({
deposit: 100,
isRegisteredAsDRep: true,
wasRegisteredAsDRep: false,
});
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export const useDRepRetireMutation = () => {

const { mutateAsync } = useMutation(postDRepRetire, {
onSuccess: () => {
setDRep({ deposit: 100, wasRegistered: true, isRegistered: false });
setDRep({
deposit: 100,
wasRegisteredAsDRep: true,
isRegisteredAsDRep: false,
});
addSuccessAlert("DRep retired.");
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ export const useGetDRepVotingPowerQuery = () => {
const { dRepID, dRep } = useCardano();

const { data, isLoading } = useQuery({
queryKey: [QUERY_KEYS.useGetDRepVotingPowerKey, dRepID, dRep?.isRegistered],
queryKey: [
QUERY_KEYS.useGetDRepVotingPowerKey,
dRepID,
dRep?.isRegisteredAsDRep,
],
queryFn: async () => {
return await getDRepVotingPower({ dRepID });
},
enabled: !!dRepID && dRep?.isRegistered,
enabled: !!dRepID && dRep?.isRegisteredAsDRep,
});

return { dRepVotingPower: data, isDRepVotingPowerLoading: isLoading };
Expand Down
8 changes: 5 additions & 3 deletions govtool/frontend/src/models/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export interface DRepInfo {
isRegistered: boolean;
wasRegistered: boolean;
deposit: number;
isRegisteredAsDRep: boolean;
isRegisteredAsSoleVoter: boolean;
wasRegisteredAsDRep: boolean;
wasRegisteredAsSoleVoter: boolean;
deposit: number | null;
}

export interface DRepData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export const DashboardGovernanceActionsCategory = () => {
.toLowerCase()
.includes(searchText.toLowerCase())
);
}, [proposals, dRep?.isRegistered, searchText, isProposalsFetchingNextPage]);
}, [
proposals,
dRep?.isRegisteredAsDRep,
searchText,
isProposalsFetchingNextPage,
]);

const closeSorts = useCallback(() => {
setSortOpen(false);
Expand Down

0 comments on commit b3fd480

Please sign in to comment.