From 95fd308e7448bf14a1789220b29b2b8c1d6dcf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Sworze=C5=84?= Date: Wed, 24 Apr 2024 11:50:58 +0200 Subject: [PATCH] fix loaders --- .../components/organisms/DashboardCards.tsx | 74 +++--- .../src/components/organisms/Footer.tsx | 3 - .../DashboardGovernanceActionsCategory.tsx | 213 +++++++++--------- .../frontend/src/pages/GovernanceActions.tsx | 59 +++-- .../src/pages/GovernanceActionsCategory.tsx | 18 +- .../src/pages/RegisterAsSoleVoter.tsx | 144 ++++++++++-- .../frontend/src/pages/RetireAsSoleVoter.tsx | 137 +++++++++-- 7 files changed, 456 insertions(+), 192 deletions(-) diff --git a/govtool/frontend/src/components/organisms/DashboardCards.tsx b/govtool/frontend/src/components/organisms/DashboardCards.tsx index dcb2d48cc..779cb2276 100644 --- a/govtool/frontend/src/components/organisms/DashboardCards.tsx +++ b/govtool/frontend/src/components/organisms/DashboardCards.tsx @@ -42,46 +42,48 @@ export const DashboardCards = () => { } return ( - = 1728 - ? "repeat(3, minmax(300px, 570px))" - : "repeat(2, minmax(300px, 530px))", - justifyContent: screenWidth < 1024 ? "center" : "flex-start", - px: screenWidth < 640 ? 2 : 5, - py: 3, - rowGap: 3, - }} - > - + + = 1728 + ? "repeat(3, minmax(300px, 570px))" + : "repeat(2, minmax(300px, 530px))", + justifyContent: screenWidth < 1024 ? "center" : "flex-start", + px: screenWidth < 640 ? 2 : 5, + py: 3, + rowGap: 3, + }} + > + - + - + - + - + + ); }; diff --git a/govtool/frontend/src/components/organisms/Footer.tsx b/govtool/frontend/src/components/organisms/Footer.tsx index 086fea35d..cfc2e5862 100644 --- a/govtool/frontend/src/components/organisms/Footer.tsx +++ b/govtool/frontend/src/components/organisms/Footer.tsx @@ -47,9 +47,6 @@ export const Footer = () => { return ( <> - {/* TODO: That box below should not be needed. - Footer should be aligned under shared Layout component */} - { return ( - - - navigate(PATHS.dashboardGovernanceActions)} - > - arrow - - {t("govActions.backToGovActions")} - - - - - {getProposalTypeLabel(category ?? "")} - - {!mappedData || isEnableLoading || isProposalsLoading ? ( - - + navigate(PATHS.dashboardGovernanceActions)} + > + arrow + + {t("govActions.backToGovActions")} + + + + + {getProposalTypeLabel(category ?? "")} + + {!mappedData || isEnableLoading || isProposalsLoading ? ( + + + + ) : !mappedData?.length ? ( + + ) : ( + + {mappedData.map((item) => ( + + { + saveScrollPosition(); + + if ( + pendingTransaction.vote?.resourceId === + item.txHash + item.index + ) { + openInNewTab( + `https://sancho.cexplorer.io/tx/${pendingTransaction.vote.transactionHash}`, + ); + } else { + navigate( + generatePath(PATHS.dashboardGovernanceActionsAction, { + proposalId: getFullGovActionId( + item.txHash, + item.index, + ), + }), + { + state: { + ...item, + openedFromCategoryPage: true, + }, + }, + ); + } + }} + txHash={item.txHash} + /> - ) : !mappedData?.length ? ( - - ) : ( + ))} + {proposalsHaveNextPage && isProposalsFetchingNextPage && ( - {mappedData.map((item) => ( - - { - saveScrollPosition(); - - if ( - pendingTransaction.vote?.resourceId === - item.txHash + item.index - ) { - openInNewTab( - `https://sancho.cexplorer.io/tx/${pendingTransaction.vote.transactionHash}`, - ); - } else { - navigate( - generatePath( - PATHS.dashboardGovernanceActionsAction, - { - proposalId: getFullGovActionId( - item.txHash, - item.index, - ), - }, - ), - { - state: { - ...item, - openedFromCategoryPage: true, - }, - }, - ); - } - }} - txHash={item.txHash} - /> - - ))} - {proposalsHaveNextPage && isProposalsFetchingNextPage && ( - - - - )} + )} - + )} ); diff --git a/govtool/frontend/src/pages/GovernanceActions.tsx b/govtool/frontend/src/pages/GovernanceActions.tsx index 69375331b..95a6f114a 100644 --- a/govtool/frontend/src/pages/GovernanceActions.tsx +++ b/govtool/frontend/src/pages/GovernanceActions.tsx @@ -49,13 +49,23 @@ export const GovernanceActions = () => { - + { }} /> )} - + - + {!proposals || isProposalsLoading ? ( ) : ( - + <> + + + )} diff --git a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx index b849b46d2..b78b013cd 100644 --- a/govtool/frontend/src/pages/GovernanceActionsCategory.tsx +++ b/govtool/frontend/src/pages/GovernanceActionsCategory.tsx @@ -83,8 +83,14 @@ export const GovernanceActionsCategory = () => { minHeight="100vh" > - - + + { ) ) : ( - + )} diff --git a/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx b/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx index 822d809ce..ad387b4da 100644 --- a/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx +++ b/govtool/frontend/src/pages/RegisterAsSoleVoter.tsx @@ -1,15 +1,89 @@ -import { useEffect } from "react"; +import { useCallback, useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; +import { Trans } from "react-i18next"; +import { Box, Link } from "@mui/material"; +import { Background, Typography } from "@atoms"; import { PATHS } from "@consts"; -import { RegisterAsSoleVoterBox } from "@organisms"; -import { useTranslation } from "@hooks"; -import { CenteredBoxPageWrapper } from "@molecules"; -import { checkIsWalletConnected } from "@/utils"; +import { useCardano, useModal } from "@context"; +import { + useGetVoterInfo, + useScreenDimension, + useTranslation, + useWalletErrorModal, +} from "@hooks"; +import { LinkWithIcon } from "@molecules"; +import { BgCard, DashboardTopNav, Footer } from "@organisms"; +import { + PROTOCOL_PARAMS_KEY, + checkIsWalletConnected, + correctAdaFormat, + getItemFromLocalStorage, + openInNewTab, +} from "@utils"; export const RegisterAsSoleVoter = () => { + const epochParams = getItemFromLocalStorage(PROTOCOL_PARAMS_KEY); const navigate = useNavigate(); + const [isLoading, setIsLoading] = useState(false); const { t } = useTranslation(); + const { isMobile } = useScreenDimension(); + const { voter } = useGetVoterInfo(); + const openWalletErrorModal = useWalletErrorModal(); + const { buildSignSubmitConwayCertTx, buildDRepRegCert, buildDRepUpdateCert } = + useCardano(); + const { openModal, closeModal } = useModal(); + + const onRegister = useCallback(async () => { + setIsLoading(true); + + try { + const certBuilder = voter?.isRegisteredAsDRep + ? await buildDRepUpdateCert() + : await buildDRepRegCert(); + const result = await buildSignSubmitConwayCertTx({ + certBuilder, + type: "registerAsSoleVoter", + }); + if (result) { + openModal({ + type: "statusModal", + state: { + status: "success", + title: t("modals.registration.title"), + message: t("modals.registration.message"), + link: `https://sancho.cexplorer.io/tx/${result}`, + buttonText: t("modals.common.goToDashboard"), + onSubmit: () => { + navigate(PATHS.dashboard); + closeModal(); + }, + dataTestId: "registration-transaction-submitted-modal", + }, + }); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (error: any) { + openWalletErrorModal({ + error, + buttonText: t("modals.common.goToDashboard"), + onSumbit: () => navigate(PATHS.dashboard), + dataTestId: "registration-transaction-error-modal", + }); + } finally { + setIsLoading(false); + } + }, [ + buildSignSubmitConwayCertTx, + buildDRepRegCert, + openModal, + voter?.isRegisteredAsDRep, + ]); + + const navigateToDashboard = useCallback( + () => navigate(PATHS.dashboard), + [navigate], + ); useEffect(() => { if (checkIsWalletConnected()) { @@ -18,13 +92,57 @@ export const RegisterAsSoleVoter = () => { }, []); return ( - - - + + + + + + + {t("soleVoter.registerHeading")} + + + openInNewTab("https://sancho.network/")} + sx={{ cursor: "pointer" }} + key="0" + />, + ]} + /> + + +