@@ -5,10 +5,9 @@ import BigNumber from 'bignumber.js';
55import { useEffect , useMemo } from 'react' ;
66import { useChainUtils } from '../useChainUtils' ;
77import { usePrices } from './usePrices' ;
8- import { defaultChainName as osmoChainName } from '@/config' ;
9- import { Pool } from '@/types/pool-models' ;
10- import { convertGammTokenToDollarValue } from '@/utils' ;
11- import { useQueryHooks } from './useQueryHooks' ;
8+ import { useGetAllBalances } from 'interchain-react/cosmos/bank/v1beta1/query.rpc.func'
9+ import { defaultContext } from '@tanstack/react-query' ;
10+ import { useGetDelegatorDelegations } from 'interchain-react/cosmos/staking/v1beta1/query.rpc.func' ;
1211
1312( BigInt . prototype as any ) . toJSON = function ( ) {
1413 return this . toString ( ) ;
@@ -23,71 +22,43 @@ export const getPagination = (limit: bigint) => ({
2322} ) ;
2423
2524export const useTotalAssets = ( chainName : string ) => {
26- const { address } = useChain ( chainName ) ;
27-
28- const { cosmosQuery, osmosisQuery, isReady, isFetching } =
29- useQueryHooks ( chainName ) ;
30-
31- const isOsmosisChain = chainName === osmoChainName ;
25+ const { address, rpcEndpoint } = useChain ( chainName ) ;
3226
3327 const allBalancesQuery : UseQueryResult < Coin [ ] > =
34- cosmosQuery . bank . v1beta1 . useAllBalances ( {
28+ useGetAllBalances ( {
29+ clientResolver : rpcEndpoint ,
3530 request : {
3631 address : address || '' ,
3732 pagination : getPagination ( 100n ) ,
33+ resolveDenom : false
3834 } ,
3935 options : {
40- enabled : isReady ,
36+ context : defaultContext ,
37+ enabled : ! ! rpcEndpoint ,
4138 select : ( { balances } ) => balances || [ ] ,
4239 } ,
4340 } ) ;
4441
4542 const delegationsQuery : UseQueryResult < Coin [ ] > =
46- cosmosQuery . staking . v1beta1 . useDelegatorDelegations ( {
43+ useGetDelegatorDelegations ( {
4744 request : {
4845 delegatorAddr : address || '' ,
4946 pagination : getPagination ( 100n ) ,
5047 } ,
5148 options : {
52- enabled : isReady ,
49+ context : defaultContext ,
50+ enabled : ! ! rpcEndpoint ,
5351 select : ( { delegationResponses } ) =>
5452 delegationResponses . map ( ( { balance } ) => balance ) || [ ] ,
5553 } ,
5654 } ) ;
5755
58- const lockedCoinsQuery : UseQueryResult < Coin [ ] > =
59- osmosisQuery . lockup . useAccountLockedCoins ( {
60- request : {
61- owner : address || '' ,
62- } ,
63- options : {
64- enabled : isReady && isOsmosisChain ,
65- select : ( { coins } ) => coins || [ ] ,
66- staleTime : Infinity ,
67- } ,
68- } ) ;
69-
70- const poolsQuery : UseQueryResult < Pool [ ] > = osmosisQuery . gamm . v1beta1 . usePools (
71- {
72- request : {
73- pagination : getPagination ( 5000n ) ,
74- } ,
75- options : {
76- enabled : isReady && isOsmosisChain ,
77- select : ( { pools } ) => pools || [ ] ,
78- staleTime : Infinity ,
79- } ,
80- }
81- ) ;
82-
8356 const pricesQuery = usePrices ( chainName ) ;
8457
8558 const dataQueries = {
86- pools : poolsQuery ,
8759 prices : pricesQuery ,
8860 allBalances : allBalancesQuery ,
8961 delegations : delegationsQuery ,
90- lockedCoins : lockedCoinsQuery ,
9162 } ;
9263
9364 const queriesToReset = [ dataQueries . allBalances , dataQueries . delegations ] ;
@@ -101,7 +72,7 @@ export const useTotalAssets = (chainName: string) => {
10172 const queries = Object . values ( dataQueries ) ;
10273 const isInitialFetching = queries . some ( ( { isFetching } ) => isFetching ) ;
10374 const isRefetching = queries . some ( ( { isRefetching } ) => isRefetching ) ;
104- const isLoading = isFetching || isInitialFetching || isRefetching ;
75+ const isLoading = delegationsQuery . isFetching || allBalancesQuery . isFetching || isInitialFetching || isRefetching ;
10576
10677 type AllQueries = typeof dataQueries ;
10778
@@ -122,68 +93,18 @@ export const useTotalAssets = (chainName: string) => {
12293
12394 const {
12495 allBalances,
125- delegations,
126- lockedCoins = [ ] ,
127- pools = [ ] ,
12896 prices = { } ,
12997 } = queriesData ;
13098
131- const stakedTotal = delegations
132- ?. map ( ( coin ) => calcCoinDollarValue ( prices , coin ) )
133- . reduce ( ( total , cur ) => total . plus ( cur ) , zero )
134- . toString ( ) ;
135-
13699 const balancesTotal = allBalances
137100 ?. filter ( ( { denom } ) => ! denom . startsWith ( 'gamm' ) && prices [ denom ] )
138101 . map ( ( coin ) => calcCoinDollarValue ( prices , coin ) )
139102 . reduce ( ( total , cur ) => total . plus ( cur ) , zero )
140103 . toString ( ) ;
141104
142- let bondedTotal ;
143- let liquidityTotal ;
144-
145- if ( isOsmosisChain ) {
146- const liquidityCoins = ( allBalances ?? [ ] ) . filter ( ( { denom } ) =>
147- denom . startsWith ( 'gamm' )
148- ) ;
149- const gammTokenDenoms = [
150- ...( liquidityCoins ?? [ ] ) ,
151- ...( lockedCoins ?? [ ] ) ,
152- ] . map ( ( { denom } ) => denom ) ;
153-
154- const uniqueDenoms = [ ...new Set ( gammTokenDenoms ) ] ;
155-
156- const poolsMap : Record < string , Pool > = pools
157- . filter ( ( { totalShares } ) => uniqueDenoms . includes ( totalShares . denom ) )
158- . filter ( ( pool ) => ! pool ?. $typeUrl ?. includes ( 'stableswap' ) )
159- . filter ( ( { poolAssets } ) => {
160- return poolAssets . every ( ( { token } ) => {
161- const isGammToken = token . denom . startsWith ( 'gamm/pool' ) ;
162- return ! isGammToken && prices [ token . denom ] ;
163- } ) ;
164- } )
165- . reduce ( ( prev , cur ) => ( { ...prev , [ cur . totalShares . denom ] : cur } ) , { } ) ;
166-
167- bondedTotal = lockedCoins
168- . map ( ( coin ) => {
169- const poolData = poolsMap [ coin . denom ] ;
170- if ( ! poolData ) return '0' ;
171- return convertGammTokenToDollarValue ( coin , poolData , prices ) ;
172- } )
173- . reduce ( ( total , cur ) => total . plus ( cur ) , zero )
174- . toString ( ) ;
175-
176- liquidityTotal = liquidityCoins
177- . map ( ( coin ) => {
178- const poolData = poolsMap [ coin . denom ] ;
179- if ( ! poolData ) return '0' ;
180- return convertGammTokenToDollarValue ( coin , poolData , prices ) ;
181- } )
182- . reduce ( ( total , cur ) => total . plus ( cur ) , zero )
183- . toString ( ) ;
184- }
185-
186- const total = [ stakedTotal , balancesTotal , bondedTotal , liquidityTotal ]
105+ const total = [
106+ balancesTotal
107+ ]
187108 . reduce ( ( total , cur ) => total . plus ( cur || 0 ) , zero )
188109 . decimalPlaces ( 2 )
189110 . toString ( ) ;
0 commit comments