MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
11.93k stars 4.88k forks source link

Improve auto detect accounts #13276

Open EHaracic opened 2 years ago

EHaracic commented 2 years ago

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. Add a New option for refreshing the list of accounts on Accounts menu.
  2. 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

NOTE: Some things looks different on the design file in comparison with the current extension version.

  1. 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:

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

EHaracic commented 2 years ago

@danjm @bschorchit Think that we need to refine this ticket. We had some discussions before but im my opinion we need to discuss it once again.

bschorchit commented 2 years ago

Answering the open question, here is the design for the refresh accounts button. Some things looks different on the design file, but the only two changes needed are:

  1. Adding the "Refresh accounts" button on the accounts menu;
  2. Adding the current total number of accounts next to the My accounts text.
bschorchit commented 2 years ago

Related to https://github.com/MetaMask/metamask-extension/issues/9470