Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: https://consensyssoftware.atlassian.net/browse/WAPI-1082
Summary
DefaultTransportduring SDK initialization when the MetaMask extension is detected, enablingwallet_sessionChangedevent listeners to work beforeconnect()is calledwallet_sessionChangedto theDefaultTransportnotification filter — the extension already broadcasts these events but the SDK was silently dropping themwindow.postMessagelisteners whenonNotification()is called, not just duringconnect()connect()is later called, and avoids sendingwallet_revokeSessionfor sessions the SDK didn't createMotivation
In configurations where the dapp uses the wallet's own injected provider (native wallet-standard adapter for Solana, or
window.ethereumfor EVM) for connection, the dapp may also create a MetaMask Connect SDK instance to listen for session change events. Previously,wallet_sessionChangedevents could not be received untilconnect()was called on the SDK because:DefaultTransport.onNotification()didn't activatewindow.postMessagelistenersDefaultTransport.#handleNotificationexplicitly filtered outwallet_sessionChangedeventsSince
DefaultTransportand the extension's injected code share the samewindow.postMessagechannel, the SDK can passively observe extension-broadcasted events — it just wasn't wired up to do so.Changes
packages/connect-multichain/src/multichain/transports/default/index.ts#handleNotification: Addedwallet_sessionChangedto the event whitelist. Also fixed a pre-existing operator precedence issue where thetypeof responseData === 'object'guard didn't cover themetamask_accountsChangedcheck.onNotification(): Addedthis.#setupMessageListener()call sowindow.postMessagelisteners are active when notification callbacks are registered (not just whenconnect()orsendEip1193Message()is called). This is safe —#setupMessageListener()is idempotent.teardown(): New method that cleans up message listeners and pending requests without sendingwallet_revokeSession. Used when tearing down a passive transport that didn't create the session.packages/connect-multichain/src/multichain/index.ts#isPassiveTransport: New flag tracking whether the current transport was set up passively for event listening (no SDK-managed connection).#setupTransport(): When no stored transport exists but the extension is detected on a web platform (DesktopWeborMetaMaskMobileWebview), creates a passiveDefaultTransportand wires up notification listeners. Does NOT calltransport.connect(), does NOT write to storage, keeps status as'loaded'.#setupDefaultTransport(): Clears the passive flag when transitioning to active mode.disconnect(): Usesteardown()instead ofdisconnect()for passive transports to avoid sendingwallet_revokeSessionfor sessions the SDK didn't create. Resets the passive flag.Test updates
packages/connect-multichain/src/init.test.ts: Updated "no transport found during init" assertion — in web environment with extension, passive transport is now expected to exist.packages/connect-multichain/src/connect.test.ts: Updated 4 assertions wheresdk.transportwas expected to throw in 'loaded' state — now conditional on platform (web has passive transport, others do not).Test plan
DefaultTransportis created on web platform with extension installed (no stored session)wallet_sessionChangedevents from the extension flow through tocore.on('wallet_sessionChanged', handler)registered beforeconnect()createMultichainClient()→connect()→ eventsconnect()→ works correctlydisconnect()in passive mode does not sendwallet_revokeSession