Skip to content

Commit

Permalink
[#80] wrap with useCallback registration card texts
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Feb 7, 2024
1 parent 6d21f03 commit dace096
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions govtool/frontend/src/components/organisms/DashboardCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const DashboardCards = () => {
formHexToBech32,
]);

const getRegistrationCardDescription = () => {
const registrationCardDescription = useMemo(() => {
if (registerTransaction.transactionHash) {
switch (registerTransaction.type) {
case "retirement":
Expand All @@ -228,9 +228,14 @@ export const DashboardCards = () => {
} else {
return t("dashboard.registration.ifYouWant");
}
};
}, [
registerTransaction.transactionHash,
registerTransaction.type,
dRep?.isRegistered,
dRep?.wasRegistered,
]);

const getRegistrationCardTitle = () => {
const registrationCardTitle = useMemo(() => {
if (registerTransaction?.transactionHash) {
switch (registerTransaction.type) {
case "retirement":
Expand All @@ -247,7 +252,12 @@ export const DashboardCards = () => {
} else {
return t("dashboard.registration.registerAsDRep");
}
};
}, [
registerTransaction?.transactionHash,
registerTransaction.type,
dRep?.isRegistered,
dRep?.wasRegistered,
]);

const renderGovActionSection = useCallback(() => {
return (
Expand Down Expand Up @@ -380,7 +390,7 @@ export const DashboardCards = () => {
? "change-metadata-button"
: "register-learn-more-button"
}
description={getRegistrationCardDescription()}
description={registrationCardDescription}
firstButtonAction={
dRep?.isRegistered
? retireAsDrep
Expand Down Expand Up @@ -421,7 +431,7 @@ export const DashboardCards = () => {
cardTitle={
dRep?.isRegistered || dRep?.wasRegistered ? t("myDRepId") : ""
}
title={getRegistrationCardTitle()}
title={registrationCardTitle}
/>
</Box>
{!dRep?.isRegistered && renderGovActionSection()}
Expand Down

0 comments on commit dace096

Please sign in to comment.