Skip to content

Commit 91bcd2f

Browse files
committed
fix: #9 empty messages in execution
1 parent 2f9af22 commit 91bcd2f

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/api/group.messages.ts

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ export function msgCreateGroupWithPolicy(values: GroupWithPolicyFormValues) {
4646
})
4747
}
4848

49+
export function msgExecute({
50+
executor,
51+
proposalId,
52+
}: {
53+
executor: string
54+
proposalId: Long
55+
}) {
56+
return GroupMsgWithTypeUrl.exec({
57+
executor,
58+
proposalId,
59+
})
60+
}
61+
4962
export function msgUpdateGroupMetadata({
5063
admin,
5164
metadata,

src/api/proposal.actions.ts

+15
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ export async function voteOnProposal({
125125
}
126126
}
127127

128+
export async function executeProposal({ proposalId }: { proposalId: Long }) {
129+
if (!Wallet.account?.address) throwError('Wallet not initialized')
130+
try {
131+
const msg = GroupMsgWithTypeUrl.exec({
132+
proposalId,
133+
executor: Wallet.account.address,
134+
})
135+
const data = await signAndBroadcast([msg])
136+
if (!data) throwError('No data returned from execution')
137+
return data
138+
} catch (err) {
139+
logError(err)
140+
}
141+
}
142+
128143
export async function fetchVotesByAddress(address?: string) {
129144
if (!Query.groups) throwError('Wallet not initialized')
130145
if (!address) throwError('Address cannot be empty')

src/pages/group-page.tsx

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { redirect, useParams } from 'react-router-dom'
22

3+
import { UIProposal } from 'types'
34
import { logError } from 'util/errors'
45

6+
import { executeProposal } from 'api/proposal.actions'
57
import { useDerivedProposals } from 'hooks/use-derived-proposals'
68
import {
79
useBalances,
810
useGroup,
911
useGroupPolicies,
1012
useGroupProposals,
1113
} from 'hooks/use-query'
14+
import { useTxToasts } from 'hooks/use-toasts'
1215

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

2226
const groupPolicy = policies?.[0]
2327
const { data: balances } = useBalances(groupPolicy?.address)
@@ -30,12 +34,25 @@ export default function GroupPage() {
3034
return null
3135
}
3236

37+
const handleExecute = async (proposal: UIProposal) => {
38+
try {
39+
const data = await executeProposal({ proposalId: proposal.id })
40+
if (data?.code !== 0) {
41+
toastSuccess(data?.transactionHash || '')
42+
} else {
43+
toastErr(data?.transactionHash || '')
44+
}
45+
} catch (err) {
46+
toastErr(err)
47+
}
48+
}
49+
3350
return (
3451
<GroupTemplate
3552
group={group}
3653
policies={policies}
3754
balances={balances}
38-
onExecute={(p) => console.log('execute proposal', p)}
55+
onExecute={handleExecute}
3956
proposals={{
4057
accepted: derivedProposals.accepted,
4158
history: derivedProposals.other,

0 commit comments

Comments
 (0)