From 948fb4923a19fe0ec0867bbff6491265d4cc3960 Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:29:45 +0700 Subject: [PATCH 1/3] feat: disable voting tally --- CHANGELOG.md | 2 +- src/config/chain/initia.ts | 1 + src/config/chain/types.ts | 1 + .../components/NoVotingPeriodTally.tsx | 26 ++++++++++++++++ .../components/ResultExplanation.tsx | 15 +++++++++ .../VotingOverview.tsx | 12 ++++++- .../status-summary/index.tsx | 25 ++++++++++++--- .../vote-details/voting-period/index.tsx | 31 +++++++++++++------ src/lib/pages/proposal-details/data.ts | 12 +++++-- 9 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 src/lib/pages/proposal-details/components/NoVotingPeriodTally.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d49230eb..9f0c0e2ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,7 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements -- [#960](https://github.com/alleslabs/celatone-frontend/pull/960) Adjust UI in contract and account detail page +- [#996](https://github.com/alleslabs/celatone-frontend/pull/996) Allow disable voting period tally config - [#983](https://github.com/alleslabs/celatone-frontend/pull/983) Add fallback for collection names that are empty string - [#982](https://github.com/alleslabs/celatone-frontend/pull/982) Support Icns in account osmosis lite version - [#973](https://github.com/alleslabs/celatone-frontend/pull/973) Remove overview text from landing page title diff --git a/src/config/chain/initia.ts b/src/config/chain/initia.ts index d40275d24..fc11e1532 100644 --- a/src/config/chain/initia.ts +++ b/src/config/chain/initia.ts @@ -87,6 +87,7 @@ export const INITIA_CHAIN_CONFIGS: ChainConfigs = { enabled: true, version: "v1", hideOpenProposal: true, + disableVotingPeriodTally: true, }, nft: { enabled: true, diff --git a/src/config/chain/types.ts b/src/config/chain/types.ts index 178474cf1..c9f068ed4 100644 --- a/src/config/chain/types.ts +++ b/src/config/chain/types.ts @@ -44,6 +44,7 @@ type GovConfig = hideOpenProposal?: boolean; disableWhitelistProposal?: boolean; disableStoreCodeProposal?: boolean; + disableVotingPeriodTally?: boolean; } | { enabled: false; diff --git a/src/lib/pages/proposal-details/components/NoVotingPeriodTally.tsx b/src/lib/pages/proposal-details/components/NoVotingPeriodTally.tsx new file mode 100644 index 000000000..5c2d716d3 --- /dev/null +++ b/src/lib/pages/proposal-details/components/NoVotingPeriodTally.tsx @@ -0,0 +1,26 @@ +import { Alert, AlertDescription } from "@chakra-ui/react"; + +import { useCurrentChain } from "lib/app-provider"; +import { CustomIcon } from "lib/components/icon"; + +export const NoVotingPeriodTallyExplanation = () => { + const { + chain: { chain_id: chainId }, + } = useCurrentChain(); + return ( + <> + The proposal tally information during voting period is unavailable in{" "} + {chainId}. It will be available + after voting period ends. + + ); +}; + +export const NoVotingPeriodTallyAlert = () => ( + + + + + + +); diff --git a/src/lib/pages/proposal-details/components/ResultExplanation.tsx b/src/lib/pages/proposal-details/components/ResultExplanation.tsx index 45d042b20..c5e9d0cdc 100644 --- a/src/lib/pages/proposal-details/components/ResultExplanation.tsx +++ b/src/lib/pages/proposal-details/components/ResultExplanation.tsx @@ -2,6 +2,7 @@ import { SkeletonText, Text } from "@chakra-ui/react"; import { isNull } from "lodash"; +import { useGovConfig } from "lib/app-provider"; import { extractParams, mapDeposit, @@ -20,6 +21,7 @@ import { ProposalStatus } from "lib/types"; import { formatPrettyPercent, formatTokenWithValueList } from "lib/utils"; import { ErrorFetchingProposalInfos } from "./ErrorFetchingProposalInfos"; +import { NoVotingPeriodTallyExplanation } from "./NoVotingPeriodTally"; import { ViewFailedReason } from "./ViewFailedReason"; const Passed = () => ( @@ -66,12 +68,25 @@ export interface ResultExplanationProps { isLoading: boolean; } +// eslint-disable-next-line complexity export const ResultExplanation = ({ proposalData, params, votesInfo, isLoading, }: ResultExplanationProps) => { + const gov = useGovConfig({ shouldRedirect: false }); + if ( + gov.enabled && + gov.disableVotingPeriodTally && + proposalData.status === ProposalStatus.VOTING_PERIOD + ) + return ( + + + + ); + if (proposalData.status === ProposalStatus.DEPOSIT_FAILED) return ( diff --git a/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverview.tsx b/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverview.tsx index 5bb4fd578..2ce02ab48 100644 --- a/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverview.tsx +++ b/src/lib/pages/proposal-details/components/proposal-overview/proposal-period-overview/VotingOverview.tsx @@ -2,7 +2,8 @@ import { Button, Flex, Text } from "@chakra-ui/react"; import type { ProposalOverviewProps } from ".."; import { ErrorFetchingProposalInfos } from "../../ErrorFetchingProposalInfos"; -import { useInternalNavigate } from "lib/app-provider"; +import { NoVotingPeriodTallyAlert } from "../../NoVotingPeriodTally"; +import { useGovConfig, useInternalNavigate } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { Loading } from "lib/components/Loading"; import { TabIndex } from "lib/pages/proposal-details/types"; @@ -20,6 +21,15 @@ const VotingOverviewBody = ({ }: ProposalOverviewProps) => { const navigate = useInternalNavigate(); + const gov = useGovConfig({ shouldRedirect: false }); + const disableVotingPeriodTally = gov.enabled && gov.disableVotingPeriodTally; + + if ( + proposalData.status === ProposalStatus.VOTING_PERIOD && + disableVotingPeriodTally + ) + return ; + if (proposalData.status === ProposalStatus.DEPOSIT_PERIOD) return ( diff --git a/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx b/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx index dd7ce0632..a45750235 100644 --- a/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx +++ b/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx @@ -4,6 +4,8 @@ import type { CSSProperties } from "react"; import type { ProposalOverviewProps } from ".."; import { ActiveDot } from "../../ActiveDot"; import { ResultExplanation } from "../../ResultExplanation"; +import { useGovConfig } from "lib/app-provider"; +import { StatusChip } from "lib/components/table"; import { ProposalStatus } from "lib/types"; import { SummaryStatusChip } from "./SummaryStatusChip"; @@ -34,6 +36,9 @@ export const StatusSummary = ({ proposalData, ...props }: ProposalOverviewProps) => { + const gov = useGovConfig({ shouldRedirect: false }); + const disableVotingPeriodTally = + gov.enabled && !!gov.disableVotingPeriodTally; const isDepositOrVoting = proposalData.status === ProposalStatus.DEPOSIT_PERIOD || proposalData.status === ProposalStatus.VOTING_PERIOD; @@ -55,10 +60,22 @@ export const StatusSummary = ({ > {isDepositOrVoting && } - - {isDepositOrVoting ? "Current" : "Final"} proposal result: - - + {disableVotingPeriodTally && + proposalData.status === ProposalStatus.VOTING_PERIOD ? ( + <> + + Current proposal status: + + + + ) : ( + <> + + {isDepositOrVoting ? "Current" : "Final"} proposal result: + + + + )} diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/index.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/index.tsx index afa4cb98a..ca3c00776 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/index.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/index.tsx @@ -11,11 +11,13 @@ import { isNull } from "lodash"; import type { ReactNode } from "react"; import type { VoteDetailsProps } from ".."; +import { NoVotingPeriodTallyAlert } from "../../NoVotingPeriodTally"; import { AmpEvent, track } from "lib/amplitude"; -import { useMobile, useTierConfig } from "lib/app-provider"; +import { useGovConfig, useMobile, useTierConfig } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { TableTitle } from "lib/components/table"; import { useProposalAnswerCounts } from "lib/services/proposal"; +import { ProposalStatus } from "lib/types"; import { scrollToComponent, scrollYPosition } from "lib/utils"; import { ProposalVotesPanel } from "./ProposalVotesPanel"; @@ -50,9 +52,11 @@ const ContentContainer = ({ const scrollComponentId = "voting-period"; export const VotingPeriod = ({ proposalData, ...props }: VoteDetailsProps) => { + const isMobile = useMobile(); const isFullTier = useTierConfig() === "full"; + const gov = useGovConfig({ shouldRedirect: false }); + const disableVotingPeriodTally = gov.enabled && gov.disableVotingPeriodTally; - const isMobile = useMobile(); const validatorVoteDisclosure = useDisclosure(); const allVoteDisclosure = useDisclosure(); @@ -111,14 +115,21 @@ export const VotingPeriod = ({ proposalData, ...props }: VoteDetailsProps) => { transition="all 0.25s ease-in-out" gap={4} > - {/* Voting Participations */} - - - - {/* Voting Results */} - - - + {proposalData.status === ProposalStatus.VOTING_PERIOD && + disableVotingPeriodTally ? ( + + ) : ( + <> + {/* Voting Participations */} + + + + {/* Voting Results */} + + + + + )} {isFullTier && ( {/* Validator Votes */} diff --git a/src/lib/pages/proposal-details/data.ts b/src/lib/pages/proposal-details/data.ts index 16948d40b..7c23a9bcf 100644 --- a/src/lib/pages/proposal-details/data.ts +++ b/src/lib/pages/proposal-details/data.ts @@ -1,4 +1,4 @@ -import { useTierConfig } from "lib/app-provider"; +import { useGovConfig, useTierConfig } from "lib/app-provider"; import { useAssetInfos } from "lib/services/assetService"; import { useMovePoolInfos } from "lib/services/move/poolService"; import { @@ -124,10 +124,16 @@ export const useDerivedProposalVotesInfo = ( proposalData: DerivedProposalDataResponse["data"], isProposalDataLoading: boolean ): DerivedProposalVotesInfoResponse => { + const gov = useGovConfig({ shouldRedirect: false }); + const disableVotingPeriodTally = gov.enabled && gov.disableVotingPeriodTally; + const isVotingPeriod = proposalData?.info?.status === ProposalStatus.VOTING_PERIOD; - const { data, isLoading } = useProposalVotesInfo(id, isVotingPeriod); + const { data, isFetching } = useProposalVotesInfo( + id, + isVotingPeriod && !disableVotingPeriodTally + ); if (!isVotingPeriod) { return { @@ -138,6 +144,6 @@ export const useDerivedProposalVotesInfo = ( return { data, - isLoading, + isLoading: isFetching, }; }; From 845249af335f5fa78407eeaa842616ecfadf1d94 Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:31:05 +0700 Subject: [PATCH 2/3] fix: changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f0c0e2ef..33a05143d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Improvements - [#996](https://github.com/alleslabs/celatone-frontend/pull/996) Allow disable voting period tally config +- [#960](https://github.com/alleslabs/celatone-frontend/pull/960) Adjust UI in contract and account detail page - [#983](https://github.com/alleslabs/celatone-frontend/pull/983) Add fallback for collection names that are empty string - [#982](https://github.com/alleslabs/celatone-frontend/pull/982) Support Icns in account osmosis lite version - [#973](https://github.com/alleslabs/celatone-frontend/pull/973) Remove overview text from landing page title From b7d0441c8896694471630c1533b9d8d32b46276c Mon Sep 17 00:00:00 2001 From: songwongtp <16089160+songwongtp@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:26:23 +0700 Subject: [PATCH 3/3] fix: comment --- .../components/proposal-overview/status-summary/index.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx b/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx index a45750235..b42abaf41 100644 --- a/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx +++ b/src/lib/pages/proposal-details/components/proposal-overview/status-summary/index.tsx @@ -37,8 +37,7 @@ export const StatusSummary = ({ ...props }: ProposalOverviewProps) => { const gov = useGovConfig({ shouldRedirect: false }); - const disableVotingPeriodTally = - gov.enabled && !!gov.disableVotingPeriodTally; + const disableVotingPeriodTally = gov.enabled && gov.disableVotingPeriodTally; const isDepositOrVoting = proposalData.status === ProposalStatus.DEPOSIT_PERIOD || proposalData.status === ProposalStatus.VOTING_PERIOD;