MetaMask / metamask-mobile

Mobile web browser providing access to websites that use the Ethereum blockchain
https://metamask.io
Other
2.16k stars 1.12k forks source link

Since Version 6.5.0 Kotlin native app WalletConnect v1 deeplinks can't be handled by Metamask #6469

Closed idelburgo-iomob closed 1 year ago

idelburgo-iomob commented 1 year ago

Describe the bug Prior to this versions I have an implementation of WalletConnect v1 working smoothly with Metamask that allowed to connect the wallet to my app, and then sign a message with the wallet. All this using WalletConnect v1, using the deeplinks provided by it.

Screenshots If applicable, add screenshots or links to help explain your problem

To Reproduce Through my app

  1. Generate a connection with WalletConnect v1 SDK
  2. With the Uri provided by the SDK launch an Intent to open it.
  3. MetaMask opens but can't handle the deeplink.

Different attempts were done:

Expected behavior MetaMask should open the modal to accept the connection and then with the next deeplink (to sign a message) open a new modal with the Signing Request. All this was already working with my implementation before.

Smartphone (please complete the following information):

Code used

Add this to the Application class:

companion object {
        private lateinit var client: OkHttpClient
        private lateinit var moshi: Moshi
        private lateinit var storage: WCSessionStore
        private lateinit var bridge: BridgeServer
        lateinit var config: Session.Config
        lateinit var session: Session

        private const val bridgeUrl = "https://bridge.walletconnect.org"
        private val metaData = Session.PeerMeta(
            name = "<Name>",
            url = "<URL>",
            description = "WalletConnect Integration",
            icons = listOf("https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/master/Icon/Gradient/Icon.png")
        )

        fun resetSession() {
            nullOnThrow { session }?.clearCallbacks()
            val key = ByteArray(32).also { Random().nextBytes(it) }.toNoPrefixHexString()
            config = Session.Config(UUID.randomUUID().toString(), bridgeUrl, key)
            session = WCSession(
                config,
                MoshiPayloadAdapter(moshi),
                storage,
                OkHttpTransport.Builder(client, moshi),
                metaData
            )
            session.offer()
        }
    }

and initialize the variables in the Application onCreate:

//  for v1
        moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
        client = OkHttpClient.Builder().build()
        storage = FileWCSessionStore(File(cacheDir, "session_store.json").apply { createNewFile() }, moshi)
        bridge = BridgeServer(moshi)
        bridge.start()

After this, wherever you need to get the link use:

WalletIntegrationExample.resetSession()
        WalletIntegrationExample.session.addCallback(this)
        var deep = WalletIntegrationExample.config.toWCUri()
        println("WALLET_CONN -> V1 LINK: $deep")
//        _connectionUri.value = "metamask://wc?uri=${WalletIntegrationExample.config.toWCUri()}"
//        _connectionUri.value = "wc://wc?uri=${deep}"
        _connectionUri.value = deep

connectionUri is a LiveData that triggers the opening of the Link, allowing to select the wallet in the last two cases, whereas case 1 opens metamask directly.


to be added after bug submission by internal support / PM Severity

anaamolnar commented 1 year ago

Hello, @idelburgo-iomob. Thanks for reporting! I will pass this on to the team.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 7 days. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 7 days with no activity. If you feel this was closed in error please reopen and provide evidence on the current production app. Thank you for your contributions.