-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
196 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
govtool/frontend/src/components/organisms/RegisterAsDRepSteps/WhatRetirementMeans.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
import { Typography } from "@atoms"; | ||
import { useCardano, useModal } from "@context"; | ||
import { useGetVoterInfo, useScreenDimension, useTranslation } from "@hooks"; | ||
|
||
import { BgCard } from ".."; | ||
|
||
export const WhatRetirementMeans = ({ | ||
onClickCancel, | ||
}: { | ||
onClickCancel: () => void; | ||
}) => { | ||
const { | ||
isPendingTransaction, | ||
buildDRepRetirementCert, | ||
buildSignSubmitConwayCertTx, | ||
} = useCardano(); | ||
const { t } = useTranslation(); | ||
const { isMobile } = useScreenDimension(); | ||
const { closeModal, openModal } = useModal(); | ||
const [isRetirementLoading, setIsRetirementLoading] = | ||
useState<boolean>(false); | ||
const { voter } = useGetVoterInfo(); | ||
|
||
const onSubmit = () => { | ||
onClickCancel(); | ||
closeModal(); | ||
}; | ||
|
||
const retireAsDrep = useCallback(async () => { | ||
try { | ||
setIsRetirementLoading(true); | ||
const isPendingTx = isPendingTransaction(); | ||
if (isPendingTx) return; | ||
if (!voter?.deposit) throw new Error(t("errors.appCannotGetDeposit")); | ||
|
||
const certBuilder = await buildDRepRetirementCert( | ||
voter?.deposit.toString(), | ||
); | ||
const result = await buildSignSubmitConwayCertTx({ | ||
certBuilder, | ||
type: "retireAsDrep", | ||
voterDeposit: voter?.deposit.toString(), | ||
}); | ||
if (result) { | ||
openModal({ | ||
type: "statusModal", | ||
state: { | ||
buttonText: t("modals.common.goToDashboard"), | ||
dataTestId: "retirement-transaction-submitted-modal", | ||
link: "https://adanordic.com/latest_transactions", | ||
message: t("modals.retirement.message"), | ||
onSubmit, | ||
status: "success", | ||
title: t("modals.retirement.title"), | ||
}, | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (error: any) { | ||
const errorMessage = error.info ? error.info : error; | ||
|
||
openModal({ | ||
type: "statusModal", | ||
state: { | ||
buttonText: t("modals.common.goToDashboard"), | ||
dataTestId: "retirement-transaction-error-modal", | ||
message: errorMessage, | ||
onSubmit, | ||
status: "warning", | ||
title: t("modals.common.oops"), | ||
}, | ||
}); | ||
} finally { | ||
setIsRetirementLoading(false); | ||
} | ||
}, [ | ||
buildDRepRetirementCert, | ||
buildSignSubmitConwayCertTx, | ||
isPendingTransaction, | ||
openModal, | ||
voter?.deposit, | ||
]); | ||
|
||
return ( | ||
<BgCard | ||
actionButtonLabel={t("retirement.continue")} | ||
backButtonLabel={t("cancel")} | ||
isLoadingActionButton={isRetirementLoading} | ||
onClickActionButton={retireAsDrep} | ||
onClickBackButton={onClickCancel} | ||
sx={{ pb: isMobile ? undefined : 5, pt: isMobile ? 4 : 8 }} | ||
> | ||
<Typography sx={{ textAlign: "center" }} variant="headline4"> | ||
{t("retirement.whatRetirementMeansTitle")} | ||
</Typography> | ||
<Typography | ||
fontWeight={400} | ||
sx={{ | ||
pb: isMobile ? 4 : 6, | ||
pt: 4, | ||
textAlign: "center", | ||
whiteSpace: "pre-line", | ||
}} | ||
variant="body1" | ||
> | ||
{t("retirement.whatRetirementMeansDescription")} | ||
</Typography> | ||
</BgCard> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useEffect } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { Box } from "@mui/material"; | ||
|
||
import { Background } from "@atoms"; | ||
import { PATHS } from "@consts"; | ||
import { DashboardTopNav, WhatRetirementMeans } from "@organisms"; | ||
import { useScreenDimension, useTranslation } from "@hooks"; | ||
import { LinkWithIcon } from "@molecules"; | ||
import { checkIsWalletConnected } from "@utils"; | ||
|
||
export const RetireAsDrep = () => { | ||
const navigate = useNavigate(); | ||
const { t } = useTranslation(); | ||
const { isMobile } = useScreenDimension(); | ||
|
||
useEffect(() => { | ||
if (checkIsWalletConnected()) { | ||
navigate(PATHS.home); | ||
} | ||
}, []); | ||
|
||
const onClickBackToDashboard = () => navigate(PATHS.dashboard); | ||
|
||
return ( | ||
<Background isReverted> | ||
<Box | ||
sx={{ display: "flex", flexDirection: "column", minHeight: "100vh" }} | ||
> | ||
<DashboardTopNav title={t("retirement.retireAsDrep")} /> | ||
<LinkWithIcon | ||
label={t("backToDashboard")} | ||
onClick={onClickBackToDashboard} | ||
sx={{ | ||
mb: isMobile ? 0 : 1.5, | ||
ml: isMobile ? 2 : 5, | ||
mt: isMobile ? 3 : 1.5, | ||
}} | ||
/> | ||
<WhatRetirementMeans onClickCancel={onClickBackToDashboard} /> | ||
</Box> | ||
</Background> | ||
); | ||
}; |
Oops, something went wrong.