Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/669-update-delegate-card #671

Merged
merged 5 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 101 additions & 71 deletions govtool/frontend/src/components/molecules/AutomatedVotingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { Box, Divider } from "@mui/material";

import { Button, Typography } from "@atoms";
import { Button, LoadingButton, Typography } from "@atoms";
import { primaryBlue } from "@consts";
import { useModal } from "@context";
import { useScreenDimension, useTranslation } from "@hooks";
import { AutomatedVotingCardProps } from "./types";
import { openInNewTab } from "@utils";

import { Card } from "./Card";
import { primaryBlue } from "@/consts";
import { useModal } from "@/context";
import { AutomatedVotingCardProps } from "./types";

export const AutomatedVotingCard = ({
description,
inProgress,
isConnected,
isDelegateLoading,
isSelected,
onClickDelegate,
onClickInfo,
title,
votingPower,
transactionId,
}: AutomatedVotingCardProps) => {
const { isMobile, screenWidth } = useScreenDimension();
const { openModal } = useModal();
const { t } = useTranslation();

const onClickShowTransaction = () =>
openInNewTab(`https://sancho.cexplorer.io/tx/${transactionId}`);

return (
<Card
{...(inProgress && {
Expand All @@ -37,7 +44,7 @@ export const AutomatedVotingCard = ({
boxShadow: `0px 4px 15px 0px ${primaryBlue.c100}`,
display: "flex",
flex: 1,
flexDirection: screenWidth < 1440 ? "column" : "row",
flexDirection: screenWidth < 1024 ? "column" : "row",
justifyContent: "space-between",
mt: inProgress || isSelected ? 2 : 0,
py: 2.25,
Expand All @@ -46,83 +53,106 @@ export const AutomatedVotingCard = ({
<Box
sx={{
flex: 1,
mb: screenWidth < 1440 ? 1.5 : 0,
width: screenWidth < 1440 ? "100%" : "auto",
mb: screenWidth < 1024 ? 1.5 : 0,
width: screenWidth < 1024 ? "100%" : "auto",
}}
>
<Typography>{title}</Typography>
<Typography fontWeight={400} sx={{ mt: 0.5 }} variant="body2">
<Typography
fontWeight={400}
sx={{
mt: 0.5,
color: screenWidth < 1024 ? "neutralGray" : "textBlack",
width: screenWidth < 1024 ? "auto" : "60%",
}}
variant="body2"
>
{description}
</Typography>
{transactionId && (
<Button
onClick={onClickShowTransaction}
sx={{ width: "fit-content", p: 0 }}
variant="text"
>
{t("dashboard.cards.showTransaction")}
</Button>
)}
</Box>
<Divider
flexItem
orientation={screenWidth < 1440 ? "horizontal" : "vertical"}
sx={{ ml: screenWidth < 1440 ? 0 : 1 }}
variant={screenWidth < 1440 ? "fullWidth" : "middle"}
/>
<Box
sx={{
alignContent: "flex-start",
display: "flex",
flexDirection: "column",
px: screenWidth < 1440 ? 0 : 4.25,
py: screenWidth < 1440 ? 1 : 0,
width: screenWidth < 1440 ? "100%" : "auto",
}}
>
<Typography color="neutralGray" fontWeight={500} variant="caption">
{t("dRepDirectory.votingPower")}
</Typography>
<Typography sx={{ display: "flex", flexDirection: "row", mt: 0.5 }}>
{'₳ '}
{votingPower}
</Typography>
</Box>
<Divider
flexItem
orientation={screenWidth < 1440 ? "horizontal" : "vertical"}
sx={{ mr: screenWidth < 1440 ? 0 : 1 }}
variant={screenWidth < 1440 ? "fullWidth" : "middle"}
/>
<Box
sx={{
display: "flex",
flexDirection: "row",
gap: 2.5,
mt: screenWidth < 1440 ? 3 : 0,
width: screenWidth < 1440 ? "100%" : "auto",
}}
>
<Button
// TODO handle button click
onClick={onClickInfo}
size={isMobile ? "medium" : "large"}
sx={{ flex: screenWidth < 768 ? 1 : undefined }}
variant="outlined"
>
{t("info")}
</Button>
{!isConnected
? (
{!inProgress && !isSelected && (
<>
<Divider
flexItem
orientation={screenWidth < 1024 ? "horizontal" : "vertical"}
sx={{ ml: screenWidth < 1024 ? 0 : 1 }}
variant={screenWidth < 1024 ? "fullWidth" : "middle"}
/>
<Box
sx={{
alignContent: "flex-start",
display: "flex",
flexDirection: "column",
px: screenWidth < 1024 ? 0 : 4.25,
py: screenWidth < 1024 ? 1 : 0,
width: screenWidth < 1024 ? "100%" : "auto",
}}
>
<Typography color="neutralGray" fontWeight={500} variant="caption">
{t("dRepDirectory.votingPower")}
</Typography>
<Typography sx={{ display: "flex", flexDirection: "row", mt: 0.5 }}>
{"₳ "}
{votingPower}
</Typography>
</Box>
<Divider
flexItem
orientation={screenWidth < 1024 ? "horizontal" : "vertical"}
sx={{ mr: screenWidth < 1024 ? 0 : 1 }}
variant={screenWidth < 1024 ? "fullWidth" : "middle"}
/>
<Box
sx={{
display: "flex",
flexDirection: "row",
gap: 2.5,
mt: screenWidth < 1024 ? 3 : 0,
width: screenWidth < 1024 ? "100%" : "auto",
}}
>
<Button
onClick={() => openModal({ type: "chooseWallet" })}
// TODO handle button click
onClick={onClickInfo}
size={isMobile ? "medium" : "large"}
sx={{ flex: screenWidth < 768 ? 1 : undefined }}
variant="outlined"
>
{t("connectToDelegate")}
{t("info")}
</Button>
)
: !isSelected && (
<Button
onClick={onClickDelegate}
size={isMobile ? "medium" : "large"}
sx={{ flex: screenWidth < 768 ? 1 : undefined }}
>
{t("delegate")}
</Button>
)}
</Box>
{!isConnected ? (
<Button
onClick={() => openModal({ type: "chooseWallet" })}
size={isMobile ? "medium" : "large"}
sx={{ flex: screenWidth < 768 ? 1 : undefined }}
>
{t("connectToDelegate")}
</Button>
) : (
!isSelected && (
<LoadingButton
isLoading={isDelegateLoading}
onClick={onClickDelegate}
size={isMobile ? "medium" : "large"}
sx={{ flex: screenWidth < 768 ? 1 : undefined }}
variant="contained"
>
{t("delegate")}
</LoadingButton>
)
)}
</Box>
</>
)}
</Card>
);
};
26 changes: 15 additions & 11 deletions govtool/frontend/src/components/molecules/DashboardActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { FC, ReactNode } from "react";

import { Button, LoadingButton, LoadingButtonProps, Typography } from "@atoms";
import { useScreenDimension, useTranslation } from "@hooks";
import { openInNewTab } from "@utils";

import { Card } from "./Card";
import { openInNewTab } from "@/utils";

export type DashboardActionCardProps = {
buttons?: LoadingButtonProps[];
Expand All @@ -17,6 +18,7 @@ export type DashboardActionCardProps = {
state?: "active" | "inProgress" | "default";
title?: ReactNode;
transactionId?: string;
isSpaceBetweenButtons?: boolean;
};

export const DashboardActionCard: FC<DashboardActionCardProps> = ({
Expand All @@ -33,6 +35,7 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
state = "default",
title,
transactionId,
isSpaceBetweenButtons,
} = props;

const { screenWidth } = useScreenDimension();
Expand Down Expand Up @@ -103,20 +106,21 @@ export const DashboardActionCard: FC<DashboardActionCardProps> = ({
)}
</Typography>
) : null}
{children}
{transactionId && (
<Button
onClick={onClickShowTransaction}
sx={{ width: "fit-content", p: 0 }}
variant="text"
>
{t("dashboard.cards.showTransaction")}
</Button>
)}
</Box>
{children}
{transactionId && (
<Button
onClick={onClickShowTransaction}
sx={{ width: "fit-content", p: 0 }}
variant="text"
>
{t("dashboard.cards.showTransaction")}
</Button>
)}
<Box
display="flex"
flexDirection={screenWidth < 640 ? "column" : "row"}
justifyContent={isSpaceBetweenButtons ? "space-between" : undefined}
mt={3}
gap={2}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTranslation } from "@hooks";
import { Card } from "./Card";
import { SoleVoterActionProps } from "./types";

export const SoleVoterAction = ({
export const DelegationAction = ({
dRepId,
onClickArrow,
sx,
Expand Down
6 changes: 3 additions & 3 deletions govtool/frontend/src/components/molecules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./DataActionsBar";
export * from "./DataActionsFilters";
export * from "./DataActionsSorting";
export * from "./DataMissingInfoBox";
export * from "./DelegationAction";
export * from "./DRepInfoCard";
export * from "./EmptyStateGovernanceActionsCategory";
export * from "./Field";
Expand All @@ -27,13 +28,12 @@ export * from "./GovernanceActionsDatesBox";
export * from "./GovernanceVotedOnCard";
export * from "./LinkWithIcon";
export * from "./OrderActionsChip";
export * from "./PageTitle";
export * from "./Share";
export * from "./Share";
export * from "./SliderArrow";
export * from "./SliderArrows";
export * from "./SoleVoterAction";
export * from "./Step";
export * from "./PageTitle";
export * from "./Share";
export * from "./VoteActionForm";
export * from "./VotesSubmitted";
export * from "./WalletInfoCard";
Expand Down
2 changes: 2 additions & 0 deletions govtool/frontend/src/components/molecules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ export type AutomatedVotingCardProps = {
onClickInfo: () => void;
title: string;
votingPower: string | number;
isDelegateLoading?: boolean;
transactionId?: string;
};
Loading
Loading