-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sole Voter transactions added and UI components unification
- Loading branch information
1 parent
1d13549
commit af1d6f1
Showing
21 changed files
with
1,241 additions
and
810 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions
75
govtool/frontend/src/components/molecules/BottomBoxButtons.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,75 @@ | ||
import { useMemo } from "react"; | ||
import { Box } from "@mui/material"; | ||
|
||
import { Button, LoadingButton } from "@atoms"; | ||
import { useScreenDimension, useTranslation } from "@hooks"; | ||
|
||
interface Props { | ||
leftButtonAction: () => void; | ||
rightButtonAction: () => void; | ||
rightButtonIsLoading?: boolean; | ||
leftButtonText?: string; | ||
rightButtonText?: string; | ||
} | ||
|
||
export const BottomBoxButtons = ({ | ||
leftButtonAction, | ||
rightButtonAction, | ||
rightButtonIsLoading, | ||
leftButtonText, | ||
rightButtonText, | ||
}: Props) => { | ||
const { isMobile } = useScreenDimension(); | ||
const { t } = useTranslation(); | ||
|
||
const renderBackButton = useMemo(() => { | ||
return ( | ||
<Button | ||
data-testid={"back-button"} | ||
onClick={leftButtonAction} | ||
size="extraLarge" | ||
sx={{ | ||
px: 6, | ||
width: isMobile ? "100%" : "auto", | ||
}} | ||
variant="outlined" | ||
> | ||
{leftButtonText ?? t("cancel")} | ||
</Button> | ||
); | ||
}, [isMobile]); | ||
|
||
const renderRegisterButton = useMemo(() => { | ||
return ( | ||
<LoadingButton | ||
data-testid={"register-button"} | ||
isLoading={rightButtonIsLoading} | ||
onClick={rightButtonAction} | ||
sx={{ | ||
borderRadius: 50, | ||
textTransform: "none", | ||
px: 6, | ||
width: isMobile ? "100%" : "auto", | ||
height: 48, | ||
fontSize: 16, | ||
}} | ||
variant="contained" | ||
> | ||
{rightButtonText ?? t("continue")} | ||
</LoadingButton> | ||
); | ||
}, [rightButtonIsLoading, isMobile]); | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
flexDirection={isMobile ? "column" : "row"} | ||
justifyContent="space-around" | ||
mt={6} | ||
> | ||
{isMobile ? renderRegisterButton : renderBackButton} | ||
<Box px={2} py={isMobile ? 1.5 : 0} /> | ||
{isMobile ? renderBackButton : renderRegisterButton} | ||
</Box> | ||
); | ||
}; |
108 changes: 108 additions & 0 deletions
108
govtool/frontend/src/components/molecules/CenteredBoxPageWrapper.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,108 @@ | ||
import { FC, PropsWithChildren } from "react"; | ||
import { Box, Link } from "@mui/material"; | ||
|
||
import { Background, Typography } from "@atoms"; | ||
import { ICONS } from "@consts"; | ||
import { DashboardTopNav } from "@organisms"; | ||
import { useScreenDimension } from "@hooks"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { theme } from "@/theme"; | ||
|
||
interface Props { | ||
pageTitle: string; | ||
backButtonText: string; | ||
backButtonPath: string; | ||
isVotingPowerHidden?: boolean; | ||
} | ||
export const CenteredBoxPageWrapper: FC<PropsWithChildren<Props>> = ({ | ||
pageTitle, | ||
backButtonText, | ||
backButtonPath, | ||
isVotingPowerHidden, | ||
children, | ||
}) => { | ||
const { isMobile, screenWidth, pagePadding } = useScreenDimension(); | ||
const navigate = useNavigate(); | ||
const { | ||
palette: { boxShadow2 }, | ||
} = theme; | ||
|
||
return ( | ||
<Background isReverted> | ||
<Box display={"flex"} minHeight={"100vh"} flexDirection="column"> | ||
<DashboardTopNav | ||
imageSRC={ICONS.appLogoIcon} | ||
imageWidth={isMobile ? undefined : 42} | ||
imageHeight={isMobile ? 24 : 35} | ||
title={pageTitle} | ||
isVotingPowerHidden={isVotingPowerHidden} | ||
/> | ||
<Box | ||
display={"flex"} | ||
justifyContent={"center"} | ||
flexDirection={"column"} | ||
mt={isMobile ? 0 : 7} | ||
height={isMobile ? "100%" : "auto"} | ||
sx={{ marginTop: "97px" }} | ||
> | ||
{isMobile && ( | ||
<Box borderBottom={1} borderColor={"#fff"}> | ||
<Typography | ||
variant="body2" | ||
sx={{ | ||
ml: 2, | ||
my: "26px", | ||
fontSize: "24px", | ||
fontWeight: 400, | ||
}} | ||
> | ||
{pageTitle} | ||
</Typography> | ||
</Box> | ||
)} | ||
<Link | ||
data-testid={"back-button"} | ||
sx={{ | ||
cursor: "pointer", | ||
display: "flex", | ||
textDecoration: "none", | ||
my: 3, | ||
marginLeft: isMobile ? 2 : "40px", | ||
}} | ||
onClick={() => navigate(backButtonPath)} | ||
> | ||
<img | ||
src={ICONS.arrowLeftThinIcon} | ||
alt="arrow" | ||
style={{ marginRight: "4px" }} | ||
/> | ||
<Typography | ||
variant="body2" | ||
color="primary" | ||
sx={{ | ||
fontWeight: 400, | ||
paddingTop: "1px", | ||
}} | ||
> | ||
{backButtonText} | ||
</Typography> | ||
</Link> | ||
<Box display={"flex"} justifyContent={"center"}> | ||
<Box | ||
width={screenWidth < 768 ? "auto" : "52vw"} | ||
boxShadow={isMobile ? "" : `2px 2px 20px 0px ${boxShadow2}`} | ||
px={pagePadding} | ||
py={isMobile ? 3 : 8} | ||
borderRadius={"20px"} | ||
height="auto" | ||
> | ||
<Box display="flex" flexDirection="column"> | ||
{children} | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</Background> | ||
); | ||
}; |
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
76 changes: 76 additions & 0 deletions
76
govtool/frontend/src/components/organisms/RegisterAsSoleVoterBox.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,76 @@ | ||
import { useCallback, useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { PATHS } from "@consts"; | ||
import { RegisterAsSoleVoterBoxContent } from "@organisms"; | ||
import { BottomBoxButtons } from "@molecules"; | ||
import { useCardano, useModal } from "@context"; | ||
|
||
export const RegisterAsSoleVoterBox = () => { | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
|
||
const { buildSignSubmitConwayCertTx, buildDRepRegCert } = useCardano(); | ||
const navigate = useNavigate(); | ||
const { openModal, closeModal } = useModal(); | ||
const { t } = useTranslation(); | ||
|
||
const onRegister = useCallback(async () => { | ||
setIsLoading(true); | ||
|
||
try { | ||
const certBuilder = await buildDRepRegCert(); | ||
const result = await buildSignSubmitConwayCertTx({ | ||
certBuilder, | ||
type: "soleVoterRegistration", | ||
registrationType: "registration", | ||
}); | ||
if (result) | ||
openModal({ | ||
type: "statusModal", | ||
state: { | ||
status: "success", | ||
title: t("modals.registration.title"), | ||
message: t("modals.registration.message"), | ||
link: "https://adanordic.com/latest_transactions", | ||
buttonText: t("modals.common.goToDashboard"), | ||
onSubmit: () => { | ||
navigate(PATHS.dashboard); | ||
closeModal(); | ||
}, | ||
dataTestId: "registration-transaction-submitted-modal", | ||
}, | ||
}); | ||
} catch (e: any) { | ||
const errorMessage = e.info ? e.info : e; | ||
|
||
openModal({ | ||
type: "statusModal", | ||
state: { | ||
status: "warning", | ||
title: t("modals.common.oops"), | ||
message: errorMessage, | ||
buttonText: t("modals.common.goToDashboard"), | ||
onSubmit: () => { | ||
navigate(PATHS.dashboard); | ||
closeModal(); | ||
}, | ||
dataTestId: "registration-transaction-error-modal", | ||
}, | ||
}); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, [buildSignSubmitConwayCertTx, buildDRepRegCert, openModal]); | ||
|
||
return ( | ||
<> | ||
<RegisterAsSoleVoterBoxContent /> | ||
<BottomBoxButtons | ||
leftButtonAction={() => navigate(PATHS.dashboard)} | ||
rightButtonAction={onRegister} | ||
rightButtonIsLoading={isLoading} | ||
/> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.