From 3e7d5b1f720014e405aa5ee917636348483cc91f Mon Sep 17 00:00:00 2001 From: Kane Thomas Date: Fri, 20 Dec 2024 11:47:41 -0500 Subject: [PATCH] use positons value from summary for wallet balance (#6358) --- src/hooks/useWalletBalances.ts | 24 +++++------------------- src/resources/summary/summary.ts | 4 ++++ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/hooks/useWalletBalances.ts b/src/hooks/useWalletBalances.ts index fbafc1c909e..9f1e912e437 100644 --- a/src/hooks/useWalletBalances.ts +++ b/src/hooks/useWalletBalances.ts @@ -3,11 +3,7 @@ import { useMemo } from 'react'; import { Address } from 'viem'; import useAccountSettings from './useAccountSettings'; import { useAddysSummary } from '@/resources/summary/summary'; -import { useQueries } from '@tanstack/react-query'; -import { fetchPositions, positionsQueryKey } from '@/resources/defi/PositionsQuery'; -import { RainbowPositions } from '@/resources/defi/types'; import { add, convertAmountToNativeDisplay } from '@/helpers/utilities'; -import { queryClient } from '@/react-query'; const QUERY_CONFIG = { staleTime: 60_000, // 1 minute @@ -43,7 +39,7 @@ const useWalletBalances = (wallets: AllRainbowWallets): WalletBalanceResult => { [wallets] ); - const { data: summaryData, isLoading: isSummaryLoading } = useAddysSummary( + const { data: summaryData, isLoading } = useAddysSummary( { addresses: allAddresses, currency: nativeCurrency, @@ -51,17 +47,6 @@ const useWalletBalances = (wallets: AllRainbowWallets): WalletBalanceResult => { QUERY_CONFIG ); - const positionQueries = useQueries({ - queries: allAddresses.map(address => ({ - queryKey: positionsQueryKey({ address, currency: nativeCurrency }), - queryFn: () => fetchPositions({ address, currency: nativeCurrency }), - enabled: !!address, - ...QUERY_CONFIG, - })), - }); - - const isLoading = isSummaryLoading || positionQueries.some(query => query.isLoading); - const balances = useMemo(() => { const result: Record = {}; @@ -70,9 +55,10 @@ const useWalletBalances = (wallets: AllRainbowWallets): WalletBalanceResult => { for (const address of allAddresses) { const lowerCaseAddress = address.toLowerCase() as Address; const assetBalance = summaryData?.data?.addresses?.[lowerCaseAddress]?.summary?.asset_value?.toString() || '0'; - const positionData = queryClient.getQueryData(positionsQueryKey({ address, currency: nativeCurrency })); - const positionsBalance = positionData ? positionData.totals.total.amount : '0'; - const totalAccountBalance = add(assetBalance, positionsBalance); + const positionsBalance = summaryData?.data?.addresses?.[lowerCaseAddress]?.summary?.positions_value?.toString() || '0'; + const claimablesBalance = summaryData?.data?.addresses?.[lowerCaseAddress]?.summary?.claimables_value?.toString() || '0'; + + const totalAccountBalance = add(assetBalance, add(positionsBalance, claimablesBalance)); result[lowerCaseAddress] = { assetBalanceAmount: assetBalance, diff --git a/src/resources/summary/summary.ts b/src/resources/summary/summary.ts index cd0ef1d8542..71c68ff92b5 100644 --- a/src/resources/summary/summary.ts +++ b/src/resources/summary/summary.ts @@ -51,6 +51,8 @@ interface AddysSummary { num_erc20s: number; last_activity: number; asset_value: number | null; + claimables_value: number | null; + positions_value: number | null; }; }; summary_by_chain: { @@ -63,6 +65,8 @@ interface AddysSummary { num_erc20s: number; last_activity: number; asset_value: number | null; + claimables_value: number | null; + positions_value: number | null; }; }; };