Commit e76aaf4
authored
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
2 files changed
+8
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
503 | | - | |
504 | 503 | | |
505 | 504 | | |
506 | 505 | | |
507 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 21 | + | |
26 | 22 | | |
27 | 23 | | |
28 | 24 | | |
| |||
79 | 75 | | |
80 | 76 | | |
81 | 77 | | |
82 | | - | |
| 78 | + | |
83 | 79 | | |
84 | 80 | | |
85 | 81 | | |
| |||
190 | 186 | | |
191 | 187 | | |
192 | 188 | | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 189 | + | |
200 | 190 | | |
201 | 191 | | |
202 | 192 | | |
| |||
0 commit comments