Skip to content

fix: fix selectedAddress and nftController instantiation#22856

Merged
sahar-fehri merged 10 commits intodevelopfrom
fix/fix-import-nft-incorrect-selectedAddress
Feb 13, 2024
Merged

fix: fix selectedAddress and nftController instantiation#22856
sahar-fehri merged 10 commits intodevelopfrom
fix/fix-import-nft-incorrect-selectedAddress

Conversation

@sahar-fehri
Copy link
Copy Markdown
Contributor

@sahar-fehri sahar-fehri commented Feb 7, 2024

Description

Noticed that when you freshly import the extension, usse testDapp to deploy and mint an NFT, then manually import the NFT.
you will be able to see the NFT. Then when you switch to another account and go back to the account that has the NFT;
1- you wont be able to see the NFTs you imported earlier
2- When you try to import them again you will get an error (fired from core when trying to verify ownership)

Noticed that this was due to core having the wrong userAddress to check ownership for, and then in metamask.js, the selectedAddress retrieved does not match the user's selected Address

This behavior is also reported to be on v11.10.0, on this issue: #22796

Related issues

Fixes: #22796
Fixes: #22798

Manual testing steps

  1. Remove and reimport the extension
  2. Use testDapp to deploy and mint the NFT
  3. Add the NFT manually by clicking "import NFT"
  4. You should be able to see your newly import NFT
  5. Create new account
  6. Go back to the account that has the NFT
  7. You should be able to see the NFT you imported

Screenshots/Recordings

Before

devBefore.mov

After

DevAfter.mov

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@sahar-fehri sahar-fehri requested a review from a team as a code owner February 7, 2024 14:12
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 7, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@sahar-fehri sahar-fehri marked this pull request as draft February 7, 2024 16:28
@sahar-fehri sahar-fehri added the team-core-extension-ux Core Extension UX team label Feb 8, 2024
@sahar-fehri sahar-fehri marked this pull request as ready for review February 8, 2024 15:53
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [a1558d8]
Page Load Metrics (943 ± 185 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint843711335928
domContentLoaded116126168
load6842585943385185
domInteractive116126168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 130 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (3844eac) 68.47% compared to head (02a751c) 68.47%.
Report is 4 commits behind head on develop.

Files Patch % Lines
app/scripts/metamask-controller.js 33.33% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #22856      +/-   ##
===========================================
+ Coverage    68.47%   68.47%   +0.01%     
===========================================
  Files         1088     1088              
  Lines        42956    42962       +6     
  Branches     11436    11432       -4     
===========================================
+ Hits         29410    29417       +7     
+ Misses       13546    13545       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

!currentTabIsConnectedToNextAddress;

try {
await _setSelectedAddress(address);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_setSelectedAddress function will switch preferencesController's selected address, even though account is not found in accountsController,

it might cause inconsistent address state between preferencesController and accountsController.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid this inconsistency, we will first check if the account is found first, then we will update the controllers.
If account was not found, no controllers will be updated.

@darkwing darkwing added the needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. label Feb 13, 2024
@sahar-fehri sahar-fehri force-pushed the fix/fix-import-nft-incorrect-selectedAddress branch from 122b25e to 02a751c Compare February 13, 2024 18:12
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [02a751c]
Page Load Metrics (1067 ± 68 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint11961020610952
domContentLoaded96724178
load9031407106714268
domInteractive96724178
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 130 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@sahar-fehri sahar-fehri merged commit 167036f into develop Feb 13, 2024
@sahar-fehri sahar-fehri deleted the fix/fix-import-nft-incorrect-selectedAddress branch February 13, 2024 20:22
@github-actions github-actions bot locked and limited conversation to collaborators Feb 13, 2024
@metamaskbot metamaskbot added the release-11.12.0 Issue or pull request that will be included in release 11.12.0 label Feb 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. release-11.12.0 Issue or pull request that will be included in release 11.12.0 team-core-extension-ux Core Extension UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Autodetect NFTs not working on Mainnet [Bug]: NFTs (both ERC-721 and ERC-1155) cannot be imported manually

9 participants