wakumo / flutter-wallet-connect-v2

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

Issue with accepting connection - "Unsupported methods for namespace" - wallet_connect_v2 #17

Closed huantd0111 closed 1 year ago

huantd0111 commented 1 year ago

Hello,

I hope this message finds you well. I am facing an issue with the wallet_connect_v2 Flutter library when trying to accept a connection. Specifically, I receive the error message "Unsupported methods for namespace." I have attempted to upgrade to the latest version of the library but encountered this problem during the approval process.

To provide more context, I have followed your example for implementing the connection approval process, and it seems to be working fine with the older version. However, after upgrading to the latest version, when I reach the "approve" step and build a SessionApproval object, it looks like this:

{
  "id": "c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969",
  "namespaces": {
    "eip155": {
      "accounts": ["eip155:5:0x5d35c1b9b2ae614bf9b470af9ae4a544f355afc1"],
      "methods": ["eth_signTypedData_v4", "eth_sign", "eth_signTransaction", "eth_signTypedData"],
      "events": ["chainChanged", "accountsChanged"]
    }
  }
}

However, when I call wcClientV2.approveSession(approval: approval);, I get the following error message:

_onEventError approve_error Unsupported methods for namespace.

To further assist you in troubleshooting, I've included some relevant log information during the connection process:

`

flutter: onEvent data = {name: connection_status, data: {isConnected: true}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: My Wallet: _onSessionProposal {"id":"c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969","proposer":{"name":"React App","url":"https://react-app.walletconnect.com","description":"React App for WalletConnect","icons":["https://avatars.githubusercontent.com/u/37784886"],"redirect":null},"namespaces":{"eip155":{"chains":["eip155:5"],"methods":["eth_sendTransaction","personal_sign"],"events":["chainChanged","accountsChanged"]}},"optionalNamespaces":{"eip155":{"chains":["eip155:5"],"methods":["eth_signTypedData_v4","eth_sign","eth_signTransaction","eth_signTypedData"],"events":[]}}}
flutter: My Wallet: [{network: Instance of 'NetworkSupport', currency: _code: eth_test eth_test,, account: Account{address: 0x5d35c1b9b2ae614bf9b470af9ae4a544f355afc1, index: 0, addressName: null, balance: Balance{_decimal: 0, _balance: 0, _decimalBalance: 0.0, _beautyBalance: 0, _displayBalance: null, _precision: 6, _usdtBalance: null}}}]

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}
flutter: onEvent data = {data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}, name: proposal}

flutter: onEvent data = {name: proposal, data: {id: c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969, namespaces: {eip155: {chains: [eip155:5], methods: [eth_sendTransaction, personal_sign], events: [chainChanged, accountsChanged]}}, proposer: {icons: [https://avatars.githubusercontent.com/u/37784886], redirect: null, name: React App, description: React App for WalletConnect, url: https://react-app.walletconnect.com}, optionalNamespaces: {eip155: {chains: [eip155:5], methods: [eth_signTypedData_v4, eth_sign, eth_signTransaction, eth_signTypedData], events: []}}}}

flutter: My Wallet: ----------

flutter: My Wallet: {"id":"c4cfa7d03950e101abcc116cace0814f6bc7e555dd2129ff3639b829b9717969","namespaces":{"eip155":{"accounts":["eip155:5:0x5d35c1b9b2ae614bf9b470af9ae4a544f355afc1"],"methods":["eth_signTypedData_v4","eth_sign","eth_signTransaction","eth_signTypedData"],"events":["chainChanged","accountsChanged"]}}}

flutter: My Wallet: ----------

flutter: My Wallet: _onEventError approve_error Unsupported methods for namespace`

As you can see from the logs, the object I created seems to be fine. I have verified it and compared it with the previous version, and they are identical.

Could you please help me troubleshoot this issue? I have noticed some asset loading errors, but I'm not sure if they are related to the problem. I appreciate any insights or guidance you can provide to resolve this.

ludowkm commented 1 year ago

Hello @huantd0111 , thank you for the issue report. I just tried the https://react-app.walletconnect.com/ and it still happen the error like you. But when i try with another dApps like Uniswap, Pancake, it still work as usual so let me debug the see the raw proposal request between react-app and other dApps for more details then get back to you soon.

huantd0111 commented 1 year ago

Hello @ludowkm ,

Thank you for your quick response and your efforts to help. I tried with popular dApps like Uniswap, Pancake, and encountered similar errors. I suspect that some methods might not be supported, so I hard-coded with an object as shown in the code snippet below:

      final approval = SessionApproval(id: widget.proposal.id, namespaces: {
        'eip155': SessionNamespace(
          accounts: ['eip155:5:0x57CB13cbef735FbDD65f5f2866638c546464E45F'],
          methods: ['eth_sendTransaction', 'eth_sign', 'personal_sign', 'eth_signTypedData'],
          events: [],
        )
      });
      Logger.log('----------');
      Logger.log(jsonEncode(approval));
      Logger.log('----------');
      widget.wcClientV2.approveSession(approval: approval);

However, I still received the error "_onEventError approve_error Unsupported events for namespace." I'd like to provide some additional log information from my tests as follows:

flutter: onEvent data = {data: {id: edba505378b2857b00e4132e587578b2ccf87ac6c704ac167202d54f01937437, namespaces: {eip155: {chains: [eip155:1], methods: [eth_sendTransaction, personal_sign], events: [accountsChanged, chainChanged]}}, proposer: {icons: [https://app.uniswap.org/./favicon.png, https://app.uniswap.org/./images/192x192_App_Icon.png, https://app.uniswap.org/./images/512x512_App_Icon.png], redirect: null, name: Uniswap Interface, description: Swap or provide liquidity on the Uniswap Protocol, url: https://app.uniswap.org}, optionalNamespaces: {eip155: {chains: [eip155:80001, eip155:42161, eip155:10, eip155:420, eip155:1, eip155:56, eip155:43114, eip155:44787, eip155:42220, eip155:5, eip155:11155111, eip155:137, eip155:421613], methods: [eth_sendTransaction, eth_sign, eth_signTypedData, personal_sign, eth_signTypedData_v4], events: [accountsChanged, chainChanged]}}}, name: proposal}

flutter: My Wallet: ----------

flutter: My Wallet: {"id":"46786bedac41e2bddbd700d9a20209a45fd6dc08bc63bded1406f9bab26ac014","namespaces":{"eip155":{"accounts":["eip155:5:0x57CB13cbef735FbDD65f5f2866638c546464E45F"],"methods":["eth_sendTransaction","eth_sign","personal_sign","eth_signTypedData"],"events":[]}}}

flutter: My Wallet: ----------

flutter: My Wallet: _onEventError approve_error Unsupported events for namespace

I understand that you have previously tried with PancakeSwap and did not encounter the same issue. However, after performing the "approve" action, the DApp did not update the interface and remained stuck on the connection screen. It seems they have since updated their application, and you are now able to connect without any problems.

Regarding the hard-coded object mentioned earlier, it appears that the error still persists despite using that approach.

huantd0111 commented 1 year ago

As I mentioned before, I suspected that certain methods were not supported, despite DApps efforts to require them. To solve this I followed the instructions provided in the issues link However, I regret that the repair attempt did not yield the expected results.

I'll provide the steps to reproduce: "wallet_connect_v2" version 1.0.6 and Simulator iOS 16.4.

ludowkm commented 1 year ago

Hi @huantd0111, i think this must be an issue from wallet connect SDK, from your console log, you can see it. They only accept approval with required namespaces (methods and events) only so if we use optional namespaces (which much more than required namespaces) then the error is occur. The main issue now is if we approve with required namespaces only then it does not contain needed methods for using later. So to fix this one, DApps must initiate enough require namespaces (would be better to have same with optional namespaces), like Uniswap and Pancake, they specified correctly then this error does not occur. Finally, to get over this issue, you will need to validate empty methods and events from required namespaces before using optional namespaces, also validate to include required methods and events then it will be ok.

ludowkm commented 1 year ago

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