Skip to content

fix: updated utils to handle corrupted account state#40955

Merged
NidhiKJha merged 1 commit intomainfrom
fix-39699
Mar 17, 2026
Merged

fix: updated utils to handle corrupted account state#40955
NidhiKJha merged 1 commit intomainfrom
fix-39699

Conversation

@NidhiKJha
Copy link
Member

@NidhiKJha NidhiKJha commented Mar 17, 2026

Description

The contacts list page (ContactsListPage) and the add/edit contact forms crash when an internal account has corrupted state — specifically when account.metadata or account.metadata.name is undefined. This can happen due to state corruption or migration edge cases.

This PR adds defensive handling in the contact list utility functions (buildDuplicateContactMap, hasDuplicateContacts, isDuplicateContact) via a getAccountName helper that safely accesses account?.metadata?.name, falling back to an empty string. Accounts with missing names are filtered out of duplicate detection rather than causing a runtime crash.

A component-level test is added to ContactsListPage to verify the page renders without crashing when an account has missing metadata

Changelog

CHANGELOG entry: Fixed a crash on the contacts page when an internal account had corrupted or missing metadata.

Related issues

Fixes: #39699

Manual testing steps

  1. Open MetaMask and navigate to the Contacts page via the global menu
  2. Verify the contacts page loads and existing contacts are displayed
  3. Add a new contact and verify it saves successfully

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Note

Low Risk
Low risk: adds defensive null/undefined handling around InternalAccount.metadata.name in duplicate-contact utilities and a regression test to prevent crashes from corrupted account state.

Overview
Prevents the Contacts UI from crashing when an InternalAccount is missing metadata/metadata.name by introducing a safe getAccountName helper and skipping unnamed accounts in duplicate-name detection (buildDuplicateContactMap, hasDuplicateContacts, isDuplicateContact).

Adds a ContactsListPage test that renders the page with a deliberately malformed internal account to verify the page still loads and shows contacts.

Written by Cursor Bugbot for commit 0e43dc2. This will update automatically on new commits. Configure here.

@metamaskbot metamaskbot added the team-core-extension-ux Core Extension UX team label Mar 17, 2026
@NidhiKJha NidhiKJha changed the title updated utils to handle corrupted account state fix: updated utils to handle corrupted account state Mar 17, 2026
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
68.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 17, 2026

Builds ready [0e43dc2]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account379274574126485574
total379274574126485574
Confirm Txconfirm_tx603360316034160346034
total603360316034160346034
Bridge User Actionsbridge_load_page22318825524241255
bridge_load_asset_picker2532432616255261
bridge_search_token7597587590759759
total1245120412852912601285
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14601233178311815081700
load12041008145810012501403
domContentLoaded1198100314199812451394
domInteractive3016114222593
firstPaint1517031767215249
backgroundConnect21419627814216245
firstReactRender21114662233
initialActions104113
loadScripts100081412179610371192
setupStore1476171723
numNetworkReqs393185164078
Power User HomeuiStartup58282201181103155650111633
load13211137176913713871642
domContentLoaded13021131175713013491595
domInteractive39212343832109
firstPaint212861392154268372
backgroundConnect252633514834307131829254
firstReactRender25184342733
initialActions105113
loadScripts1073925151212311031367
setupStore1663861828
numNetworkReqs1557829446173256
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2182182180218218
srpButtonToSrpForm93919529595
confirmSrpToPwForm22222202222
pwFormToMetricsScreen15151501515
metricsToWalletReadyScreen15151601516
doneButtonToHomeScreen6486436544654654
openAccountMenuToAccountListLoaded2916289229311729312931
total3923387639633639513963
Onboarding New WalletcreateWalletToSocialScreen2202192211221221
srpButtonToPwForm1191111307123130
createPwToRecoveryScreen99111911
skipBackupToMetricsScreen43395144551
agreeButtonToOnboardingSuccess18161911819
doneButtonToAssetList648371913196764913
total1060776135520611631355
Asset DetailsassetClickToPriceChart685289147789
total685289147789
Solana Asset DetailsassetClickToPriceChart1314019758189197
total1314019758189197
Import Srp HomeloginToHomeScreen2352233623671123562367
openAccountMenuAfterLogin75491102183110
homeAfterImportWithNewWallet1685504271092322922710
total41462943518789247025187
Send TransactionsopenSendPageFromHome24222932429
selectTokenToSendFormLoaded34243953839
reviewTransactionToConfirmationPage91485896739923967
total9779361027339831027
SwapopenSwapPageFromHome968010812107108
fetchAndDisplaySwapQuotes268826852690226902690
total2784277127981127922798
🌐 Dapp Page Load Benchmarks

Current Commit: 0e43dc2 | Date: 3/17/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±40ms) 🟡 | historical mean value: 1.03s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 728ms (±37ms) 🟢 | historical mean value: 726ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 80ms (±11ms) 🟢 | historical mean value: 89ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 40ms 1.01s 1.33s 1.07s 1.33s
domContentLoaded 728ms 37ms 707ms 1.01s 760ms 1.01s
firstPaint 80ms 11ms 60ms 164ms 88ms 164ms
firstContentfulPaint 80ms 11ms 60ms 164ms 88ms 164ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 58 Bytes (0%)
  • ui: 5.59 KiB (0.07%)
  • common: 46 Bytes (0%)

@NidhiKJha NidhiKJha added this pull request to the merge queue Mar 17, 2026
Merged via the queue into main with commit ea7121b Mar 17, 2026
195 of 200 checks passed
@NidhiKJha NidhiKJha deleted the fix-39699 branch March 17, 2026 12:54
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2026
@metamaskbot metamaskbot added the release-13.24.0 Issue or pull request that will be included in release 13.24.0 label Mar 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.24.0 Issue or pull request that will be included in release 13.24.0 size-S team-core-extension-ux Core Extension UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: You have duplicate contacts

4 participants