Skip to content

Commit

Permalink
fix: #9 empty messages in execution
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo committed May 2, 2023
1 parent 19d44ce commit 2f9af22
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/api/policy.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function encodeDecisionPolicy({
}) {
const windows = {
minExecutionPeriod: secondsToDuration(1),
votingPeriod: daysToDuration(votingWindow),
// TODO: undo change before merging
votingPeriod: secondsToDuration(votingWindow), // daysToDuration(votingWindow),
}
if (policyType === 'percentage') {
if (!percentage) throwError('Must provide percentage value')
Expand Down
11 changes: 7 additions & 4 deletions src/api/proposal.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ export function toUIProposal(sdkProposal: ProposalSDKType): UIProposal {
groupPolicyVersion: sdkProposal.group_policy_version,
groupVersion: sdkProposal.group_version,
id: sdkProposal.id,
messages: sdkProposal.messages.map((msg) => ({
typeUrl: msg.type_url,
value: msg.value,
})),
messages: sdkProposal.messages.map(
(msg: any) =>
({
typeUrl: msg['@type'],
value: msg,
} as Any),
), // TODO
metadata: getProposalMetadata(sdkProposal.metadata, {
title: `Proposal #${sdkProposal.id}`,
}),
Expand Down
10 changes: 6 additions & 4 deletions src/components/organisms/proposal-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function renderAction(action: ProposalAction, groupPolicyAddress: string) {
}
}

const SendReview = ({
export const SendReview = ({
groupPolicyAddress,
values,
}: {
Expand All @@ -90,7 +90,7 @@ const SendReview = ({
return (
<FormCard title="Send">
<Stack spacing={SPACING.formStack}>
<ReviewItem label="Type">{values.sendType}</ReviewItem>
{'sendType' in values && <ReviewItem label="Type">{values.sendType}</ReviewItem>}
<ReviewItem label="From Address">
<Truncate
clickToCopy
Expand All @@ -110,7 +110,7 @@ const SendReview = ({
)
}

const StakeReview = ({
export const StakeReview = ({
groupPolicyAddress,
values,
}: {
Expand All @@ -121,7 +121,9 @@ const StakeReview = ({
return (
<FormCard title="Stake">
<Stack spacing={SPACING.formStack}>
<ReviewItem label="Type">{values.stakeType}</ReviewItem>
{'stakeType' in values && (
<ReviewItem label="Type">{values.stakeType}</ReviewItem>
)}
<ReviewItem label="Delegator">
<Truncate
clickToCopy
Expand Down
40 changes: 39 additions & 1 deletion src/components/organisms/proposal-summary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import type { UIGroup, UIProposal, Vote, VoteOptionType } from 'types'
import { Any } from '@haveanicedavid/regen-ts/types/codegen/google/protobuf/any'

import type {
ProposalSendFormValues,
ProposalStakeFormValues,
UIGroup,
UIProposal,
Vote,
VoteOptionType,
} from 'types'
import { formatDate } from 'util/date'
import { VoteOption } from 'util/enums'

Expand All @@ -17,6 +26,7 @@ import {
Text,
} from '@/atoms'
import { VoteButtons } from '@/molecules/vote-buttons'
import { SendReview, StakeReview } from '@/organisms/proposal-review'

import { VotesGraph } from './votes-graph'

Expand Down Expand Up @@ -52,6 +62,9 @@ export const ProposalSummary = ({
</Stack>
<Heading>{proposal.metadata.title}</Heading>
<Text>{proposal.metadata.summary}</Text>
{proposal.messages.map((msg) =>
renderMessage(msg, proposal.groupPolicyAddress),
)}
</Stack>
</CardBody>
<CardBody bg={cardBgDark} borderRightRadius="lg">
Expand Down Expand Up @@ -89,3 +102,28 @@ export const ProposalSummary = ({
</Card>
)
}

function renderMessage(msg: Any, groupPolicyAddress: string) {
if (!msg) return null
switch (msg.typeUrl) {
case '/cosmos.bank.v1beta1.MsgSend':
return (
<SendReview
groupPolicyAddress={groupPolicyAddress}
values={msg as unknown as ProposalSendFormValues}
/>
)
case '/cosmos.staking.v1beta1.MsgDelegate':
case '/cosmos.staking.v1beta1.MsgBeginRedelegate':
case '/cosmos.staking.v1beta1.MsgUndelegate':
case '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward':
return (
<StakeReview
groupPolicyAddress={groupPolicyAddress}
values={msg as unknown as ProposalStakeFormValues}
/>
)
default:
return null
}
}

0 comments on commit 2f9af22

Please sign in to comment.