Skip to content

Commit 772b5a0

Browse files
author
Eason Smith
committed
removed interchain-query from example stake-tokens
1 parent dab37f7 commit 772b5a0

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

Diff for: examples/stake-tokens/hooks/useStakingData.ts

+38-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { useEffect, useMemo } from 'react';
22
import { useChain } from '@interchain-kit/react';
33
import BigNumber from 'bignumber.js';
4-
import { createRpcQueryHooks } from 'interchain-query';
54
import { bondStatusToJSON, BondStatus } from 'interchainjs/cosmos/staking/v1beta1/staking'
65
import { useRpcClient, useRpcEndpoint } from 'interchainjs/react-query'
76
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'
816

917
import { usePrices } from './usePrices';
1018
import { getCoin, getExponent } from '@/config';
@@ -24,7 +32,7 @@ import {
2432
};
2533

2634
export const useStakingData = (chainName: string) => {
27-
const { address, getRpcEndpoint } = useChain(chainName);
35+
const { address, getRpcEndpoint, rpcEndpoint } = useChain(chainName);
2836

2937
const coin = getCoin(chainName);
3038
const exp = getExponent(chainName);
@@ -52,46 +60,49 @@ export const useStakingData = (chainName: string) => {
5260
},
5361
});
5462

55-
const { cosmos: cosmosQuery } = createRpcQueryHooks({
56-
rpc: rpcClientQuery.data,
57-
});
58-
5963
const isDataQueryEnabled = !!address && !!rpcClientQuery.data;
6064

61-
const balanceQuery = cosmosQuery.bank.v1beta1.useBalance({
65+
const balanceQuery = useGetBalance({
66+
clientResolver: rpcEndpoint,
6267
request: {
6368
address: address || '',
6469
denom: coin.base,
6570
},
6671
options: {
72+
context: defaultContext,
6773
enabled: isDataQueryEnabled,
6874
select: ({ balance }) => shiftDigits(balance?.amount || '0', -exp),
6975
},
7076
});
7177

72-
const myValidatorsQuery = cosmosQuery.staking.v1beta1.useDelegatorValidators({
78+
const myValidatorsQuery = useGetDelegatorValidators({
79+
clientResolver: rpcEndpoint,
7380
request: {
7481
delegatorAddr: address || '',
7582
pagination: undefined,
7683
},
7784
options: {
85+
context: defaultContext,
7886
enabled: isDataQueryEnabled,
7987
select: ({ validators }) => parseValidators(validators),
8088
},
8189
});
8290

8391
const rewardsQuery =
84-
cosmosQuery.distribution.v1beta1.useDelegationTotalRewards({
92+
useGetDelegationTotalRewards({
93+
clientResolver: rpcEndpoint,
8594
request: {
8695
delegatorAddress: address || '',
8796
},
8897
options: {
98+
context: defaultContext,
8999
enabled: isDataQueryEnabled,
90100
select: (data) => parseRewards(data, coin.base, -exp),
91101
},
92102
});
93103

94-
const validatorsQuery = cosmosQuery.staking.v1beta1.useValidators({
104+
const validatorsQuery = useGetValidators({
105+
clientResolver: rpcEndpoint,
95106
request: {
96107
status: bondStatusToJSON(
97108
BondStatus.BOND_STATUS_BONDED
@@ -105,6 +116,7 @@ export const useStakingData = (chainName: string) => {
105116
},
106117
},
107118
options: {
119+
context: defaultContext,
108120
enabled: isDataQueryEnabled,
109121
select: ({ validators }) => {
110122
const sorted = validators.sort((a, b) =>
@@ -115,7 +127,8 @@ export const useStakingData = (chainName: string) => {
115127
},
116128
});
117129

118-
const delegationsQuery = cosmosQuery.staking.v1beta1.useDelegatorDelegations({
130+
const delegationsQuery = useGetDelegatorDelegations({
131+
clientResolver: rpcEndpoint,
119132
request: {
120133
delegatorAddr: address || '',
121134
pagination: {
@@ -127,36 +140,46 @@ export const useStakingData = (chainName: string) => {
127140
},
128141
},
129142
options: {
143+
context: defaultContext,
130144
enabled: isDataQueryEnabled,
131145
select: ({ delegationResponses }) =>
132146
parseDelegations(delegationResponses, -exp),
133147
},
134148
});
135149

136-
const unbondingDaysQuery = cosmosQuery.staking.v1beta1.useParams({
150+
const unbondingDaysQuery = useGetParams({
151+
clientResolver: rpcEndpoint,
137152
options: {
153+
context: defaultContext,
138154
enabled: isDataQueryEnabled,
139155
select: ({ params }) => parseUnbondingDays(params),
140156
},
141157
});
142158

143-
const annualProvisionsQuery = cosmosQuery.mint.v1beta1.useAnnualProvisions({
159+
const annualProvisionsQuery = useGetAnnualProvisions({
160+
clientResolver: rpcEndpoint,
161+
request: {},
144162
options: {
163+
context: defaultContext,
145164
enabled: isDataQueryEnabled,
146165
select: parseAnnualProvisions,
147166
retry: false,
148167
},
149168
});
150169

151-
const poolQuery = cosmosQuery.staking.v1beta1.usePool({
170+
const poolQuery = useGetPool({
171+
clientResolver: rpcEndpoint,
152172
options: {
173+
context: defaultContext,
153174
enabled: isDataQueryEnabled,
154175
select: ({ pool }) => pool,
155176
},
156177
});
157178

158-
const communityTaxQuery = cosmosQuery.distribution.v1beta1.useParams({
179+
const communityTaxQuery = useGetParamsDistribution({
180+
clientResolver: rpcEndpoint,
159181
options: {
182+
context: defaultContext,
160183
enabled: isDataQueryEnabled,
161184
select: ({ params }) => shiftDigits(params?.communityTax || '0', -18),
162185
},

0 commit comments

Comments
 (0)