Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only aggregate PortfolioBalance if on Popular Network #12961

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Routes from '../../../../../constants/navigation/Routes';
import { MetaMetricsEvents } from '../../../../../core/Analytics';
import {
selectChainId,
selectIsPopularNetwork,
selectProviderConfig,
selectTicker,
} from '../../../../../selectors/networkController';
Expand Down Expand Up @@ -68,11 +69,14 @@ export const PortfolioBalance = () => {
const isTokenNetworkFilterEqualCurrentNetwork = useSelector(
selectIsTokenNetworkFilterEqualCurrentNetwork,
);
const isPopularNetwork = useSelector(selectIsPopularNetwork);

const formattedTokensWithBalancesPerChain = useGetFormattedTokensPerChain(
[selectedInternalAccount as InternalAccount],
isTokenNetworkFilterEqualCurrentNetwork,
!isTokenNetworkFilterEqualCurrentNetwork && isPopularNetwork,
allChainIDs,
);

const totalFiatBalancesCrossChain: TotalFiatBalancesCrossChains =
useGetTotalFiatBalanceCrossChains(
[selectedInternalAccount as InternalAccount],
Expand Down
13 changes: 1 addition & 12 deletions app/components/hooks/useGetFormattedTokensPerChain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,6 @@ describe('useGetFormattedTokensPerChain', () => {
},
],
},
{
chainId: '0xe708',
tokensWithBalances: [
{
address: '0x0D1E753a25eBda689453309112904807625bEFBe',
symbol: 'CAKE',
decimals: 18,
balance: '0.00164',
tokenBalanceFiat: 0,
},
],
},
],
};

Expand All @@ -204,6 +192,7 @@ describe('useGetFormattedTokensPerChain', () => {
},
);

// Note, we are currently only aggregating for popular networks
expect(result.current).toEqual(expectedResult);
});
});
8 changes: 4 additions & 4 deletions app/components/hooks/useGetFormattedTokensPerChain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface MarketDataMapping {

export const useGetFormattedTokensPerChain = (
accounts: InternalAccount[],
shouldGetTokensPerCurrentChain: boolean,
shouldAggregateAcrossChains: boolean, // We don't always want to aggregate across chains.
allChainIDs: string[],
): {
[address: string]: {
Expand Down Expand Up @@ -85,9 +85,9 @@ export const useGetFormattedTokensPerChain = (
return {};
}

const networksToFormat = shouldGetTokensPerCurrentChain
? [currentChainId]
: allChainIDs;
const networksToFormat = shouldAggregateAcrossChains
? allChainIDs
: [currentChainId];

const result: {
[address: string]: {
Expand Down
Loading