Skip to content

Commit

Permalink
revert unrelated and update todo
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo committed May 19, 2023
1 parent 2c7b7b0 commit 91fc424
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 93 deletions.
13 changes: 0 additions & 13 deletions src/api/group.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ export function msgCreateGroupWithPolicy(values: GroupWithPolicyFormValues) {
})
}

export function msgExecute({
executor,
proposalId,
}: {
executor: string
proposalId: Long
}) {
return GroupMsgWithTypeUrl.exec({
executor,
proposalId,
})
}

export function msgUpdateGroupMetadata({
admin,
metadata,
Expand Down
3 changes: 1 addition & 2 deletions src/api/policy.messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ export function encodeDecisionPolicy({
}) {
const windows = {
minExecutionPeriod: secondsToDuration(1),
// TODO: undo change before merging
votingPeriod: secondsToDuration(votingWindow), // daysToDuration(votingWindow),
votingPeriod: daysToDuration(votingWindow),
}
if (policyType === 'percentage') {
if (!percentage) throwError('Must provide percentage value')
Expand Down
15 changes: 0 additions & 15 deletions src/api/proposal.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ export async function createProposal({
}
}

export async function executeProposal({ proposalId }: { proposalId: Long }) {
if (!Wallet.account?.address) throwError('Wallet not initialized')
try {
const msg = GroupMsgWithTypeUrl.exec({
proposalId,
executor: Wallet.account.address,
})
const data = await signAndBroadcast([msg])
if (!data) throwError('No data returned from execution')
return data
} catch (err) {
logError(err)
}
}

export async function voteOnProposal({
option,
proposalId,
Expand Down
3 changes: 2 additions & 1 deletion src/api/proposal.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ export function toUIProposal(sdkProposal: ProposalSDKType): UIProposal {
groupPolicyVersion: sdkProposal.group_policy_version,
groupVersion: sdkProposal.group_version,
id: sdkProposal.id,
// TODO(#9): dependent on https://github.com/regen-network/regen-js/issues/71
messages: sdkProposal.messages.map(
(msg: any) =>
({
typeUrl: msg['@type'],
value: msg,
} as Any),
), // TODO
),
metadata: getProposalMetadata(sdkProposal.metadata, {
title: `Proposal #${sdkProposal.id}`,
}),
Expand Down
12 changes: 5 additions & 7 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) {
}
}

export const SendReview = ({
const SendReview = ({
groupPolicyAddress,
values,
}: {
Expand All @@ -90,7 +90,7 @@ export const SendReview = ({
return (
<FormCard title="Send">
<Stack spacing={SPACING.formStack}>
{'sendType' in values && <ReviewItem label="Type">{values.sendType}</ReviewItem>}
<ReviewItem label="Type">{values.sendType}</ReviewItem>
<ReviewItem label="From Address">
<Truncate
clickToCopy
Expand All @@ -103,14 +103,14 @@ export const SendReview = ({
<ReviewItem label="To Address">{values.toAddress}</ReviewItem>
)}
{/* TODO(#19): add support for currencies other than staking denom */}
<ReviewItem label="Amount">{values.amount + ' uregen'}</ReviewItem>
<ReviewItem label="Amount">{values.amount + ' REGEN'}</ReviewItem>
<ReviewItem label="Transaction Fee">{formatFee(fee)}</ReviewItem>
</Stack>
</FormCard>
)
}

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

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

Expand All @@ -26,7 +17,6 @@ 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 @@ -62,9 +52,6 @@ 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 @@ -102,28 +89,3 @@ 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
}
}
2 changes: 1 addition & 1 deletion src/components/organisms/send-single-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const SingleForm = (props: {
name="amount"
label="Amount"
maxValue={props.maxAmount}
denom="uregen" // TODO
denom={getFeeDenom(fee)}
/>
<FeeDisplayField />
<FormSubmitHiddenButton id={props.formId} onSubmit={props.onSubmit} />
Expand Down
15 changes: 1 addition & 14 deletions src/pages/group-page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { redirect, useParams } from 'react-router-dom'

import { UIProposal } from 'types'
import { logError } from 'util/errors'

import { executeProposal } from 'api/proposal.actions'
import { useDerivedProposals } from 'hooks/use-derived-proposals'
import {
useBalances,
useGroup,
useGroupPolicies,
useGroupProposals,
} from 'hooks/use-query'
import { useTxToasts } from 'hooks/use-toasts'

import { Loading } from '@/molecules/loading'
import { GroupTemplate } from '@/templates/group-template'
Expand All @@ -21,7 +18,6 @@ export default function GroupPage() {
const { data: group, isLoading: isLoadingGroup } = useGroup(groupId)
const { data: policies } = useGroupPolicies(groupId)
const { data: proposals, isLoading: isLoadingProposals } = useGroupProposals(groupId)
const { toastSuccess, toastErr } = useTxToasts()

const groupPolicy = policies?.[0]
const { data: balances } = useBalances(groupPolicy?.address)
Expand All @@ -34,21 +30,12 @@ export default function GroupPage() {
return null
}

const handleExecute = async (proposal: UIProposal) => {
try {
const data = await executeProposal({ proposalId: proposal.id })
toastSuccess(data?.transactionHash || '')
} catch (err) {
toastErr(err)
}
}

return (
<GroupTemplate
group={group}
policies={policies}
balances={balances}
onExecute={handleExecute}
onExecute={(p) => console.log('execute proposal', p)}
proposals={{
accepted: derivedProposals.accepted,
history: derivedProposals.other,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/proposal-create-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function ProposalCreate() {
actions,
title,
summary,
denom: 'uregen', // TODO
denom: getFeeDenom(fee),
groupPolicyAddress: groupPolicy.address,
metadata: { title, summary },
proposers: [account.address],
Expand Down

0 comments on commit 91fc424

Please sign in to comment.