@@ -5,10 +5,9 @@ import BigNumber from 'bignumber.js';
5
5
import { useEffect , useMemo } from 'react' ;
6
6
import { useChainUtils } from '../useChainUtils' ;
7
7
import { 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' ;
12
11
13
12
( BigInt . prototype as any ) . toJSON = function ( ) {
14
13
return this . toString ( ) ;
@@ -23,71 +22,43 @@ export const getPagination = (limit: bigint) => ({
23
22
} ) ;
24
23
25
24
export 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 ) ;
32
26
33
27
const allBalancesQuery : UseQueryResult < Coin [ ] > =
34
- cosmosQuery . bank . v1beta1 . useAllBalances ( {
28
+ useGetAllBalances ( {
29
+ clientResolver : rpcEndpoint ,
35
30
request : {
36
31
address : address || '' ,
37
32
pagination : getPagination ( 100n ) ,
33
+ resolveDenom : false
38
34
} ,
39
35
options : {
40
- enabled : isReady ,
36
+ context : defaultContext ,
37
+ enabled : ! ! rpcEndpoint ,
41
38
select : ( { balances } ) => balances || [ ] ,
42
39
} ,
43
40
} ) ;
44
41
45
42
const delegationsQuery : UseQueryResult < Coin [ ] > =
46
- cosmosQuery . staking . v1beta1 . useDelegatorDelegations ( {
43
+ useGetDelegatorDelegations ( {
47
44
request : {
48
45
delegatorAddr : address || '' ,
49
46
pagination : getPagination ( 100n ) ,
50
47
} ,
51
48
options : {
52
- enabled : isReady ,
49
+ context : defaultContext ,
50
+ enabled : ! ! rpcEndpoint ,
53
51
select : ( { delegationResponses } ) =>
54
52
delegationResponses . map ( ( { balance } ) => balance ) || [ ] ,
55
53
} ,
56
54
} ) ;
57
55
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
-
83
56
const pricesQuery = usePrices ( chainName ) ;
84
57
85
58
const dataQueries = {
86
- pools : poolsQuery ,
87
59
prices : pricesQuery ,
88
60
allBalances : allBalancesQuery ,
89
61
delegations : delegationsQuery ,
90
- lockedCoins : lockedCoinsQuery ,
91
62
} ;
92
63
93
64
const queriesToReset = [ dataQueries . allBalances , dataQueries . delegations ] ;
@@ -101,7 +72,7 @@ export const useTotalAssets = (chainName: string) => {
101
72
const queries = Object . values ( dataQueries ) ;
102
73
const isInitialFetching = queries . some ( ( { isFetching } ) => isFetching ) ;
103
74
const isRefetching = queries . some ( ( { isRefetching } ) => isRefetching ) ;
104
- const isLoading = isFetching || isInitialFetching || isRefetching ;
75
+ const isLoading = delegationsQuery . isFetching || allBalancesQuery . isFetching || isInitialFetching || isRefetching ;
105
76
106
77
type AllQueries = typeof dataQueries ;
107
78
@@ -122,68 +93,18 @@ export const useTotalAssets = (chainName: string) => {
122
93
123
94
const {
124
95
allBalances,
125
- delegations,
126
- lockedCoins = [ ] ,
127
- pools = [ ] ,
128
96
prices = { } ,
129
97
} = queriesData ;
130
98
131
- const stakedTotal = delegations
132
- ?. map ( ( coin ) => calcCoinDollarValue ( prices , coin ) )
133
- . reduce ( ( total , cur ) => total . plus ( cur ) , zero )
134
- . toString ( ) ;
135
-
136
99
const balancesTotal = allBalances
137
100
?. filter ( ( { denom } ) => ! denom . startsWith ( 'gamm' ) && prices [ denom ] )
138
101
. map ( ( coin ) => calcCoinDollarValue ( prices , coin ) )
139
102
. reduce ( ( total , cur ) => total . plus ( cur ) , zero )
140
103
. toString ( ) ;
141
104
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
+ ]
187
108
. reduce ( ( total , cur ) => total . plus ( cur || 0 ) , zero )
188
109
. decimalPlaces ( 2 )
189
110
. toString ( ) ;
0 commit comments