Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proposal of an user #222

Merged
merged 5 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#222](https://github.com/alleslabs/celatone-frontend/pull/222) Add proposals of an account
- [#218](https://github.com/alleslabs/celatone-frontend/pull/218) Add instantiated and admin contracts of an account
- [#192](https://github.com/alleslabs/celatone-frontend/pull/192) Add alternative sidebar with only icons
- [#210](https://github.com/alleslabs/celatone-frontend/pull/210) New design for token card, currently support price
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Grid } from "@chakra-ui/react";

import { TableHeader } from "lib/components/table";

export const RelatedProposalsHeader = ({
export const ProposalsTableHeader = ({
templateColumns,
}: {
templateColumns: GridProps["templateColumns"];
Expand All @@ -14,7 +14,7 @@ export const RelatedProposalsHeader = ({
<TableHeader>Proposal Title</TableHeader>
<TableHeader textAlign="center">Status</TableHeader>
<TableHeader>Vote Finish on</TableHeader>
<TableHeader>Resolve Block Height</TableHeader>
<TableHeader>Resolved Block Height</TableHeader>
<TableHeader>Type</TableHeader>
<TableHeader>Proposer</TableHeader>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Flex, Grid, Text } from "@chakra-ui/react";
import { ExplorerLink } from "lib/components/ExplorerLink";
import { TableRow } from "lib/components/table";
import { useGetAddressType } from "lib/hooks";
import type { ContractRelatedProposals } from "lib/types";
import type { Proposal } from "lib/types";
import { ProposalStatus } from "lib/types";
import { dateFromNow, formatUTC } from "lib/utils";

import { StatusChip } from "./StatusChip";

interface RelatedProposalsRowProps {
proposal: ContractRelatedProposals;
interface ProposalsTableRowProps {
proposal: Proposal;
templateColumns: GridProps["templateColumns"];
}

Expand All @@ -20,9 +20,9 @@ const VotingEndTimeRender = ({
depositEndTime,
status,
}: {
votingEndTime: ContractRelatedProposals["votingEndTime"];
depositEndTime: ContractRelatedProposals["depositEndTime"];
status: ContractRelatedProposals["status"];
votingEndTime: Proposal["votingEndTime"];
depositEndTime: Proposal["depositEndTime"];
status: Proposal["status"];
}) => {
if (status === ProposalStatus.INACTIVE) {
return <Text color="text.dark">N/A</Text>;
Expand Down Expand Up @@ -59,7 +59,7 @@ const ResolvedHeightRender = ({
resolvedHeight,
isInactive,
}: {
resolvedHeight: RelatedProposalsRowProps["proposal"]["resolvedHeight"];
resolvedHeight: ProposalsTableRowProps["proposal"]["resolvedHeight"];
isInactive: boolean;
}) => {
if (isInactive) return <Text color="text.dark">N/A</Text>;
Expand All @@ -80,10 +80,10 @@ const ResolvedHeightRender = ({
}
};

export const RelatedProposalsRow = ({
export const ProposalsTableRow = ({
proposal,
templateColumns,
}: RelatedProposalsRowProps) => {
}: ProposalsTableRowProps) => {
const getAddressType = useGetAddressType();
const isInactive = proposal.status === ProposalStatus.INACTIVE;
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { chakra, Tag } from "@chakra-ui/react";
import type { CSSProperties } from "react";

import type { ContractRelatedProposals } from "lib/types";
import type { Proposal } from "lib/types";
import { ProposalStatus } from "lib/types";

const StyledTag = chakra(Tag, {
Expand All @@ -16,7 +16,7 @@ const StyledTag = chakra(Tag, {
});

const getBgColor = (
status: ContractRelatedProposals["status"]
status: Proposal["status"]
): CSSProperties["backgroundColor"] => {
switch (status) {
case ProposalStatus.DEPOSIT_PERIOD:
Expand All @@ -34,11 +34,7 @@ const getBgColor = (
}
};

export const StatusChip = ({
status,
}: {
status: ContractRelatedProposals["status"];
}) => {
export const StatusChip = ({ status }: { status: Proposal["status"] }) => {
return (
<StyledTag bgColor={getBgColor(status)}>
{status === ProposalStatus.INACTIVE ? "DepositFailed" : status}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/table/proposals/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./ProposalsTableHeader";
export * from "./ProposalsTableRow";
6 changes: 3 additions & 3 deletions src/lib/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const documents = {
types.GetRelatedProposalsByContractAddressPaginationDocument,
"\n query getRelatedProposalsCountByContractAddress($contractAddress: String!) {\n contract_proposals_aggregate(\n where: { contract: { address: { _eq: $contractAddress } } }\n ) {\n aggregate {\n count\n }\n }\n }\n":
types.GetRelatedProposalsCountByContractAddressDocument,
"\n query getProposalsByWalletAddressPagination(\n $walletAddress: String!\n $offset: Int!\n $pageSize: Int!\n ) {\n proposals(\n where: { account: { address: { _eq: $walletAddress } } }\n offset: $offset\n limit: $pageSize\n ) {\n title\n status\n voting_end_time\n deposit_end_time\n type\n id\n }\n }\n":
"\n query getProposalsByWalletAddressPagination(\n $walletAddress: String!\n $offset: Int!\n $pageSize: Int!\n ) {\n proposals(\n where: { account: { address: { _eq: $walletAddress } } }\n order_by: { id: desc }\n offset: $offset\n limit: $pageSize\n ) {\n title\n status\n voting_end_time\n deposit_end_time\n type\n id\n contract_proposals {\n resolved_height\n }\n code_proposals {\n resolved_height\n }\n }\n }\n":
types.GetProposalsByWalletAddressPaginationDocument,
"\n query getProposalsCountByWalletAddress($walletAddress: String!) {\n proposals_aggregate(\n where: { account: { address: { _eq: $walletAddress } } }\n ) {\n aggregate {\n count\n }\n }\n }\n":
types.GetProposalsCountByWalletAddressDocument,
Expand Down Expand Up @@ -129,8 +129,8 @@ export function graphql(
source: "\n query getRelatedProposalsCountByContractAddress($contractAddress: String!) {\n contract_proposals_aggregate(\n where: { contract: { address: { _eq: $contractAddress } } }\n ) {\n aggregate {\n count\n }\n }\n }\n"
): typeof documents["\n query getRelatedProposalsCountByContractAddress($contractAddress: String!) {\n contract_proposals_aggregate(\n where: { contract: { address: { _eq: $contractAddress } } }\n ) {\n aggregate {\n count\n }\n }\n }\n"];
export function graphql(
source: "\n query getProposalsByWalletAddressPagination(\n $walletAddress: String!\n $offset: Int!\n $pageSize: Int!\n ) {\n proposals(\n where: { account: { address: { _eq: $walletAddress } } }\n offset: $offset\n limit: $pageSize\n ) {\n title\n status\n voting_end_time\n deposit_end_time\n type\n id\n }\n }\n"
): typeof documents["\n query getProposalsByWalletAddressPagination(\n $walletAddress: String!\n $offset: Int!\n $pageSize: Int!\n ) {\n proposals(\n where: { account: { address: { _eq: $walletAddress } } }\n offset: $offset\n limit: $pageSize\n ) {\n title\n status\n voting_end_time\n deposit_end_time\n type\n id\n }\n }\n"];
source: "\n query getProposalsByWalletAddressPagination(\n $walletAddress: String!\n $offset: Int!\n $pageSize: Int!\n ) {\n proposals(\n where: { account: { address: { _eq: $walletAddress } } }\n order_by: { id: desc }\n offset: $offset\n limit: $pageSize\n ) {\n title\n status\n voting_end_time\n deposit_end_time\n type\n id\n contract_proposals {\n resolved_height\n }\n code_proposals {\n resolved_height\n }\n }\n }\n"
): typeof documents["\n query getProposalsByWalletAddressPagination(\n $walletAddress: String!\n $offset: Int!\n $pageSize: Int!\n ) {\n proposals(\n where: { account: { address: { _eq: $walletAddress } } }\n order_by: { id: desc }\n offset: $offset\n limit: $pageSize\n ) {\n title\n status\n voting_end_time\n deposit_end_time\n type\n id\n contract_proposals {\n resolved_height\n }\n code_proposals {\n resolved_height\n }\n }\n }\n"];
export function graphql(
source: "\n query getProposalsCountByWalletAddress($walletAddress: String!) {\n proposals_aggregate(\n where: { account: { address: { _eq: $walletAddress } } }\n ) {\n aggregate {\n count\n }\n }\n }\n"
): typeof documents["\n query getProposalsCountByWalletAddress($walletAddress: String!) {\n proposals_aggregate(\n where: { account: { address: { _eq: $walletAddress } } }\n ) {\n aggregate {\n count\n }\n }\n }\n"];
Expand Down
48 changes: 48 additions & 0 deletions src/lib/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7327,6 +7327,14 @@ export type GetProposalsByWalletAddressPaginationQuery = {
deposit_end_time: any;
type: string;
id: number;
contract_proposals: Array<{
__typename?: "contract_proposals";
resolved_height?: number | null;
}>;
code_proposals: Array<{
__typename?: "code_proposals";
resolved_height?: number | null;
}>;
}>;
};

Expand Down Expand Up @@ -10783,6 +10791,20 @@ export const GetProposalsByWalletAddressPaginationDocument = {
],
},
},
{
kind: "Argument",
name: { kind: "Name", value: "order_by" },
value: {
kind: "ObjectValue",
fields: [
{
kind: "ObjectField",
name: { kind: "Name", value: "id" },
value: { kind: "EnumValue", value: "desc" },
},
],
},
},
{
kind: "Argument",
name: { kind: "Name", value: "offset" },
Expand Down Expand Up @@ -10815,6 +10837,32 @@ export const GetProposalsByWalletAddressPaginationDocument = {
},
{ kind: "Field", name: { kind: "Name", value: "type" } },
{ kind: "Field", name: { kind: "Name", value: "id" } },
{
kind: "Field",
name: { kind: "Name", value: "contract_proposals" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "resolved_height" },
},
],
},
},
{
kind: "Field",
name: { kind: "Name", value: "code_proposals" },
selectionSet: {
kind: "SelectionSet",
selections: [
{
kind: "Field",
name: { kind: "Name", value: "resolved_height" },
},
],
},
},
],
},
},
Expand Down
6 changes: 3 additions & 3 deletions src/lib/model/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useAccountDetailsTableCounts = (walletAddress: HumanAddr) => {
useContractListCountByAdmin(walletAddress);
const { data: contractsCount, refetch: refetchContractsCount } =
useInstantiatedCountByUserQuery(walletAddress);
const { data: proposalCount, refetch: refetchProposalCount } =
const { data: proposalsCount, refetch: refetchProposalsCount } =
useProposalsCountByWalletAddress(walletAddress);
const { data: countTxs, refetch: refetchCountTxs } = useTxQueryCount(
walletAddress,
Expand All @@ -42,12 +42,12 @@ export const useAccountDetailsTableCounts = (walletAddress: HumanAddr) => {
contractsAdminCount,
contractsCount,
countTxs,
proposalCount,
proposalsCount,
},
refetchCodes,
refetchContractsAdminCount,
refetchContractsCount,
refetchCountTxs,
refetchProposalCount,
refetchProposalsCount,
};
};
2 changes: 2 additions & 0 deletions src/lib/pages/account-details/components/tables/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./contracts";
export * from "./proposals";
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Box, Flex } from "@chakra-ui/react";
import { observer } from "mobx-react-lite";
import type { ChangeEvent } from "react";

import { Loading } from "lib/components/Loading";
import { Pagination } from "lib/components/pagination";
import { usePaginator } from "lib/components/pagination/usePaginator";
import { EmptyState } from "lib/components/state/EmptyState";
import { TableContainer } from "lib/components/table";
import {
ProposalsTableHeader,
ProposalsTableRow,
} from "lib/components/table/proposals";
import { TableTitle } from "lib/components/table/TableTitle";
import { ViewMore } from "lib/components/table/ViewMore";
import { useProposalsByWalletAddressPagination } from "lib/services/proposalService";
import type { HumanAddr, Option } from "lib/types";

interface ProposalsTableProps {
walletAddress: HumanAddr;
scrollComponentId: string;
totalData: Option<number>;
refetchCount: () => void;
onViewMore?: () => void;
}

const ProposalsTableBody = observer(
({
walletAddress,
scrollComponentId,
totalData,
refetchCount,
onViewMore,
}: ProposalsTableProps) => {
const {
pagesQuantity,
currentPage,
setCurrentPage,
pageSize,
setPageSize,
offset,
} = usePaginator({
total: totalData,
initialState: {
pageSize: 10,
currentPage: 1,
isDisabled: false,
},
});
const { data: proposals, isLoading } =
useProposalsByWalletAddressPagination(
walletAddress,
offset,
onViewMore ? 5 : pageSize
);

const onPageChange = (nextPage: number) => {
refetchCount();
setCurrentPage(nextPage);
};

const onPageSizeChange = (e: ChangeEvent<HTMLSelectElement>) => {
const size = Number(e.target.value);
refetchCount();
setPageSize(size);
setCurrentPage(1);
};

const templateColumns =
"100px minmax(300px, 1fr) 150px 280px 180px 190px 160px";

if (isLoading) return <Loading />;
if (!proposals?.length)
return (
<Flex
py="64px"
direction="column"
borderY="1px solid"
borderColor="pebble.700"
>
<EmptyState message="This account did not open any proposals before." />
</Flex>
);
return (
<>
<TableContainer>
<ProposalsTableHeader templateColumns={templateColumns} />
{proposals.map((proposal) => (
<ProposalsTableRow
key={proposal.proposalId}
proposal={proposal}
templateColumns={templateColumns}
/>
))}
</TableContainer>
{totalData &&
(onViewMore
? totalData > 5 && <ViewMore onClick={onViewMore} />
: totalData > 10 && (
<Pagination
currentPage={currentPage}
pagesQuantity={pagesQuantity}
offset={offset}
totalData={totalData}
scrollComponentId={scrollComponentId}
pageSize={pageSize}
onPageChange={onPageChange}
onPageSizeChange={onPageSizeChange}
/>
))}
</>
);
}
);

export const ProposalsTable = ({
totalData,
...componentProps
}: ProposalsTableProps) => (
<Box mt={12} mb={4}>
<TableTitle title="Opened Proposals" count={totalData ?? 0} />
<ProposalsTableBody totalData={totalData} {...componentProps} />
</Box>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ProposalsTable";
Loading