MetaMask / MetaMask/metamask-extension
eth_requestAccounts connects to previously connected account, not what is currently in focus
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
**Describe the bug**
Suppose I've connected to a dapp from account 1.
If I leave the website, go to another website where I use account 2, account 2 is now in focus.
Now if I then go back to the original dapp which previously connected on account 1, if I click the 'connect' button, it shows i've connected.
Clicking metamask however shows that I am not connected because I am looking at account 2.
This seems like a bug.
**Steps to reproduce (REQUIRED)**
Steps to reproduce the behavior, libraries used with version number, and/or any setup information to easily reproduce:
1. Go to app.uniswap.org
2. Click on connect with Account 1, ie `await provider.request({ method: 'eth_requestAccounts' })` is called
3. Close the tab.
4. Open a new tab. and change the metamask account to Account 2.
5. Go to app.uniswap.org. (it calls eth_requestAccounts without a click by user, but that doesn't matter). It connects you to account 1 even though Account 2 is in focus for metamask.
It appears uniswap gets around this confusing ux by showing the address of the connected account.
**Expected behavior**
I would expect that when an app calls eth_requestAccounts, that it returns the account in focus. If the account in focus was previously connected, then connect it. If the account in focus was not previously connected, request permissions for the new account.
**Screenshots**
n/a
**Browser details (please complete the following information):**
- OS: OSX
- Hardware Wallet: n/a
- Browser: Version 94.0.4606.81 (Official Build) (x86_64)
- MetaMask Version: 10.2.2
Contributor guide
Research direction
Start by tracing the eth_requestAccounts entry point and how the focused MetaMask account is compared with previously granted permissions. Reproduce the Account 1/Account 2 sequence described with app.uniswap.org; done means the focused account is returned or prompted for permission instead of silently reconnecting the earlier account.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- authentication, authorization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100