Skip to content

App crash when sorting/filtering on home main wallet view #21218

@chrisleewilcox

Description

@chrisleewilcox

View issue in GitHub: #21218

<@U031X90D3UN> very nasty bug if QA can reproduce it, it's in production now <@U032XS4NP9U> <@U03MH92G9V2> <@U03D9UANH63> <@U0299E6KGNN>

🔴 Title: iOS app bricks after selecting token list sort (e.g., “Balance ↓”); requires reinstall to recover

Env: iOS (latest production), MetaMask Mobile, 7.56.5

View: Wallet (Home → token list)

Error shown:

TypeError: Cannot read property 'localeCompare' of null```
*Severity:* Critical (bricks app until full reinstall)

Description
From the *Home token list*, if the user sets a *sort/filter* such as *Descending by balance*, the app crashes to the generic error screen on next render and becomes unrecoverable. Force-quitting and relaunching does not help; only uninstall + reinstall clears the state. The crash message indicates the Wallet view throws on `localeCompare` of `null`.

Steps to Reproduce
1. Open *Home* (token list).
2. Set sort/filter to *Balance (Descending)* (also reproducible with some other sort options).
3. Navigate away/back or relaunch app.
*Actual:*
• App shows error screen and remains stuck: _“TypeError: Cannot read property 'localeCompare' of null.”_
• Relaunch keeps failing (persisted bad sort state).
• Only full reinstall fixes.
*Expected:*
• Token list sorts safely without crash.
• If any token metadata is missing (`symbol`, `name`, `fiat`, `balance`), comparator handles nulls gracefully.
• App should never brick due to a saved UI preference.
Suspected Root Cause
• *Comparator assumes non-null strings/numbers* (e.g., `symbol.localeCompare(...)`, numeric compare on `balance`), but one or more tokens in list have `null/undefined` fields (often from long-tail assets or partially loaded metadata).
• *Preference persistence* saves the failing sort; on startup, the Wallet view re-applies it and crashes again → *boot-loop*.
Recommendations / Fix
1. *Defensive comparators*
    ◦ Coalesce nulls: `const symA = tokenA?.symbol ?? ''; const symB = tokenB?.symbol ?? '';`
    ◦ For numeric sorts, default to `0` and put nulls at list end.
    ◦ Guard mixed types and NaN.
2. *Resilient state on launch*
    ◦ If a sort throws or yields invalid comparison, *fallback to default sort* (name A→Z) and log once.
    ◦ Add try/catch around sort pipeline; never propagate to render.
3. *Data hygiene*
    ◦ Ensure token list adapter normalizes fields (symbol/name/fiat/balance) and marks unknowns with placeholders.
4. *Recovery UX*
    ◦ Provide a *“Reset list settings”* link on the error screen that clears token-list preferences (sort/filter/search).
    ◦ Or add a startup “safe mode” that skips custom sort if previous session crashed in Wallet view.
5. *Telemetry &amp; QA*
    ◦ Log null/undefined rate per field and the chosen comparator.
    ◦ Regression test with tokens missing `symbol`, missing `fiat`, zero/undefined `balance`, and mixed locales.
Acceptance Criteria
• Selecting *any* sort option (Balance, Name, Chain, Value) never crashes even with partial metadata.
• Relaunch after setting a sort does *not* brick the app.
• Error screen includes *Reset list settings* which successfully restores access if something else goes wrong.
• Crash-free rate for Wallet view ≥ 99.9% over 7 days post-fix.

[Slack Message](https://consensys.slack.com/archives/C06FXU326RL/p1760549022743929?thread_ts=1760549022.743929&cid=C06FXU326RL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    INVALID-ISSUE-TEMPLATEIssue's body doesn't match any issue template.regression-prod-*Regression bug that was found in production in release *regression-prod-7.56.5Regression bug that was found in production in release 7.56.5release-7.57.0Issue or pull request that will be included in release 7.57.0release-7.58.0Issue or pull request that will be included in release 7.58.0team-assetstype-bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    To be triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions