Skip to content

Commit 175af1f

Browse files
chore: implementing isHomepageRedesignV1Enabled feature flag logic
1 parent a763ac1 commit 175af1f

File tree

4 files changed

+105
-5
lines changed

4 files changed

+105
-5
lines changed

app/components/UI/Assets/components/Balance/AccountGroupBalance.test.tsx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
22
import AccountGroupBalance from './AccountGroupBalance';
33
import { WalletViewSelectorsIDs } from '../../../../../../e2e/selectors/wallet/WalletView.selectors';
4-
import renderWithProvider, { renderScreen } from '../../../../../util/test/renderWithProvider';
4+
import renderWithProvider, {
5+
renderScreen,
6+
} from '../../../../../util/test/renderWithProvider';
57
import { backgroundState } from '../../../../../util/test/initial-root-state';
68

79
jest.mock('../../../../../selectors/assets/balances', () => ({
@@ -11,6 +13,10 @@ jest.mock('../../../../../selectors/assets/balances', () => ({
1113
selectBalanceChangeBySelectedAccountGroup: jest.fn(() => () => null),
1214
}));
1315

16+
jest.mock('../../../../../selectors/featureFlagController/homepage', () => ({
17+
selectHomepageRedesignV1Enabled: jest.fn(() => false),
18+
}));
19+
1420
const testState = {
1521
engine: {
1622
backgroundState: {
@@ -57,10 +63,14 @@ describe('AccountGroupBalance', () => {
5763
expect(queryByTestId('account-group-balance-empty-state')).toBeNull();
5864
});
5965

60-
it('renders balance empty state when balance is zero', () => {
66+
it('renders balance empty state when balance is zero and feature flag is enabled', () => {
6167
const { selectBalanceBySelectedAccountGroup } = jest.requireMock(
6268
'../../../../../selectors/assets/balances',
6369
);
70+
const { selectHomepageRedesignV1Enabled } = jest.requireMock(
71+
'../../../../../selectors/featureFlagController/homepage',
72+
);
73+
6474
(selectBalanceBySelectedAccountGroup as jest.Mock).mockImplementation(
6575
() => ({
6676
walletId: 'wallet-1',
@@ -70,6 +80,9 @@ describe('AccountGroupBalance', () => {
7080
}),
7181
);
7282

83+
// Enable the feature flag for this test
84+
(selectHomepageRedesignV1Enabled as jest.Mock).mockReturnValue(true);
85+
7386
const { getByTestId, queryByTestId } = renderScreen(
7487
() => <AccountGroupBalance />,
7588
{ name: 'AccountGroupBalance' },
@@ -80,4 +93,34 @@ describe('AccountGroupBalance', () => {
8093
expect(getByTestId('account-group-balance-empty-state')).toBeDefined();
8194
expect(queryByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT)).toBeNull();
8295
});
96+
97+
it('does not render balance empty state when balance is zero but feature flag is disabled', () => {
98+
const { selectBalanceBySelectedAccountGroup } = jest.requireMock(
99+
'../../../../../selectors/assets/balances',
100+
);
101+
const { selectHomepageRedesignV1Enabled } = jest.requireMock(
102+
'../../../../../selectors/featureFlagController/homepage',
103+
);
104+
105+
(selectBalanceBySelectedAccountGroup as jest.Mock).mockImplementation(
106+
() => ({
107+
walletId: 'wallet-1',
108+
groupId: 'wallet-1/group-1',
109+
totalBalanceInUserCurrency: 0, // Zero balance
110+
userCurrency: 'usd',
111+
}),
112+
);
113+
114+
// Ensure the feature flag is disabled for this test
115+
(selectHomepageRedesignV1Enabled as jest.Mock).mockReturnValue(false);
116+
117+
const { getByTestId, queryByTestId } = renderWithProvider(
118+
<AccountGroupBalance />,
119+
{ state: testState },
120+
);
121+
122+
// Should render balance text, not empty state
123+
expect(getByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT)).toBeTruthy();
124+
expect(queryByTestId('account-group-balance-empty-state')).toBeNull();
125+
});
83126
});

app/components/UI/Assets/components/Balance/AccountGroupBalance.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
selectBalanceBySelectedAccountGroup,
99
selectBalanceChangeBySelectedAccountGroup,
1010
} from '../../../../../selectors/assets/balances';
11+
import { selectHomepageRedesignV1Enabled } from '../../../../../selectors/featureFlagController/homepage';
1112
import SensitiveText, {
1213
SensitiveTextLength,
1314
} from '../../../../../component-library/components/Texts/SensitiveText';
@@ -27,6 +28,9 @@ const AccountGroupBalance = () => {
2728
const balanceChange1d = useSelector(
2829
selectBalanceChangeBySelectedAccountGroup('1d'),
2930
);
31+
const isHomepageRedesignV1Enabled = useSelector(
32+
selectHomepageRedesignV1Enabled,
33+
);
3034

3135
const togglePrivacy = useCallback(
3236
(value: boolean) => {
@@ -51,7 +55,7 @@ const AccountGroupBalance = () => {
5155
<Skeleton width={100} height={40} />
5256
<Skeleton width={100} height={20} />
5357
</View>
54-
) : hasZeroBalance ? (
58+
) : hasZeroBalance && isHomepageRedesignV1Enabled ? (
5559
<>
5660
<BalanceEmptyState testID="account-group-balance-empty-state" />
5761
</>

app/components/UI/Tokens/TokenList/PortfolioBalance/index.test.tsx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jest.mock('../../../../hooks/useMultichainBalances', () => ({
3434
})),
3535
}));
3636

37+
jest.mock('../../../../../selectors/featureFlagController/homepage', () => ({
38+
selectHomepageRedesignV1Enabled: jest.fn(() => false),
39+
}));
40+
3741
jest.mock('../../../../../core/Engine', () => ({
3842
getTotalEvmFiatAccountBalance: jest.fn(),
3943
context: {
@@ -253,7 +257,13 @@ describe('PortfolioBalance', () => {
253257
expect(PreferencesController.setPrivacyMode).toHaveBeenCalledWith(true);
254258
});
255259

256-
it('displays BalanceEmptyState when balance is zero', () => {
260+
it('displays BalanceEmptyState when balance is zero and feature flag is enabled', () => {
261+
// Mock the feature flag to be enabled
262+
const { selectHomepageRedesignV1Enabled } = jest.requireMock(
263+
'../../../../../selectors/featureFlagController/homepage',
264+
);
265+
(selectHomepageRedesignV1Enabled as jest.Mock).mockReturnValue(true);
266+
257267
// Mock zero balance
258268
const mockSelectedAccountMultichainBalanceZero = {
259269
displayBalance: '$0.00',
@@ -286,6 +296,45 @@ describe('PortfolioBalance', () => {
286296
expect(queryByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT)).toBeNull();
287297
});
288298

299+
it('does not display BalanceEmptyState when balance is zero but feature flag is disabled', () => {
300+
// Ensure feature flag is disabled
301+
const { selectHomepageRedesignV1Enabled } = jest.requireMock(
302+
'../../../../../selectors/featureFlagController/homepage',
303+
);
304+
(selectHomepageRedesignV1Enabled as jest.Mock).mockReturnValue(false);
305+
306+
// Mock zero balance
307+
const mockSelectedAccountMultichainBalanceZero = {
308+
displayBalance: '$0.00',
309+
displayCurrency: 'USD',
310+
totalFiatBalance: 0,
311+
totalNativeTokenBalance: '0',
312+
nativeTokenUnit: 'ETH',
313+
shouldShowAggregatedPercentage: false,
314+
isPortfolioVieEnabled: false,
315+
aggregatedBalance: {
316+
ethFiat: 123.45,
317+
tokenFiat: 0,
318+
tokenFiat1dAgo: 0,
319+
ethFiat1dAgo: 100.0,
320+
},
321+
isLoadingAccount: false,
322+
tokenFiatBalancesCrossChains: [],
323+
};
324+
325+
const mockedHook = jest.mocked(useSelectedAccountMultichainBalances);
326+
mockedHook.mockReturnValue({
327+
selectedAccountMultichainBalance:
328+
mockSelectedAccountMultichainBalanceZero,
329+
});
330+
331+
const { getByTestId, queryByTestId } = renderPortfolioBalance(initialState);
332+
333+
// Should render balance text, not empty state
334+
expect(getByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT)).toBeTruthy();
335+
expect(queryByTestId('portfolio-balance-empty-state')).toBeNull();
336+
});
337+
289338
it('displays loader when balance is not available', () => {
290339
// Mock undefined balance
291340
const mockedHook = jest.mocked(useSelectedAccountMultichainBalances);

app/components/UI/Tokens/TokenList/PortfolioBalance/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useSelectedAccountMultichainBalances } from '../../../../hooks/useMulti
1515
import Loader from '../../../../../component-library/components-temp/Loader/Loader';
1616
import NonEvmAggregatedPercentage from '../../../../../component-library/components-temp/Price/AggregatedPercentage/NonEvmAggregatedPercentage';
1717
import { selectIsEvmNetworkSelected } from '../../../../../selectors/multichainNetworkController';
18+
import { selectHomepageRedesignV1Enabled } from '../../../../../selectors/featureFlagController/homepage';
1819
import BalanceEmptyState from '../../../BalanceEmptyState';
1920

2021
export const PortfolioBalance = React.memo(() => {
@@ -26,6 +27,9 @@ export const PortfolioBalance = React.memo(() => {
2627
const { selectedAccountMultichainBalance } =
2728
useSelectedAccountMultichainBalances();
2829
const isEvmSelected = useSelector(selectIsEvmNetworkSelected);
30+
const isHomepageRedesignV1Enabled = useSelector(
31+
selectHomepageRedesignV1Enabled,
32+
);
2933

3034
const renderAggregatedPercentage = () => {
3135
if (
@@ -70,7 +74,7 @@ export const PortfolioBalance = React.memo(() => {
7074
<View style={styles.loaderWrapper}>
7175
<Loader />
7276
</View>
73-
) : hasZeroBalance ? (
77+
) : hasZeroBalance && isHomepageRedesignV1Enabled ? (
7478
<BalanceEmptyState testID="portfolio-balance-empty-state" />
7579
) : (
7680
<TouchableOpacity

0 commit comments

Comments
 (0)