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

Prevent showing error when proposal type is unknown #365

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion graphql-schema/proposal.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Proposal implements Node {
proposalId: Int!
title: String!
description: String!
type: ProposalType!
type: String!
submitTime: DateTime!
depositEndTime: DateTime
"Sum of all deposit in chain's coin denom (non chain's coin denom deposits excluded)"
Expand Down
6 changes: 3 additions & 3 deletions graphql-server/pkg/resolvers/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func (r *proposalResolver) ProposalID(ctx context.Context, obj *models.Proposal)
return obj.ID, nil
}

func (r *proposalResolver) Type(ctx context.Context, obj *models.Proposal) (models.ProposalType, error) {
func (r *proposalResolver) Type(ctx context.Context, obj *models.Proposal) (string, error) {
proposalType := new(models.ProposalType)
err := proposalType.UnmarshalGQL(obj.ProposalType)
if err != nil {
return "", nil
return obj.ProposalType, nil
}

return *proposalType, nil
return proposalType.String(), nil
}

func (r *proposalResolver) DepositTotal(ctx context.Context, obj *models.Proposal) ([]types.DbDecCoin, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ const ProposalTypeAndProposer: React.FC<{ proposal: Proposal }> = ({
}) => {
const { type, proposerAddress, submitTime } = proposal;

const typeNameId = getProposalTypeMessage(type);
Copy link
Contributor

Choose a reason for hiding this comment

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

memo?


return (
<div
className={cn(
Expand All @@ -175,7 +177,7 @@ const ProposalTypeAndProposer: React.FC<{ proposal: Proposal }> = ({
<LocalizedText messageID="ProposalDetail.proposalType" />
</p>
<p className={cn("text-sm", "mb-4")}>
<LocalizedText messageID={getProposalTypeMessage(type)} />
{typeNameId !== null ? <LocalizedText messageID={typeNameId} /> : type}
</p>
<p className={cn("text-sm", "text-app-lightgreen", "mb-1")}>
<LocalizedText messageID="ProposalDetail.publishedBy" />
Expand Down
11 changes: 10 additions & 1 deletion react-app/src/components/proposals/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const ProposalCard: React.FC<ProposalCardProps> = (props) => {
});
}, [proposal]);

const proposalTypeNameId = useMemo(
() => getProposalTypeMessage(proposal.type),
[proposal]
);

return (
<div
className={cn(
Expand Down Expand Up @@ -86,7 +91,11 @@ const ProposalCard: React.FC<ProposalCardProps> = (props) => {
"text-app-darkgrey"
)}
>
<LocalizedText messageID={getProposalTypeMessage(proposal.type)} />
{proposalTypeNameId !== null ? (
<LocalizedText messageID={proposalTypeNameId} />
) : (
proposal.type
)}
</span>
<h1
className={cn(
Expand Down
4 changes: 2 additions & 2 deletions react-app/src/components/proposals/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getProposalStatusBadgeConfig(
}
}

export function getProposalTypeMessage(type: ProposalType): MessageID {
export function getProposalTypeMessage(type: string): MessageID | null {
switch (type) {
case ProposalType.Text:
return "ProposalScreen.proposalType.text";
Expand All @@ -40,7 +40,7 @@ export function getProposalTypeMessage(type: ProposalType): MessageID {
case ProposalType.CancelSoftwareUpgrade:
return "ProposalScreen.proposalType.cancelSoftwareUpgrade";
default:
throw new Error("Unknown proposal type");
return null;
}
}

Expand Down