MetaMask / metamask-android-sdk

MetaMask SDK for Android
Other
47 stars 13 forks source link

[Bug]: Connect function not working with EthereumRequest #115

Closed Gagandeep0312 closed 5 months ago

Gagandeep0312 commented 6 months ago

Provide environment information

I am trying to use connect with function with Method EthereumMethod.ADD_ETHEREUM_CHAIN to connect and add the Chain.

MetaMask Android SDK Version

0.5.4

MetaMask Mobile app Version

v7.21.0(1317)

Android Version

14

Describe the Bug

` val request = EthereumRequest(method = EthereumMethod.ADD_ETHEREUM_CHAIN.value, params = listOf(mapOf( "chainId" to "0xa86a",

        "rpcUrls" to "https://api.avax.network/ext/bc/C/rpc",

    )))

    ethereum.connectWith(request,callback)`. I am trying to connect metamask on same time try to add the Chain. but It does nothing, It redirects to metamask but hold on dashboard screen, Connect bottomsheet not showing.  If I use the ethereum.connect(), then its working fine. 

Expected Behavior

when trying to connect with Any request, It should execute the connect then requested function on follow to execute. What really my job is to Connect-> Add Chain-> Switch to new Chain on single transaction, without doing Back and forth. Is it visible?

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

No response

To Reproduce

` ethereum.disconnect(true) val request = EthereumRequest(method = EthereumMethod.ADD_ETHEREUM_CHAIN.value, params = listOf(mapOf( "chainId" to AppVariables.ETHEREUM_CHAIN_ID,

        "rpcUrls" to AppVariables.ETHEREUM_RPC_URL,

    )))

    ethereum.connectWith(request,callback)`
elefantel commented 6 months ago

Hi @Gagandeep0312 thanks for the issue! We have tried to replicate it but were not able to get it. But looking at your request, there are a few mistakes:

  1. It is missing the chainName, and this would result in a -32602 error code with error message "Expected non-empty string 'chainName'. Received null".
  2. rpcUrls should be an array not a string The request The request should like this (in Kotlin):
        val params: MutableMap<String, Any> = mutableMapOf(
            "chainId" to "0xa86a",
            "chainName" to "Avalanche",
            "rpcUrls" to listOf("https://api.avax.network/ext/bc/C/rpc")
        )
        val addChainRequest = EthereumRequest(
            method = EthereumMethod.ADD_ETHEREUM_CHAIN.value,
            params = listOf(params)
        )

See the demos below showing the modified the test dapp to add a connect with add chain request • chainName is missing on the video on the left - the request fails • All expected params provided on the video on the right - the request succeeds

Please fix your request and try again and let us know?

Missing chainName All params provided
christopherferreira9 commented 5 months ago

Hi @Gagandeep0312 ! I'm going to be closing this issue since there hasn't been any activity on it. Please feel free to open a new issue if you're still experiencing issues.