-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #785 from alleslabs/feat/cfe-216-vote-details-quorum
feat: quorum information on vote section
- Loading branch information
Showing
10 changed files
with
212 additions
and
35 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
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,45 @@ | ||
import { Flex, Text, type FlexProps, Heading } from "@chakra-ui/react"; | ||
|
||
import { d0Formatter, formatPrettyPercent } from "lib/utils"; | ||
|
||
interface VpPercentCardProps { | ||
name: string; | ||
ratio: Big; | ||
power: Big; | ||
color: FlexProps["bgColor"]; | ||
isCompact: boolean; | ||
} | ||
|
||
export const VpPercentCard = ({ | ||
name, | ||
ratio, | ||
power, | ||
color, | ||
isCompact, | ||
}: VpPercentCardProps) => ( | ||
<Flex | ||
direction={isCompact ? "row-reverse" : "column"} | ||
justifyContent="flex-end" | ||
gap={2} | ||
w="full" | ||
> | ||
<Flex direction="column" gap={isCompact ? 1 : 2} align="start"> | ||
<Text variant="body2" color="text.main"> | ||
{name} | ||
</Text> | ||
<Flex direction={isCompact ? "row" : "column"} gap={isCompact ? 2 : 0}> | ||
<Heading as="h6" variant="h6" fontWeight={600}> | ||
{formatPrettyPercent(ratio.toNumber())} | ||
</Heading> | ||
<Text variant="body2" color="text.dark"> | ||
({d0Formatter(power, "0")}) | ||
</Text> | ||
</Flex> | ||
</Flex> | ||
<Flex | ||
bgColor={color} | ||
borderRadius={10} | ||
{...(isCompact ? { w: 1, h: "full" } : { w: "full", h: 1 })} | ||
/> | ||
</Flex> | ||
); |
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
122 changes: 122 additions & 0 deletions
122
src/lib/pages/proposal-details/components/vote-details/voting-period/VotingQuorum.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,122 @@ | ||
import { Divider, Flex, Heading, Spacer, Text } from "@chakra-ui/react"; | ||
import big from "big.js"; | ||
|
||
import type { VoteDetailsProps } from ".."; | ||
import { ErrorFetchingProposalInfos } from "../../ErrorFetchingProposalInfos"; | ||
import { VoteQuorumBadge } from "../../VoteQuorumBadge"; | ||
import { VoteQuorumCircle } from "../../VoteQuorumCircle"; | ||
import { VoteQuorumText } from "../../VoteQuorumText"; | ||
import { VpPercentCard } from "../../VpPercentCard"; | ||
import { useMobile } from "lib/app-provider"; | ||
import { Loading } from "lib/components/Loading"; | ||
import { | ||
extractParams, | ||
normalizeVotesInfo, | ||
} from "lib/pages/proposal-details/utils"; | ||
|
||
export const VotingQuorum = ({ | ||
proposalData, | ||
params, | ||
votesInfo, | ||
isLoading, | ||
}: VoteDetailsProps) => { | ||
const isMobile = useMobile(); | ||
if (isLoading) return <Loading my={0} />; | ||
if (!params || !votesInfo) return <ErrorFetchingProposalInfos />; | ||
|
||
const { quorum } = extractParams(params, proposalData.isExpedited); | ||
const { abstain, nonAbstainVotes, totalVotes } = | ||
normalizeVotesInfo(votesInfo); | ||
|
||
const votes = votesInfo.yes.add(votesInfo.no).add(votesInfo.noWithVeto); | ||
const allVotes = votes.add(votesInfo.abstain); | ||
|
||
return ( | ||
<Flex direction="column" gap={4}> | ||
<Flex gap={2} align="center"> | ||
{isMobile ? ( | ||
<> | ||
<VoteQuorumBadge | ||
status={proposalData.status} | ||
quorum={quorum} | ||
totalVotes={totalVotes} | ||
isCompact | ||
/> | ||
<Text variant="body1" color="text.main"> | ||
Quorum | ||
</Text> | ||
</> | ||
) : ( | ||
<> | ||
<Heading as="h6" variant="h6" textColor="text.main"> | ||
Vote Participations | ||
</Heading> | ||
<VoteQuorumBadge | ||
status={proposalData.status} | ||
quorum={quorum} | ||
totalVotes={totalVotes} | ||
isCompact={false} | ||
/> | ||
<Spacer /> | ||
<Text variant="body3" textColor="text.dark"> | ||
* Voting power displayed in bracket | ||
</Text> | ||
</> | ||
)} | ||
</Flex> | ||
{isMobile && <Divider borderColor="gray.700" />} | ||
<Flex | ||
direction={{ base: "column", md: "row" }} | ||
gap={{ base: 3, md: 12 }} | ||
align="center" | ||
textAlign={{ base: "center", md: "start" }} | ||
w="full" | ||
> | ||
<VoteQuorumCircle | ||
quorum={quorum} | ||
nonAbstainVotes={nonAbstainVotes} | ||
totalVotes={totalVotes} | ||
isCompact={false} | ||
isBgGray={!isMobile} | ||
/> | ||
<Flex direction="column" gap={4} w="full"> | ||
<VoteQuorumText | ||
status={proposalData.status} | ||
quorum={quorum} | ||
totalVotes={totalVotes} | ||
isCompact={false} | ||
/> | ||
<Flex direction={isMobile ? "column" : "row"} gap={isMobile ? 3 : 8}> | ||
<VpPercentCard | ||
name="Voted" | ||
ratio={nonAbstainVotes} | ||
power={votes} | ||
color="primary.main" | ||
isCompact={isMobile} | ||
/> | ||
<VpPercentCard | ||
name="Voted Abstain" | ||
ratio={abstain} | ||
power={votesInfo.abstain} | ||
color="secondary.main" | ||
isCompact={isMobile} | ||
/> | ||
<Divider | ||
orientation="vertical" | ||
h="auto" | ||
color="gray.700" | ||
display={{ base: "none", lg: "flex" }} | ||
/> | ||
<VpPercentCard | ||
name="Did not vote" | ||
ratio={big(1).minus(totalVotes)} | ||
power={votesInfo.totalVotingPower.minus(allVotes)} | ||
color="gray.800" | ||
isCompact={isMobile} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</Flex> | ||
</Flex> | ||
); | ||
}; |
Oops, something went wrong.