@@ -3,10 +3,12 @@ import { useChain } from '@interchain-kit/react';
33import { useQueries } from '@tanstack/react-query' ;
44import { ProposalStatus } from 'interchainjs/cosmos/gov/v1beta1/gov' ;
55import { Proposal as ProposalV1 } from 'interchainjs/cosmos/gov/v1/gov' ;
6- import { useQueryHooks } from '.' ;
76import { getTitle , paginate , parseQuorum } from '@/utils' ;
87import { useGetVote } from '@interchainjs/react/cosmos/gov/v1/query.rpc.react' ;
98import { defaultContext } from '@tanstack/react-query' ;
9+ import { useGetProposals } from '@interchainjs/react/cosmos/gov/v1/query.rpc.react' ;
10+ import { useGetPool } from '@interchainjs/react/cosmos/staking/v1beta1/query.rpc.react' ;
11+ import { useGetParams } from '@interchainjs/react/cosmos/gov/v1/query.rpc.react' ;
1012
1113( BigInt . prototype as any ) . toJSON = function ( ) {
1214 return this . toString ( ) ;
@@ -38,51 +40,56 @@ export function processProposals(proposals: ProposalV1[]) {
3840
3941export function useVotingData ( chainName : string ) {
4042 const [ isLoading , setIsLoading ] = useState ( false ) ;
41- const { address } = useChain ( chainName ) ;
42- const { cosmos, isReady, isFetching } = useQueryHooks ( chainName ) ;
43+ const { address, rpcEndpoint } = useChain ( chainName ) ;
4344
44- // cosmos.gov.v1.useProposals
45-
46- const proposalsQuery = cosmos . gov . v1 . useProposals ( {
45+ const proposalsQuery = useGetProposals ( {
46+ clientResolver : rpcEndpoint ,
4747 request : {
4848 voter : '' ,
4949 depositor : '' ,
5050 pagination : paginate ( 50n , true ) ,
5151 proposalStatus : ProposalStatus . PROPOSAL_STATUS_UNSPECIFIED ,
5252 } ,
5353 options : {
54- enabled : isReady ,
54+ context : defaultContext ,
55+ enabled : ! ! rpcEndpoint ,
5556 staleTime : Infinity ,
5657 select : ( { proposals } ) => processProposals ( proposals ) ,
5758 } ,
5859 } ) ;
5960
60- const bondedTokensQuery = cosmos . staking . v1beta1 . usePool ( {
61+ const bondedTokensQuery = useGetPool ( {
62+ clientResolver : rpcEndpoint ,
6163 options : {
62- enabled : isReady ,
64+ context : defaultContext ,
65+ enabled : ! ! rpcEndpoint ,
6366 staleTime : Infinity ,
6467 select : ( { pool } ) => pool ?. bondedTokens ,
6568 } ,
6669 } ) ;
6770
68- const quorumQuery = cosmos . gov . v1 . useParams ( {
71+ const quorumQuery = useGetParams ( {
72+ clientResolver : rpcEndpoint ,
6973 request : { paramsType : 'tallying' } ,
7074 options : {
71- enabled : isReady ,
75+ context : defaultContext ,
76+ enabled : ! ! rpcEndpoint ,
7277 staleTime : Infinity ,
7378 select : ( { tallyParams } ) => parseQuorum ( tallyParams ?. quorum as any ) ,
7479 } ,
7580 } ) ;
7681
77- const votedProposalsQuery = cosmos . gov . v1 . useProposals ( {
82+ const votedProposalsQuery = useGetProposals ( {
83+ clientResolver : rpcEndpoint ,
7884 request : {
7985 voter : address || '/' , // use '/' to differentiate from proposalsQuery
8086 depositor : '' ,
8187 pagination : paginate ( 50n , true ) ,
8288 proposalStatus : ProposalStatus . PROPOSAL_STATUS_UNSPECIFIED ,
8389 } ,
8490 options : {
85- enabled : isReady && Boolean ( address ) ,
91+ context : defaultContext ,
92+ enabled : ! ! rpcEndpoint && Boolean ( address ) ,
8693 select : ( { proposals } ) => proposals ,
8794 keepPreviousData : true ,
8895 } ,
@@ -138,8 +145,10 @@ export function useVotingData(chainName: string) {
138145 singleQueries . votedProposals . isFetching ||
139146 votesQueries . some ( ( { isFetching } ) => isFetching ) ;
140147
148+ const isFetching = proposalsQuery . isFetching || votedProposalsQuery . isFetching || bondedTokensQuery . isFetching || quorumQuery . isFetching
149+
141150 const loading =
142- isFetching || isStaticQueriesFetching || isDynamicQueriesFetching ;
151+ isFetching || isStaticQueriesFetching || isDynamicQueriesFetching
143152
144153 useEffect ( ( ) => {
145154 // no loading when refetching
@@ -154,12 +163,12 @@ export function useVotingData(chainName: string) {
154163 } ;
155164
156165 const singleQueriesData = useMemo ( ( ) => {
157- if ( isStaticQueriesFetching || ! isReady ) return ;
166+ if ( isStaticQueriesFetching || ! proposalsQuery . isFetched || ! votedProposalsQuery . isFetched ) return ;
158167
159168 return Object . fromEntries (
160169 Object . entries ( singleQueries ) . map ( ( [ key , query ] ) => [ key , query . data ] )
161170 ) as SingleQueriesData ;
162- } , [ isStaticQueriesFetching , isReady ] ) ;
171+ } , [ isStaticQueriesFetching , proposalsQuery . isFetched , votedProposalsQuery . isFetched ] ) ;
163172
164173 const votes = useMemo ( ( ) => {
165174 const votesEntries = votesQueries
0 commit comments