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: multi-type proposals #749

Merged
merged 8 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
7 changes: 4 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,7 @@ export const ProposalTextCell = ({
maxW={showName ? undefined : "full"}
className={showName ? undefined : "ellipsis"}
>
{type}
{types.join(" / ")}
</Text>
</Flex>
</Flex>
Expand Down
10 changes: 6 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,11 @@ 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) => (
<Text 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 +88,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
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;
}
Loading