wakumo / flutter-wallet-connect-v2

WalletConnect V2 for Flutter
MIT License
24 stars 7 forks source link

[Android] _onSessionProposal event not received with certain DApps #18

Closed huantd0111 closed 1 year ago

huantd0111 commented 1 year ago

Issue with flutter-wallet-connect-v2: _onSessionProposal event not received on Android for certain DApps (PancakeSwap and Uniswap)

Description: I'm reaching out for support regarding an issue I'm facing with the flutter-wallet-connect-v2 library. After updating to the latest version 1.0.6, I've encountered a problem where the _onSessionProposal event is not being received when connecting with certain DApps on the Android platform. The affected DApps include PancakeSwap and Uniswap.

Platform and Environment:

Issue Details:

  1. Upon calling the function await _wcClientV2.pair(uri: url);, no events are triggered when connecting with PancakeSwap and Uniswap DApps.
  2. The first log received after the function call is: onEvent data = {name: connection_status, data: {isConnected: true}}.
  3. Subsequent events, including the _onSessionProposal event, are not received, even after restarting the application and reconnecting.

Additional Observations:

Request for Assistance: I kindly request your support in resolving this issue with the flutter-wallet-connect-v2 library on the Android platform. As other DApps work fine, it seems to be specific to PancakeSwap and Uniswap connections. If there are any specific configurations, customizations, or logs needed from my side to facilitate the investigation, please let me know, and I'll be glad to provide them.

Thank you for your attention and assistance in resolving this matter.

huantd0111 commented 1 year ago

After further testing on a real device (Samsung Galaxy S8+ Android 9), I experienced a similar behavior. Upon installing the application, I initially received the _onSessionProposal notification as expected. However, after that, the issue resurfaced and persisted across all other DApps. Even when I restarted the app and created new instances, the problem remained unresolved.

This additional information might help in diagnosing the issue. If there are any specific steps or tests you would like me to perform to assist in resolving this matter, please let me know. Your support is greatly appreciated. Thank you.

huongse7en commented 1 year ago

I'm having the same problem, did you find a solution?

ludowkm commented 1 year ago

Hi @huantd0111 @huongse7en , i just tested on device Samsung A71, Android 12 and it worked well. I will take note this issue to try to test on another devices to reproduce.

huantd0111 commented 1 year ago

@ludowkm After investigating, I have identified the root cause of this issue. Specifically, after calling the _walletConnectV2Plugin.dispose(), it seems that the events are no longer being listened to, even when we initialize a new instance of WalletConnectV2. This means that WalletConnectV2 will not be able to establish a connection after dispose() is called.

To provide more context with the example application, after the "Init WalletConnect" is called for the first time, if you use Flutter's "Hot restart" tool, the application restarts, and it gets stuck at the loading screen when you press "Init WalletConnect".

To resolve this issue, we need to ensure that event listeners are set up correctly even after calling dispose(). This way, WalletConnectV2 can establish connections properly even after disposing of previous instances. The implementation should be updated to handle event listeners consistently, even during hot restarts.

ludowkm commented 1 year ago

This must be our implementation and it's not issue of this library so i close this issue, feel free to re-open if there is anything else.

rhamnett commented 1 year ago

@ludowkm I found that your example code on pub dev causes issues with optional namespace so I added an additional check and it fixes the request.

            final List<String> chainList = [];
            chainList.addAll(proposal.namespaces['eip155']!
                .chains!); // This line might throw the null error
            if (proposal.optionalNamespaces?['eip155']?.chains != null) {
              chainList.addAll(proposal.optionalNamespaces!['eip155']!.chains!);
            }
            final chainIDs = chainList.toSet().toList();

You probably want to update Pub Dev