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

feat: proposal lite #966

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#966](https://github.com/alleslabs/celatone-frontend/pull/966) Support lite version for proposal details
- [#951](https://github.com/alleslabs/celatone-frontend/pull/951) Support contract details lite version with LCD endpoint
- [#961](https://github.com/alleslabs/celatone-frontend/pull/961) Add and refactor proposal related lcd endpoints
- [#952](https://github.com/alleslabs/celatone-frontend/pull/952) Support module details page lite version with LCD endpoint
Expand Down
1 change: 1 addition & 0 deletions src/lib/app-provider/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export enum CELATONE_QUERY_KEYS {
// X/GOV
PROPOSAL_DATA = "CELATONE_QUERY_PROPOSAL_DATA",
PROPOSAL_DATA_LCD = "CELATONE_QUERY_PROPOSAL_DATA_LCD",
PROPOSAL_DEPOSITS_LCD = "CELATONE_QUERY_PROPOSAL_DEPOSITS_LCD",
PROPOSAL_VOTES_INFO = "CELATONE_QUERY_PROPOSAL_VOTES_INFO",
PROPOSAL_VOTES = "CELATONE_QUERY_PROPOSAL_VOTES",
PROPOSAL_VALIDATOR_VOTES = "CELATONE_QUERY_PROPOSAL_VALIDATOR_VOTES",
Expand Down
8 changes: 7 additions & 1 deletion src/lib/pages/proposal-details/components/DepositList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ import { Flex } from "@chakra-ui/react";

import { useMobile } from "lib/app-provider";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { Loading } from "lib/components/Loading";
import type { ProposalDeposit } from "lib/types";

import { DepositAmounts } from "./DepositAmounts";

interface DepositListProps {
proposalDeposits: ProposalDeposit[];
isDepositsLoading: boolean;
}

export const DepositList = ({ proposalDeposits }: DepositListProps) => {
export const DepositList = ({
proposalDeposits,
isDepositsLoading,
}: DepositListProps) => {
const isMobile = useMobile();

if (isDepositsLoading) return <Loading />;
return (
<div>
{proposalDeposits.map((deposit, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ import { Flex, Text } from "@chakra-ui/react";

import { TokenImageRender } from "lib/components/token";
import type { TokenWithValue } from "lib/types";
import {
formatTokenWithValue,
formatUTokenWithPrecision,
getTokenLabel,
} from "lib/utils";
import { formatUTokenWithPrecision, getTokenLabel } from "lib/utils";

interface DepositRatioProps {
current: TokenWithValue;
min: TokenWithValue;
isDepositOrVoting: boolean;
isCompact: boolean;
}

export const DepositRatio = ({
current,
min,
isDepositOrVoting,
isCompact,
}: DepositRatioProps) => (
<Flex gap={1} align="center" minW="fit-content">
<Text variant={isCompact ? "body2" : "body1"} alignContent="center">
<Text variant={isCompact ? "body2" : "body1"}>
<span style={{ fontWeight: 500 }}>
{formatUTokenWithPrecision(
current.amount,
Expand All @@ -29,16 +27,26 @@ export const DepositRatio = ({
isCompact ? 2 : undefined
)}
</span>
<span
style={{
color: isCompact
? "var(--chakra-colors-text-main)"
: "var(--chakra-colors-accent-main)",
}}
>
{" / "}
</span>
{formatTokenWithValue(min, isCompact ? 2 : undefined)}
{isDepositOrVoting && (
<>
<span
style={{
color: isCompact
? "var(--chakra-colors-text-main)"
: "var(--chakra-colors-accent-main)",
}}
>
{" / "}
</span>
{formatUTokenWithPrecision(
min.amount,
min.precision ?? 0,
false,
isCompact ? 2 : undefined
)}
</>
)}
{` ${getTokenLabel(min.denom, min.symbol)}`}
</Text>
{!isCompact && (
<TokenImageRender
Expand Down
33 changes: 24 additions & 9 deletions src/lib/pages/proposal-details/components/deposit-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,53 @@ import { ProgressBar } from "./ProgressBar";
interface DepositBarProps {
deposit: ProposalData["totalDeposit"];
minDeposit: TokenWithValue[];
isDepositOrVoting: boolean;
isCompact: boolean;
}

export const DepositBar = ({
deposit,
minDeposit,
isDepositOrVoting,
isCompact,
}: DepositBarProps) => {
const pairDeposit = mapDeposit(deposit, minDeposit);
return (
<Flex direction="column" gap="2px" w="full">
<Flex direction="column" ml={isCompact ? 0 : 2} gap="2px" w="full">
{pairDeposit.map(({ current, min }) => (
<Flex
key={min.denom}
direction={isCompact ? "column" : "row"}
align="center"
w="full"
gap={isCompact ? 0 : 2}
>
<ProgressBar
value={current.amount}
max={min.amount}
isCompact={isCompact}
/>
{isDepositOrVoting && (
<ProgressBar
value={current.amount}
max={min.amount}
isCompact={isCompact}
/>
)}
{isCompact ? (
<Flex align="center" justify="space-between">
<Flex align="center" w="full" justify="space-between">
<Text variant="body2" textColor="text.dark" fontWeight={500}>
Deposited
</Text>
<DepositRatio current={current} min={min} isCompact />
<DepositRatio
current={current}
min={min}
isDepositOrVoting={isDepositOrVoting}
isCompact
/>
</Flex>
) : (
<DepositRatio current={current} min={min} isCompact={false} />
<DepositRatio
current={current}
min={min}
isDepositOrVoting={isDepositOrVoting}
isCompact={false}
/>
)}
</Flex>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import type Big from "big.js";
import Big from "big.js";
import dayjs from "dayjs";

import { StatusSummary } from "../status-summary";
Expand Down Expand Up @@ -51,8 +51,14 @@ const data: Omit<
value: undefined,
},
],
version: "v1",
votingTime: null,
finalTallyResult: {
yes: Big(0),
abstain: Big(0),
no: Big(0),
noWithVeto: Big(0),
totalVotingPower: null,
},
};

const params: ProposalParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ export interface ProposalOverviewProps {
votesInfo: Option<ProposalVotesInfo>;
params: Option<ProposalParams>;
isLoading: boolean;
isDepositsLoading: boolean;
}

export const ProposalOverview = ({
proposalData,
votesInfo,
params,
isLoading,
...props
}: ProposalOverviewProps) => (
<Grid
gridTemplateColumns={{ base: "1fr", xl: "2fr minmax(360px, 1fr)" }}
Expand All @@ -33,24 +32,14 @@ export const ProposalOverview = ({
>
<GridItem>
<Flex direction="column" gap={8}>
<StatusSummary
proposalData={proposalData}
votesInfo={votesInfo}
params={params}
isLoading={isLoading}
/>
<StatusSummary proposalData={proposalData} {...props} />
<ProposalDescription description={proposalData.description} />
<ProposalMetadata metadata={proposalData.metadata} />
<ProposalMessages messages={proposalData.messages} />
</Flex>
</GridItem>
<GridItem>
<ProposalPeriodOverview
proposalData={proposalData}
votesInfo={votesInfo}
params={params}
isLoading={isLoading}
/>
<ProposalPeriodOverview proposalData={proposalData} {...props} />
</GridItem>
</Grid>
);
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const DepositOverviewBody = ({
proposalData,
params,
isLoading,
isDepositsLoading,
}: Omit<ProposalOverviewProps, "votesInfo">) => {
const navigate = useInternalNavigate();

Expand Down Expand Up @@ -45,11 +46,13 @@ const DepositOverviewBody = ({
<DepositBar
deposit={proposalData.totalDeposit}
minDeposit={minDeposit}
isDepositOrVoting
isCompact
/>
)}
<DepositList
proposalDeposits={proposalData.proposalDeposits.slice(0, 5)}
isDepositsLoading={isDepositsLoading}
/>
{proposalData.proposalDeposits.length > 0 && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const StatusSummary = ({
proposalData,
...props
}: ProposalOverviewProps) => {
const isOngoing =
const isDepositOrVoting =
proposalData.status === ProposalStatus.DEPOSIT_PERIOD ||
proposalData.status === ProposalStatus.VOTING_PERIOD;
return (
Expand All @@ -54,9 +54,9 @@ export const StatusSummary = ({
justify="space-between"
>
<Flex align="center" gap={2} whiteSpace="nowrap">
{isOngoing && <ActiveDot />}
{isDepositOrVoting && <ActiveDot />}
<Text variant="body1" textColor="text.main" fontWeight={700}>
{isOngoing ? "Current" : "Final"} proposal result:
{isDepositOrVoting ? "Current" : "Final"} proposal result:
</Text>
<SummaryStatusChip proposalData={proposalData} {...props} />
</Flex>
Expand Down
46 changes: 26 additions & 20 deletions src/lib/pages/proposal-details/components/proposal-top/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex, Heading, Text } from "@chakra-ui/react";

import { useMobile } from "lib/app-provider";
import { useMobile, useTierConfig } from "lib/app-provider";
import { Breadcrumb } from "lib/components/Breadcrumb";
import { DotSeparator } from "lib/components/DotSeparator";
import { Expedited } from "lib/components/Expedited";
Expand All @@ -18,13 +18,14 @@ interface ProposalTopProps {
}

export const ProposalTop = ({ proposalData }: ProposalTopProps) => {
const isFullTier = useTierConfig() === "full";
const isMobile = useMobile();

const isDepositOrVoting =
proposalData.status === ProposalStatus.DEPOSIT_PERIOD ||
proposalData.status === ProposalStatus.VOTING_PERIOD;
return (
<Flex direction="column" mb={6} gap={5}>
<Flex direction="column" gap={5}>
<Breadcrumb
items={[
{
Expand Down Expand Up @@ -114,37 +115,42 @@ export const ProposalTop = ({ proposalData }: ProposalTopProps) => {
</Text>
)}
</Flex>
<Flex>
{proposalData.createdHeight ? (
<Flex
gap={{ base: 0, md: 2 }}
direction={{ base: "column", md: "row" }}
alignItems={{ base: "flex-start", md: "center" }}
>
{proposalData.createdHeight && (
<Flex gap={2} alignItems="center">
<Text color="text.dark" variant="body2" fontWeight={500}>
Created Height:
</Text>
<ExplorerLink
type="block_height"
value={proposalData.createdHeight.toString()}
showCopyOnHover
>
{proposalData.createdHeight.toString()}
</ExplorerLink>
{!isMobile && <DotSeparator />}
</Flex>
)}
<Flex gap={2} alignItems="center">
<Text color="text.dark" variant="body2" fontWeight={500}>
Created Height:
</Text>
<ExplorerLink
type="block_height"
value={proposalData.createdHeight.toString()}
showCopyOnHover
>
{proposalData.createdHeight.toString()}
</ExplorerLink>
{!isMobile && <DotSeparator />}
</Flex>
<Text variant="body2" color="text.dark">
{formatUTC(proposalData.submitTime)}
</Text>
</Flex>
</Flex>
) : (
<Text color="text.dark" variant="body2">
<span style={{ fontWeight: 500 }}>Created Time: </span>
{formatUTC(proposalData.submitTime)}
</Text>
)}
</Flex>
</Flex>
<ViewProposalJson id={proposalData.id} status={proposalData.status} />
</Flex>
<ProposalInfo data={proposalData} />
{(isFullTier || isDepositOrVoting) && (
<ProposalInfo data={proposalData} />
)}
</Flex>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ export const TimeInfoItem = ({ data }: TimeInfoItemProps) => {
<>
<InfoItem label="Deposit Start">
<Text variant="body2" color="text.dark">
{data.submitTime ? `${formatUTC(data.submitTime)}` : "N/A"}
{formatUTC(data.submitTime)}
</Text>
</InfoItem>
<InfoItem label="Deposit End">
<Text variant="body2" color="text.dark">
{data.depositEndTime
? `${formatUTC(data.depositEndTime)}`
: "N/A"}
{formatUTC(data.depositEndTime)}
</Text>
</InfoItem>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ interface ProposalStatusProps {

export const ProposalInfo = ({ data }: ProposalStatusProps) => (
<Flex
background="gray.900"
borderRadius="8px"
direction={{ base: "column", lg: "row" }}
gap={{ base: 3, lg: 8 }}
px={4}
py={3}
gap={{ base: 3, lg: 8 }}
direction={{ base: "column", lg: "row" }}
mb={6}
borderRadius="8px"
background="gray.900"
>
<InfoItem label="Proposal Status">
<Flex minW="110px">
Expand Down
Loading
Loading