From dace09651e6b41bc2080c22b4edec221005b41cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sza=C5=82owski?= Date: Wed, 7 Feb 2024 10:29:13 +0100 Subject: [PATCH] [#80] wrap with useCallback registration card texts --- .../components/organisms/DashboardCards.tsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/govtool/frontend/src/components/organisms/DashboardCards.tsx b/govtool/frontend/src/components/organisms/DashboardCards.tsx index 8eb669fd5..2d91be87c 100644 --- a/govtool/frontend/src/components/organisms/DashboardCards.tsx +++ b/govtool/frontend/src/components/organisms/DashboardCards.tsx @@ -213,7 +213,7 @@ export const DashboardCards = () => { formHexToBech32, ]); - const getRegistrationCardDescription = () => { + const registrationCardDescription = useMemo(() => { if (registerTransaction.transactionHash) { switch (registerTransaction.type) { case "retirement": @@ -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": @@ -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 ( @@ -380,7 +390,7 @@ export const DashboardCards = () => { ? "change-metadata-button" : "register-learn-more-button" } - description={getRegistrationCardDescription()} + description={registrationCardDescription} firstButtonAction={ dRep?.isRegistered ? retireAsDrep @@ -421,7 +431,7 @@ export const DashboardCards = () => { cardTitle={ dRep?.isRegistered || dRep?.wasRegistered ? t("myDRepId") : "" } - title={getRegistrationCardTitle()} + title={registrationCardTitle} /> {!dRep?.isRegistered && renderGovActionSection()}