MetaMask / MetaMask/metamask-extension

Improve auto detect accounts

Open
#13,276 3 comments 0 reactions 1 assignee Claimed by @amerkadicE View on GitHub
external-contributor INVALID-ISSUE-TEMPLATE PS-team type-enhancement ux-papercuts
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

### **User Story**
As a user, I want MetaMask to auto-detect my accounts with balance even when I have some accounts in between them that doesn’t hold any balance so I don’t get confused and think that I’ve somehow lost important accounts.

Goals

We want to start auto-detecting accounts for the current network every time the user logs in, switch networks or click a refresh account link. We also want to check if the next 3 accounts have funds.

### Figma/Notion links

**Notion**:https://www.notion.so/Auto-detect-3-accounts-past-an-account-with-balance-e9e41b0067ff445e9e7b0cc46ab85fe2

Figma: https://www.figma.com/file/33geacOStnlnJeBZhquDn7/Refresh-Accounts?node-id=0%3A1

### Acceptance criteria

1. Improve the current method for auto-detecting accounts so that: "The MetaMask auto-detect my accounts with balance even when I have some accounts in between them that doesn’t hold any balance so I don’t get confused and think that I’ve somehow lost important accounts."
**We want to check if the next 3 accounts have funds.**


#### Steps to Reproduce the issue:

- 1. Create accounts 1-4
- 2. Have a balance on account 1 and account 4, but no balance on account 2 and account 3
- 3. Import the wallet in a new installation and notice that account 4 won’t show up

2. Add a New option for refreshing the list of accounts on Accounts menu.
3. Add the current total number of accounts next to the _"My accounts"_ text. The _"total number"_ will show the number of accounts added to the wallet.

![image](https://user-images.githubusercontent.com/49436614/155483153-7a4c9879-732f-4a8d-8159-66cfc4cf9aae.png)
#### NOTE: Some things looks different on the design file in comparison with the current extension version.

4. Auto-detect accounts for the current network every time the user:
- Logs in,
- Switch networks or
- Click a refresh account option/link.

### Create 4 PR-s for following tasks:
1. Extract the existing logic into a separate method
Add the refresh button and apply the new method when that is called
2. Handle the login logout case
3. Handle the network switch case
4. Update the new method to check up to 3 accounts

### Notes

#### Scenarios:
- If accounts 1 and 4 have balance (2 and 3 does not have a balance), show all accounts (1,2,3,4 ).
- We always show all added accounts, regardless of selected networks (as it is currently implemented).
- Auto-detecting method will check accounts on the current selected network, not all networks added to the Metamask extension.
#### Slack discussion, method and notes: https://consensys.slack.com/archives/C02GH833686/p1645707181601199?thread_ts=1645700370.317969&cid=C02GH833686

##### Auto-detecting acccounts algorithm

begin
Take an index of the last account in the list
Add next account
Check the balance
While account balance > 0
add next account
check balance
End while

Repeat
if the balance == 0
add next account
check balance
end if
If if the balance > 0 go to step 1
Until the number of accounts with 0 balance is = 3

Remove the accounts with 0 balance from end of the list. Do not remove it if it is the only account on the list
end

### Open questions
No open questions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.