|
| 1 | +import { Box } from "@mui/material"; |
| 2 | +import { useTranslation } from "react-i18next"; |
| 3 | +import { useNavigate } from "react-router-dom"; |
| 4 | + |
| 5 | +import I18n from "@/i18n"; |
| 6 | +import { BUDGET_DISCUSSION_PATHS, PATHS, PDF_PATHS } from "@/consts"; |
| 7 | +import { useCardano, useModal } from "@/context"; |
| 8 | + |
| 9 | +import { Typography, Button } from "../../atoms"; |
| 10 | +import { HomeCard } from "../../molecules/HomeCard"; |
| 11 | + |
| 12 | +const isProposalDiscussionForumEnabled = JSON.parse( |
| 13 | + import.meta.env.VITE_IS_PROPOSAL_DISCUSSION_FORUM_ENABLED, |
| 14 | +); |
| 15 | + |
| 16 | +const CONNECT_WALLET_TO_CARDS = [ |
| 17 | + ...(isProposalDiscussionForumEnabled |
| 18 | + ? [ |
| 19 | + { |
| 20 | + title: I18n.t( |
| 21 | + "home.connectWalletTo.cards.discussBudgetProposals.title", |
| 22 | + ), |
| 23 | + description: I18n.t( |
| 24 | + "home.connectWalletTo.cards.discussBudgetProposals.description", |
| 25 | + ), |
| 26 | + path: BUDGET_DISCUSSION_PATHS.budgetDiscussion, |
| 27 | + }, |
| 28 | + { |
| 29 | + title: I18n.t( |
| 30 | + "home.connectWalletTo.cards.createBudgetProposal.title", |
| 31 | + ), |
| 32 | + description: I18n.t( |
| 33 | + "home.connectWalletTo.cards.createBudgetProposal.description", |
| 34 | + ), |
| 35 | + path: BUDGET_DISCUSSION_PATHS.budgetDiscussion, |
| 36 | + }, |
| 37 | + { |
| 38 | + title: I18n.t( |
| 39 | + "home.connectWalletTo.cards.discussGovernanceActions.title", |
| 40 | + ), |
| 41 | + description: I18n.t( |
| 42 | + "home.connectWalletTo.cards.discussGovernanceActions.description", |
| 43 | + ), |
| 44 | + path: PDF_PATHS.proposalDiscussion, |
| 45 | + }, |
| 46 | + { |
| 47 | + title: I18n.t( |
| 48 | + "home.connectWalletTo.cards.proposeGovernanceAction.title", |
| 49 | + ), |
| 50 | + description: I18n.t( |
| 51 | + "home.connectWalletTo.cards.proposeGovernanceAction.description", |
| 52 | + ), |
| 53 | + path: PDF_PATHS.proposalDiscussionPropose, |
| 54 | + }, |
| 55 | + ] |
| 56 | + : []), |
| 57 | + { |
| 58 | + title: I18n.t("home.connectWalletTo.cards.registerToVote.title"), |
| 59 | + description: I18n.t( |
| 60 | + "home.connectWalletTo.cards.registerToVote.description", |
| 61 | + ), |
| 62 | + path: PATHS.registerAsDirectVoter, |
| 63 | + }, |
| 64 | + { |
| 65 | + title: I18n.t("home.connectWalletTo.cards.delegateVote.title"), |
| 66 | + description: I18n.t("home.connectWalletTo.cards.delegateVote.description"), |
| 67 | + path: PATHS.dRepDirectory, |
| 68 | + }, |
| 69 | + { |
| 70 | + title: I18n.t("home.connectWalletTo.cards.becomeDRep.title"), |
| 71 | + description: I18n.t("home.connectWalletTo.cards.becomeDRep.description"), |
| 72 | + path: PATHS.registerAsdRep, |
| 73 | + }, |
| 74 | + { |
| 75 | + title: I18n.t("home.connectWalletTo.cards.voteOnGovernanceActions.title"), |
| 76 | + description: I18n.t( |
| 77 | + "home.connectWalletTo.cards.voteOnGovernanceActions.description", |
| 78 | + ), |
| 79 | + path: PATHS.dashboardGovernanceActions, |
| 80 | + }, |
| 81 | +]; |
| 82 | + |
| 83 | +export const ConnectWalletTo = () => { |
| 84 | + const { t } = useTranslation(); |
| 85 | + const { openModal } = useModal(); |
| 86 | + const { isEnabled, stakeKey } = useCardano(); |
| 87 | + const navigate = useNavigate(); |
| 88 | + |
| 89 | + const handleCardClick = ({ path }: { path?: string }) => { |
| 90 | + if (!path) return; |
| 91 | + openModal({ |
| 92 | + type: "chooseWallet", |
| 93 | + state: { |
| 94 | + pathToNavigate: path, |
| 95 | + }, |
| 96 | + }); |
| 97 | + }; |
| 98 | + |
| 99 | + const onClickConnectButton = () => { |
| 100 | + if (isEnabled && stakeKey) { |
| 101 | + navigate(PATHS.dashboard); |
| 102 | + } |
| 103 | + openModal({ type: "chooseWallet" }); |
| 104 | + }; |
| 105 | + |
| 106 | + return ( |
| 107 | + <Box my={4} component="section" data-testid="connect-wallet-to-section"> |
| 108 | + <Box display="flex" justifyContent="space-between" alignItems="center"> |
| 109 | + <Typography variant="title2"> |
| 110 | + {t("home.connectWalletTo.section.title")} |
| 111 | + </Typography> |
| 112 | + <Button |
| 113 | + data-testid="connect-wallet-button" |
| 114 | + onClick={onClickConnectButton} |
| 115 | + size="extraLarge" |
| 116 | + variant="contained" |
| 117 | + > |
| 118 | + {t("wallet.connectWallet")} |
| 119 | + </Button> |
| 120 | + </Box> |
| 121 | + <Box |
| 122 | + display="grid" |
| 123 | + gridTemplateColumns={{ |
| 124 | + xxs: "repeat(1, 1fr)", |
| 125 | + sm: "repeat(2, 1fr)", |
| 126 | + lg: "repeat(3, 1fr)", |
| 127 | + }} |
| 128 | + gap={4} |
| 129 | + mt={4} |
| 130 | + > |
| 131 | + {CONNECT_WALLET_TO_CARDS.map(({ title, description, path }) => ( |
| 132 | + <HomeCard |
| 133 | + key={title} |
| 134 | + title={title} |
| 135 | + description={description} |
| 136 | + onCardClick={path ? () => handleCardClick({ path }) : undefined} |
| 137 | + /> |
| 138 | + ))} |
| 139 | + </Box> |
| 140 | + </Box> |
| 141 | + ); |
| 142 | +}; |
0 commit comments