Skip to content

Conversation

unickhow
Copy link

@unickhow unickhow commented Sep 9, 2025

Explanation

This PR fixes an issue where SDK hooks do not receive feedback when users cancel or close the MetaMask extension connection window. Previously reported in issues #214 and partially addressed in #1202, this problem persisted because connectWithExtensionProvider was silently catching and ignoring connection errors without emitting appropriate events.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

Note

On extension connect error, emit ConnectWithResponse, optionally send REJECTED analytics, restore original provider, and rethrow; tests updated for these behaviors.

  • Provider Manager (connectWithExtensionProvider):
    • Error handling overhaul:
      • Emit MetaMaskSDKEvent.ConnectWithResponse with { error } on failure.
      • Send TrackingEvents.REJECTED when analytics enabled.
      • Restore instance.activeProvider and window.ethereum from sdkProvider if present.
      • Re-throw the error after handling.
    • Success path unchanged: persist STORAGE_PROVIDER_TYPE=extension, set extensionActive, emit ProviderUpdate (EXTENSION), send SDK_USE_EXTENSION analytics.
  • Tests (connectWithExtensionProvider.test.ts):
    • Add/extend cases for rejection, analytics disabled, and missing sdkProvider.
    • Assert event emission, analytics behavior, error propagation, and provider restoration.

Written by Cursor Bugbot for commit b8a7195. This will update automatically on new commits. Configure here.

@unickhow unickhow marked this pull request as ready for review September 9, 2025 14:47
@unickhow unickhow requested a review from a team as a code owner September 9, 2025 14:47
expect(instance.activeProvider).toStrictEqual((global.window as any).extension);

consoleWarnSpy.mockRestore();
});
Copy link

Choose a reason for hiding this comment

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

Bug: SDK Provider Overwrite Causes Test Failures

The connectWithExtensionProvider function unconditionally assigns instance.sdkProvider = instance.activeProvider before attempting connection. This overwrites the original SDK provider if the function is called multiple times. In error scenarios, this also causes instance.sdkProvider to always be truthy, which incorrectly triggers provider restoration in tests and prevents verifying behavior when no previous provider is available.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

1 participant