Skip to content

fix: Tokens disappearing when updating #9148

Merged
tommasini merged 5 commits intomainfrom
fix/9122-tokens-disappearing-2
Apr 8, 2024
Merged

fix: Tokens disappearing when updating #9148
tommasini merged 5 commits intomainfrom
fix/9122-tokens-disappearing-2

Conversation

@tommasini
Copy link
Copy Markdown
Contributor

@tommasini tommasini commented Apr 5, 2024

Description

The variable newlySelectedInternalAccount.address, that was being returned by the AccountsController:selectedAccountChange event was on a lowercase format. We were duplicating the accounts, so one account was checksummed and another not, which was making the tokens be on storage but not showing because the new selected account was not with tokens imported.

This is a how the data storage was:

{"allDetectedTokens": {"0x1": {"0x2990079bcdEe240329a520d2444386FC119da21a": [Array]}, "0xa86a": {"0x2990079bcdEe240329a520d2444386FC119da21a": [Array], "0x2990079bcdee240329a520d2444386fc119da21a": [Array]}}, "allIgnoredTokens": {}, "allTokens": {"0xa86a": {"0x2990079bcdEe240329a520d2444386FC119da21a": [Array]}}, "detectedTokens": [{"address": "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7", "aggregators": [Array], "decimals": 6, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7.png", "isERC721": false, "name": "TetherToken", "symbol": "USDT"}, {"address": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", "aggregators": [Array], "decimals": 6, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e.png", "isERC721": false, "name": "USD Coin", "symbol": "USDC"}, {"address": "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", "aggregators": [Array], "decimals": 18, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7.png", "isERC721": false, "name": "Wrapped AVAX", "symbol": "WAVAX"}, {"address": "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB", "aggregators": [Array], "decimals": 18, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab.png", "isERC721": false, "name": "Wrapped Ether", "symbol": "WETH.E"}, {"address": "0x50b7545627a5162F82A992c33b87aDc75187B218", "aggregators": [Array], "decimals": 8, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x50b7545627a5162f82a992c33b87adc75187b218.png", "isERC721": false, "name": "Wrapped BTC", "symbol": "WBTC.E"}, {"address": "0x63a72806098Bd3D9520cC43356dD78afe5D386D9", "aggregators": [Array], "decimals": 18, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x63a72806098bd3d9520cc43356dd78afe5d386d9.png", "isERC721": false, "name": "Aave Token", "symbol": "AAVE.E"}, {"address": "0x8b82A291F83ca07Af22120ABa21632088fC92931", "aggregators": [Array], "decimals": 18, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x8b82a291f83ca07af22120aba21632088fc92931.png", "isERC721": false, "name": "Ethereum  Wormhole ", "symbol": "ETH"}, {"address": "0x120AD3e5A7c796349e591F1570D9f7980F4eA9cb", "aggregators": [Array], "decimals": 6, "image": "https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x120ad3e5a7c796349e591f1570d9f7980f4ea9cb.png", "isERC721": false, "name": "Axelar Wrapped LUNA", "symbol": "LUNA"}], "ignoredTokens": [], "tokens": []}

This is how it is now:

{
   "allDetectedTokens":{
      "0x1":{
         "0x2990079bcdEe240329a520d2444386FC119da21a":[
            "Array"
         ]
      },
      "0xa86a":{
         "0x2990079bcdEe240329a520d2444386FC119da21a":[
            "Array"
         ]
      }
   },
   "allIgnoredTokens":{
      
   },
   "allTokens":{
      "0xa86a":{
         "0x2990079bcdEe240329a520d2444386FC119da21a":[
            "Array"
         ]
      }
   },
   "detectedTokens":[
      
   ],
   "ignoredTokens":[
      
   ],
   "tokens":[
      {
         "address":"0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":6,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7.png",
         "name":"TetherToken",
         "symbol":"USDT"
      },
      {
         "address":"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":6,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e.png",
         "name":"USD Coin",
         "symbol":"USDC"
      },
      {
         "address":"0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":18,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7.png",
         "name":"Wrapped AVAX",
         "symbol":"WAVAX"
      },
      {
         "address":"0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":18,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab.png",
         "name":"Wrapped Ether",
         "symbol":"WETH.E"
      },
      {
         "address":"0x50b7545627a5162F82A992c33b87aDc75187B218",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":8,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x50b7545627a5162f82a992c33b87adc75187b218.png",
         "name":"Wrapped BTC",
         "symbol":"WBTC.E"
      },
      {
         "address":"0x63a72806098Bd3D9520cC43356dD78afe5D386D9",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":18,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x63a72806098bd3d9520cc43356dd78afe5d386d9.png",
         "name":"Aave Token",
         "symbol":"AAVE.E"
      },
      {
         "address":"0x8b82A291F83ca07Af22120ABa21632088fC92931",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":18,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x8b82a291f83ca07af22120aba21632088fc92931.png",
         "name":"Ethereum  Wormhole ",
         "symbol":"ETH"
      },
      {
         "address":"0x120AD3e5A7c796349e591F1570D9f7980F4eA9cb",
         "aggregators":[
            "Array"
         ],
         "balanceError":null,
         "decimals":6,
         "image":"https://static.metafi.codefi.network/api/v1/tokenIcons/43114/0x120ad3e5a7c796349e591f1570d9f7980f4ea9cb.png",
         "name":"Axelar Wrapped LUNA",
         "symbol":"LUNA"
      }
   ]
}

