Skip to content

Commit 9f7ff09

Browse files
author
Eason Smith
committed
use v1 of proposal API
1 parent 70f5701 commit 9f7ff09

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

examples/vote-proposal/components/voting/Proposal.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import {
1414
Proposal as IProposal,
1515
ProposalStatus,
16-
} from "interchain-query/cosmos/gov/v1beta1/gov";
16+
} from "interchain-query/cosmos/gov/v1/gov";
1717
import {
1818
exponentiate,
1919
formatDate,
@@ -59,7 +59,7 @@ export function Proposal({
5959
bondedTokens,
6060
onVoteSuccess = () => { },
6161
}: ProposalProps) {
62-
const vote = votes?.[proposal.proposalId.toString()];
62+
const vote = votes?.[proposal.id.toString()];
6363

6464
const [showMore, setShowMore] = useState(false);
6565
const [voteType, setVoteType] = useState<GovernanceVoteType>();
@@ -267,29 +267,29 @@ export function Proposal({
267267
<GovernanceVoteBreakdown
268268
voteType="yes"
269269
title="Yes"
270-
votePercentage={percent(proposal.finalTallyResult?.yes, total)}
270+
votePercentage={percent(proposal.finalTallyResult?.yesCount, total)}
271271
description={`${exponentiate(
272-
proposal.finalTallyResult?.yes,
272+
proposal.finalTallyResult?.yesCount,
273273
-exponent,
274274
).toFixed(2)
275275
} ${coin.symbol}`}
276276
/>
277277
<GovernanceVoteBreakdown
278278
voteType="abstain"
279279
title="Abstain"
280-
votePercentage={percent(proposal.finalTallyResult?.abstain, total)}
280+
votePercentage={percent(proposal.finalTallyResult?.abstainCount, total)}
281281
description={`${exponentiate(
282-
proposal.finalTallyResult?.abstain,
282+
proposal.finalTallyResult?.abstainCount,
283283
-exponent,
284284
).toFixed(2)
285285
} ${coin.symbol}`}
286286
/>
287287
<GovernanceVoteBreakdown
288288
voteType="no"
289289
title="No"
290-
votePercentage={percent(proposal.finalTallyResult?.no, total)}
290+
votePercentage={percent(proposal.finalTallyResult?.noCount, total)}
291291
description={`${exponentiate(
292-
proposal.finalTallyResult?.no,
292+
proposal.finalTallyResult?.noCount,
293293
-exponent,
294294
).toFixed(2)
295295
} ${coin.symbol}`}
@@ -298,11 +298,11 @@ export function Proposal({
298298
voteType="noWithVeto"
299299
title="No with veto"
300300
votePercentage={percent(
301-
proposal.finalTallyResult?.noWithVeto,
301+
proposal.finalTallyResult?.noWithVetoCount,
302302
total,
303303
)}
304304
description={`${exponentiate(
305-
proposal.finalTallyResult?.noWithVeto,
305+
proposal.finalTallyResult?.noWithVetoCount,
306306
-exponent,
307307
).toFixed(2)
308308
} ${coin.symbol}`}
@@ -314,7 +314,7 @@ export function Proposal({
314314
<GovernanceResultCard
315315
resultType="passed"
316316
label="Passed"
317-
votePercentage={percent(proposal.finalTallyResult?.yes, total)}
317+
votePercentage={percent(proposal.finalTallyResult?.yesCount, total)}
318318
/>
319319
)
320320
: null}
@@ -324,10 +324,10 @@ export function Proposal({
324324
resultType="rejected"
325325
label="Rejected"
326326
votePercentage={+(percent(
327-
proposal.finalTallyResult?.no,
327+
proposal.finalTallyResult?.noCount,
328328
total,
329329
) +
330-
percent(proposal.finalTallyResult?.noWithVeto, total))
330+
percent(proposal.finalTallyResult?.noWithVetoCount, total))
331331
.toFixed(2)}
332332
/>
333333
)

examples/vote-proposal/components/voting/Voting.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Proposal as IProposal,
55
ProposalStatus,
66
TallyResult,
7-
} from "interchain-query/cosmos/gov/v1beta1/gov";
7+
} from "interchain-query/cosmos/gov/v1/gov";
88
import {
99
BasicModal,
1010
Box,
@@ -38,10 +38,10 @@ function status(s: ProposalStatus) {
3838

3939
function votes(result: TallyResult) {
4040
return {
41-
yes: Number(result.yes) || 0,
42-
no: Number(result.no) || 0,
43-
abstain: Number(result.abstain) || 0,
44-
noWithVeto: Number(result.noWithVeto) || 0,
41+
yes: Number(result.yesCount) || 0,
42+
no: Number(result.noCount) || 0,
43+
abstain: Number(result.abstainCount) || 0,
44+
noWithVeto: Number(result.noWithVetoCount) || 0,
4545
};
4646
}
4747

@@ -68,11 +68,11 @@ export function Voting({ chainName }: VotingProps) {
6868
{data.proposals?.map((proposal, index) => (
6969
<Box
7070
my="$8"
71-
key={proposal.proposalId?.toString() || index}
71+
key={proposal.id?.toString() || index}
7272
position="relative"
7373
attributes={{ onClick: () => onClickProposal(index) }}
7474
>
75-
{data.votes[proposal.proposalId.toString()]
75+
{data.votes[proposal.id.toString()]
7676
? (
7777
<Box
7878
position="absolute"
@@ -90,7 +90,7 @@ export function Voting({ chainName }: VotingProps) {
9090
)
9191
: null}
9292
<GovernanceProposalItem
93-
id={`# ${proposal.proposalId?.toString()}`}
93+
id={`# ${proposal.id?.toString()}`}
9494
key={proposal.submitTime?.getTime()}
9595
// @ts-ignore
9696
title={proposal.content?.title || ""}

examples/vote-proposal/hooks/useVoting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cosmos } from 'interchain-query';
33
import { toast } from '@interchain-ui/react';
44
import { useChain } from '@cosmos-kit/react';
55
import { coins, StdFee } from '@cosmjs/stargate';
6-
import { Proposal } from "interchain-query/cosmos/gov/v1beta1/gov";
6+
import { Proposal } from "interchain-query/cosmos/gov/v1/gov";
77
import { useTx } from '@/hooks';
88
import { getCoin } from '@/utils';
99

@@ -33,7 +33,7 @@ export function useVoting({ chainName, proposal }: useVotingOptions) {
3333
const msg = MessageComposer.fromPartial.vote({
3434
option,
3535
voter: address,
36-
proposalId: proposal.proposalId,
36+
proposalId: proposal.id,
3737
});
3838

3939
const fee: StdFee = {

examples/vote-proposal/hooks/useVotingData.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useState } from 'react';
22
import { useChain } from '@cosmos-kit/react';
33
import { useQueries } from '@tanstack/react-query';
44
import { Proposal, ProposalStatus } from 'interchain-query/cosmos/gov/v1beta1/gov';
5+
import { Proposal as ProposalV1 } from 'interchain-query/cosmos/gov/v1/gov';
56
import { useQueryHooks, useRpcQueryClient } from '.';
67
import { getTitle, paginate, parseQuorum } from '@/utils';
78

@@ -13,9 +14,9 @@ export interface Votes {
1314
[key: string]: number;
1415
}
1516

16-
export function processProposals(proposals: Proposal[]) {
17+
export function processProposals(proposals: ProposalV1[]) {
1718
const sorted = proposals.sort(
18-
(a, b) => Number(b.proposalId) - Number(a.proposalId)
19+
(a, b) => Number(b.id) - Number(a.id)
1920
);
2021

2122
proposals.forEach((proposal) => {
@@ -39,7 +40,9 @@ export function useVotingData(chainName: string) {
3940
const { rpcQueryClient } = useRpcQueryClient(chainName);
4041
const { cosmos, isReady, isFetching } = useQueryHooks(chainName);
4142

42-
const proposalsQuery = cosmos.gov.v1beta1.useProposals({
43+
// cosmos.gov.v1.useProposals
44+
45+
const proposalsQuery = cosmos.gov.v1.useProposals({
4346
request: {
4447
voter: '',
4548
depositor: '',
@@ -61,16 +64,16 @@ export function useVotingData(chainName: string) {
6164
},
6265
});
6366

64-
const quorumQuery = cosmos.gov.v1beta1.useParams({
67+
const quorumQuery = cosmos.gov.v1.useParams({
6568
request: { paramsType: 'tallying' },
6669
options: {
6770
enabled: isReady,
6871
staleTime: Infinity,
69-
select: ({ tallyParams }) => parseQuorum(tallyParams?.quorum),
72+
select: ({ tallyParams }) => parseQuorum(tallyParams?.quorum as any),
7073
},
7174
});
7275

73-
const votedProposalsQuery = cosmos.gov.v1beta1.useProposals({
76+
const votedProposalsQuery = cosmos.gov.v1.useProposals({
7477
request: {
7578
voter: address || '/', // use '/' to differentiate from proposalsQuery
7679
depositor: '',
@@ -85,11 +88,11 @@ export function useVotingData(chainName: string) {
8588
});
8689

8790
const votesQueries = useQueries({
88-
queries: (votedProposalsQuery.data || []).map(({ proposalId }) => ({
89-
queryKey: ['voteQuery', proposalId, address],
91+
queries: (votedProposalsQuery.data || []).map(({ id }) => ({
92+
queryKey: ['voteQuery', id, address],
9093
queryFn: () =>
91-
rpcQueryClient?.cosmos.gov.v1beta1.vote({
92-
proposalId,
94+
rpcQueryClient?.cosmos.gov.v1.vote({
95+
proposalId: id,
9396
voter: address || '',
9497
}),
9598
enabled: Boolean(rpcQueryClient) && Boolean(address) && Boolean(votedProposalsQuery.data),

0 commit comments

Comments
 (0)