You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<!--
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**
<!--
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?
-->
This PR fixes a critical crash that occurred when rendering token lists
and interacting with staking functionality. The issue was caused by the
`isStaked` property in the `TokenI` interface being `undefined` in some
cases, which broke boolean operations in various components throughout
the app.
**Root Cause:**
The `assetToToken` function was directly assigning `asset.isStaked`
without ensuring it was always a boolean value. When this property was
`undefined`, components that performed boolean operations like
`!evmAsset?.isStaked` or `token.isETH && !token.isStaked` would behave
unexpectedly, leading to crashes.
**Solution:**
Changed the assignment from `isStaked: asset.isStaked` to `isStaked:
asset.isStaked || false` to ensure the property is always a boolean.
This guarantees:
- `true` when `asset.isStaked` is `true`
- `false` when `asset.isStaked` is `false` or `undefined`
The fix is minimal, backward-compatible, and addresses the unstake
regression by providing consistent behavior across all components using
the `isStaked` property.
## **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: Fixed a crash that occurred when viewing token lists
and interacting with staking functionality
## **Related issues**
Fixes: #19668
## **Manual testing steps**
```gherkin
Feature: Token list and staking functionality stability
When user taps on a token with staking available
Then the app should not crash
And the staking options should be displayed correctly
And the isStaked property should be handled properly in all components
And the unstake button should not crash the app
```
## **Screenshots/Recordings**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- App crash when viewing token lists or interacting with staking
functionality - crash logs would show undefined property errors -->
### **After**
<!-- Token lists render correctly, staking functionality works without
crashes, all boolean operations on isStaked property work as expected
-->
## **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.
0 commit comments