Skip to content

Commit e76aaf4

Browse files
fix: cp-7.60.0 staked eth balances show first account staked balance across accounts (#23257)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** 1. What is the reason for the change? There is a bug where we are not able to see the correct staked ethereum balance when there are multiple accounts with staked ethereum. There is also a bug where we are not able to see the APR and Earn History for a user with 0 staked ethereum balance. 2. What is the improvement/solution? - Ensure that the native asset is not set isStaked true, as the Staked Ethereum asset is the one which should be set isStaked true. - Add accountId to filtering of token data in assets list selector to ensure we have correct balances across multiple accounts for staked ethereum. - Allow zero value staked ethereum in the allTokens selector, but limit to supported staking chains to lessen amount of tokens returned. <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/MUSD-114 Fixes: https://consensyssoftware.atlassian.net/browse/MUSD-112 Fixes: #23259 Fixes: #23260 ## **Manual testing steps** ```gherkin Feature: fix staked eth balances across multiple accounts and apr / earn history for zero balance staked eth Scenario: user has multiple accounts with ETH Given user stakes ETH on all accounts When user views the token list Then the Staked Ethereum balance should be correct in each account Then the Staked Ethereum asset detail page should show the correct amount for the account Then the Ethereum asset detail page should show the correct Staked Ethereum amount Scenario: user has multiple accounts with ETH, 1 with 0 Staked ETH Given user has 0 Staked Eth on an account When user views the token list Then the Staked Ethereum balance should not show in token list Then the Ethereum asset detail page should show no Staked Ethereum at all Then the Ethereum asset detail page should show APR and Earn History even when 0 Staked ETH ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** https://github.com/user-attachments/assets/b08a1c20-6e57-45cf-b238-53d3b5008b6a <!-- [screenshots/recordings] --> ### **After** https://github.com/user-attachments/assets/488c8b0e-57a8-4228-8e6f-0b43c00ee952 <img width="200" alt="Simulator Screenshot - iPhone 17 Pro - 2025-11-25 at 10 15 28" src="https://github.com/user-attachments/assets/0ee7d224-8b4e-413a-8f52-9e7db6eb5182" /> <img width="200" alt="Simulator Screenshot - iPhone 17 Pro - 2025-11-25 at 10 15 31" src="https://github.com/user-attachments/assets/8c41b2b2-64fa-4a07-bd7a-80f98f7c6194" /> <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Ensure native assets are never marked staked, include a distinct Staked Ethereum entry, and adjust zero-balance filtering to retain native/staked tokens on the current network; update tests accordingly. > > - **Selectors**: > - Set `isStaked: false` for native balances in `selectedAccountNativeTokenCachedBalanceByChainId*`. > - Update `selectNativeTokensAcrossChains` to always add a separate "Staked Ethereum" token alongside the native asset using cached staked balance data. > - Modify zero-balance behavior in `selectEvmTokensWithZeroBalanceFilter` to keep native and staked tokens on the current network when hiding zero balances. > - Cleanup: remove unused `toHex` import. > - **Tests**: > - Adjust expectations for `isStaked` on native balances and zero-balance filtering results. > - Assert presence of "Staked Ethereum" in filtered lists and updated token counts. > - Maintain memoization and network filtering coverage. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ce72756. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent f607762 commit e76aaf4

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

app/selectors/multichain/evm.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('Multichain Selectors', () => {
156156
'0x1': {
157157
balance: '0x1',
158158
stakedBalance: '0x2',
159-
isStaked: true,
159+
isStaked: false,
160160
name: '',
161161
},
162162
'0x89': {
@@ -500,11 +500,13 @@ describe('Multichain Selectors', () => {
500500
} as unknown as RootState;
501501

502502
const result = selectEvmTokensWithZeroBalanceFilter(testState);
503-
504503
expect(result).toBeDefined();
505504
expect(result.every((token) => token.isNative === true)).toBeTruthy();
506505
expect(result.every((token) => token.balance === '0')).toBeTruthy();
507-
expect(result.length).toBe(2); // Native tokens should remain
506+
expect(
507+
result.some((token) => token.name === 'Staked Ethereum'),
508+
).toBeTruthy();
509+
expect(result.length).toBe(3); // Native tokens should remain and Staked Ethereum
508510
});
509511
});
510512

app/selectors/multichain/evm.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ import {
1818
} from '../networkController';
1919
import { TokenI } from '../../components/UI/Tokens/types';
2020
import { renderFromWei, weiToFiat } from '../../util/number';
21-
import {
22-
hexToBN,
23-
toChecksumHexAddress,
24-
toHex,
25-
} from '@metamask/controller-utils';
21+
import { hexToBN, toChecksumHexAddress } from '@metamask/controller-utils';
2622
import {
2723
selectConversionRate,
2824
selectCurrencyRates,
@@ -79,7 +75,7 @@ export const selectedAccountNativeTokenCachedBalanceByChainIdForAddress =
7975
result[chainId] = {
8076
balance: account.balance,
8177
stakedBalance: account.stakedBalance ?? '0x0',
82-
isStaked: account.stakedBalance !== '0x0',
78+
isStaked: false,
8379
name: '',
8480
};
8581
}
@@ -190,13 +186,7 @@ export const selectNativeTokensAcrossChainsForAddress = createSelector(
190186
// Non-staked tokens
191187
tokensByChain[nativeChainId].push(tokenByChain);
192188

193-
if (
194-
nativeTokenInfoByChainId &&
195-
nativeTokenInfoByChainId.isStaked &&
196-
nativeTokenInfoByChainId.stakedBalance !== '0x00' &&
197-
nativeTokenInfoByChainId.stakedBalance !== toHex(0) &&
198-
nativeTokenInfoByChainId.stakedBalance !== '0'
199-
) {
189+
if (nativeTokenInfoByChainId && !nativeTokenInfoByChainId.isStaked) {
200190
// Staked tokens
201191
tokensByChain[nativeChainId].push({
202192
...nativeTokenInfoByChainId,

0 commit comments

Comments
 (0)