WalletConnect / WalletConnectKotlinV2

WalletConnect Kotlin SDK v2
Apache License 2.0
190 stars 69 forks source link

Wallets Migrated to v2 not working with DeepLink and Native Implementation #899

Open idelburgo-iomob opened 1 year ago

idelburgo-iomob commented 1 year ago

Describe the bug While using WalletConnect v2, can't connect to a wallet supposedly migrated to v2 already. SDK Version

To Reproduce In an example app I created Steps to reproduce the behavior:

  1. Initialize CoreClient and SignClient with all the parameters
  2. Use SignClient.connect method and on the Success callback launch the "pairing.uri" to the desired wallet
  3. Wallet opens but no modal to accept connection

Expected behavior Wallet to open the modal and accept the connection to then sign a message. Tested with [example Wallet v2] (https://react-wallet.walletconnect.com/) and all the process works smoothly. Several wallets "migrated" to v2 does not open the modal to accept the connection they just open reacting to the deeplink, but keeps there without doing nothing

Screenshots If applicable, add screenshots to help explain your problem.

Device (please complete the following information):

Additional context I would like to know if I'm are the one doing something wrong or the wallets are not supporting really v2 as the example wallet https://react-wallet.walletconnect.com/ works without any flaw to connect and sign the message.

CODE used:

In the Application class

//for v2
        val projectId = "<My project ID>" //Get Project ID at https://cloud.walletconnect.com/
        val relayUrl = "relay.walletconnect.com"
        val serverUrl = "wss://$relayUrl?projectId=${projectId}"
        val connectionType = ConnectionType.AUTOMATIC
        val application = this //Android Application level class
        println("WALLET_CONN -> serverUrl: $serverUrl")
        val appMetaData = Core.Model.AppMetaData(
            name = "WalletIntegration Example",
            description = "Kotlin Requester Implementation",
            url = "<URL here>",
            icons = listOf("https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/master/Icon/Gradient/Icon.png"),
            redirect = "<My redirect>"
        )
        CoreClient.initialize(relayServerUrl = serverUrl, connectionType = connectionType, application = application, metaData = appMetaData) {error ->
            println("WALLET_CONN -> Error initialize Core $error")
        }

        SignClient.initialize(init = Sign.Params.Init(core = CoreClient)) { error ->
            println("WALLET_CONN -> Error initialize Sign $error")
        }

Where connecting

fun signV2() {
        /*Namespace identifier*/
        val namespace: String = "eip155" // reference: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md#syntax
        /*List of chains that wallet will be requested for*/
        val chains: List<String> = listOf(
            "eip155:42220" // Celo main net
        )
        /*List of methods that wallet will be requested for*/
        val methods: List<String> = listOf(
            "personal_sign" // ATM we only want to sign
        )
        /*List of events that wallet will be requested for*/
        val events: List<String> = listOf(
            "chainChanged",
            "accountChanged"
        ) // Actually all possible events

        val expiry = (System.currentTimeMillis() / 1000) + TimeUnit.SECONDS.convert(7, TimeUnit.DAYS)
        val properties: Map<String, String> = mapOf("sessionExpiry" to "$expiry")

        val namespaces: Map<String, Sign.Model.Namespace.Proposal> = mapOf(
            namespace to Sign.Model.Namespace.Proposal(
                chains,
                methods,
                events)
        )

        val pairing: Core.Model.Pairing = CoreClient.Pairing.create()!!

        val connectParams = Sign.Params.Connect(
            namespaces = namespaces,
            optionalNamespaces = namespaces,
            properties = properties,
            pairing = pairing)

        SignClient.connect(connectParams,
        onSuccess = {
            println("WALLET_CONN -> SignClient success")
            var deeplink = pairing.uri
            println("WALLET_CONN -> link: $deeplink")
            pairingDeeplink = "$deeplink" // Tried with "wc://wc?uri=$deeplink" too but is not working
            _connectionUri.postValue("$pairingDeeplink") // LiveData that triggers to open the link URI, allowing to select the wallet to open
        }, onError = { error ->
            println("WALLET_CONN -> SignClient error: $error")
        })
    }
jakubuid commented 1 year ago

Hey, @idelburgo-iomob can you list all the wallets that you use to test deep link flow?

idelburgo-iomob commented 1 year ago

Sure, thanks for your answer @jakubuid Tried the following (all of them appear under v2 in the explorer)

Maybe I'm doing something wrong, but as the example wallet is working perfectly I can't see what. Followed documentation and all the examples.

jakubuid commented 1 year ago

We're aware of that and we're working with them closely to add the correct support for deep link flow ASAP Thanks for pointing out this

Ekoios-Michael commented 1 year ago

Hi @jakubuid I had the same issue. I tried to use Wallet Connect V2 to initialize a session to TrustWallet via the DeepLink Android. But I only link to Trust Wallet and don't appear anything after. Expect: link opens TrustWallet through Wallet Connect V2 and the confirmation modal appears to accept the connection session I glad if you can support me. Thank in advance

idelburgo-iomob commented 1 year ago

@jakubuid in 20 days v1 will be shutoff. Is there any estimation of when will this be solved? As I need to fully implement it and test before that date.

jakubuid commented 1 year ago

Hey all, we work closely with those wallets to add the correct support for deep links, see the following:

Raenar4k commented 1 year ago

Yeah, same issue. I've opened this before: https://github.com/WalletConnect/WalletConnectKotlinV2/issues/793 It seems that while wallets support v2, issue in sdk prevented deeplinks from working.

For now im waiting confirmation from WalletConnect team on updated and working wallets, before our team starts any work on integration.

jakubuid commented 1 year ago

Trust - within the latest update on PlayStore - deep linking flow works

It seems that while wallets support v2, issue in sdk prevented deeplinks from working.

The above is true only for Auth use case -we're planning to release a new sdk version till EOW

idelburgo-iomob commented 1 year ago

Trust - within the latest update on PlayStore - deep linking flow works

It seems that while wallets support v2, issue in sdk prevented deeplinks from working.

The above is true only for Auth use case -we're planning to release a new sdk version till EOW

So this won't work in my case, using Core + Sign SDKs? I need to sign a message and be able to "sendTransaction"

Raenar4k commented 1 year ago

The above is true only for Auth use case -we're planning to release a new sdk version till EOW

So fixed sdk is not out yet? As the issue was closed i thought you had released fixed version, and all it would take is for wallets to update and release versions with the fix. Why close issue if fixed sdk is not even released?

idelburgo-iomob commented 1 year ago

I tested with my app, and after updating TrustWallet, still happening the same. Are you/them checking with deeplinks from Android native (kotlin) apps? (Not from React Native or other hybrid apps). @jakubuid

jakubuid commented 1 year ago

TrustWallet - version 7.24.2 - deeplinking flow working with https://github.com/WalletConnect/WalletConnectKotlinV2/tree/develop/samples/dapp supporting Core + Sign

https://github.com/WalletConnect/WalletConnectKotlinV2/assets/23366251/2fcfa798-44eb-451f-95d0-3c71b5191c6e

idelburgo-iomob commented 1 year ago

As far as I can see it is using Web3Modal SDK. Am I right? Im using Core + Sign. Won't it work with them? Im using [Core 1.15.0, Sign 2.13.0], should I try the next one or this is not the problem?

Web3Modal appears to be in alpha, so can't rely on it

Shitikyan commented 1 year ago

I have the same case with separate wallets and need help to make WC2 work somehow with some wallets.

For Trust Wallet, the signing process only functions correctly when we send the sign body in the format of ["$msg", "$account"]. And after that signature is not what I expect and what I get from Metamask F.E.

However, for Zerion Wallet, the connection does not work at all, and the modal to accept the connection does not appear. For Spot Wallet, the connection does not work, and the modal to accept the connection appears with an "Authentication failed" error.

https://github.com/WalletConnect/WalletConnectKotlinV2/assets/41128384/afbd6c4e-7210-48c1-a67c-3971652102f8

https://github.com/WalletConnect/WalletConnectKotlinV2/assets/41128384/fa1c8cf2-8383-4529-a9be-0e75fa2808e2

https://github.com/WalletConnect/WalletConnectKotlinV2/assets/41128384/0a785fb2-efbb-48a1-827b-639a0e1bed47

If you already have some wallets which are working on full flow with Kotlin XML (Even if with Compass), please share.

idelburgo-iomob commented 1 year ago

Which SDKs are you using in that example @Shitikyan ?? Is it a native kotlin app?

Shitikyan commented 1 year ago

We are using Android SDK 13(Tiramisu) , and yes it is Kotlin app. Here are the versions of the Wallet Connect packages we are using: implementation("com.walletconnect:web3wallet:1.8.0") implementation("com.walletconnect:sign:2.13.0") implementation("com.walletconnect:android-core:1.15.0") implementation("com.walletconnect:android-bom:1.10.0")

idelburgo-iomob commented 1 year ago

We are using Android SDK 13(Tiramisu) , and yes it is Kotlin app. Here are the versions of the Wallet Connect packages we are using: implementation("com.walletconnect:web3wallet:1.8.0") implementation("com.walletconnect:sign:2.13.0") implementation("com.walletconnect:android-core:1.15.0") implementation("com.walletconnect:android-bom:1.10.0")

So how are you connecting to the wallet? with SignClient.connect() method? As I'm trying in my code in the original question? Or using the Web3Modal? or which one?

Shitikyan commented 1 year ago

For connecting to the wallet we are using SignClient.connect()


            val connectParams =  Sign.Params.Connect(namespaces, null, null, pairing)

            SignClient.connect(connectParams,
                onSuccess = { ->
                    viewModelScope.launch(Dispatchers.Main) {
                        onProposedSequence(pairing!!.uri)
                    }
                },
                onError = { error -> println(error.throwable.message) }
            )

 And for signing process SignClient.request() is used.

            val requestParams = Sign.Params.Request(
                sessionTopic = topic,
                method = "personal_sign",
                params = params,
                chainId = "$parentChain:$chainId"
            )

            SignClient.request(  requestParams, { },  { }   )

            SignClient.getActiveSessionByTopic(topic)?.redirect?.toUri()
                ?.let { deepLinkUri ->  onProposedSequence(deepLinkUri) }
idelburgo-iomob commented 1 year ago

@Shitikyan I have been checking again and again, and I'm doing almost the same, instead of using the onproposedSequence I'm setting the uri into a viewmodel var (livedata) and opening the link. But still happening the same. Would be great if you could check my code (posted in the original question) very fast and see if you can point out my error, because apparently I have it as you and the example.

jakubuid commented 1 year ago

For the successful deep linking connection please follow this guide: https://docs.walletconnect.com/2.0/android/guides/mobile-linking Where you can find Dapp and Wallet sections

Dapp must send a correct uri deep link schema (described in docs) and wallet must register correct intent filter with correct schema to be able to receive a deep link from dapp

Shitikyan commented 1 year ago

@jakubuid Is there a working version example? What I am using I took from Example

jakubuid commented 1 year ago

Yes, run our example dapp and wallet:

idelburgo-iomob commented 1 year ago

I read all the documentation and the example. Managed to test in some other devices, and my implementation is working with Trustwallet (it was correct, found something is happening with my test device). But still wallets not being able to process the requests.

I have found that there is an issue with the model Im using to test: Xiaomi Mi 10 T Lite (Android 12), tested with 3 other devices and its working.

@jakubuid Is it still on the calendar that everyone using v1 will stop working? There are a lot of wallets that haven't migrated or that the migration does not work properly (as you said you were working with them). TrustWallet is the only one I have managed to fully do what I need.

idelburgo-iomob commented 1 year ago

Yes, run our example dapp and wallet:

Tried to run the example, but after changing the projectId to mine, can't run because the app does not have the google-services.json file. Do you have any Readme about how to make it work?

jakubuid commented 1 year ago

I see, please use those distribution links to get apps:

idelburgo-iomob commented 1 year ago

I see, please use those distribution links to get apps:

Im sorry to say, with that app its happening the same as with my code referenced here: https://github.com/WalletConnect/WalletConnectKotlinV2/issues/899#issuecomment-1564063682

TrustWallet is working on other devices (as I said before something to happen with my test device), so Im having the same issues pointed in that comment except for Trustwallet that is working now.

I have no problem about this, just pending work to do, but my inquiries are about v1 sunset and what is happening with the wallets, because our users will have no option to work with. So, how can we solve the issue of v1 sunset without wallets working?

jakubuid commented 1 year ago

@idelburgo-iomob are you referring only to deep linking flow? Can you share your dapp where I can scan a QR code and test the connection with those wallets?

Regarding deep linking flow on native dapp - Trust works well which is already a huge user base - we work with BitKeep to improve it as well - deep linking flow on mobile browsers and a scanning qr code flow are also fine - so users should be able to connect to your dapp

idelburgo-iomob commented 1 year ago

@jakubuid I am using deep linking flow, as I have native app only, the QR is not a good option for me, because the user cant scan a QR with the device if the device is needed to read the QR. (The app is showing the QR and needs the same device to scan it)

bujoralexandru commented 1 year ago

Yes, run our example dapp and wallet:

Thank you for providing this example! This works with Trust Wallet, but does not work with the latest version of Metamask Android App. The Metamask wallet is one of the more popular wallets across our user base. Any help towards fixing this issue will be greatly appreciated.

jakubuid commented 1 year ago

@bujoralexandru Android MM is in the release process that supports WalletConnect v2 - we verified that the upcoming release works correctly- we had access to internal builds - the rollout of MM on Android is pretty slow but it's going on

bujoralexandru commented 1 year ago

@jakubuid Thank you so much for the fast response! So, I guess, testing with TrustWallet on Android should behave 1-on-1 like Metamask (after they release the correct version)?

I feel like it is a bit unsafe to sunset v1, while a major player in the crypto wallet market still hasn't got v2 right.

jakubuid commented 1 year ago

MM should reached 100% rollout by now - so it should be available for you as well - and yes the experience is the same

bujoralexandru commented 1 year ago

Thank you, @jakubuid - just to crosscheck, latest release on Android is May 24th, 2023, version 7.0.1?

idelburgo-iomob commented 1 year ago

@jakubuid Nice to hear! I tried my example application and the connect is working, but when sending the personal_sign it is opening Metamask and not appearing the modal to accept the signing. (This flow I have is working as it is for TrustWallet)

I also tried the app you sent me (WC Dapp) and its crashing when returning from accepting the connection to MetaMask :( Do you have any newer app in which you can do the process? Maybe this one is outdated?

idelburgo-iomob commented 1 year ago

Just to add more info: when sending the personal_sign (working in TrustWallet) it is returning instantly to my app to the onError delegate with the following message: Error(throwable=kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 300 ms)

Also giving me the following error on the onSessionRequestResponse: SessionRequestResponse(topic=4abc99af036b30cd5310b58042da3a0bc8225f2f1c22171159d41667e16e57e0, chainId=eip155:42220, method=personal_sign, result=JsonRpcError(id=1687332726651309, code=-32602, message=Invalid params))

Just to add: TrustWallet is also returning the timeout onError, but working the personal_sign.

This is the error happening in the app you shared:

Caused by: java.util.NoSuchElementException: Array contains no element matching the predicate.
at com.walletconnect.sample.dapp.ui.routes.composable_routes.session.SessionViewModel.getSessions(SessionViewModel.kt:1110)
at com.walletconnect.sample.dapp.ui.routes.composable_routes.session.SessionViewModel.getSessions$default(SessionViewModel.kt:44)
at com.walletconnect.sample.dapp.ui.routes.composable_routes.session.SessionViewModel.<init>(SessionViewModel.kt:21)
... 80 more
Raenar4k commented 1 year ago

@jakubuid Can you please give timeline when auth integration will work? Tested it today with latest code for auth.requester and fresh trust wallet, still does not recognize as valid qr code (used deeplink)

jakubuid commented 1 year ago

@idelburgo-iomob Below there's a video showing a working example with Trust - the same result is for MM https://github.com/WalletConnect/WalletConnectKotlinV2/assets/23366251/efbe4576-6d70-40ad-b178-7d1554a46578

I'm not able to reproduce your errors - it seems that sth is wrong in your implementation - I'm happy to help but I need more details.

Caused by: java.util.NoSuchElementException: Array contains no element matching the predicate. - this is sample dapp error - we'll investigate it but it's not related to the protocol itself

@Raenar4k the auth integration works on Trust via scanning QR code - there's indeed some problem on deeplinks, will report it to Trust

idelburgo-iomob commented 1 year ago

@jakubuid yes, as I said, I have no problem with Trust, just with MM. With TrustWallet I can make the same process you are showing. But not with MM.

If my implementation is working smoothly with Trust, shouldn't it be working the same with MM?

Plz, let me know if you solve the crash in the example app so I can test with MM. Is this app working with MM for you?

idelburgo-iomob commented 1 year ago

@jakubuid What you mean about more details? I can share with you whatever you need. I have my example app here in github. Its just a fragment+viewmodel with two buttons to connect and sign when it is connected.

jakubuid commented 1 year ago

As you can see on the video - MM works fine: https://github.com/WalletConnect/WalletConnectKotlinV2/assets/23366251/0e9b964b-84a3-4bf4-9f98-81ab9fa37a33

Plz, let me know if you solve the crash in the example app so I can test with MM. Is this app working with MM for you? - please for now clear app's storage it should help

Can you share please your repo then? I'll have a look

idelburgo-iomob commented 1 year ago

After a fresh Install of your example Dapp and Metamask. It has worked!

But my app is giving the same error of Invalid params.

My code is in: https://github.com/idelburgo-iomob/walletConnectIntegrationExample it just connects with Celo right now. if you want to change the chain just set it in MainViewModel:146 @jakubuid

Let me know if you see something wrong. If you manage to know would be great as it is the only problem I have to finish the migration to v2.

Raenar4k commented 1 year ago

the auth integration works on Trust via scanning QR code - there's indeed some problem on deeplinks, will report it to Trust

@jakubuid QR code scanning does not work for me either. This is fresh version from play store + fresh code from wallet connect repo:

https://github.com/WalletConnect/WalletConnectKotlinV2/assets/13849790/f368c7cb-f799-49b2-b42d-f9d656739c63

Raenar4k commented 1 year ago

@jakubuid is there a wallet that support auth.requester demo at this moment? Spot replies that QR code is not valid both on scan and deeplink, MM just does nothing.

Raenar4k commented 1 year ago

@jakubuid

Below there's a video showing a working example with Trust - the same result is for MM

Can confirm that samples.dapp is working for Spot and Trust wallet, both QR and deeplink! Nice. :) (Auth.requester does not sadly - still Not a WalletConnect valid QR code)

idelburgo-iomob commented 1 year ago

@jakubuid Thx for your time and patience, managed to find my error.

When sending the parameters to the "personal_sign" method TrustWallet is accepting the account as: "eip155:1:" whereas Metamask is only accepting the account without the "eip155:1" part. It is clear in the documentation but I didnt manage to see it as it was working

idelburgo-iomob commented 1 year ago

The only problem I have is TrustWallet not working in some devices, at least in my test one, but works on the rest. So I assume is a problem with my specific model