1
1
import { useEffect , useMemo } from 'react' ;
2
2
import { useChain } from '@interchain-kit/react' ;
3
3
import BigNumber from 'bignumber.js' ;
4
- import { createRpcQueryHooks } from 'interchain-query' ;
5
4
import { bondStatusToJSON , BondStatus } from 'interchainjs/cosmos/staking/v1beta1/staking'
6
5
import { useRpcClient , useRpcEndpoint } from 'interchainjs/react-query'
7
6
import { defaultContext } from '@tanstack/react-query' ;
7
+ import { useGetBalance } from '@interchainjs/react/cosmos/bank/v1beta1/query.rpc.react'
8
+ import { useGetDelegatorValidators } from '@interchainjs/react/cosmos/staking/v1beta1/query.rpc.react'
9
+ import { useGetValidators } from '@interchainjs/react/cosmos/staking/v1beta1/query.rpc.react'
10
+ import { useGetDelegationTotalRewards } from '@interchainjs/react/cosmos/distribution/v1beta1/query.rpc.react'
11
+ import { useGetDelegatorDelegations } from '@interchainjs/react/cosmos/staking/v1beta1/query.rpc.react'
12
+ import { useGetParams } from '@interchainjs/react/cosmos/staking/v1beta1/query.rpc.react'
13
+ import { useGetAnnualProvisions } from '@interchainjs/react/cosmos/mint/v1beta1/query.rpc.react'
14
+ import { useGetPool } from '@interchainjs/react/cosmos/staking/v1beta1/query.rpc.react'
15
+ import { useGetParams as useGetParamsDistribution } from '@interchainjs/react/cosmos/distribution/v1beta1/query.rpc.react'
8
16
9
17
import { usePrices } from './usePrices' ;
10
18
import { getCoin , getExponent } from '@/config' ;
@@ -24,7 +32,7 @@ import {
24
32
} ;
25
33
26
34
export const useStakingData = ( chainName : string ) => {
27
- const { address, getRpcEndpoint } = useChain ( chainName ) ;
35
+ const { address, getRpcEndpoint, rpcEndpoint } = useChain ( chainName ) ;
28
36
29
37
const coin = getCoin ( chainName ) ;
30
38
const exp = getExponent ( chainName ) ;
@@ -52,46 +60,49 @@ export const useStakingData = (chainName: string) => {
52
60
} ,
53
61
} ) ;
54
62
55
- const { cosmos : cosmosQuery } = createRpcQueryHooks ( {
56
- rpc : rpcClientQuery . data ,
57
- } ) ;
58
-
59
63
const isDataQueryEnabled = ! ! address && ! ! rpcClientQuery . data ;
60
64
61
- const balanceQuery = cosmosQuery . bank . v1beta1 . useBalance ( {
65
+ const balanceQuery = useGetBalance ( {
66
+ clientResolver : rpcEndpoint ,
62
67
request : {
63
68
address : address || '' ,
64
69
denom : coin . base ,
65
70
} ,
66
71
options : {
72
+ context : defaultContext ,
67
73
enabled : isDataQueryEnabled ,
68
74
select : ( { balance } ) => shiftDigits ( balance ?. amount || '0' , - exp ) ,
69
75
} ,
70
76
} ) ;
71
77
72
- const myValidatorsQuery = cosmosQuery . staking . v1beta1 . useDelegatorValidators ( {
78
+ const myValidatorsQuery = useGetDelegatorValidators ( {
79
+ clientResolver : rpcEndpoint ,
73
80
request : {
74
81
delegatorAddr : address || '' ,
75
82
pagination : undefined ,
76
83
} ,
77
84
options : {
85
+ context : defaultContext ,
78
86
enabled : isDataQueryEnabled ,
79
87
select : ( { validators } ) => parseValidators ( validators ) ,
80
88
} ,
81
89
} ) ;
82
90
83
91
const rewardsQuery =
84
- cosmosQuery . distribution . v1beta1 . useDelegationTotalRewards ( {
92
+ useGetDelegationTotalRewards ( {
93
+ clientResolver : rpcEndpoint ,
85
94
request : {
86
95
delegatorAddress : address || '' ,
87
96
} ,
88
97
options : {
98
+ context : defaultContext ,
89
99
enabled : isDataQueryEnabled ,
90
100
select : ( data ) => parseRewards ( data , coin . base , - exp ) ,
91
101
} ,
92
102
} ) ;
93
103
94
- const validatorsQuery = cosmosQuery . staking . v1beta1 . useValidators ( {
104
+ const validatorsQuery = useGetValidators ( {
105
+ clientResolver : rpcEndpoint ,
95
106
request : {
96
107
status : bondStatusToJSON (
97
108
BondStatus . BOND_STATUS_BONDED
@@ -105,6 +116,7 @@ export const useStakingData = (chainName: string) => {
105
116
} ,
106
117
} ,
107
118
options : {
119
+ context : defaultContext ,
108
120
enabled : isDataQueryEnabled ,
109
121
select : ( { validators } ) => {
110
122
const sorted = validators . sort ( ( a , b ) =>
@@ -115,7 +127,8 @@ export const useStakingData = (chainName: string) => {
115
127
} ,
116
128
} ) ;
117
129
118
- const delegationsQuery = cosmosQuery . staking . v1beta1 . useDelegatorDelegations ( {
130
+ const delegationsQuery = useGetDelegatorDelegations ( {
131
+ clientResolver : rpcEndpoint ,
119
132
request : {
120
133
delegatorAddr : address || '' ,
121
134
pagination : {
@@ -127,36 +140,46 @@ export const useStakingData = (chainName: string) => {
127
140
} ,
128
141
} ,
129
142
options : {
143
+ context : defaultContext ,
130
144
enabled : isDataQueryEnabled ,
131
145
select : ( { delegationResponses } ) =>
132
146
parseDelegations ( delegationResponses , - exp ) ,
133
147
} ,
134
148
} ) ;
135
149
136
- const unbondingDaysQuery = cosmosQuery . staking . v1beta1 . useParams ( {
150
+ const unbondingDaysQuery = useGetParams ( {
151
+ clientResolver : rpcEndpoint ,
137
152
options : {
153
+ context : defaultContext ,
138
154
enabled : isDataQueryEnabled ,
139
155
select : ( { params } ) => parseUnbondingDays ( params ) ,
140
156
} ,
141
157
} ) ;
142
158
143
- const annualProvisionsQuery = cosmosQuery . mint . v1beta1 . useAnnualProvisions ( {
159
+ const annualProvisionsQuery = useGetAnnualProvisions ( {
160
+ clientResolver : rpcEndpoint ,
161
+ request : { } ,
144
162
options : {
163
+ context : defaultContext ,
145
164
enabled : isDataQueryEnabled ,
146
165
select : parseAnnualProvisions ,
147
166
retry : false ,
148
167
} ,
149
168
} ) ;
150
169
151
- const poolQuery = cosmosQuery . staking . v1beta1 . usePool ( {
170
+ const poolQuery = useGetPool ( {
171
+ clientResolver : rpcEndpoint ,
152
172
options : {
173
+ context : defaultContext ,
153
174
enabled : isDataQueryEnabled ,
154
175
select : ( { pool } ) => pool ,
155
176
} ,
156
177
} ) ;
157
178
158
- const communityTaxQuery = cosmosQuery . distribution . v1beta1 . useParams ( {
179
+ const communityTaxQuery = useGetParamsDistribution ( {
180
+ clientResolver : rpcEndpoint ,
159
181
options : {
182
+ context : defaultContext ,
160
183
enabled : isDataQueryEnabled ,
161
184
select : ( { params } ) => shiftDigits ( params ?. communityTax || '0' , - 18 ) ,
162
185
} ,
0 commit comments