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

fix(wallets): correct disconnect handling for Pera and Defly #272

Merged
merged 6 commits into from
Sep 24, 2024

Conversation

drichar
Copy link
Collaborator

@drichar drichar commented Sep 24, 2024

Description

This PR fixes the disconnect event handling for Pera and Defly wallets. It addresses an issue where the wallet state wasn't updating correctly when a session was deleted in the mobile app.

Details

  • Implemented disconnect event listener registration in connect method
  • Added proper handling of disconnect events to update the wallet store
  • Updated test suites for Pera and Defly wallets to cover disconnect scenarios
  • Ensured compatibility with Pera Connect v1 and v2 (beta) implementations
  • Refactored mock structures in tests to accurately represent wallet interfaces

This fix improves wallet connection management reliability, especially when disconnecting from the mobile app. Users will now see the correct wallet state in their applications after external disconnection.

Closes #271

The disconnect event listeners for Pera (v1), Pera (v2), and Defly wallets are now properly registered after successful connection. This ensures that deleting a session in the wallet's mobile app triggers the `onDisconnect` method, correctly updating the `WalletProvider` store.

- Moved disconnect event listener registration to the `connect` method
- Removed premature event listener registration in `initializeClient`
The `onDisconnect` method in `BaseWallet` is now an arrow function to preserve the correct 'this' context when called as an event listener. This fixes an issue where 'this.store' was undefined in `removeWallet` when the disconnect event was triggered.

- Changed `onDisconnect` from a regular method to an arrow function
- Added debug logging when removing wallet from store
- Add tests for disconnect event listener registration
- Implement tests for handling disconnect events
- Update mock structures for Pera and Defly wallets
@drichar drichar merged commit caa7f48 into main Sep 24, 2024
1 check passed
@drichar drichar deleted the fix/271-pera-defly-disconnect-listener branch September 24, 2024 21:58
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.

Pera and Defly providers are not listening for disconnect events
1 participant