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

feat(pera): add auto-connect for Pera Discover browser #323

Merged
merged 5 commits into from
Dec 7, 2024

Conversation

drichar
Copy link
Collaborator

@drichar drichar commented Dec 6, 2024

Description

This PR adds automatic connection functionality for Pera wallet when running in the Pera Discover browser environment. The auto-connect happens during session resumption to ensure SSR compatibility and respect existing wallet connections.

Details

  • Added auto-connect detection for Pera Discover browser during session resumption
  • Added check to prevent auto-connect when another wallet is already active
  • Implemented silent error handling for auto-connect attempts
  • Added logging for both successful and failed connection attempts
  • Added comprehensive test coverage for auto-connect scenarios

Closes #311

Add automatic connection attempt when Pera wallet is initialized in the Pera
Discover browser environment. The connection attempt is handled silently with
appropriate logging for success and failure cases.
Add type check for window and navigator objects to prevent errors during
server-side rendering. This ensures the Pera auto-connect feature only
runs in browser environments.
Extract auto-connect logic from constructor into a private async method for better
error handling and testability. Update tests to use prototype mocking pattern
consistent with other wallet implementations.

- Move auto-connect logic into private `autoConnect` method
- Use async/await with try/catch for better error handling
- Update tests to mock method on prototype before wallet creation
- Align test patterns with other wallet implementations
Move auto-connect logic from constructor to `resumeSession` method in Pera wallet
implementations to fix SSR compatibility issues. Auto-connect now only triggers
when no other wallet is active and after client-side hydration.
Remove private `autoConnect` method from Pera wallet implementations since the
functionality is now handled directly in resumeSession.
@drichar drichar force-pushed the feat/pera-auto-connect branch from e0e17a4 to afc11e6 Compare December 7, 2024 03:47
@drichar drichar merged commit 4d04fb1 into v4 Dec 7, 2024
1 check passed
@drichar drichar deleted the feat/pera-auto-connect branch December 7, 2024 06:36
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