Related issues

Fixes: #9122

Manual testing steps

  1. Go to uniswap, pancake swap, open sea
  2. Connect with those dapps
  3. Disconnected with those dapps
  4. Performed a swap on uniswap on avalanche and binance smart chain

Screenshots/Recordings

Upgrade path recording:

Uploading Screen Recording 2024-04-05 at 13.14.41.mov…

Before

RPReplay_Final1712163751.MP4

After

screen-20240408-200805.mp4

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • 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.

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 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.

@tommasini tommasini added team-accounts-framework Accounts team team-mobile-platform Mobile Platform team release-7.20.0 Issue or pull request that will be included in release 7.20.0 labels Apr 5, 2024
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.99%. Comparing base (1c1c9ed) to head (311a2d0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9148   +/-   ##
=======================================
  Coverage   45.98%   45.99%           
=======================================
  Files        1273     1273           
  Lines       31342    31338    -4     
  Branches     3213     3213           
=======================================
  Hits        14414    14414           
+ Misses      16079    16075    -4     
  Partials      849      849           

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 311a2d0
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/e471a640-8754-4630-9f8d-cccc810011a6

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@tommasini tommasini added the regression-RC DEPRECATED: Please use "regresssion-RC-x.y.z" label instead label Apr 5, 2024
@tommasini tommasini marked this pull request as ready for review April 5, 2024 13:15
@tommasini tommasini requested a review from a team as a code owner April 5, 2024 13:15
@tommasini tommasini changed the title fix: Tokens disappearing when updating (DRAFT) fix: Tokens disappearing when updating Apr 5, 2024
Copy link
Copy Markdown
Contributor

@owencraston owencraston left a comment

Choose a reason for hiding this comment

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

why not remove the selectedAddress: accountsController.getSelectedAccount().address, on line 521 if we are going to stick to using the preferences controller as the source of truth?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2024

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 06da26f
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/a30877bc-52aa-4270-a5e1-1e5bf198463d

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link
Copy Markdown
Contributor

@owencraston owencraston left a comment

Choose a reason for hiding this comment

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

Code looks good to me and I did a QA pass and it also looked good.

Test paths

  • on version 7.19.0 QA build...
  • imported an account via SRP with eth
  • imported an account via private key with eth and tokens (orangefox.eth)
  • imported tokens on mainnet
  • added custom networks (polygon, BNB)
  • imported available tokens
  • switched networks
  • added a new account
  • updated to a QA build of this branch
  • all accounts were present with the correct names
  • all mainnet balances were correct
  • all mainnet tokens were present with the correct balances
  • all custom network balances were correct
  • all custom neto\work tokens and token balances were present and correct

Video

screen-20240408-200805.mp4

@tommasini tommasini merged commit aecffbf into main Apr 8, 2024
@tommasini tommasini deleted the fix/9122-tokens-disappearing-2 branch April 8, 2024 19:34
@github-actions github-actions bot locked and limited conversation to collaborators Apr 8, 2024
@metamaskbot metamaskbot added the release-7.21.0 Issue or pull request that will be included in release 7.21.0 label Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

regression-RC DEPRECATED: Please use "regresssion-RC-x.y.z" label instead release-7.20.0 Issue or pull request that will be included in release 7.20.0 release-7.21.0 Issue or pull request that will be included in release 7.21.0 team-accounts-framework Accounts team team-mobile-platform Mobile Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Tokens go missing after upgrade on imported accounts

4 participants