Skip to content

Commit 7191eb2

Browse files
feat: implementing empty balance state component
1 parent d16ce99 commit 7191eb2

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,40 @@ describe('AccountGroupBalance', () => {
4545
}),
4646
);
4747

48-
const { getByTestId } = renderWithProvider(<AccountGroupBalance />, {
49-
state: testState,
50-
});
48+
const { getByTestId, queryByTestId } = renderWithProvider(
49+
<AccountGroupBalance />,
50+
{
51+
state: testState,
52+
},
53+
);
54+
55+
// Should render balance text, not empty state
56+
expect(getByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT)).toBeTruthy();
57+
expect(queryByTestId('account-group-balance-empty-state')).toBeNull();
58+
});
5159

52-
const el = getByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT);
53-
expect(el).toBeTruthy();
60+
it('renders balance empty state when balance is zero', () => {
61+
const { selectBalanceBySelectedAccountGroup } = jest.requireMock(
62+
'../../../../../selectors/assets/balances',
63+
);
64+
(selectBalanceBySelectedAccountGroup as jest.Mock).mockImplementation(
65+
() => ({
66+
walletId: 'wallet-1',
67+
groupId: 'wallet-1/group-1',
68+
totalBalanceInUserCurrency: 0, // Zero balance
69+
userCurrency: 'usd',
70+
}),
71+
);
72+
73+
const { getByTestId, queryByTestId } = renderWithProvider(
74+
<AccountGroupBalance />,
75+
{
76+
state: testState,
77+
},
78+
);
79+
80+
// Should render BalanceEmptyState instead of balance text
81+
expect(getByTestId('account-group-balance-empty-state')).toBeDefined();
82+
expect(queryByTestId(WalletViewSelectorsIDs.TOTAL_BALANCE_TEXT)).toBeNull();
5483
});
5584
});

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { WalletViewSelectorsIDs } from '../../../../../../e2e/selectors/wallet/W
1616
import { Skeleton } from '../../../../../component-library/components/Skeleton';
1717
import { useFormatters } from '../../../../hooks/useFormatters';
1818
import AccountGroupBalanceChange from '../../components/BalanceChange/AccountGroupBalanceChange';
19+
import BalanceEmptyState from '../../../BalanceEmptyState';
1920

2021
const AccountGroupBalance = () => {
2122
const { PreferencesController } = Engine.context;
@@ -38,10 +39,23 @@ const AccountGroupBalance = () => {
3839
const userCurrency = groupBalance?.userCurrency ?? '';
3940
const displayBalance = formatCurrency(totalBalance, userCurrency);
4041

42+
// Check if balance is zero (empty state) - only check when we have balance data
43+
const hasZeroBalance =
44+
groupBalance && groupBalance.totalBalanceInUserCurrency === 0;
45+
4146
return (
4247
<View style={styles.accountGroupBalance}>
4348
<View>
44-
{groupBalance ? (
49+
{!groupBalance ? (
50+
<View style={styles.skeletonContainer}>
51+
<Skeleton width={100} height={40} />
52+
<Skeleton width={100} height={20} />
53+
</View>
54+
) : hasZeroBalance ? (
55+
<>
56+
<BalanceEmptyState testID="account-group-balance-empty-state" />
57+
</>
58+
) : (
4559
<TouchableOpacity
4660
onPress={() => togglePrivacy(!privacyMode)}
4761
testID="balance-container"
@@ -66,11 +80,6 @@ const AccountGroupBalance = () => {
6680
/>
6781
)}
6882
</TouchableOpacity>
69-
) : (
70-
<View style={styles.skeletonContainer}>
71-
<Skeleton width={100} height={40} />
72-
<Skeleton width={100} height={20} />
73-
</View>
7483
)}
7584
</View>
7685
</View>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import TextComponent, {
1313
} from '../../../../component-library/components/Texts/Text';
1414
import { TokenI } from '../types';
1515
import { strings } from '../../../../../locales/i18n';
16-
import { TokenListFooter } from './TokenListFooter';
1716
import { TokenListItem, TokenListItemBip44 } from './TokenListItem';
1817
import { WalletViewSelectorsIDs } from '../../../../../e2e/selectors/wallet/WalletView.selectors';
1918
import { useNavigation } from '@react-navigation/native';
@@ -107,7 +106,6 @@ const TokenListComponent = ({
107106
return `${item.address}-${item.chainId}-${staked}-${idx}`;
108107
}}
109108
decelerationRate="fast"
110-
ListFooterComponent={<TokenListFooter />}
111109
refreshControl={
112110
<RefreshControl
113111
colors={[colors.primary.default]}

0 commit comments

Comments
 (0)