1- import type { PortfolioDecomposition } from 'defi-sdk' ;
21import type { Account } from 'src/background/account/Account' ;
32import { getAddressActivity } from 'src/ui/shared/requests/useAddressActivity' ;
43import { INTERNAL_SYMBOL_CONTEXT } from 'src/background/Wallet/Wallet' ;
@@ -13,7 +12,10 @@ import type {
1312 WalletMeta ,
1413} from 'src/modules/zerion-api/requests/wallet-get-meta' ;
1514import { PREMIUM_PRIORITY } from 'src/modules/zerion-api/requests/wallet-get-meta' ;
16- import { getAddressesPortfolio } from './getTotalWalletsBalance' ;
15+ import type {
16+ Params ,
17+ WalletPortfolio ,
18+ } from 'src/modules/zerion-api/requests/wallet-get-portfolio' ;
1719import {
1820 getProviderForMixpanel ,
1921 getProviderNameFromGroup ,
@@ -45,9 +47,17 @@ function getFundedStatsByEcosystem(
4547 } ;
4648}
4749
50+ async function queryWalletPortfolio ( params : Params ) {
51+ return backgroundQueryClient . fetchQuery ( {
52+ queryKey : [ 'walletGetPortfolio' , params ] ,
53+ queryFn : ( ) => ZerionAPI . walletGetPortfolio ( params ) ,
54+ staleTime : 20000 ,
55+ } ) ;
56+ }
57+
4858async function getPortfolioStats ( addresses : string [ ] ) {
4959 return Promise . allSettled ( [
50- getAddressesPortfolio ( addresses ) ,
60+ queryWalletPortfolio ( { addresses, currency : 'usd' } ) ,
5161 getAddressActivity ( { addresses } , { cachePolicy : 'cache-first' } ) ,
5262 ] ) . then ( ( [ result1 , result2 ] ) => {
5363 return {
@@ -111,12 +121,12 @@ async function fetchWalletsMeta({ addresses }: { addresses: string[] }) {
111121 } ) ;
112122}
113123
114- function getChainBreakdown ( portfolio : PortfolioDecomposition | null ) {
124+ function getChainBreakdown ( portfolio : WalletPortfolio | null ) {
115125 const chainBreakdown : Record < string , number > = { } ;
116126 if ( portfolio ) {
117- for ( const internalId in portfolio . positions_chains_distribution ) {
127+ for ( const internalId in portfolio . positionsChainsDistribution ) {
118128 const key = `${ internalId } _balance` ;
119- chainBreakdown [ key ] = portfolio . positions_chains_distribution [ internalId ] ;
129+ chainBreakdown [ key ] = portfolio . positionsChainsDistribution [ internalId ] ;
120130 }
121131 }
122132 return chainBreakdown ;
@@ -209,8 +219,8 @@ export async function getUserProperties(account: Account) {
209219 num_funded_evm_wallets : fundedStatsByEcosystem . evmFundedCount ,
210220 num_watchlist_solana_wallets : readonlySolanaAddressesCount ?? 0 ,
211221 num_watchlist_evm_wallets : readonlyEvmAddressesCount ?? 0 ,
212- total_balance : portfolioStats ?. portfolio ?. total_value ?? 0 ,
213- ...getChainBreakdown ( portfolioStats ?. portfolio ?? null ) ,
222+ total_balance : portfolioStats ?. portfolio ?. data . totalValue ?? 0 ,
223+ ...getChainBreakdown ( portfolioStats ?. portfolio ?. data ?? null ) ,
214224 currency : 'usd' ,
215225 language : 'en' ,
216226 zerion_premium_holder : zerionStats ?. zerion_premium_holder ?? false ,
0 commit comments