Skip to content

Conversation

@ffmcgee725
Copy link
Member

@ffmcgee725 ffmcgee725 commented Feb 3, 2025

This PR fixes #3853:

Currently when the user locks the wallet (either manually or by timer) the wallet emits an accountsChanged event with an empty array to all connected dapps. This is very confusing since it cannot be immediately distinguished from permissions being revoked, resulting in dapps not handling these two cases gracefully.

We should stop emitting the accountsChanged event when the wallet is locked.

This change addresses this by removing handleUnlockStateChanged functionality from the BaseProvider, as it was decided it does not make sense to announce any account related information when the extension locks/unlocks:

Extensions pull request that will be pulling this change for the fix: MetaMask/metamask-extension#30067

Extension working with updated providers lib:

Screen.Recording.2025-02-03.at.15.44.50.mov

@ffmcgee725 ffmcgee725 requested a review from a team February 3, 2025 15:13
// EIP-1193 connect
this._handleConnect(chainId);
this._handleChainChanged({ chainId, networkVersion });
this._handleUnlockStateChanged({ accounts, isUnlocked });
Copy link
Contributor

@jiexi jiexi Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not confident we initialize the value of isUnlocked to true without this

Copy link
Member Author

@ffmcgee725 ffmcgee725 Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning we should still get isUnlocked from deconstructing initial state

      const { accounts, chainId, isUnlocked, networkVersion } = initialState;

and set it in this function

this._state.isUnlocked = isUnlocked;

Or just default to true ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it's not necessary to set this after df0acbf

@adonesky1 adonesky1 force-pushed the fix/locked-wallet-behaviour-eth_accounts-accountsChanged branch from 2ecc8af to e109526 Compare February 3, 2025 18:31
Gudahtt
Gudahtt previously approved these changes Feb 3, 2025
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor suggestion, but LGTM!

}
return this._state.isUnlocked;
},
isUnlocked: async () => !this._state.isPermanentlyDisconnected,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would be nice to have a unit test for this, I don't see one. I know it wasn't covered previously (so it seems), but it looks like it would be easy to add. And coverage is decent for the rest of the file otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding it quite difficult to simulate the unrecoverable disconnection event to actually toggle the isPermanentlyDisconnected state... any ideas on how to achieve this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 60bb239

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adonesky1 seems not much has to be done since the state isPermanentlyDisconnected initializes to false on BaseProvider parent class, so we just assert the return is it's negated value

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ffmcgee725 ffmcgee725 merged commit bda8d72 into main Feb 3, 2025
19 checks passed
@ffmcgee725 ffmcgee725 deleted the fix/locked-wallet-behaviour-eth_accounts-accountsChanged branch February 3, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants