WalletConnect / WalletConnectFlutterV2

WalletConnect v2 client made in Dart for Flutter.
https://pub.dev/packages/walletconnect_flutter_v2
Apache License 2.0
114 stars 60 forks source link

Pass chainId to registerRequestHandler #258

Closed Rimantovas closed 7 months ago

Rimantovas commented 8 months ago

Is your feature request related to a problem? Please describe. When having multiple EVM chains connected, it is hard to determine which chain to interact with

Describe the solution you'd like Pass chainId parameter to registerRequestHandler handler function. Since we already have it in _onSessionRequest, it won't be hard to implement.

quetool commented 8 months ago

Hello @Rimantovas, not sure I follow your concern 🤔 Could you elaborate a bit more?

Rimantovas commented 8 months ago

The following method passes the session topic and request parameters to the handler. It would be nice to also get the chainId

 @override
  void registerRequestHandler({
    required String chainId,
    required String method,
    dynamic Function(String, dynamic)? handler,
  }) {
    try {
      return signEngine.registerRequestHandler(
        chainId: chainId,
        method: method,
        handler: handler,
      );
    } catch (e) {
      rethrow;
    }
  }
quetool commented 8 months ago

Ok but what do you mean by "having multiple EVM chains connected"? You can not have "multiple EVM chains connected". Your paired session between dapp/wallet always works on the current active chain.

Rimantovas commented 8 months ago

Yes, you can only have one active chain at a time, but you can pass multiple chains as optional namespaces.

Rimantovas commented 7 months ago

Created a pull request that solves this issue @quetool

quetool commented 7 months ago

Hello @Rimantovas! Here you can see the PR that would fix your issue! TL;DR: After this PR is merged you will have to handle your methods with onSessionRequest subscription (as it was supposed to be originally but was broken). method handlers registration will still work perfectly but if you want to access the current chainId then onSessionRequest subscription is your way to go https://github.com/WalletConnect/WalletConnectFlutterV2/pull/269