Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: "accountsChanged" not triggered when account is not yet connected. #26011

Open
Crismon96 opened this issue Jul 22, 2024 · 0 comments
Open
Labels
external-contributor regression-prod-11.16.15 Regression bug that was found in production in release 11.16.15 Sev3-low Low severity; minimal to no impact upon users team-wallet-api-platform type-bug type-enhancement

Comments

@Crismon96
Copy link

Describe the bug

I am using this event API: https://docs.metamask.io/wallet/reference/provider-api#accountschanged

The event is only emitted when the account is already connected to the dApp. I need to handle the use case that a user switches from a connected account to one that is not connected yet. It is ok if I can not see the address or interact with the account but I need to be notified of the change.
Would be great to know if this is an actual bug or intended behavior and there is another proper(!) workaround for my need.

Expected behavior

Event to be emitted when the user changes to an account that is not yet connected:

 window.ethereum.on('accountsChanged', (e) => {
 // this is called whenever the account is connected or not. So I can prompt the user to allow access.
        connectWallet()
      });

Screenshots/Recordings

No response

Steps to reproduce

  1. Connect to provider with an account that has access.
  2. Switch accounts to another account that does not have access.
  3. Observe that event is not emitted

Error messages or log output

Nothing is logged.

Detection stage

In production (default)

Version

11.16.15

Build type

None

Browser

Firefox

Operating system

Linux

Hardware wallet

No response

Additional context

Using ethers 6 to create provider instance.

Severity

  • quite important as my app looks broken when user switchers accounts and doesn't realize the issue on its own.
@metamaskbot metamaskbot added external-contributor regression-prod-11.16.15 Regression bug that was found in production in release 11.16.15 labels Jul 22, 2024
@gauthierpetetin gauthierpetetin added the Sev3-low Low severity; minimal to no impact upon users label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-contributor regression-prod-11.16.15 Regression bug that was found in production in release 11.16.15 Sev3-low Low severity; minimal to no impact upon users team-wallet-api-platform type-bug type-enhancement
Projects
Status: To be fixed
Status: To be fixed
Development

No branches or pull requests

5 participants