Skip to content

chore: cherry-pick #9764 - #9765

Merged
NicolasMassart merged 1 commit into
release/7.23.0from
chore/cherry-pick-9764
May 28, 2024
Merged

chore: cherry-pick #9764#9765
NicolasMassart merged 1 commit into
release/7.23.0from
chore/cherry-pick-9764

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

This PR cherry-picks #9764

<!--
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**

1. What is the reason for the change?
- This error occurs one a fresh install after importing an account from
SRP that has multiple accounts WITH balances (In my case I was testing
an account that had 5 addresses with balances). The reason for this is
because when importing an SRP, each account gets imported one by one
until we find an address that has a zero balance. [Once we find the
address with a zero balance, we remove that account and the account
import is
complete](https://github.com/MetaMask/metamask-mobile/blob/main/app/util/importAdditionalAccounts.js#L49-L61).
This unveiled an issue in the AccountsController (which is not being
used to display the wallet info) because when a new account is added we
[eagerly set the latest account as the selected
account](https://github.com/MetaMask/core/blob/v123.0.0/packages/accounts-controller/src/AccountsController.ts#L751).
This caused two issues.
- The selected account after an import would be the last account in the
list. This differs from production which defaults to the first account.
- Since the last account in the list was set to selected, when it gets
removed in this step
[here](https://github.com/MetaMask/metamask-mobile/blob/main/app/util/importAdditionalAccounts.js#L59),
the UI/Controller are still referencing the account that just got
deleted, causing a race condition and resulting in the crash we see in
the video.

3. What is the improvement/solution?
- To solve this bug I am doing one simple thing, not setting the latest
added account to selected. This comes in the form of a patch due to the
urgency of this fix but we will work to find a better more long term
solution in the latest accounts controller release.
- We are already working on a longer term fix
[here](MetaMask/core#4322).
- This does not effect the selected account logic in the UI since the
[front end is already manually setting an account to selected when a new
account is
added](https://github.com/MetaMask/metamask-mobile/blob/e0a4bec1ce82415a3be892e719194ff829beb05f/app/components/Views/AddAccountActions/AddAccountActions.tsx#L44).
This can be seen in my vide below.

## **Related issues**

Fixes: #9749

## **Manual testing steps**

1. Run this branch without any previous instance of metamask installed
3. import a wallet from SRP that has multiple addresses with a balance.
This is essential to truly test this feature.
4. after importing the account, you should be sent to the wallet home
screen
5. wait for things to load because this screen is very very slow.
6. NOTICE that the selected account is always account 1
7. open the account picker and notice that their are multiple addresses
created with the correct balances
8. there should be no crash
9. click on the account picker and add a new account
10. this account should get created and should now become the selected
account
11. force close the app by swiping it away and then reopen
12. upon unlocking the wallet the selected account should be the same
account that was selected before.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**



https://github.com/MetaMask/metamask-mobile/assets/22918444/2396608d-c30e-4421-88e3-e14b21a799e8



### **After**



https://github.com/MetaMask/metamask-mobile/assets/22918444/9b0ec7d2-4d48-4142-b2b8-dd680a392b3a

NOTE: The performance of this home screen is terrible and is not related
to the AccountsController. @Cal-L has [separate incoming fix for
this](#9753).

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] 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](https://jsdoc.app/) format
if applicable
- [ ] 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.
@owencraston
owencraston marked this pull request as ready for review May 28, 2024 01:12
@owencraston
owencraston requested a review from a team May 28, 2024 01:12

@Cal-L Cal-L left a comment

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.

Lgtm

@github-actions

github-actions Bot commented May 28, 2024

Copy link
Copy Markdown
Contributor Author

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: d19d061
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/9b5c1ea3-3980-4151-a123-4590655025c5

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

@NicolasMassart
NicolasMassart merged commit 9fbe7e7 into release/7.23.0 May 28, 2024
@NicolasMassart
NicolasMassart deleted the chore/cherry-pick-9764 branch May 28, 2024 16:45
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants