From 86252244a81709e029d0a978d909c4582e755b6b Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 7 May 2024 00:27:36 +0700 Subject: [PATCH 01/27] feat(pages): update table for lite version --- src/lib/app-provider/env.ts | 2 + .../table/proposals/ProposalsTableHeader.tsx | 6 +- .../proposals/ProposalsTableMobileCard.tsx | 31 +-- .../table/proposals/ProposalsTableRow.tsx | 23 +- .../components/ProposalsTableFull.tsx | 202 ++++++++++++++++++ .../components/ProposalsTableLite.tsx | 107 ++++++++++ src/lib/pages/proposals/index.tsx | 201 +---------------- src/lib/services/wasm/proposal/lcd.ts | 71 ++++++ src/lib/services/wasm/proposal/types.ts | 53 +++++ src/lib/types/proposal.ts | 9 + 10 files changed, 485 insertions(+), 220 deletions(-) create mode 100644 src/lib/pages/proposals/components/ProposalsTableFull.tsx create mode 100644 src/lib/pages/proposals/components/ProposalsTableLite.tsx diff --git a/src/lib/app-provider/env.ts b/src/lib/app-provider/env.ts index f69d7ce50..a83e12399 100644 --- a/src/lib/app-provider/env.ts +++ b/src/lib/app-provider/env.ts @@ -68,7 +68,9 @@ export enum CELATONE_QUERY_KEYS { PROPOSAL_ANSWER_COUNTS = "CELATONE_QUERY_PROPOSAL_ANSWER_COUNTS", RELATED_PROPOSALS_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_RELATED_PROPOSALS_BY_CONTRACT_ADDRESS", PROPOSALS_BY_ADDRESS = "CELATONE_QUERY_PROPOSALS_BY_ADDRESS", + PROPOSAL_DATA_LCD = "CELATONE_QUERY_PROPOSAL_DATA_LCD", PROPOSALS = "CELATONE_QUERY_PROPOSALS", + PROPOSALS_LCD = "CELATONE_QUERY_PROPOSALS_LCD", PROPOSAL_PARAMS = "CELATONE_QUERY_PROPOSAL_PARAMS", PROPOSAL_TYPES = "CELATONE_QUERY_PROPOSAL_TYPES", GOV_PARAMS = "CELATONE_QUERY_GOV_PARAMS", diff --git a/src/lib/components/table/proposals/ProposalsTableHeader.tsx b/src/lib/components/table/proposals/ProposalsTableHeader.tsx index 7a95626c7..f9dc6c2fa 100644 --- a/src/lib/components/table/proposals/ProposalsTableHeader.tsx +++ b/src/lib/components/table/proposals/ProposalsTableHeader.tsx @@ -2,6 +2,7 @@ import type { DividerProps, GridProps } from "@chakra-ui/react"; import { Grid, Text } from "@chakra-ui/react"; import { TableHeader, TableHeaderFreeze } from "../tableComponents"; +import { useTierConfig } from "lib/app-provider"; interface ProposalsTableHeaderProps { templateColumns: GridProps["templateColumns"]; @@ -12,8 +13,11 @@ export const ProposalsTableHeader = ({ templateColumns, boxShadow, }: ProposalsTableHeaderProps) => { + const tier = useTierConfig(); + // TODO - Revisit split columnsWidth const columnsWidth = templateColumns?.toString().split(" "); + return ( Proposal ID @@ -28,7 +32,7 @@ export const ProposalsTableHeader = ({ Status Voting ends - Resolved Block Height + {tier === "full" && Resolved Block Height} Proposed By ); diff --git a/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx b/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx index e71a56978..23ae54448 100644 --- a/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx +++ b/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx @@ -2,7 +2,7 @@ import { Flex } from "@chakra-ui/react"; import { MobileCardTemplate } from "../MobileCardTemplate"; import { MobileLabel } from "../MobileLabel"; -import { useInternalNavigate } from "lib/app-provider"; +import { useInternalNavigate, useTierConfig } from "lib/app-provider"; import { ExplorerLink } from "lib/components/ExplorerLink"; import type { Proposal } from "lib/types"; import { ProposalStatus } from "lib/types"; @@ -20,6 +20,7 @@ export interface ProposalsTableMobileCardProps { export const ProposalsTableMobileCard = ({ proposal, }: ProposalsTableMobileCardProps) => { + const tier = useTierConfig(); const navigate = useInternalNavigate(); const onCardSelect = (proposalId: number) => @@ -65,19 +66,21 @@ export const ProposalsTableMobileCard = ({ } bottomContent={ - <> - - - - - - - - - + tier === "full" && ( + <> + + + + + + + + + + ) } onClick={() => onCardSelect(proposal.id)} /> diff --git a/src/lib/components/table/proposals/ProposalsTableRow.tsx b/src/lib/components/table/proposals/ProposalsTableRow.tsx index afd55eee9..3e731a545 100644 --- a/src/lib/components/table/proposals/ProposalsTableRow.tsx +++ b/src/lib/components/table/proposals/ProposalsTableRow.tsx @@ -2,7 +2,7 @@ import type { DividerProps, GridProps } from "@chakra-ui/react"; import { Grid } from "@chakra-ui/react"; import { TableRow, TableRowFreeze } from "../tableComponents"; -import { useInternalNavigate } from "lib/app-provider"; +import { useInternalNavigate, useTierConfig } from "lib/app-provider"; import { ExplorerLink } from "lib/components/ExplorerLink"; import { StopPropagationBox } from "lib/components/StopPropagationBox"; import type { Proposal } from "lib/types"; @@ -25,6 +25,7 @@ export const ProposalsTableRow = ({ templateColumns, boxShadow, }: ProposalsTableRowProps) => { + const tier = useTierConfig(); const navigate = useInternalNavigate(); const onRowSelect = (proposalId: number) => @@ -86,15 +87,17 @@ export const ProposalsTableRow = ({ status={proposal.status} /> - - - - - + {tier === "full" && ( + + + + + + )} { + const router = useRouter(); + const { address } = useCurrentChain(); + const { currentChainId } = useCelatoneApp(); + const isMobile = useMobile(); + + const [proposer, setProposer] = useState>(); + const [statuses, setStatuses] = useState([]); + const [types, setTypes] = useState([]); + const [search, setSearch] = useState(""); + const debouncedSearch = useDebounce(search); + + const { + pagesQuantity, + currentPage, + setCurrentPage, + pageSize, + setPageSize, + offset, + } = usePaginator({ + initialState: { + pageSize: 10, + currentPage: 1, + isDisabled: false, + }, + }); + + const { + data: proposals, + isLoading, + error, + } = useProposals( + pageSize, + offset, + proposer, + statuses, + types, + debouncedSearch + ); + + useEffect(() => { + if (router.isReady) track(AmpEvent.TO_PROPOSAL_LIST); + }, [router.isReady]); + + useEffect(() => { + setProposer(undefined); + setStatuses([]); + setTypes([]); + setSearch(""); + }, [currentChainId, address]); + + useEffect(() => { + setCurrentPage(1); + setPageSize(10); + }, [ + proposer, + // eslint-disable-next-line react-hooks/exhaustive-deps + JSON.stringify(statuses), + // eslint-disable-next-line react-hooks/exhaustive-deps + JSON.stringify(types), + debouncedSearch, + setCurrentPage, + setPageSize, + ]); + + return ( + <> + + + setSearch(e.target.value)} + size="lg" + amptrackSection="proposal-list-search" + /> + {!isMobile && ( + + )} + + + + + + + + ) : ( + <> + {!!proposer || + statuses.length > 0 || + types.length > 0 || + search.trim().length > 0 ? ( + + ) : ( + + )} + + ) + } + /> + {proposals && proposals.total > 10 && ( + setCurrentPage(nextPage)} + onPageSizeChange={(e) => { + const size = Number(e.target.value); + setPageSize(size); + setCurrentPage(1); + }} + /> + )} + + ); +}; diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx new file mode 100644 index 000000000..79fc18a13 --- /dev/null +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -0,0 +1,107 @@ +import { Grid, GridItem } from "@chakra-ui/react"; +import { useState } from "react"; + +import InputWithIcon from "lib/components/InputWithIcon"; +import { LoadNext } from "lib/components/LoadNext"; +import { EmptyState, ErrorFetching } from "lib/components/state"; +import { ProposalsTable } from "lib/components/table"; +import { useDebounce } from "lib/hooks"; +import { + useProposalDataLcd, + useProposalsLcd, +} from "lib/services/wasm/proposal/lcd"; +import type { ProposalStatus } from "lib/types"; + +import { ProposalStatusFilter } from "./ProposalStatusFilter"; + +export const ProposalsTableLite = () => { + const [search, setSearch] = useState(""); + const debouncedSearch = useDebounce(search); + const [statuses, setStatuses] = useState([]); + + const { + data: proposalsData, + error: proposalsError, + fetchNextPage, + hasNextPage, + isLoading: isProposalsLoading, + isFetchingNextPage, + } = useProposalsLcd(); + + const { data: proposalData, isLoading: isProposalDataLoading } = + useProposalDataLcd(debouncedSearch); + + const proposal = proposalData ? [proposalData] : []; + const proposals = + debouncedSearch.trim().length > 0 ? proposal : proposalsData; + + const isLoadNext = + hasNextPage && + !isProposalsLoading && + !isProposalDataLoading && + proposals && + proposals.length > 1; + + // TODO: filter by status + + return ( + <> + + + setSearch(e.target.value)} + size="lg" + amptrackSection="proposal-list-search" + /> + + + + + + + ) : ( + <> + {statuses.length > 0 || search.trim().length > 0 ? ( + + ) : ( + + )} + + ) + } + /> + {isLoadNext && ( + + )} + + ); +}; diff --git a/src/lib/pages/proposals/index.tsx b/src/lib/pages/proposals/index.tsx index 4fca3bbe1..3614e9340 100644 --- a/src/lib/pages/proposals/index.tsx +++ b/src/lib/pages/proposals/index.tsx @@ -1,99 +1,17 @@ -import { Flex, Heading, Switch, Text } from "@chakra-ui/react"; -import { useRouter } from "next/router"; -import { useEffect, useState } from "react"; +import { Flex, Heading } from "@chakra-ui/react"; -import { AmpEvent, track } from "lib/amplitude"; -import { - useCelatoneApp, - useCurrentChain, - useGovConfig, - useMobile, -} from "lib/app-provider"; +import { useGovConfig, useMobile, useTierConfig } from "lib/app-provider"; import { NewProposalButton } from "lib/components/button/NewProposalButton"; -import InputWithIcon from "lib/components/InputWithIcon"; import PageContainer from "lib/components/PageContainer"; -import { Pagination } from "lib/components/pagination"; -import { usePaginator } from "lib/components/pagination/usePaginator"; -import { EmptyState, ErrorFetching } from "lib/components/state"; -import { ProposalsTable } from "lib/components/table"; -import { Tooltip } from "lib/components/Tooltip"; import { UserDocsLink } from "lib/components/UserDocsLink"; -import { useDebounce } from "lib/hooks"; -import { useProposals } from "lib/services/wasm/proposal"; -import type { - BechAddr20, - Option, - ProposalStatus, - ProposalType, -} from "lib/types"; -import { ProposalStatusFilter } from "./components/ProposalStatusFilter"; -import { ProposalTypeFilter } from "./components/ProposalTypeFilter"; +import { ProposalsTableFull } from "./components/ProposalsTableFull"; +import { ProposalsTableLite } from "./components/ProposalsTableLite"; const Proposals = () => { useGovConfig({ shouldRedirect: true }); const isMobile = useMobile(); - const router = useRouter(); - const { address } = useCurrentChain(); - const { currentChainId } = useCelatoneApp(); - - const [proposer, setProposer] = useState>(); - const [statuses, setStatuses] = useState([]); - const [types, setTypes] = useState([]); - const [search, setSearch] = useState(""); - const debouncedSearch = useDebounce(search); - - const { - pagesQuantity, - currentPage, - setCurrentPage, - pageSize, - setPageSize, - offset, - } = usePaginator({ - initialState: { - pageSize: 10, - currentPage: 1, - isDisabled: false, - }, - }); - const { - data: proposals, - isLoading, - error, - } = useProposals( - pageSize, - offset, - proposer, - statuses, - types, - debouncedSearch - ); - - useEffect(() => { - if (router.isReady) track(AmpEvent.TO_PROPOSAL_LIST); - }, [router.isReady]); - - useEffect(() => { - setProposer(undefined); - setStatuses([]); - setTypes([]); - setSearch(""); - }, [currentChainId, address]); - - useEffect(() => { - setCurrentPage(1); - setPageSize(10); - }, [ - proposer, - // eslint-disable-next-line react-hooks/exhaustive-deps - JSON.stringify(statuses), - // eslint-disable-next-line react-hooks/exhaustive-deps - JSON.stringify(types), - debouncedSearch, - setCurrentPage, - setPageSize, - ]); + const tier = useTierConfig(); return ( @@ -109,114 +27,7 @@ const Proposals = () => { {!isMobile && } - - - setSearch(e.target.value)} - size="lg" - amptrackSection="proposal-list-search" - /> - {!isMobile && ( - - )} - - - - - - - - ) : ( - <> - {!!proposer || - statuses.length > 0 || - types.length > 0 || - search.trim().length > 0 ? ( - - ) : ( - - )} - - ) - } - /> - {proposals && proposals.total > 10 && ( - setCurrentPage(nextPage)} - onPageSizeChange={(e) => { - const size = Number(e.target.value); - setPageSize(size); - setCurrentPage(1); - }} - /> - )} + {tier === "full" ? : } ); }; diff --git a/src/lib/services/wasm/proposal/lcd.ts b/src/lib/services/wasm/proposal/lcd.ts index e69de29bb..34df5f08a 100644 --- a/src/lib/services/wasm/proposal/lcd.ts +++ b/src/lib/services/wasm/proposal/lcd.ts @@ -0,0 +1,71 @@ +import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; +import axios from "axios"; + +import { CELATONE_QUERY_KEYS, useLCDEndpoint } from "lib/app-provider"; +import type { Option, ProposalStatus } from "lib/types"; +import { parseWithError } from "lib/utils"; + +import type { ProposalsResponseItemLcd, ProposalsResponseLcd } from "./types"; +import { zProposalsResponseItemLcd, zProposalsResponseLcd } from "./types"; + +const getProposalsLcd = async ( + endpoint: string, + paginationKey: Option, + statuses?: Omit +): Promise => + axios + .get(`${endpoint}/cosmos/gov/v1/proposals`, { + params: { + "pagination.limit": 10, + "pagination.reverse": true, + "pagination.key": paginationKey, + ...(statuses && { proposal_status: `PROPOSAL_STATUS_${statuses}` }), + }, + }) + .then(({ data }) => parseWithError(zProposalsResponseLcd, data)); + +export const useProposalsLcd = ( + statuses?: Omit +) => { + const lcdEndpoint = useLCDEndpoint(); + + const query = useInfiniteQuery( + [CELATONE_QUERY_KEYS.PROPOSALS_LCD, lcdEndpoint, statuses], + ({ pageParam }) => getProposalsLcd(lcdEndpoint, pageParam, statuses), + { + getNextPageParam: (lastPage) => lastPage.pagination.nextKey ?? undefined, + refetchOnWindowFocus: false, + } + ); + + const { data, ...rest } = query; + + return { + data: data?.pages.flatMap((page) => page.proposals), + ...rest, + }; +}; + +const getProposalDataLcd = async ( + endpoint: string, + id: string +): Promise => + axios + .get(`${endpoint}/cosmos/gov/v1/proposals/${id}`) + .then(({ data }) => + parseWithError(zProposalsResponseItemLcd, data.proposal) + ); + +export const useProposalDataLcd = (id: string, enabled = true) => { + const lcdEndpoint = useLCDEndpoint(); + + return useQuery( + [CELATONE_QUERY_KEYS.PROPOSAL_DATA_LCD, lcdEndpoint, id], + async () => getProposalDataLcd(lcdEndpoint, id), + { + retry: 1, + refetchOnWindowFocus: false, + enabled, + } + ); +}; diff --git a/src/lib/services/wasm/proposal/types.ts b/src/lib/services/wasm/proposal/types.ts index c6d87813b..b90f00db4 100644 --- a/src/lib/services/wasm/proposal/types.ts +++ b/src/lib/services/wasm/proposal/types.ts @@ -1,3 +1,4 @@ +import { capitalize } from "lodash"; import { z } from "zod"; import { @@ -5,6 +6,7 @@ import { zBig, zCoin, zProposalStatus, + zProposalStatusLcd, zProposalType, zRatio, zUtcDate, @@ -17,6 +19,7 @@ import type { Proposal, ProposalData, ProposalParams, + ProposalStatus, ProposalValidatorVote, ProposalVote, ProposalVotesInfo, @@ -24,6 +27,7 @@ import type { Token, U, } from "lib/types"; +import { zPagination } from "lib/types/rest"; import { parseTxHash, snakeToCamel } from "lib/utils"; export interface MinDeposit { @@ -230,3 +234,52 @@ export const zProposalAnswerCountsResponse = z export type ProposalAnswerCountsResponse = z.infer< typeof zProposalAnswerCountsResponse >; + +export const zProposalsResponseItemLcd = z + .object({ + id: z.string(), + messages: z + .object({ + "@type": z.string(), + }) + .passthrough() + .array() + .nullable(), + status: zProposalStatusLcd, + final_tally_result: z.object({ + yes_count: z.string(), + no_count: z.string(), + abstain_count: z.string(), + no_with_veto_count: z.string(), + }), + submit_time: zUtcDate, + deposit_end_time: zUtcDate, + total_deposit: zCoin.array(), + voting_start_time: zUtcDate, + voting_end_time: zUtcDate, + metadata: z.string(), + title: z.string(), + summary: z.string(), + proposer: zBechAddr, + }) + .transform((val) => ({ + ...snakeToCamel(val), + id: Number(val.id), + status: val.status + .replace("PROPOSAL_STATUS_", "") + .split("_") + .map((term: string) => capitalize(term.toLowerCase())) + .join("") as ProposalStatus, + resolvedHeight: null, + types: [], + isExpedited: false, + })); +export type ProposalsResponseItemLcd = z.infer< + typeof zProposalsResponseItemLcd +>; + +export const zProposalsResponseLcd = z.object({ + proposals: z.array(zProposalsResponseItemLcd), + pagination: zPagination, +}); +export type ProposalsResponseLcd = z.infer; diff --git a/src/lib/types/proposal.ts b/src/lib/types/proposal.ts index 3f415801d..27f4c840b 100644 --- a/src/lib/types/proposal.ts +++ b/src/lib/types/proposal.ts @@ -22,6 +22,15 @@ export enum ProposalStatus { } export const zProposalStatus = z.nativeEnum(ProposalStatus); +export enum ProposalStatusLcd { + PROPOSAL_STATUS_DEPOSIT_PERIOD = "PROPOSAL_STATUS_DEPOSIT_PERIOD", + PROPOSAL_STATUS_VOTING_PERIOD = "PROPOSAL_STATUS_VOTING_PERIOD", + PROPOSAL_STATUS_PASSED = "PROPOSAL_STATUS_PASSED", + PROPOSAL_STATUS_REJECTED = "PROPOSAL_STATUS_REJECTED", + PROPOSAL_STATUS_FAILED = "PROPOSAL_STATUS_FAILED", +} +export const zProposalStatusLcd = z.nativeEnum(ProposalStatusLcd); + export enum ProposalTypeCosmos { TEXT = "Text", PARAMETER = "ParameterChange", From 94c27f843bd54d81aa1d545920563f882a6053f5 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 7 May 2024 10:23:52 +0700 Subject: [PATCH 02/27] feat(components): update proposal table lite --- src/lib/pages/proposals/components/ProposalsTableLite.tsx | 2 +- src/lib/services/wasm/proposal/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx index 79fc18a13..1d3948571 100644 --- a/src/lib/pages/proposals/components/ProposalsTableLite.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -9,7 +9,7 @@ import { useDebounce } from "lib/hooks"; import { useProposalDataLcd, useProposalsLcd, -} from "lib/services/wasm/proposal/lcd"; +} from "lib/services/wasm/proposal"; import type { ProposalStatus } from "lib/types"; import { ProposalStatusFilter } from "./ProposalStatusFilter"; diff --git a/src/lib/services/wasm/proposal/index.ts b/src/lib/services/wasm/proposal/index.ts index 5069f67cb..a386acb1e 100644 --- a/src/lib/services/wasm/proposal/index.ts +++ b/src/lib/services/wasm/proposal/index.ts @@ -1,3 +1,3 @@ export * from "./api"; -// export * from "./lcd"; +export * from "./lcd"; export * from "./types"; From 12d53d00188ae66dd880db943b93c0c74a2f5c6b Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 7 May 2024 11:12:50 +0700 Subject: [PATCH 03/27] feat(pages): add filter by status in proposals listing lite version --- src/lib/components/forms/SelectInput.tsx | 1 + .../components/ProposalsTableLite.tsx | 31 ++++++++++++------- src/lib/services/wasm/proposal/helper.ts | 12 +++++++ src/lib/services/wasm/proposal/index.ts | 1 + src/lib/services/wasm/proposal/lcd.ts | 14 +++++---- src/lib/services/wasm/proposal/types.ts | 10 ++---- src/lib/types/proposal.ts | 1 + 7 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 src/lib/services/wasm/proposal/helper.ts diff --git a/src/lib/components/forms/SelectInput.tsx b/src/lib/components/forms/SelectInput.tsx index 956e7701b..0a84faf34 100644 --- a/src/lib/components/forms/SelectInput.tsx +++ b/src/lib/components/forms/SelectInput.tsx @@ -163,6 +163,7 @@ export const SelectInput = ({ borderBottomColor: hasDivider && "gray.700", }, }} + overflow="hidden" > {options.map(({ label, value, disabled, icon, iconColor, image }) => ( { const [search, setSearch] = useState(""); const debouncedSearch = useDebounce(search); - const [statuses, setStatuses] = useState([]); + const [proposalStatus, setProposalStatus] = useState( + ProposalStatusLcd.ALL + ); const { data: proposalsData, @@ -26,7 +28,7 @@ export const ProposalsTableLite = () => { hasNextPage, isLoading: isProposalsLoading, isFetchingNextPage, - } = useProposalsLcd(); + } = useProposalsLcd(proposalStatus); const { data: proposalData, isLoading: isProposalDataLoading } = useProposalDataLcd(debouncedSearch); @@ -42,7 +44,11 @@ export const ProposalsTableLite = () => { proposals && proposals.length > 1; - // TODO: filter by status + const options = Object.values(ProposalStatusLcd).map((status) => ({ + label: mapProposalStatusLcdToProposalStatus(status), + value: status, + disabled: false, + })); return ( <> @@ -62,11 +68,12 @@ export const ProposalsTableLite = () => { /> - + formLabel="Filter by Status" + options={options} + onChange={setProposalStatus} + placeholder="" + initialSelected={proposalStatus} /> @@ -78,7 +85,7 @@ export const ProposalsTableLite = () => { ) : ( <> - {statuses.length > 0 || search.trim().length > 0 ? ( + {proposalStatus || search.trim().length > 0 ? ( + status + .replace("PROPOSAL_STATUS_", "") + .split("_") + .map((term: string) => capitalize(term.toLowerCase())) + .join("") as ProposalStatus; diff --git a/src/lib/services/wasm/proposal/index.ts b/src/lib/services/wasm/proposal/index.ts index a386acb1e..ebb87e4ff 100644 --- a/src/lib/services/wasm/proposal/index.ts +++ b/src/lib/services/wasm/proposal/index.ts @@ -1,3 +1,4 @@ export * from "./api"; export * from "./lcd"; export * from "./types"; +export * from "./helper"; diff --git a/src/lib/services/wasm/proposal/lcd.ts b/src/lib/services/wasm/proposal/lcd.ts index 34df5f08a..658376ae6 100644 --- a/src/lib/services/wasm/proposal/lcd.ts +++ b/src/lib/services/wasm/proposal/lcd.ts @@ -2,7 +2,8 @@ import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; import axios from "axios"; import { CELATONE_QUERY_KEYS, useLCDEndpoint } from "lib/app-provider"; -import type { Option, ProposalStatus } from "lib/types"; +import type { Option } from "lib/types"; +import { ProposalStatusLcd } from "lib/types"; import { parseWithError } from "lib/utils"; import type { ProposalsResponseItemLcd, ProposalsResponseLcd } from "./types"; @@ -11,7 +12,7 @@ import { zProposalsResponseItemLcd, zProposalsResponseLcd } from "./types"; const getProposalsLcd = async ( endpoint: string, paginationKey: Option, - statuses?: Omit + status?: Omit ): Promise => axios .get(`${endpoint}/cosmos/gov/v1/proposals`, { @@ -19,19 +20,20 @@ const getProposalsLcd = async ( "pagination.limit": 10, "pagination.reverse": true, "pagination.key": paginationKey, - ...(statuses && { proposal_status: `PROPOSAL_STATUS_${statuses}` }), + ...(status && + status !== ProposalStatusLcd.ALL && { proposal_status: status }), }, }) .then(({ data }) => parseWithError(zProposalsResponseLcd, data)); export const useProposalsLcd = ( - statuses?: Omit + status?: Omit ) => { const lcdEndpoint = useLCDEndpoint(); const query = useInfiniteQuery( - [CELATONE_QUERY_KEYS.PROPOSALS_LCD, lcdEndpoint, statuses], - ({ pageParam }) => getProposalsLcd(lcdEndpoint, pageParam, statuses), + [CELATONE_QUERY_KEYS.PROPOSALS_LCD, lcdEndpoint, status], + ({ pageParam }) => getProposalsLcd(lcdEndpoint, pageParam, status), { getNextPageParam: (lastPage) => lastPage.pagination.nextKey ?? undefined, refetchOnWindowFocus: false, diff --git a/src/lib/services/wasm/proposal/types.ts b/src/lib/services/wasm/proposal/types.ts index b90f00db4..6343f5736 100644 --- a/src/lib/services/wasm/proposal/types.ts +++ b/src/lib/services/wasm/proposal/types.ts @@ -1,4 +1,3 @@ -import { capitalize } from "lodash"; import { z } from "zod"; import { @@ -19,7 +18,6 @@ import type { Proposal, ProposalData, ProposalParams, - ProposalStatus, ProposalValidatorVote, ProposalVote, ProposalVotesInfo, @@ -30,6 +28,8 @@ import type { import { zPagination } from "lib/types/rest"; import { parseTxHash, snakeToCamel } from "lib/utils"; +import { mapProposalStatusLcdToProposalStatus } from "./helper"; + export interface MinDeposit { amount: U>; denom: string; @@ -265,11 +265,7 @@ export const zProposalsResponseItemLcd = z .transform((val) => ({ ...snakeToCamel(val), id: Number(val.id), - status: val.status - .replace("PROPOSAL_STATUS_", "") - .split("_") - .map((term: string) => capitalize(term.toLowerCase())) - .join("") as ProposalStatus, + status: mapProposalStatusLcdToProposalStatus(val.status), resolvedHeight: null, types: [], isExpedited: false, diff --git a/src/lib/types/proposal.ts b/src/lib/types/proposal.ts index 27f4c840b..143d96d85 100644 --- a/src/lib/types/proposal.ts +++ b/src/lib/types/proposal.ts @@ -23,6 +23,7 @@ export enum ProposalStatus { export const zProposalStatus = z.nativeEnum(ProposalStatus); export enum ProposalStatusLcd { + ALL = "ALL", PROPOSAL_STATUS_DEPOSIT_PERIOD = "PROPOSAL_STATUS_DEPOSIT_PERIOD", PROPOSAL_STATUS_VOTING_PERIOD = "PROPOSAL_STATUS_VOTING_PERIOD", PROPOSAL_STATUS_PASSED = "PROPOSAL_STATUS_PASSED", From 127d881dee985c1d47a5da58dd18eea00cd33bd0 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 7 May 2024 11:22:05 +0700 Subject: [PATCH 04/27] fix(components): filter by status max height --- src/lib/pages/proposals/components/ProposalsTableLite.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx index d25dccde4..acb962970 100644 --- a/src/lib/pages/proposals/components/ProposalsTableLite.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -74,6 +74,7 @@ export const ProposalsTableLite = () => { onChange={setProposalStatus} placeholder="" initialSelected={proposalStatus} + disableMaxH /> From 4a7775403799d69061627149093a6a473c38109d Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Tue, 7 May 2024 11:31:28 +0700 Subject: [PATCH 05/27] feat(components): update proposals table lite --- .../components/ProposalsTableLite.tsx | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx index acb962970..b0c44cab0 100644 --- a/src/lib/pages/proposals/components/ProposalsTableLite.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -85,21 +85,11 @@ export const ProposalsTableLite = () => { proposalsError ? ( ) : ( - <> - {proposalStatus || search.trim().length > 0 ? ( - - ) : ( - - )} - + ) } /> From 783d5c037e0823e44df9cef2ad97b4fc28b20211 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Wed, 8 May 2024 13:49:34 +0700 Subject: [PATCH 06/27] feat(utils): move proposal folder structure --- src/lib/app-provider/env.ts | 2 +- src/lib/components/Expedited.tsx | 2 +- .../tables/OpenedProposalsTable.tsx | 2 +- .../tables/RelatedProposalsTable.tsx | 2 +- src/lib/pages/deploy/index.tsx | 2 +- .../migrate/components/MigrateOptions.tsx | 2 +- src/lib/pages/migrate/index.tsx | 2 +- .../voting-period/ProposalVotesPanel.tsx | 2 +- .../voting-period/ValidatorVotesPanel.tsx | 2 +- .../vote-details/voting-period/index.tsx | 2 +- .../validator-votes-table/index.tsx | 4 +- .../voting-period/votes-table/index.tsx | 4 +- src/lib/pages/proposal-details/data.ts | 2 +- src/lib/pages/proposal-details/index.tsx | 2 +- .../proposal/components/InitialDeposit.tsx | 2 +- src/lib/pages/proposal/store-code/index.tsx | 2 +- src/lib/pages/proposal/whitelist/index.tsx | 2 +- .../components/ProposalTypeFilter.tsx | 2 +- .../components/ProposalsTableFull.tsx | 2 +- .../components/ProposalsTableLite.tsx | 2 +- src/lib/pages/stored-codes/index.tsx | 2 +- src/lib/pages/upload/upload.tsx | 2 +- src/lib/services/move/module.ts | 2 +- src/lib/services/proposal/api.ts | 199 ++++++++++++++ .../helper.ts => proposal/helpers.ts} | 0 .../proposal/api.ts => proposal/index.ts} | 242 +++++------------- src/lib/services/proposal/lcd.ts | 35 +++ src/lib/services/{wasm => }/proposal/types.ts | 2 +- src/lib/services/searchService.ts | 2 +- src/lib/services/wasm/proposal/index.ts | 4 - src/lib/services/wasm/proposal/lcd.ts | 73 ------ src/lib/utils/proposal.ts | 2 +- 32 files changed, 326 insertions(+), 283 deletions(-) create mode 100644 src/lib/services/proposal/api.ts rename src/lib/services/{wasm/proposal/helper.ts => proposal/helpers.ts} (100%) rename src/lib/services/{wasm/proposal/api.ts => proposal/index.ts} (59%) create mode 100644 src/lib/services/proposal/lcd.ts rename src/lib/services/{wasm => }/proposal/types.ts (99%) delete mode 100644 src/lib/services/wasm/proposal/index.ts delete mode 100644 src/lib/services/wasm/proposal/lcd.ts diff --git a/src/lib/app-provider/env.ts b/src/lib/app-provider/env.ts index d55d69570..07c416b49 100644 --- a/src/lib/app-provider/env.ts +++ b/src/lib/app-provider/env.ts @@ -62,13 +62,13 @@ export enum CELATONE_QUERY_KEYS { FAUCET_INFO = "CELATONE_QUERY_FAUCET_INFO", // X/GOV PROPOSAL_DATA = "CELATONE_QUERY_PROPOSAL_DATA", + PROPOSAL_DATA_LCD = "CELATONE_QUERY_PROPOSAL_DATA_LCD", PROPOSAL_VOTES_INFO = "CELATONE_QUERY_PROPOSAL_VOTES_INFO", PROPOSAL_VOTES = "CELATONE_QUERY_PROPOSAL_VOTES", PROPOSAL_VALIDATOR_VOTES = "CELATONE_QUERY_PROPOSAL_VALIDATOR_VOTES", PROPOSAL_ANSWER_COUNTS = "CELATONE_QUERY_PROPOSAL_ANSWER_COUNTS", RELATED_PROPOSALS_BY_CONTRACT_ADDRESS = "CELATONE_QUERY_RELATED_PROPOSALS_BY_CONTRACT_ADDRESS", PROPOSALS_BY_ADDRESS = "CELATONE_QUERY_PROPOSALS_BY_ADDRESS", - PROPOSAL_DATA_LCD = "CELATONE_QUERY_PROPOSAL_DATA_LCD", PROPOSALS = "CELATONE_QUERY_PROPOSALS", PROPOSALS_LCD = "CELATONE_QUERY_PROPOSALS_LCD", PROPOSAL_PARAMS = "CELATONE_QUERY_PROPOSAL_PARAMS", diff --git a/src/lib/components/Expedited.tsx b/src/lib/components/Expedited.tsx index 919a3c4e9..947b0f2a2 100644 --- a/src/lib/components/Expedited.tsx +++ b/src/lib/components/Expedited.tsx @@ -1,6 +1,6 @@ import { Flex, SkeletonText, Text } from "@chakra-ui/react"; -import { useProposalParams } from "lib/services/wasm/proposal"; +import { useProposalParams } from "lib/services/proposal"; import type { Option, Ratio } from "lib/types"; import { formatPrettyPercent, formatSeconds } from "lib/utils"; diff --git a/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx b/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx index 974ae701e..47b9ecbb7 100644 --- a/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx +++ b/src/lib/pages/account-details/components/tables/OpenedProposalsTable.tsx @@ -11,7 +11,7 @@ import { TableTitle, ViewMore, } from "lib/components/table"; -import { useProposalsByAddress } from "lib/services/wasm/proposal"; +import { useProposalsByAddress } from "lib/services/proposal"; import type { BechAddr, Option } from "lib/types"; interface OpenedProposalsTableProps { diff --git a/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx b/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx index 3861fd248..3a6bef69d 100644 --- a/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx +++ b/src/lib/pages/contract-details/components/tables/RelatedProposalsTable.tsx @@ -4,7 +4,7 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { ProposalsTable } from "lib/components/table"; -import { useRelatedProposalsByContractAddress } from "lib/services/wasm/proposal"; +import { useRelatedProposalsByContractAddress } from "lib/services/proposal"; import type { BechAddr32, Option } from "lib/types"; interface RelatedProposalsTableProps { diff --git a/src/lib/pages/deploy/index.tsx b/src/lib/pages/deploy/index.tsx index 24e39b446..ff0c2ede9 100644 --- a/src/lib/pages/deploy/index.tsx +++ b/src/lib/pages/deploy/index.tsx @@ -17,7 +17,7 @@ import { Loading } from "lib/components/Loading"; import { Stepper } from "lib/components/stepper"; import { UserDocsLink } from "lib/components/UserDocsLink"; import WasmPageContainer from "lib/components/WasmPageContainer"; -import { useUploadAccessParams } from "lib/services/wasm/proposal"; +import { useUploadAccessParams } from "lib/services/proposal"; import { AccessConfigPermission } from "lib/types"; const getAlertContent = ( diff --git a/src/lib/pages/migrate/components/MigrateOptions.tsx b/src/lib/pages/migrate/components/MigrateOptions.tsx index 31c5c3d08..d9f741329 100644 --- a/src/lib/pages/migrate/components/MigrateOptions.tsx +++ b/src/lib/pages/migrate/components/MigrateOptions.tsx @@ -4,7 +4,7 @@ import { useCelatoneApp, useCurrentChain } from "lib/app-provider"; import { ButtonCard } from "lib/components/ButtonCard"; import { CustomIcon } from "lib/components/icon"; import { UserDocsLink } from "lib/components/UserDocsLink"; -import type { UploadAccess } from "lib/services/wasm/proposal"; +import type { UploadAccess } from "lib/services/proposal"; import type { Option } from "lib/types"; import { AccessConfigPermission } from "lib/types"; import { resolvePermission } from "lib/utils"; diff --git a/src/lib/pages/migrate/index.tsx b/src/lib/pages/migrate/index.tsx index e7dec26b7..f4cf02b47 100644 --- a/src/lib/pages/migrate/index.tsx +++ b/src/lib/pages/migrate/index.tsx @@ -18,7 +18,7 @@ import { Stepper } from "lib/components/stepper"; import WasmPageContainer from "lib/components/WasmPageContainer"; import { useUploadCode } from "lib/hooks"; import { useContractDetailByContractAddress } from "lib/services/contractService"; -import { useUploadAccessParams } from "lib/services/wasm/proposal"; +import { useUploadAccessParams } from "lib/services/proposal"; import type { BechAddr32 } from "lib/types"; import { getFirstQueryParam } from "lib/utils"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx index e73643138..25e3a417e 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx @@ -3,7 +3,7 @@ import { Button, Flex } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { TableTitle } from "lib/components/table"; -import type { ProposalAnswerCountsResponse } from "lib/services/wasm/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; import type { Option } from "lib/types"; import { ProposalVotesTable } from "./votes-table"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx index 9199b59e3..66b87bf00 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx @@ -3,7 +3,7 @@ import { Button, Flex } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { TableTitle } from "lib/components/table"; -import type { ProposalAnswerCountsResponse } from "lib/services/wasm/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; import type { Option } from "lib/types"; import { ValidatorVotesTable } from "./validator-votes-table"; 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 02b0c6f31..a8b236d27 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 @@ -15,7 +15,7 @@ import { AmpEvent, track } from "lib/amplitude"; import { useMobile } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { TableTitle } from "lib/components/table"; -import { useProposalAnswerCounts } from "lib/services/wasm/proposal"; +import { useProposalAnswerCounts } from "lib/services/proposal"; import { scrollToComponent, scrollYPosition } from "lib/utils"; import { ProposalVotesPanel } from "./ProposalVotesPanel"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx index 1ed3fef50..00f017d10 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx @@ -12,8 +12,8 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { useDebounce } from "lib/hooks"; -import type { ProposalAnswerCountsResponse } from "lib/services/wasm/proposal"; -import { useProposalValidatorVotes } from "lib/services/wasm/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; +import { useProposalValidatorVotes } from "lib/services/proposal"; import { ProposalVoteType } from "lib/types"; import type { Option, ProposalValidatorVote } from "lib/types"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx index 7e8fb55cd..bda6bc762 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx @@ -12,8 +12,8 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { useDebounce } from "lib/hooks"; -import type { ProposalAnswerCountsResponse } from "lib/services/wasm/proposal"; -import { useProposalVotes } from "lib/services/wasm/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; +import { useProposalVotes } from "lib/services/proposal"; import { ProposalVoteType } from "lib/types"; import type { Option, ProposalVote } from "lib/types"; diff --git a/src/lib/pages/proposal-details/data.ts b/src/lib/pages/proposal-details/data.ts index 7001c0d72..182eb5333 100644 --- a/src/lib/pages/proposal-details/data.ts +++ b/src/lib/pages/proposal-details/data.ts @@ -1,7 +1,7 @@ import { useMobile } from "lib/app-provider"; import { useAssetInfos } from "lib/services/assetService"; import { useMovePoolInfos } from "lib/services/move"; -import { useProposalData, useProposalParams } from "lib/services/wasm/proposal"; +import { useProposalData, useProposalParams } from "lib/services/proposal"; import type { Nullable, Option, ProposalData, ProposalParams } from "lib/types"; import { coinToTokenWithValue, compareTokenWithValues } from "lib/utils"; diff --git a/src/lib/pages/proposal-details/index.tsx b/src/lib/pages/proposal-details/index.tsx index bc60c1941..545aa0ef2 100644 --- a/src/lib/pages/proposal-details/index.tsx +++ b/src/lib/pages/proposal-details/index.tsx @@ -9,7 +9,7 @@ import { Loading } from "lib/components/Loading"; import PageContainer from "lib/components/PageContainer"; import { ErrorFetching, InvalidState } from "lib/components/state"; import { UserDocsLink } from "lib/components/UserDocsLink"; -import { useProposalVotesInfo } from "lib/services/wasm/proposal"; +import { useProposalVotesInfo } from "lib/services/proposal"; import { ProposalOverview, ProposalTop, VoteDetails } from "./components"; import { useDerivedProposalData, useDerivedProposalParams } from "./data"; diff --git a/src/lib/pages/proposal/components/InitialDeposit.tsx b/src/lib/pages/proposal/components/InitialDeposit.tsx index e00cdd471..cd6d00693 100644 --- a/src/lib/pages/proposal/components/InitialDeposit.tsx +++ b/src/lib/pages/proposal/components/InitialDeposit.tsx @@ -1,6 +1,6 @@ import { Box, Heading, Text } from "@chakra-ui/react"; -import type { GovParams } from "lib/services/wasm/proposal"; +import type { GovParams } from "lib/services/proposal"; import type { Option } from "lib/types"; import { formatSeconds } from "lib/utils"; diff --git a/src/lib/pages/proposal/store-code/index.tsx b/src/lib/pages/proposal/store-code/index.tsx index 41267336d..ccf319f38 100644 --- a/src/lib/pages/proposal/store-code/index.tsx +++ b/src/lib/pages/proposal/store-code/index.tsx @@ -54,7 +54,7 @@ import { InstantiatePermissionRadio } from "lib/components/upload/InstantiatePer import { SimulateMessageRender } from "lib/components/upload/SimulateMessageRender"; import { UploadCard } from "lib/components/upload/UploadCard"; import { useGetMaxLengthError, useTxBroadcast } from "lib/hooks"; -import { useGovParams } from "lib/services/wasm/proposal"; +import { useGovParams } from "lib/services/proposal"; import type { BechAddr, SimulateStatus, UploadSectionState } from "lib/types"; import { AccessConfigPermission, AccessType } from "lib/types"; import { diff --git a/src/lib/pages/proposal/whitelist/index.tsx b/src/lib/pages/proposal/whitelist/index.tsx index 5efd1ecbc..9641f2799 100644 --- a/src/lib/pages/proposal/whitelist/index.tsx +++ b/src/lib/pages/proposal/whitelist/index.tsx @@ -43,7 +43,7 @@ import { CustomIcon } from "lib/components/icon"; import PageContainer from "lib/components/PageContainer"; import { StickySidebar } from "lib/components/StickySidebar"; import { useGetMaxLengthError, useTxBroadcast } from "lib/hooks"; -import { useGovParams } from "lib/services/wasm/proposal"; +import { useGovParams } from "lib/services/proposal"; import type { BechAddr } from "lib/types"; import { AccessConfigPermission } from "lib/types"; import { composeSubmitWhitelistProposalMsg, getAmountToVote } from "lib/utils"; diff --git a/src/lib/pages/proposals/components/ProposalTypeFilter.tsx b/src/lib/pages/proposals/components/ProposalTypeFilter.tsx index 45ac97eef..7f211093b 100644 --- a/src/lib/pages/proposals/components/ProposalTypeFilter.tsx +++ b/src/lib/pages/proposals/components/ProposalTypeFilter.tsx @@ -18,7 +18,7 @@ import { FilterInput, } from "lib/components/filter"; import { CustomIcon } from "lib/components/icon"; -import { useProposalTypes } from "lib/services/wasm/proposal"; +import { useProposalTypes } from "lib/services/proposal"; import type { ProposalType } from "lib/types"; import { ProposalTypeCosmos } from "lib/types"; diff --git a/src/lib/pages/proposals/components/ProposalsTableFull.tsx b/src/lib/pages/proposals/components/ProposalsTableFull.tsx index 9ee0c6577..6f593b290 100644 --- a/src/lib/pages/proposals/components/ProposalsTableFull.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableFull.tsx @@ -11,7 +11,7 @@ import { EmptyState, ErrorFetching } from "lib/components/state"; import { ProposalsTable } from "lib/components/table"; import { Tooltip } from "lib/components/Tooltip"; import { useDebounce } from "lib/hooks"; -import { useProposals } from "lib/services/wasm/proposal"; +import { useProposals } from "lib/services/proposal"; import type { BechAddr20, Option, diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx index b0c44cab0..201b00ed2 100644 --- a/src/lib/pages/proposals/components/ProposalsTableLite.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -11,7 +11,7 @@ import { mapProposalStatusLcdToProposalStatus, useProposalDataLcd, useProposalsLcd, -} from "lib/services/wasm/proposal"; +} from "lib/services/proposal"; import { ProposalStatusLcd } from "lib/types"; export const ProposalsTableLite = () => { diff --git a/src/lib/pages/stored-codes/index.tsx b/src/lib/pages/stored-codes/index.tsx index 584f649e2..b4446da60 100644 --- a/src/lib/pages/stored-codes/index.tsx +++ b/src/lib/pages/stored-codes/index.tsx @@ -18,7 +18,7 @@ import { MyStoredCodesTable } from "lib/components/table"; import { UserDocsLink } from "lib/components/UserDocsLink"; import type { PermissionFilterValue } from "lib/hooks"; import { useMyCodesData } from "lib/model/code"; -import { useUploadAccessParams } from "lib/services/wasm/proposal"; +import { useUploadAccessParams } from "lib/services/proposal"; import { AccessConfigPermission } from "lib/types"; import { ProposalButton } from "./components/ProposalButton"; diff --git a/src/lib/pages/upload/upload.tsx b/src/lib/pages/upload/upload.tsx index 7d9a01a75..90bf8d525 100644 --- a/src/lib/pages/upload/upload.tsx +++ b/src/lib/pages/upload/upload.tsx @@ -13,7 +13,7 @@ import { UploadSection } from "lib/components/upload/UploadSection"; import { UserDocsLink } from "lib/components/UserDocsLink"; import WasmPageContainer from "lib/components/WasmPageContainer"; import { useUploadCode } from "lib/hooks"; -import { useUploadAccessParams } from "lib/services/wasm/proposal"; +import { useUploadAccessParams } from "lib/services/proposal"; import { AccessConfigPermission } from "lib/types"; export const Upload = ({ diff --git a/src/lib/services/move/module.ts b/src/lib/services/move/module.ts index d50747ad0..679beb31a 100644 --- a/src/lib/services/move/module.ts +++ b/src/lib/services/move/module.ts @@ -1,8 +1,8 @@ import axios from "axios"; import { z } from "zod"; +import { zProposal, zProposalsResponseItem } from "../proposal"; import { zTxsResponseItem } from "../tx"; -import { zProposal, zProposalsResponseItem } from "../wasm/proposal"; import type { AbiFormData, Addr, diff --git a/src/lib/services/proposal/api.ts b/src/lib/services/proposal/api.ts new file mode 100644 index 000000000..2d379cb85 --- /dev/null +++ b/src/lib/services/proposal/api.ts @@ -0,0 +1,199 @@ +import axios from "axios"; + +import { zProposalType } from "lib/types"; +import type { + BechAddr, + BechAddr20, + BechAddr32, + Coin, + Option, + ProposalParams, + ProposalStatus, + ProposalType, + ProposalValidatorVote, + ProposalVotesInfo, + ProposalVoteType, +} from "lib/types"; +import { parseWithError, snakeToCamel } from "lib/utils"; + +import { + zProposalAnswerCountsResponse, + zProposalDataResponse, + zProposalParamsResponse, + zProposalsResponse, + zProposalVotesInfoResponse, + zProposalVotesResponse, + zRelatedProposalsResponse, +} from "./types"; +import type { + DepositParams, + DepositParamsInternal, + ProposalAnswerCountsResponse, + ProposalDataResponse, + ProposalsResponse, + ProposalValidatorVotesResponse, + ProposalVotesResponse, + RelatedProposalsResponse, + UploadAccess, + VotingParams, + VotingParamsInternal, +} from "./types"; + +export const fetchGovDepositParams = ( + lcdEndpoint: string +): Promise => + axios + .get<{ + deposit_params: DepositParams; + }>(`${lcdEndpoint}/cosmos/gov/v1beta1/params/deposit`) + .then(({ data }) => snakeToCamel(data.deposit_params)); + +export const fetchGovVotingParams = ( + lcdEndpoint: string +): Promise => + axios + .get<{ + voting_params: VotingParams; + }>(`${lcdEndpoint}/cosmos/gov/v1beta1/params/voting`) + .then(({ data }) => snakeToCamel(data.voting_params)); + +export const fetchGovUploadAccessParams = async ( + lcdEndpoint: string +): Promise => + axios.get(`${lcdEndpoint}/upload_access`).then(({ data }) => data); + +export const getProposalParams = async ( + endpoint: string +): Promise> => + axios + .get(`${endpoint}/params`) + .then(({ data }) => parseWithError(zProposalParamsResponse, data)); + +export const getProposalTypes = async (endpoint: string) => + axios + .get(`${endpoint}/types`) + .then(({ data }) => parseWithError(zProposalType.array(), data)); + +export const getProposals = async ( + endpoint: string, + limit: number, + offset: number, + proposer: Option, + statuses: ProposalStatus[], + types: ProposalType[], + search: string +): Promise => + axios + .get(`${endpoint}`, { + params: { + limit, + offset, + proposer, + statuses: statuses.join(","), + types: types.join(","), + search, + }, + }) + .then(({ data }) => parseWithError(zProposalsResponse, data)); + +export const getProposalsByAddress = async ( + endpoint: string, + address: BechAddr, + limit: number, + offset: number +): Promise => + axios + .get(`${endpoint}/${encodeURIComponent(address)}/proposals`, { + params: { + limit, + offset, + }, + }) + .then(({ data }) => parseWithError(zProposalsResponse, data)); + +export const getRelatedProposalsByContractAddress = async ( + endpoint: string, + contractAddress: BechAddr32, + limit: number, + offset: number +): Promise => + axios + .get( + `${endpoint}/${encodeURIComponent(contractAddress)}/related-proposals`, + { + params: { + limit, + offset, + }, + } + ) + .then(({ data }) => parseWithError(zRelatedProposalsResponse, data)); + +export const getProposalData = async ( + endpoint: string, + id: number +): Promise => + axios + .get(`${endpoint}/${encodeURIComponent(id)}/info`) + .then(({ data }) => parseWithError(zProposalDataResponse, data)); + +export const getProposalVotesInfo = async ( + endpoint: string, + id: number +): Promise => + axios + .get(`${endpoint}/${encodeURIComponent(id)}/votes-info`) + .then(({ data }) => parseWithError(zProposalVotesInfoResponse, data)); + +export const getProposalVotes = async ( + endpoint: string, + id: number, + limit: number, + offset: number, + answer: ProposalVoteType, + search: string +): Promise => { + let url = `${endpoint}/${encodeURIComponent(id)}/votes?limit=${limit}&offset=${offset}`; + url = url.concat(search ? `&search=${encodeURIComponent(search)}` : ""); + url = url.concat(answer ? `&answer=${encodeURIComponent(answer)}` : ""); + + return axios + .get(url) + .then(({ data }) => parseWithError(zProposalVotesResponse, data)); +}; + +export const getProposalValidatorVotes = async ( + endpoint: string, + id: number, + limit: number, + offset: number, + answer: ProposalVoteType, + search: string +): Promise => + axios + .get(`${endpoint}/${encodeURIComponent(id)}/validator-votes`, { + params: { + limit, + offset, + answer, + search, + }, + }) + .then(({ data }) => { + const parsed = parseWithError(zProposalVotesResponse, data); + return { + items: parsed.items.map((item, idx) => ({ + ...item, + rank: idx + 1, + })), + total: parsed.total, + }; + }); + +export const getProposalAnswerCounts = async ( + endpoint: string, + id: number +): Promise => + axios + .get(`${endpoint}/${encodeURIComponent(id)}/answer-counts`) + .then(({ data }) => parseWithError(zProposalAnswerCountsResponse, data)); diff --git a/src/lib/services/wasm/proposal/helper.ts b/src/lib/services/proposal/helpers.ts similarity index 100% rename from src/lib/services/wasm/proposal/helper.ts rename to src/lib/services/proposal/helpers.ts diff --git a/src/lib/services/wasm/proposal/api.ts b/src/lib/services/proposal/index.ts similarity index 59% rename from src/lib/services/wasm/proposal/api.ts rename to src/lib/services/proposal/index.ts index 6a386df4d..ed1a29cb6 100644 --- a/src/lib/services/wasm/proposal/api.ts +++ b/src/lib/services/proposal/index.ts @@ -1,12 +1,15 @@ +import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; import type { UseQueryOptions, UseQueryResult } from "@tanstack/react-query"; -import { useQuery } from "@tanstack/react-query"; -import axios from "axios"; import { useCallback } from "react"; -import { CELATONE_QUERY_KEYS, useBaseApiRoute } from "lib/app-provider"; -import { useAssetInfos } from "lib/services/assetService"; -import { useMovePoolInfos } from "lib/services/move/poolService"; -import { big, zProposalType } from "lib/types"; +import { useAssetInfos } from "../assetService"; +import { useMovePoolInfos } from "../move/poolService"; +import { + CELATONE_QUERY_KEYS, + useBaseApiRoute, + useLCDEndpoint, +} from "lib/app-provider"; +import { big } from "lib/types"; import type { BechAddr, BechAddr20, @@ -15,8 +18,8 @@ import type { Option, ProposalParams, ProposalStatus, + ProposalStatusLcd, ProposalType, - ProposalValidatorVote, ProposalVotesInfo, ProposalVoteType, Token, @@ -26,57 +29,37 @@ import { deexponentify, formatTokenWithValue, getTokenLabel, - parseWithError, - snakeToCamel, } from "lib/utils"; import { - zProposalAnswerCountsResponse, - zProposalDataResponse, - zProposalParamsResponse, - zProposalsResponse, - zProposalVotesInfoResponse, - zProposalVotesResponse, - zRelatedProposalsResponse, -} from "./types"; + fetchGovDepositParams, + fetchGovUploadAccessParams, + fetchGovVotingParams, + getProposalAnswerCounts, + getProposalData, + getProposalParams, + getProposals, + getProposalsByAddress, + getProposalTypes, + getProposalValidatorVotes, + getProposalVotes, + getProposalVotesInfo, + getRelatedProposalsByContractAddress, +} from "./api"; +import { getProposalDataLcd, getProposalsLcd } from "./lcd"; import type { - DepositParams, - DepositParamsInternal, GovParams, ProposalAnswerCountsResponse, ProposalDataResponse, ProposalsResponse, + ProposalsResponseItemLcd, + ProposalsResponseLcd, ProposalValidatorVotesResponse, ProposalVotesResponse, RelatedProposalsResponse, UploadAccess, - VotingParams, - VotingParamsInternal, } from "./types"; -const fetchGovDepositParams = ( - lcdEndpoint: string -): Promise => - axios - .get<{ - deposit_params: DepositParams; - }>(`${lcdEndpoint}/cosmos/gov/v1beta1/params/deposit`) - .then(({ data }) => snakeToCamel(data.deposit_params)); - -const fetchGovVotingParams = ( - lcdEndpoint: string -): Promise => - axios - .get<{ - voting_params: VotingParams; - }>(`${lcdEndpoint}/cosmos/gov/v1beta1/params/voting`) - .then(({ data }) => snakeToCamel(data.voting_params)); - -const fetchGovUploadAccessParams = async ( - lcdEndpoint: string -): Promise => - axios.get(`${lcdEndpoint}/upload_access`).then(({ data }) => data); - export const useGovParams = (): UseQueryResult => { const lcdEndpoint = useBaseApiRoute("rest"); const cosmwasmEndpoint = useBaseApiRoute("cosmwasm"); @@ -146,13 +129,6 @@ export const useUploadAccessParams = (): UseQueryResult => { ); }; -const getProposalParams = async ( - endpoint: string -): Promise> => - axios - .get(`${endpoint}/params`) - .then(({ data }) => parseWithError(zProposalParamsResponse, data)); - export const useProposalParams = () => { const endpoint = useBaseApiRoute("proposals"); return useQuery>( @@ -162,11 +138,6 @@ export const useProposalParams = () => { ); }; -const getProposalTypes = async (endpoint: string) => - axios - .get(`${endpoint}/types`) - .then(({ data }) => parseWithError(zProposalType.array(), data)); - export const useProposalTypes = () => { const endpoint = useBaseApiRoute("proposals"); return useQuery( @@ -176,28 +147,6 @@ export const useProposalTypes = () => { ); }; -const getProposals = async ( - endpoint: string, - limit: number, - offset: number, - proposer: Option, - statuses: ProposalStatus[], - types: ProposalType[], - search: string -): Promise => - axios - .get(`${endpoint}`, { - params: { - limit, - offset, - proposer, - statuses: statuses.join(","), - types: types.join(","), - search, - }, - }) - .then(({ data }) => parseWithError(zProposalsResponse, data)); - export const useProposals = ( limit: number, offset: number, @@ -234,20 +183,27 @@ export const useProposals = ( ); }; -const getProposalsByAddress = async ( - endpoint: string, - address: BechAddr, - limit: number, - offset: number -): Promise => - axios - .get(`${endpoint}/${encodeURIComponent(address)}/proposals`, { - params: { - limit, - offset, - }, - }) - .then(({ data }) => parseWithError(zProposalsResponse, data)); +export const useProposalsLcd = ( + status?: Omit +) => { + const lcdEndpoint = useLCDEndpoint(); + + const query = useInfiniteQuery( + [CELATONE_QUERY_KEYS.PROPOSALS_LCD, lcdEndpoint, status], + ({ pageParam }) => getProposalsLcd(lcdEndpoint, pageParam, status), + { + getNextPageParam: (lastPage) => lastPage.pagination.nextKey ?? undefined, + refetchOnWindowFocus: false, + } + ); + + const { data, ...rest } = query; + + return { + data: data?.pages.flatMap((page) => page.proposals), + ...rest, + }; +}; export const useProposalsByAddress = ( address: BechAddr, @@ -269,24 +225,6 @@ export const useProposalsByAddress = ( ); }; -const getRelatedProposalsByContractAddress = async ( - endpoint: string, - contractAddress: BechAddr32, - limit: number, - offset: number -): Promise => - axios - .get( - `${endpoint}/${encodeURIComponent(contractAddress)}/related-proposals`, - { - params: { - limit, - offset, - }, - } - ) - .then(({ data }) => parseWithError(zRelatedProposalsResponse, data)); - export const useRelatedProposalsByContractAddress = ( contractAddress: BechAddr32, offset: number, @@ -316,14 +254,6 @@ export const useRelatedProposalsByContractAddress = ( ); }; -const getProposalData = async ( - endpoint: string, - id: number -): Promise => - axios - .get(`${endpoint}/${encodeURIComponent(id)}/info`) - .then(({ data }) => parseWithError(zProposalDataResponse, data)); - export const useProposalData = (id: number, enabled = true) => { const endpoint = useBaseApiRoute("proposals"); @@ -334,13 +264,19 @@ export const useProposalData = (id: number, enabled = true) => { ); }; -const getProposalVotesInfo = async ( - endpoint: string, - id: number -): Promise => - axios - .get(`${endpoint}/${encodeURIComponent(id)}/votes-info`) - .then(({ data }) => parseWithError(zProposalVotesInfoResponse, data)); +export const useProposalDataLcd = (id: string, enabled = true) => { + const lcdEndpoint = useLCDEndpoint(); + + return useQuery( + [CELATONE_QUERY_KEYS.PROPOSAL_DATA_LCD, lcdEndpoint, id], + async () => getProposalDataLcd(lcdEndpoint, id), + { + retry: 1, + refetchOnWindowFocus: false, + enabled, + } + ); +}; export const useProposalVotesInfo = (id: number) => { const endpoint = useBaseApiRoute("proposals"); @@ -352,23 +288,6 @@ export const useProposalVotesInfo = (id: number) => { ); }; -const getProposalVotes = async ( - endpoint: string, - id: number, - limit: number, - offset: number, - answer: ProposalVoteType, - search: string -): Promise => { - let url = `${endpoint}/${encodeURIComponent(id)}/votes?limit=${limit}&offset=${offset}`; - url = url.concat(search ? `&search=${encodeURIComponent(search)}` : ""); - url = url.concat(answer ? `&answer=${encodeURIComponent(answer)}` : ""); - - return axios - .get(url) - .then(({ data }) => parseWithError(zProposalVotesResponse, data)); -}; - export const useProposalVotes = ( id: number, limit: number, @@ -394,34 +313,6 @@ export const useProposalVotes = ( ); }; -const getProposalValidatorVotes = async ( - endpoint: string, - id: number, - limit: number, - offset: number, - answer: ProposalVoteType, - search: string -): Promise => - axios - .get(`${endpoint}/${encodeURIComponent(id)}/validator-votes`, { - params: { - limit, - offset, - answer, - search, - }, - }) - .then(({ data }) => { - const parsed = parseWithError(zProposalVotesResponse, data); - return { - items: parsed.items.map((item, idx) => ({ - ...item, - rank: idx + 1, - })), - total: parsed.total, - }; - }); - export const useProposalValidatorVotes = ( id: number, limit: number, @@ -451,14 +342,6 @@ export const useProposalValidatorVotes = ( ); }; -const getProposalAnswerCounts = async ( - endpoint: string, - id: number -): Promise => - axios - .get(`${endpoint}/${encodeURIComponent(id)}/answer-counts`) - .then(({ data }) => parseWithError(zProposalAnswerCountsResponse, data)); - export const useProposalAnswerCounts = ( id: number, validatorOnly = false @@ -471,3 +354,6 @@ export const useProposalAnswerCounts = ( { retry: 1, refetchOnWindowFocus: false } ); }; + +export * from "./types"; +export * from "./helpers"; diff --git a/src/lib/services/proposal/lcd.ts b/src/lib/services/proposal/lcd.ts new file mode 100644 index 000000000..a13fd008d --- /dev/null +++ b/src/lib/services/proposal/lcd.ts @@ -0,0 +1,35 @@ +import axios from "axios"; + +import type { Option } from "lib/types"; +import { ProposalStatusLcd } from "lib/types"; +import { parseWithError } from "lib/utils"; + +import type { ProposalsResponseItemLcd, ProposalsResponseLcd } from "./types"; +import { zProposalsResponseItemLcd, zProposalsResponseLcd } from "./types"; + +export const getProposalsLcd = async ( + endpoint: string, + paginationKey: Option, + status?: Omit +): Promise => + axios + .get(`${endpoint}/cosmos/gov/v1/proposals`, { + params: { + "pagination.limit": 10, + "pagination.reverse": true, + "pagination.key": paginationKey, + ...(status && + status !== ProposalStatusLcd.ALL && { proposal_status: status }), + }, + }) + .then(({ data }) => parseWithError(zProposalsResponseLcd, data)); + +export const getProposalDataLcd = async ( + endpoint: string, + id: string +): Promise => + axios + .get(`${endpoint}/cosmos/gov/v1/proposals/${id}`) + .then(({ data }) => + parseWithError(zProposalsResponseItemLcd, data.proposal) + ); diff --git a/src/lib/services/wasm/proposal/types.ts b/src/lib/services/proposal/types.ts similarity index 99% rename from src/lib/services/wasm/proposal/types.ts rename to src/lib/services/proposal/types.ts index 6343f5736..e5de3e0dd 100644 --- a/src/lib/services/wasm/proposal/types.ts +++ b/src/lib/services/proposal/types.ts @@ -28,7 +28,7 @@ import type { import { zPagination } from "lib/types/rest"; import { parseTxHash, snakeToCamel } from "lib/utils"; -import { mapProposalStatusLcdToProposalStatus } from "./helper"; +import { mapProposalStatusLcdToProposalStatus } from "./helpers"; export interface MinDeposit { amount: U>; diff --git a/src/lib/services/searchService.ts b/src/lib/services/searchService.ts index 9fadfac33..d030d423e 100644 --- a/src/lib/services/searchService.ts +++ b/src/lib/services/searchService.ts @@ -25,10 +25,10 @@ import { useModuleByAddressLcd } from "./move/moduleService"; import { useAddressByICNSName, useICNSNamesByAddress } from "./nameService"; import type { ICNSNamesResponse } from "./ns"; import { usePoolByPoolId } from "./poolService"; +import { useProposalData } from "./proposal"; import { useTxData } from "./tx"; import { useValidatorData } from "./validatorService"; import { useCodeDataByCodeId } from "./wasm/code"; -import { useProposalData } from "./wasm/proposal"; export type SearchResultType = | "Code ID" diff --git a/src/lib/services/wasm/proposal/index.ts b/src/lib/services/wasm/proposal/index.ts deleted file mode 100644 index ebb87e4ff..000000000 --- a/src/lib/services/wasm/proposal/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./api"; -export * from "./lcd"; -export * from "./types"; -export * from "./helper"; diff --git a/src/lib/services/wasm/proposal/lcd.ts b/src/lib/services/wasm/proposal/lcd.ts deleted file mode 100644 index 658376ae6..000000000 --- a/src/lib/services/wasm/proposal/lcd.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; -import axios from "axios"; - -import { CELATONE_QUERY_KEYS, useLCDEndpoint } from "lib/app-provider"; -import type { Option } from "lib/types"; -import { ProposalStatusLcd } from "lib/types"; -import { parseWithError } from "lib/utils"; - -import type { ProposalsResponseItemLcd, ProposalsResponseLcd } from "./types"; -import { zProposalsResponseItemLcd, zProposalsResponseLcd } from "./types"; - -const getProposalsLcd = async ( - endpoint: string, - paginationKey: Option, - status?: Omit -): Promise => - axios - .get(`${endpoint}/cosmos/gov/v1/proposals`, { - params: { - "pagination.limit": 10, - "pagination.reverse": true, - "pagination.key": paginationKey, - ...(status && - status !== ProposalStatusLcd.ALL && { proposal_status: status }), - }, - }) - .then(({ data }) => parseWithError(zProposalsResponseLcd, data)); - -export const useProposalsLcd = ( - status?: Omit -) => { - const lcdEndpoint = useLCDEndpoint(); - - const query = useInfiniteQuery( - [CELATONE_QUERY_KEYS.PROPOSALS_LCD, lcdEndpoint, status], - ({ pageParam }) => getProposalsLcd(lcdEndpoint, pageParam, status), - { - getNextPageParam: (lastPage) => lastPage.pagination.nextKey ?? undefined, - refetchOnWindowFocus: false, - } - ); - - const { data, ...rest } = query; - - return { - data: data?.pages.flatMap((page) => page.proposals), - ...rest, - }; -}; - -const getProposalDataLcd = async ( - endpoint: string, - id: string -): Promise => - axios - .get(`${endpoint}/cosmos/gov/v1/proposals/${id}`) - .then(({ data }) => - parseWithError(zProposalsResponseItemLcd, data.proposal) - ); - -export const useProposalDataLcd = (id: string, enabled = true) => { - const lcdEndpoint = useLCDEndpoint(); - - return useQuery( - [CELATONE_QUERY_KEYS.PROPOSAL_DATA_LCD, lcdEndpoint, id], - async () => getProposalDataLcd(lcdEndpoint, id), - { - retry: 1, - refetchOnWindowFocus: false, - enabled, - } - ); -}; diff --git a/src/lib/utils/proposal.ts b/src/lib/utils/proposal.ts index ba46c65e9..ddc60a49e 100644 --- a/src/lib/utils/proposal.ts +++ b/src/lib/utils/proposal.ts @@ -1,6 +1,6 @@ import type { Coin } from "@cosmjs/stargate"; -import type { MinDeposit } from "lib/services/wasm/proposal"; +import type { MinDeposit } from "lib/services/proposal"; import { big } from "lib/types"; import type { Option } from "lib/types"; From ea6b17949507cfbf17a8267a24a11210380a59ed Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Wed, 8 May 2024 15:49:00 +0700 Subject: [PATCH 07/27] feat(components): update proposals table lite according to ac test --- src/lib/components/forms/SelectInput.tsx | 41 ++++++++++++------- .../table/proposals/ProposalsTable.tsx | 7 +++- .../proposals/ProposalsTableMobileCard.tsx | 6 +++ .../components/ProposalsTableLite.tsx | 21 ++++++---- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/lib/components/forms/SelectInput.tsx b/src/lib/components/forms/SelectInput.tsx index 1dced5f33..d711f1981 100644 --- a/src/lib/components/forms/SelectInput.tsx +++ b/src/lib/components/forms/SelectInput.tsx @@ -21,6 +21,7 @@ interface SelectInputProps { formLabel?: string; options: { label: string; + chipContainerComponent?: JSX.Element; value: T; disabled: boolean; icon?: IconKeys; @@ -164,21 +165,31 @@ export const SelectInput = ({ }} overflow="hidden" > - {options.map(({ label, value, disabled, icon, iconColor, image }) => ( - { - setSelected(label); - onChange(value); - onClose(); - }} - disabled={disabled} - > - {image} - {icon && } - {label} - - ))} + {options.map( + ({ + label, + value, + disabled, + icon, + iconColor, + image, + chipContainerComponent, + }) => ( + { + setSelected(label); + onChange(value); + onClose(); + }} + disabled={disabled} + > + {image && {image}} + {icon && } + {chipContainerComponent ?? label} + + ) + )} {helperTextComponent && ( { + const tier = useTierConfig(); const isMobile = useMobile(); if (isLoading) return ; if (!proposals?.length) return emptyState; const templateColumns = - "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 180px 160px"; + tier === "full" + ? "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 180px 160px" + : "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 160px"; const boxShadow = "16px 0 32px -10px"; return isMobile ? ( diff --git a/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx b/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx index 23ae54448..30f91ac3c 100644 --- a/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx +++ b/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx @@ -63,6 +63,12 @@ export const ProposalsTableMobileCard = ({ status={proposal.status} /> + {tier === "lite" && ( + + + + + )} } bottomContent={ diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx index 201b00ed2..eef5a6c17 100644 --- a/src/lib/pages/proposals/components/ProposalsTableLite.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -5,7 +5,7 @@ import { SelectInput } from "lib/components/forms"; import InputWithIcon from "lib/components/InputWithIcon"; import { LoadNext } from "lib/components/LoadNext"; import { EmptyState, ErrorFetching } from "lib/components/state"; -import { ProposalsTable } from "lib/components/table"; +import { ProposalsTable, StatusChip } from "lib/components/table"; import { useDebounce } from "lib/hooks"; import { mapProposalStatusLcdToProposalStatus, @@ -44,19 +44,24 @@ export const ProposalsTableLite = () => { proposals && proposals.length > 1; - const options = Object.values(ProposalStatusLcd).map((status) => ({ - label: mapProposalStatusLcdToProposalStatus(status), - value: status, - disabled: false, - })); + const options = Object.values(ProposalStatusLcd).map((status) => { + const mapStatus = mapProposalStatusLcdToProposalStatus(status); + + return { + label: status === ProposalStatusLcd.ALL ? "All Status" : mapStatus, + value: status, + disabled: false, + chipContainerComponent: , + }; + }); return ( <> Date: Wed, 8 May 2024 16:51:25 +0700 Subject: [PATCH 08/27] feat(components): update proposals table lite according to ac test --- src/lib/components/forms/SelectInput.tsx | 30 ++++++++++++++++--- .../components/ProposalsTableLite.tsx | 2 +- src/lib/types/proposal.ts | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/lib/components/forms/SelectInput.tsx b/src/lib/components/forms/SelectInput.tsx index d711f1981..146ce72e8 100644 --- a/src/lib/components/forms/SelectInput.tsx +++ b/src/lib/components/forms/SelectInput.tsx @@ -1,4 +1,5 @@ import { + Box, Flex, Input, InputGroup, @@ -133,12 +134,26 @@ export const SelectInput = ({ /> )} + {selectedOption?.chipContainerComponent && ( + + {selectedOption.chipContainerComponent} + + )} ({ }} disabled={disabled} > - {image && {image}} - {icon && } - {chipContainerComponent ?? label} + + + {image && {image}} + {icon && } + {chipContainerComponent ?? label} + + {selected === label && chipContainerComponent && ( + + )} + ) )} diff --git a/src/lib/pages/proposals/components/ProposalsTableLite.tsx b/src/lib/pages/proposals/components/ProposalsTableLite.tsx index eef5a6c17..8e64f8379 100644 --- a/src/lib/pages/proposals/components/ProposalsTableLite.tsx +++ b/src/lib/pages/proposals/components/ProposalsTableLite.tsx @@ -48,7 +48,7 @@ export const ProposalsTableLite = () => { const mapStatus = mapProposalStatusLcdToProposalStatus(status); return { - label: status === ProposalStatusLcd.ALL ? "All Status" : mapStatus, + label: mapStatus, value: status, disabled: false, chipContainerComponent: , diff --git a/src/lib/types/proposal.ts b/src/lib/types/proposal.ts index 143d96d85..14a7c25b4 100644 --- a/src/lib/types/proposal.ts +++ b/src/lib/types/proposal.ts @@ -23,7 +23,7 @@ export enum ProposalStatus { export const zProposalStatus = z.nativeEnum(ProposalStatus); export enum ProposalStatusLcd { - ALL = "ALL", + ALL = "ALL_STATUSES", PROPOSAL_STATUS_DEPOSIT_PERIOD = "PROPOSAL_STATUS_DEPOSIT_PERIOD", PROPOSAL_STATUS_VOTING_PERIOD = "PROPOSAL_STATUS_VOTING_PERIOD", PROPOSAL_STATUS_PASSED = "PROPOSAL_STATUS_PASSED", From 0a3389877187a6b97c8e0e7eed57af877be533f0 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Thu, 9 May 2024 10:55:32 +0700 Subject: [PATCH 09/27] fix(components): table width in proposed by col --- src/lib/components/table/proposals/ProposalsTable.tsx | 4 ++-- src/lib/services/proposal/index.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/components/table/proposals/ProposalsTable.tsx b/src/lib/components/table/proposals/ProposalsTable.tsx index 68694ad14..9f673a93a 100644 --- a/src/lib/components/table/proposals/ProposalsTable.tsx +++ b/src/lib/components/table/proposals/ProposalsTable.tsx @@ -26,8 +26,8 @@ export const ProposalsTable = ({ const templateColumns = tier === "full" - ? "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 180px 160px" - : "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 160px"; + ? "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 180px 180px" + : "100px minmax(360px, 2fr) minmax(150px, 1fr) 330px 180px"; const boxShadow = "16px 0 32px -10px"; return isMobile ? ( diff --git a/src/lib/services/proposal/index.ts b/src/lib/services/proposal/index.ts index ed1a29cb6..0c0861302 100644 --- a/src/lib/services/proposal/index.ts +++ b/src/lib/services/proposal/index.ts @@ -7,7 +7,7 @@ import { useMovePoolInfos } from "../move/poolService"; import { CELATONE_QUERY_KEYS, useBaseApiRoute, - useLCDEndpoint, + useLcdEndpoint, } from "lib/app-provider"; import { big } from "lib/types"; import type { @@ -186,7 +186,7 @@ export const useProposals = ( export const useProposalsLcd = ( status?: Omit ) => { - const lcdEndpoint = useLCDEndpoint(); + const lcdEndpoint = useLcdEndpoint(); const query = useInfiniteQuery( [CELATONE_QUERY_KEYS.PROPOSALS_LCD, lcdEndpoint, status], @@ -265,7 +265,7 @@ export const useProposalData = (id: number, enabled = true) => { }; export const useProposalDataLcd = (id: string, enabled = true) => { - const lcdEndpoint = useLCDEndpoint(); + const lcdEndpoint = useLcdEndpoint(); return useQuery( [CELATONE_QUERY_KEYS.PROPOSAL_DATA_LCD, lcdEndpoint, id], From d8dc524ecdb256f69e80d6c32b8e4dce4e2f895e Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Thu, 9 May 2024 14:03:50 +0700 Subject: [PATCH 10/27] feat(types): move proposal type to typse folder --- .../migrate/components/MigrateOptions.tsx | 2 +- .../voting-period/ProposalVotesPanel.tsx | 2 +- .../voting-period/ValidatorVotesPanel.tsx | 2 +- .../validator-votes-table/index.tsx | 2 +- .../voting-period/votes-table/index.tsx | 2 +- .../proposal/components/InitialDeposit.tsx | 2 +- src/lib/services/move/module.ts | 3 +- src/lib/services/proposal/api.ts | 35 +++++++++---------- src/lib/services/proposal/index.ts | 25 +++++++------ src/lib/services/proposal/lcd.ts | 11 ++++-- src/lib/services/types/index.ts | 1 + .../{proposal/types.ts => types/proposal.ts} | 3 +- src/lib/utils/proposal.ts | 2 +- 13 files changed, 47 insertions(+), 45 deletions(-) rename src/lib/services/{proposal/types.ts => types/proposal.ts} (98%) diff --git a/src/lib/pages/migrate/components/MigrateOptions.tsx b/src/lib/pages/migrate/components/MigrateOptions.tsx index d9f741329..f6f776137 100644 --- a/src/lib/pages/migrate/components/MigrateOptions.tsx +++ b/src/lib/pages/migrate/components/MigrateOptions.tsx @@ -4,7 +4,7 @@ import { useCelatoneApp, useCurrentChain } from "lib/app-provider"; import { ButtonCard } from "lib/components/ButtonCard"; import { CustomIcon } from "lib/components/icon"; import { UserDocsLink } from "lib/components/UserDocsLink"; -import type { UploadAccess } from "lib/services/proposal"; +import type { UploadAccess } from "lib/services/types"; import type { Option } from "lib/types"; import { AccessConfigPermission } from "lib/types"; import { resolvePermission } from "lib/utils"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx index 25e3a417e..164c536b0 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/ProposalVotesPanel.tsx @@ -3,7 +3,7 @@ import { Button, Flex } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { TableTitle } from "lib/components/table"; -import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/types"; import type { Option } from "lib/types"; import { ProposalVotesTable } from "./votes-table"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx index 66b87bf00..bc4a3c097 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/ValidatorVotesPanel.tsx @@ -3,7 +3,7 @@ import { Button, Flex } from "@chakra-ui/react"; import { useMobile } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; import { TableTitle } from "lib/components/table"; -import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/types"; import type { Option } from "lib/types"; import { ValidatorVotesTable } from "./validator-votes-table"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx index 00f017d10..17adf6386 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/validator-votes-table/index.tsx @@ -12,8 +12,8 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { useDebounce } from "lib/hooks"; -import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; import { useProposalValidatorVotes } from "lib/services/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/types"; import { ProposalVoteType } from "lib/types"; import type { Option, ProposalValidatorVote } from "lib/types"; diff --git a/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx b/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx index bda6bc762..916bde29e 100644 --- a/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx +++ b/src/lib/pages/proposal-details/components/vote-details/voting-period/votes-table/index.tsx @@ -12,8 +12,8 @@ import { Pagination } from "lib/components/pagination"; import { usePaginator } from "lib/components/pagination/usePaginator"; import { EmptyState, ErrorFetching } from "lib/components/state"; import { useDebounce } from "lib/hooks"; -import type { ProposalAnswerCountsResponse } from "lib/services/proposal"; import { useProposalVotes } from "lib/services/proposal"; +import type { ProposalAnswerCountsResponse } from "lib/services/types"; import { ProposalVoteType } from "lib/types"; import type { Option, ProposalVote } from "lib/types"; diff --git a/src/lib/pages/proposal/components/InitialDeposit.tsx b/src/lib/pages/proposal/components/InitialDeposit.tsx index cd6d00693..60934001a 100644 --- a/src/lib/pages/proposal/components/InitialDeposit.tsx +++ b/src/lib/pages/proposal/components/InitialDeposit.tsx @@ -1,6 +1,6 @@ import { Box, Heading, Text } from "@chakra-ui/react"; -import type { GovParams } from "lib/services/proposal"; +import type { GovParams } from "lib/services/types"; import type { Option } from "lib/types"; import { formatSeconds } from "lib/utils"; diff --git a/src/lib/services/move/module.ts b/src/lib/services/move/module.ts index 95eaef477..39922c477 100644 --- a/src/lib/services/move/module.ts +++ b/src/lib/services/move/module.ts @@ -1,8 +1,7 @@ import axios from "axios"; import { z } from "zod"; -import { zProposal, zProposalsResponseItem } from "../proposal"; -import { zTxsResponseItem } from "../types"; +import { zProposal, zProposalsResponseItem, zTxsResponseItem } from "../types"; import type { AbiFormData, Addr, diff --git a/src/lib/services/proposal/api.ts b/src/lib/services/proposal/api.ts index 2d379cb85..a307a0774 100644 --- a/src/lib/services/proposal/api.ts +++ b/src/lib/services/proposal/api.ts @@ -1,21 +1,5 @@ import axios from "axios"; -import { zProposalType } from "lib/types"; -import type { - BechAddr, - BechAddr20, - BechAddr32, - Coin, - Option, - ProposalParams, - ProposalStatus, - ProposalType, - ProposalValidatorVote, - ProposalVotesInfo, - ProposalVoteType, -} from "lib/types"; -import { parseWithError, snakeToCamel } from "lib/utils"; - import { zProposalAnswerCountsResponse, zProposalDataResponse, @@ -24,7 +8,7 @@ import { zProposalVotesInfoResponse, zProposalVotesResponse, zRelatedProposalsResponse, -} from "./types"; +} from "../types/proposal"; import type { DepositParams, DepositParamsInternal, @@ -37,7 +21,22 @@ import type { UploadAccess, VotingParams, VotingParamsInternal, -} from "./types"; +} from "../types/proposal"; +import { zProposalType } from "lib/types"; +import type { + BechAddr, + BechAddr20, + BechAddr32, + Coin, + Option, + ProposalParams, + ProposalStatus, + ProposalType, + ProposalValidatorVote, + ProposalVotesInfo, + ProposalVoteType, +} from "lib/types"; +import { parseWithError, snakeToCamel } from "lib/utils"; export const fetchGovDepositParams = ( lcdEndpoint: string diff --git a/src/lib/services/proposal/index.ts b/src/lib/services/proposal/index.ts index 0c0861302..e958c2ee0 100644 --- a/src/lib/services/proposal/index.ts +++ b/src/lib/services/proposal/index.ts @@ -4,6 +4,18 @@ import { useCallback } from "react"; import { useAssetInfos } from "../assetService"; import { useMovePoolInfos } from "../move/poolService"; +import type { + GovParams, + ProposalAnswerCountsResponse, + ProposalDataResponse, + ProposalsResponse, + ProposalsResponseItemLcd, + ProposalsResponseLcd, + ProposalValidatorVotesResponse, + ProposalVotesResponse, + RelatedProposalsResponse, + UploadAccess, +} from "../types/proposal"; import { CELATONE_QUERY_KEYS, useBaseApiRoute, @@ -47,18 +59,6 @@ import { getRelatedProposalsByContractAddress, } from "./api"; import { getProposalDataLcd, getProposalsLcd } from "./lcd"; -import type { - GovParams, - ProposalAnswerCountsResponse, - ProposalDataResponse, - ProposalsResponse, - ProposalsResponseItemLcd, - ProposalsResponseLcd, - ProposalValidatorVotesResponse, - ProposalVotesResponse, - RelatedProposalsResponse, - UploadAccess, -} from "./types"; export const useGovParams = (): UseQueryResult => { const lcdEndpoint = useBaseApiRoute("rest"); @@ -355,5 +355,4 @@ export const useProposalAnswerCounts = ( ); }; -export * from "./types"; export * from "./helpers"; diff --git a/src/lib/services/proposal/lcd.ts b/src/lib/services/proposal/lcd.ts index a13fd008d..3822e58b3 100644 --- a/src/lib/services/proposal/lcd.ts +++ b/src/lib/services/proposal/lcd.ts @@ -1,12 +1,17 @@ import axios from "axios"; +import type { + ProposalsResponseItemLcd, + ProposalsResponseLcd, +} from "../types/proposal"; +import { + zProposalsResponseItemLcd, + zProposalsResponseLcd, +} from "../types/proposal"; import type { Option } from "lib/types"; import { ProposalStatusLcd } from "lib/types"; import { parseWithError } from "lib/utils"; -import type { ProposalsResponseItemLcd, ProposalsResponseLcd } from "./types"; -import { zProposalsResponseItemLcd, zProposalsResponseLcd } from "./types"; - export const getProposalsLcd = async ( endpoint: string, paginationKey: Option, diff --git a/src/lib/services/types/index.ts b/src/lib/services/types/index.ts index 4f61d5757..76d30e741 100644 --- a/src/lib/services/types/index.ts +++ b/src/lib/services/types/index.ts @@ -2,3 +2,4 @@ export * from "./block"; export * from "./validator"; export * from "./wasm"; export * from "./tx"; +export * from "./proposal"; diff --git a/src/lib/services/proposal/types.ts b/src/lib/services/types/proposal.ts similarity index 98% rename from src/lib/services/proposal/types.ts rename to src/lib/services/types/proposal.ts index e5de3e0dd..3a8506a78 100644 --- a/src/lib/services/proposal/types.ts +++ b/src/lib/services/types/proposal.ts @@ -1,5 +1,6 @@ import { z } from "zod"; +import { mapProposalStatusLcdToProposalStatus } from "../proposal/helpers"; import { zBechAddr, zBig, @@ -28,8 +29,6 @@ import type { import { zPagination } from "lib/types/rest"; import { parseTxHash, snakeToCamel } from "lib/utils"; -import { mapProposalStatusLcdToProposalStatus } from "./helpers"; - export interface MinDeposit { amount: U>; denom: string; diff --git a/src/lib/utils/proposal.ts b/src/lib/utils/proposal.ts index ddc60a49e..d2601a8eb 100644 --- a/src/lib/utils/proposal.ts +++ b/src/lib/utils/proposal.ts @@ -1,6 +1,6 @@ import type { Coin } from "@cosmjs/stargate"; -import type { MinDeposit } from "lib/services/proposal"; +import type { MinDeposit } from "lib/services/types"; import { big } from "lib/types"; import type { Option } from "lib/types"; From 22c7dfc06db0204e61d70d298ce3aa4a67e8f2f9 Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Fri, 10 May 2024 11:00:55 +0700 Subject: [PATCH 11/27] fix(components): fix pr comments --- CHANGELOG.md | 3 ++- src/lib/components/button/NewProposalButton.tsx | 7 ++++++- src/lib/services/proposal/index.ts | 12 ++++++------ src/lib/services/types/proposal.ts | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d90ad92b..ccffe9ba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Features -- [#906](https://github.com/alleslabs/celatone-frontend/pull/906) Transaction details page list version with LCD endpoint +- [#910](https://github.com/alleslabs/celatone-frontend/pull/910) Proposals page lite version with LCD endpoint +- [#906](https://github.com/alleslabs/celatone-frontend/pull/906) Transaction details page lite version with LCD endpoint - [#898](https://github.com/alleslabs/celatone-frontend/pull/898) Adjust navigation and overview page for lite version - [#912](https://github.com/alleslabs/celatone-frontend/pull/912) Support lite version validator list - [#901](https://github.com/alleslabs/celatone-frontend/pull/901) Support lite version recent codes diff --git a/src/lib/components/button/NewProposalButton.tsx b/src/lib/components/button/NewProposalButton.tsx index 8936d235e..a9aa71391 100644 --- a/src/lib/components/button/NewProposalButton.tsx +++ b/src/lib/components/button/NewProposalButton.tsx @@ -4,10 +4,15 @@ import { Tooltip } from "../Tooltip"; import { AmpEvent, track } from "lib/amplitude"; import { useGovConfig, useInternalNavigate } from "lib/app-provider"; import { CustomIcon } from "lib/components/icon"; +// import { useGovParams } from "lib/services/proposalService"; +// import { AccessConfigPermission } from "lib/types"; export const NewProposalButton = () => { const navigate = useInternalNavigate(); const govConfig = useGovConfig({ shouldRedirect: false }); + // const { data: govParams } = useGovParams(); + // const isPermissionless = + // govParams?.uploadAccess.permission === AccessConfigPermission.EVERYBODY; if (govConfig.enabled && govConfig.hideOpenProposal) return null; @@ -26,7 +31,7 @@ export const NewProposalButton = () => { > Create New Proposal - + - {tier === "full" && ( + {isFullTier && ( { - const tier = useTierConfig(); + const isFullTier = useTierConfig() === "full"; const govConfig = useGovConfig({ shouldRedirect: false }); const wasmConfig = useWasmConfig({ shouldRedirect: false }); const moveConfig = useMoveConfig({ shouldRedirect: false }); @@ -43,19 +43,18 @@ export const NavDrawer = () => { const { getSavedPublicProjects } = usePublicProjectStore(); const { isOpen, onOpen, onClose } = useDisclosure(); - const navMenu = - tier === "full" - ? getNavDrawerFull( - govConfig.enabled, - wasmConfig.enabled, - moveConfig.enabled, - nftConfig.enabled - ) - : getNavDrawerLite( - govConfig.enabled, - wasmConfig.enabled, - moveConfig.enabled - ); + const navMenu = isFullTier + ? getNavDrawerFull( + govConfig.enabled, + wasmConfig.enabled, + moveConfig.enabled, + nftConfig.enabled + ) + : getNavDrawerLite( + govConfig.enabled, + wasmConfig.enabled, + moveConfig.enabled + ); if (publicProject.enabled) { navMenu.push({ diff --git a/src/lib/layout/navbar/index.tsx b/src/lib/layout/navbar/index.tsx index 577f09956..ab4145a9c 100644 --- a/src/lib/layout/navbar/index.tsx +++ b/src/lib/layout/navbar/index.tsx @@ -39,92 +39,91 @@ const Navbar = observer(({ isExpand, setIsExpand }: NavbarProps) => { const isCurrentPage = useIsCurrentPage(); const wasm = useWasmConfig({ shouldRedirect: false }); const move = useMoveConfig({ shouldRedirect: false }); - const tier = useTierConfig(); + const isFullTier = useTierConfig() === "full"; const { address } = useCurrentChain(); - const navMenu: MenuInfo[] = - tier === "full" - ? [ - { - category: "Your Account", - slug: "your-account", - submenu: [...getYourAccountSubmenu(address)], - }, - ...(publicProject.enabled - ? getPublicProjectsSubmenu( - publicProject.enabled, - getSavedPublicProjects() - ) - : []), - ...(move.enabled || wasm.enabled - ? [ - { - category: "Developer Tools", - slug: StorageKeys.DevSidebar, - submenu: [ - ...getDevSubmenuMove(move.enabled), - ...getDevSubmenuWasm(wasm.enabled), - ], - subSection: [ - ...getWalletSubSectionMove(move.enabled), - ...getWalletSubSectionWasm(wasm.enabled), - { - category: "This Device", - submenu: [ - { - name: "Saved Accounts", - slug: "/saved-accounts", - icon: "admin" as IconKeys, - }, - ...getDeviceSubmenuWasm(wasm.enabled), - ], - }, - ], - }, - ] - : []), - ] - : [ - { - category: "Your Account", - slug: "your-account", - submenu: [ - ...getYourAccountSubmenu(address), - ...getYourAccountSubmenuLite(wasm.enabled, move.enabled), - ], - }, - ...(publicProject.enabled - ? getPublicProjectsSubmenu( - publicProject.enabled, - getSavedPublicProjects() - ) - : []), - ...(move.enabled || wasm.enabled - ? [ - { - category: "Developer Tools", - slug: StorageKeys.DevSidebar, - submenu: [ - ...getDevSubmenuMove(move.enabled), - ...getDevSubmenuWasm(wasm.enabled), - ], - subSection: [ - { - category: "This Device", - submenu: [ - { - name: "Saved Accounts", - slug: "/saved-accounts", - icon: "admin" as IconKeys, - }, - ...getDeviceSubmenuWasm(wasm.enabled), - ], - }, - ], - }, - ] - : []), - ]; + const navMenu: MenuInfo[] = isFullTier + ? [ + { + category: "Your Account", + slug: "your-account", + submenu: [...getYourAccountSubmenu(address)], + }, + ...(publicProject.enabled + ? getPublicProjectsSubmenu( + publicProject.enabled, + getSavedPublicProjects() + ) + : []), + ...(move.enabled || wasm.enabled + ? [ + { + category: "Developer Tools", + slug: StorageKeys.DevSidebar, + submenu: [ + ...getDevSubmenuMove(move.enabled), + ...getDevSubmenuWasm(wasm.enabled), + ], + subSection: [ + ...getWalletSubSectionMove(move.enabled), + ...getWalletSubSectionWasm(wasm.enabled), + { + category: "This Device", + submenu: [ + { + name: "Saved Accounts", + slug: "/saved-accounts", + icon: "admin" as IconKeys, + }, + ...getDeviceSubmenuWasm(wasm.enabled), + ], + }, + ], + }, + ] + : []), + ] + : [ + { + category: "Your Account", + slug: "your-account", + submenu: [ + ...getYourAccountSubmenu(address), + ...getYourAccountSubmenuLite(wasm.enabled, move.enabled), + ], + }, + ...(publicProject.enabled + ? getPublicProjectsSubmenu( + publicProject.enabled, + getSavedPublicProjects() + ) + : []), + ...(move.enabled || wasm.enabled + ? [ + { + category: "Developer Tools", + slug: StorageKeys.DevSidebar, + submenu: [ + ...getDevSubmenuMove(move.enabled), + ...getDevSubmenuWasm(wasm.enabled), + ], + subSection: [ + { + category: "This Device", + submenu: [ + { + name: "Saved Accounts", + slug: "/saved-accounts", + icon: "admin" as IconKeys, + }, + ...getDeviceSubmenuWasm(wasm.enabled), + ], + }, + ], + }, + ] + : []), + ]; return ( diff --git a/src/lib/layout/subheader/index.tsx b/src/lib/layout/subheader/index.tsx index 3ccf22293..a5afe60ae 100644 --- a/src/lib/layout/subheader/index.tsx +++ b/src/lib/layout/subheader/index.tsx @@ -19,7 +19,7 @@ import { getSubHeaderFull, getSubHeaderLite } from "./utils"; const ACTIVE_COLOR = "primary.light"; const SubHeader = () => { - const tier = useTierConfig(); + const isFullTier = useTierConfig() === "full"; const govConfig = useGovConfig({ shouldRedirect: false }); const wasmConfig = useWasmConfig({ shouldRedirect: false }); const moveConfig = useMoveConfig({ shouldRedirect: false }); @@ -30,7 +30,7 @@ const SubHeader = () => { const subHeaderMenu = useMemo( () => - tier === "full" + isFullTier ? getSubHeaderFull( govConfig.enabled, wasmConfig.enabled, @@ -40,7 +40,7 @@ const SubHeader = () => { ) : getSubHeaderLite(govConfig.enabled, wasmConfig.enabled), [ - tier, + isFullTier, govConfig.enabled, wasmConfig.enabled, moveConfig.enabled, diff --git a/src/lib/pages/proposals/components/ProposalStatusFilter.tsx b/src/lib/pages/proposals/components/ProposalStatusFilter.tsx index f1bbe581c..4eddecb93 100644 --- a/src/lib/pages/proposals/components/ProposalStatusFilter.tsx +++ b/src/lib/pages/proposals/components/ProposalStatusFilter.tsx @@ -39,12 +39,11 @@ export const ProposalStatusFilter = forwardRef< }: ProposalStatusFilterProps, ref ) => { - const tier = useTierConfig(); const [keyword, setKeyword] = useState(""); const [isDropdown, setIsDropdown] = useState(false); const inputRef = useRef(null); const boxRef = useRef(null); - const isFullTier = tier === "full"; + const isFullTier = useTierConfig() === "full"; const OPTIONS = isFullTier ? Object.values(ProposalStatus) diff --git a/src/lib/pages/proposals/index.tsx b/src/lib/pages/proposals/index.tsx index 3614e9340..bd1bc0dd9 100644 --- a/src/lib/pages/proposals/index.tsx +++ b/src/lib/pages/proposals/index.tsx @@ -11,7 +11,7 @@ import { ProposalsTableLite } from "./components/ProposalsTableLite"; const Proposals = () => { useGovConfig({ shouldRedirect: true }); const isMobile = useMobile(); - const tier = useTierConfig(); + const isFullTier = useTierConfig() === "full"; return ( @@ -27,7 +27,7 @@ const Proposals = () => { {!isMobile && } - {tier === "full" ? : } + {isFullTier ? : } ); }; diff --git a/src/lib/pages/validators/index.tsx b/src/lib/pages/validators/index.tsx index 6f3d487e7..3959e3137 100644 --- a/src/lib/pages/validators/index.tsx +++ b/src/lib/pages/validators/index.tsx @@ -24,7 +24,7 @@ const SCROLL_COMPONENT_ID = "validator-table-header"; const Validators = () => { const router = useRouter(); const isMobile = useMobile(); - const tier = useTierConfig(); + const isFullTier = useTierConfig() === "full"; useGovConfig({ shouldRedirect: true }); const [isActive, setIsActive] = useState(true); @@ -64,7 +64,7 @@ const Validators = () => { setOrder={setOrder} isDesc={isDesc} setIsDesc={setIsDesc} - allowUptime={tier === "full"} + allowUptime={isFullTier} /> )} { - {tier === "full" ? ( + {isFullTier ? ( => axios - .get(`${endpoint}/cosmos/gov/v1/proposals/${id}`) + .get(`${endpoint}/cosmos/gov/v1/proposals/${encodeURI(id)}`) .then(({ data }) => parseWithError(zProposalsResponseItemLcd, data.proposal) ); diff --git a/src/lib/services/validator/index.ts b/src/lib/services/validator/index.ts index cbca518f4..555226f77 100644 --- a/src/lib/services/validator/index.ts +++ b/src/lib/services/validator/index.ts @@ -131,8 +131,7 @@ export const useValidatorDataLcd = ( }; export const useValidatorStakingProvisions = (enabled: boolean) => { - const tier = useTierConfig(); - const isFullTier = tier === "full"; + const isFullTier = useTierConfig() === "full"; const apiEndpoint = useBaseApiRoute("validators"); const lcdEndpoint = useLcdEndpoint(); const endpoint = isFullTier ? apiEndpoint : lcdEndpoint; @@ -155,8 +154,7 @@ export const useValidatorStakingProvisions = (enabled: boolean) => { }; export const useValidatorDelegators = (validatorAddress: ValidatorAddr) => { - const tier = useTierConfig(); - const isFullTier = tier === "full"; + const isFullTier = useTierConfig() === "full"; const isInitia = useInitia(); const apiEndpoint = useBaseApiRoute("validators"); const lcdEndpoint = useLcdEndpoint(); From 4f9d6aa0e9ab05251db2e10050ea78c1bc862a9a Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Fri, 17 May 2024 15:47:00 +0700 Subject: [PATCH 25/27] feat(types): update pr comments --- src/lib/services/types/proposal.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/services/types/proposal.ts b/src/lib/services/types/proposal.ts index 65d5b59e1..cab056399 100644 --- a/src/lib/services/types/proposal.ts +++ b/src/lib/services/types/proposal.ts @@ -242,8 +242,7 @@ export const zProposalsResponseItemLcd = z "@type": z.string(), }) .passthrough() - .array() - .nullable(), + .array(), status: z.string(), final_tally_result: z.object({ yes_count: z.string(), @@ -264,7 +263,6 @@ export const zProposalsResponseItemLcd = z }) .transform((val) => ({ ...snakeToCamel(val), - id: Number(val.id), status: val.status .replace("PROPOSAL_STATUS_", "") .split("_") From 9bb7e09d3c01c5f5d9ec7d989e9ae27896ff9c8f Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Fri, 17 May 2024 16:10:47 +0700 Subject: [PATCH 26/27] feat(pages): fix pr comments --- .../components/table/proposals/ProposalsTableMobileCard.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx b/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx index 30f91ac3c..e979f51c4 100644 --- a/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx +++ b/src/lib/components/table/proposals/ProposalsTableMobileCard.tsx @@ -20,7 +20,7 @@ export interface ProposalsTableMobileCardProps { export const ProposalsTableMobileCard = ({ proposal, }: ProposalsTableMobileCardProps) => { - const tier = useTierConfig(); + const isFullTier = useTierConfig() === "full"; const navigate = useInternalNavigate(); const onCardSelect = (proposalId: number) => @@ -63,7 +63,7 @@ export const ProposalsTableMobileCard = ({ status={proposal.status} /> - {tier === "lite" && ( + {!isFullTier && ( @@ -72,7 +72,7 @@ export const ProposalsTableMobileCard = ({ } bottomContent={ - tier === "full" && ( + isFullTier && ( <> From 3cd9cd03392d455d1506263cbee47fb1958a765d Mon Sep 17 00:00:00 2001 From: Poafs1 Date: Mon, 20 May 2024 10:47:04 +0700 Subject: [PATCH 27/27] feat(types): update types proposals --- src/lib/services/types/proposal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/services/types/proposal.ts b/src/lib/services/types/proposal.ts index cab056399..0002eb51b 100644 --- a/src/lib/services/types/proposal.ts +++ b/src/lib/services/types/proposal.ts @@ -269,7 +269,7 @@ export const zProposalsResponseItemLcd = z .map((term: string) => capitalize(term.toLowerCase())) .join("") as ProposalStatus, resolvedHeight: null, - types: [], + types: val.messages.map((msg) => msg["@type"]), isExpedited: val.expedited, })); export type ProposalsResponseItemLcd = z.infer<