From 971bad8da5c576ff4668c5abb05e5b691816ba0a Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 1 Jul 2026 12:58:32 -0300 Subject: [PATCH] Portfolio: Fix - show chart loader while repopulating after re-enabling --- .../AssetBalanceHistoryScreen.spec.tsx | 11 ++++----- .../screens/portfolioChartVisibility.spec.tsx | 24 ++++++++++++------- .../usePortfolioBalanceChartReadiness.ts | 3 ++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/navigation/wallet/screens/exchange-rate/AssetBalanceHistoryScreen.spec.tsx b/src/navigation/wallet/screens/exchange-rate/AssetBalanceHistoryScreen.spec.tsx index 88f0b43d9..da4306a64 100644 --- a/src/navigation/wallet/screens/exchange-rate/AssetBalanceHistoryScreen.spec.tsx +++ b/src/navigation/wallet/screens/exchange-rate/AssetBalanceHistoryScreen.spec.tsx @@ -294,7 +294,7 @@ describe('AssetBalanceHistoryScreen', () => { ); }); - it('does not mount chart work while the asset initial populate scope is still running', async () => { + it('mounts chart work with a loader while the asset initial populate scope is still running', async () => { const shared = sharedFactory(); isPopulateLoadingForWallets.mockReturnValue(true); mockState.PORTFOLIO = { @@ -316,11 +316,10 @@ describe('AssetBalanceHistoryScreen', () => { TestRenderer.create(); }); - expect(latestBalanceHistoryChartProps).toBeUndefined(); - expect(usePortfolioAnalysis).toHaveBeenLastCalledWith( - expect.objectContaining({ - enabled: false, - }), + expect(latestBalanceHistoryChartProps).toBeDefined(); + expect(latestBalanceHistoryChartProps.showLoaderWhenNoSnapshots).toBe(true); + expect(latestBalanceHistoryChartProps.isBalanceChartDataReadyToQuery).toBe( + false, ); }); diff --git a/src/navigation/wallet/screens/portfolioChartVisibility.spec.tsx b/src/navigation/wallet/screens/portfolioChartVisibility.spec.tsx index 77d8f0b9b..074bbeb1e 100644 --- a/src/navigation/wallet/screens/portfolioChartVisibility.spec.tsx +++ b/src/navigation/wallet/screens/portfolioChartVisibility.spec.tsx @@ -1092,7 +1092,7 @@ describe('portfolio chart visibility guards', () => { expect(mockBalanceHistoryChart).not.toHaveBeenCalled(); }); - it('does not mount the Home portfolio balance chart while its initial populate scope is still running', async () => { + it('mounts the Home portfolio balance chart with a loader while its initial populate scope is still running', async () => { resetState(true, { completedFullPopulate: false, populateStatus: makePopulateStatus(), @@ -1111,11 +1111,13 @@ describe('portfolio chart visibility guards', () => { expect( view!.root.findAllByProps({testID: 'portfolio-balance-toggle'}).length, ).toBeGreaterThan(0); - expect(mockBalanceHistoryChart).not.toHaveBeenCalled(); - expect( - view!.root.findAllByProps({testID: 'portfolio-balance-change-row'}) - .length, - ).toBe(0); + expect(mockBalanceHistoryChart).toHaveBeenCalledWith( + expect.objectContaining({ + showLoaderWhenNoSnapshots: true, + isBalanceChartDataReadyToQuery: false, + }), + undefined, + ); }); it('renders the Home portfolio balance chart when a full-populate timestamp exists', async () => { @@ -1207,7 +1209,7 @@ describe('portfolio chart visibility guards', () => { }); it.each(chartSurfaceCases)( - 'does not mount the %s balance chart while its initial populate scope is still running', + 'mounts the %s balance chart with a loader while its initial populate scope is still running', async (_screen, makeScreen) => { resetState(true, { completedFullPopulate: false, @@ -1218,7 +1220,13 @@ describe('portfolio chart visibility guards', () => { renderWithTheme(makeScreen()); }); - expect(mockBalanceHistoryChart).not.toHaveBeenCalled(); + expect(mockBalanceHistoryChart).toHaveBeenCalledWith( + expect.objectContaining({ + showLoaderWhenNoSnapshots: true, + isBalanceChartDataReadyToQuery: false, + }), + undefined, + ); }, ); diff --git a/src/portfolio/ui/hooks/usePortfolioBalanceChartReadiness.ts b/src/portfolio/ui/hooks/usePortfolioBalanceChartReadiness.ts index 1086254d7..22ca12532 100644 --- a/src/portfolio/ui/hooks/usePortfolioBalanceChartReadiness.ts +++ b/src/portfolio/ui/hooks/usePortfolioBalanceChartReadiness.ts @@ -95,7 +95,8 @@ export default function usePortfolioBalanceChartReadiness(args: { (isBalanceChartDataReadyToQuery && (hasHistoricalChartData || shouldRenderZeroBalanceChart)) || shouldPreserveStaleBalanceChart; - const shouldShowChartLoader = !canRenderBalanceChart && isChartDataPending; + const shouldShowChartLoader = + !canRenderBalanceChart && (isChartDataPending || isScopePopulateLoading); const shouldMountBalanceChart = canRenderBalanceChart || shouldShowChartLoader;