-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tsx
170 lines (154 loc) · 5.65 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import React from "react";
import { Box, Stack, Tooltip, Typography, useTheme } from "@mui/material";
import { useTranslation } from "react-i18next";
import { t } from "i18next";
import { VotesAbstainIcon, VotesNoIcon, VotesNoneIcon, VotesYesIcon, multiYesIcon } from "src/commons/resources";
import { ChipContainer } from "src/pages/NativeScriptsAndSC/Card";
import { POOLS_ACTION_TYPE, STATUS_VOTE } from "src/commons/utils/constants";
import { GovernanceVote } from "src/components/GovernanceVotes";
import { CardGovernanceVote, StatusContainer, TitleCard } from "./styles";
interface ICardGovernanceVotes {
data: GovernanceVote;
}
export const actionTypeListDrep = [
{ value: POOLS_ACTION_TYPE.ALL, text: t("pool.any") },
{ value: POOLS_ACTION_TYPE.NO_CONFIDENCE, text: t("pool.typeMotion") },
{ value: POOLS_ACTION_TYPE.UPDATE_COMMITTEE, text: t("pool.typeConstitutional") },
{ value: POOLS_ACTION_TYPE.NEW_CONSTITUTION, text: t("drep.updateConstitution") },
{ value: POOLS_ACTION_TYPE.HARD_FORK_INITIATION_ACTION, text: t("pool.typeHardFork") },
{ value: POOLS_ACTION_TYPE.PARAMETER_CHANGE_ACTION, text: t("drep.protocolChange") },
{ value: POOLS_ACTION_TYPE.TREASURY_WITHDRAWALS_ACTION, text: t("drep.treasuryWithdrawals") },
{ value: POOLS_ACTION_TYPE.INFO_ACTION, text: t("pool.typeInfo") }
];
const CardGovernanceVotes: React.FC<ICardGovernanceVotes> = ({ data }) => {
const { status, txHash, type, vote, votingPower, index, isRepeatVote } = data;
const theme = useTheme();
const { t } = useTranslation();
return (
<CardGovernanceVote>
<Box p={2}>
<Box display="flex" justifyContent="space-between" width="100%">
<Box maxWidth="400px" flex={1}>
<Tooltip title={txHash} placement="top" arrow>
<TitleCard>
{actionTypeListDrep.find((action) => action.value === type)?.text} #{index}
</TitleCard>
</Tooltip>
</Box>
<>
<VoteStatus status={vote} isRepeatVote={isRepeatVote} />
</>
</Box>
<Stack paddingTop="24px" spacing={"14px"}>
<Box display="flex" alignItems="center" flexWrap={"wrap"}>
<Typography
fontWeight={600}
fontSize="16px"
lineHeight="18.75px"
color={theme.palette.secondary.light}
paddingRight="8px"
>
{t("pool.actionType")}:
</Typography>
<Typography fontWeight={400} fontSize="16px" lineHeight="18.75px" color={theme.palette.secondary.light}>
{actionTypeListDrep.find((action) => action.value === type)?.text}
</Typography>
</Box>
<Box display="flex" alignItems="center" flexWrap="wrap">
<Typography
fontWeight={600}
fontSize="16px"
lineHeight="18.75px"
color={theme.palette.secondary.light}
paddingRight="8px"
>
{t("pool.status")}:
</Typography>
<GovernanceStatus status={status} />
</Box>
<Box display="flex" alignItems="center" flexWrap="wrap">
<Typography
fontWeight={600}
fontSize="16px"
lineHeight="18.75px"
color={theme.palette.secondary.light}
paddingRight="8px"
>
{t("pool.votingPower")}:
</Typography>
<Typography fontWeight={400} fontSize="16px" lineHeight="18.75px" color={theme.palette.secondary.light}>
{votingPower ? `${votingPower} ADA` : "N/A"}
</Typography>
</Box>
</Stack>
</Box>
</CardGovernanceVote>
);
};
export default CardGovernanceVotes;
export const VoteStatus: React.FC<{ status: string; isRepeatVote?: boolean }> = ({ status, isRepeatVote = false }) => {
const { t } = useTranslation();
const renderStatus = (key: string) => {
switch (key) {
case STATUS_VOTE.YES:
if (isRepeatVote) {
return [multiYesIcon, "success"];
} else {
return [VotesYesIcon, "success"];
}
case STATUS_VOTE.NO:
return [VotesNoIcon, "error"];
case STATUS_VOTE.ABSTAIN:
return [VotesAbstainIcon, "warning"];
default:
return [VotesNoneIcon, "info"];
}
};
const typeStatus = renderStatus(status);
return (
<ChipContainer
Icon={typeStatus[0]}
message={
<Box component={Typography} textTransform="uppercase" fontSize="12px" fontWeight={500}>
{status ? status : t("pool.none")}
</Box>
}
variant={typeStatus[1] as "success" | "warning" | "info" | "error"}
/>
);
};
export const GovernanceStatus: React.FC<{ status: string | null }> = ({ status }) => {
const theme = useTheme();
const { t } = useTranslation();
const renderStatus = (key: string) => {
switch (key) {
case STATUS_VOTE.RATIFIED:
return "success";
case STATUS_VOTE.OPEN_BALLOT:
return "warning";
case STATUS_VOTE.ENACTED:
return "info";
default:
return "info";
}
};
const typeStatus = renderStatus(status || "");
return (
<StatusContainer>
<ChipContainer
message={
<Typography
textTransform="uppercase"
fontWeight={500}
fontSize="12px"
lineHeight="23px"
color={theme.palette.secondary.light}
>
{status === STATUS_VOTE.OPEN_BALLOT ? t("pool.open") : !status ? t("common.N/A") : status}
</Typography>
}
variant={typeStatus as "success" | "warning" | "info" | "error"}
/>
</StatusContainer>
);
};