Skip to content

Commit

Permalink
Merge pull request #749 from alleslabs/feat/cfe-136-proposal-types
Browse files Browse the repository at this point in the history
feat: multi-type proposals
  • Loading branch information
songwongtp authored Jan 26, 2024
2 parents dc4089c + 5cb43e7 commit 44699e6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

- [#749](https://github.com/alleslabs/celatone-frontend/pull/749) Add multi-type proposals

### Improvements

- [#750](https://github.com/alleslabs/celatone-frontend/pull/750) api v1 - recent codes list
Expand Down
16 changes: 13 additions & 3 deletions src/lib/components/table/proposals/ProposalTextCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { useRef, useState } from "react";

import { DotSeparator } from "lib/components/DotSeparator";
import { Expedited } from "lib/components/Expedited";
import type { ProposalType } from "lib/types";

interface ProposalTextCellProps {
title: string;
type: string;
types: ProposalType[];
isExpedited: boolean;
isDepositOrVoting: boolean;
}

export const ProposalTextCell = ({
title,
type,
types,
isExpedited,
isDepositOrVoting,
}: ProposalTextCellProps) => {
Expand Down Expand Up @@ -69,7 +70,16 @@ export const ProposalTextCell = ({
maxW={showName ? undefined : "full"}
className={showName ? undefined : "ellipsis"}
>
{type}
{types.map((msgType, index) => (
<span key={msgType + index.toString()}>
{index > 0 && (
<span style={{ color: "var(--chakra-colors-accent-main)" }}>
{" / "}
</span>
)}
{msgType}
</span>
))}
</Text>
</Flex>
</Flex>
Expand Down
15 changes: 11 additions & 4 deletions src/lib/components/table/proposals/ProposalsTableMobileCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ export const ProposalsTableMobileCard = ({
<Text color="text.main" variant="body2" wordBreak="break-word">
{proposal.title}
</Text>
<Text color="text.dark" variant="body3" wordBreak="break-word">
{proposal.type}
</Text>
{proposal.types.map((msgType, index) => (
<Text
key={msgType + index.toString()}
color="text.dark"
variant="body3"
wordBreak="break-word"
>
{msgType}
</Text>
))}
</Flex>
<Flex direction="column" gap={1}>
<MobileLabel label="Voting Ends" />
Expand Down Expand Up @@ -86,7 +93,7 @@ export const ProposalsTableMobileCard = ({
!isDepositFailed
? () => {
trackMintScan("proposal-detail", {
type: proposal.type,
types: proposal.types,
status: proposal.status,
});
// TOOD: revisit retrieving url (make a proper hook)
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/table/proposals/ProposalsTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ProposalsTableRow = ({
!isDepositFailed
? () => {
trackMintScan("proposal-detail", {
type: proposal.type,
types: proposal.types,
status: proposal.status,
});
// TOOD: revisit retrieving url (make a proper hook)
Expand Down Expand Up @@ -86,7 +86,7 @@ export const ProposalsTableRow = ({
>
<ProposalTextCell
title={proposal.title}
type={proposal.type}
types={proposal.types}
isExpedited={proposal.isExpedited}
isDepositOrVoting={isDepositOrVoting}
/>
Expand Down
14 changes: 14 additions & 0 deletions src/lib/pages/proposals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ const Proposals = () => {
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 (
<PageContainer>
<Flex justify="space-between" alignItems="center">
Expand Down
31 changes: 3 additions & 28 deletions src/lib/services/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const zProposalsResponseItem = z
resolved_height: z.number().nullable(),
status: zProposalStatus,
title: z.string(),
type: zProposalType,
types: zProposalType.array(),
voting_end_time: zUtcDate.nullable(),
})
.transform<Proposal>((val) => ({
Expand All @@ -87,7 +87,7 @@ const zProposalsResponseItem = z
resolvedHeight: val.resolved_height,
status: val.status,
title: val.title,
type: val.type,
types: val.types,
votingEndTime: val.voting_end_time,
}));

Expand Down Expand Up @@ -135,34 +135,9 @@ export const getProposalsByAddress = async (
})
.then(({ data }) => zProposalsResponse.parse(data));

const zRelatedProposalsResponseItem = z
.object({
deposit_end_time: zUtcDate,
proposal_id: z.number().nonnegative(),
is_expedited: z.boolean(),
proposer: zBechAddr,
resolved_height: z.number().nullable(),
status: zProposalStatus,
title: z.string(),
type: zProposalType,
voting_end_time: zUtcDate,
})
.transform<Proposal>((val) => ({
depositEndTime: val.deposit_end_time,
proposalId: val.proposal_id,
isExpedited: val.is_expedited,
proposer: val.proposer,
resolvedHeight: val.resolved_height,
status: val.status,
title: val.title,
type: val.type,
votingEndTime: val.voting_end_time,
}));

const zRelatedProposalsResponse = z.object({
items: z.array(zRelatedProposalsResponseItem),
items: z.array(zProposalsResponseItem),
});

export type RelatedProposalsResponse = z.infer<
typeof zRelatedProposalsResponse
>;
Expand Down
3 changes: 2 additions & 1 deletion src/lib/services/proposalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export const useRelatedProposalsByModuleIdPagination = (
votingEndTime: parseDate(proposal.proposal.voting_end_time),
depositEndTime: parseDate(proposal.proposal.deposit_end_time),
resolvedHeight: proposal.proposal.resolved_height ?? null,
type: proposal.proposal.type as ProposalType,
// TODO: fix
types: [proposal.proposal.type as ProposalType],
proposer: proposal.proposal.account?.address as BechAddr,
isExpedited: Boolean(proposal.proposal.is_expedited),
}))
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface Proposal {
votingEndTime: Nullable<Date>;
depositEndTime: Date;
resolvedHeight: Nullable<number>;
type: ProposalType;
types: ProposalType[];
proposer: Option<BechAddr>;
isExpedited: boolean;
}

1 comment on commit 44699e6

@vercel
Copy link

@vercel vercel bot commented on 44699e6 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.