Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error(throwable=com.walletconnect.android.internal.common.exception.NoRelayConnectionException: No connection available) #478

Closed
devarogundade opened this issue Nov 8, 2022 · 12 comments
Labels
bug Something isn't working

Comments

@devarogundade
Copy link

Describe the bug
Error(throwable=com.walletconnect.android.internal.common.exception.NoRelayConnectionException: No connection available)

SDK Version

  • Client: Kotlin
  • Version 2.1.0

To Reproduce

In the Application class

override fun onCreate() {
super.onCreate()

    val projectId = "xxx"
    val relayUrl = "relay.walletconnect.com"
    val serverUrl = "wss://$relayUrl?projectId=$projectId"
    val connectionType = ConnectionType.AUTOMATIC
    val appMetaData = Core.Model.AppMetaData(
        name = "Buidl Player",
        description = "Watch buidl videos with this app",
        url = "xxx",
        icons = listOf("xxx"),
        redirect = "kotlin-dapp-wc:/request"
    )

    CoreClient.initialize(
        relayServerUrl = serverUrl,
        connectionType = connectionType,
        application = this,
        metaData = appMetaData
    )

    val init = Sign.Params.Init(CoreClient)
    SignClient.initialize(init) { error -> Log.d("Application", "onCreate: $error") }
}

In a fragment

private fun connectToWallet() {
    val dappDelegate = object : SignClient.DappDelegate {
        override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) {
            // Triggered when Dapp receives the session approval from wallet
            Log.d("TAG", "onSessionApproved: $approvedSession")
        }

        override fun onSessionRejected(rejectedSession: Sign.Model.RejectedSession) {
            // Triggered when Dapp receives the session rejection from wallet
            Log.d("TAG", "onSessionRejected: $rejectedSession")
        }

        override fun onSessionUpdate(updatedSession: Sign.Model.UpdatedSession) = Unit
        override fun onSessionExtend(session: Sign.Model.Session) = Unit
        override fun onSessionEvent(sessionEvent: Sign.Model.SessionEvent) = Unit
        override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) = Unit
        override fun onSessionRequestResponse(response: Sign.Model.SessionRequestResponse) =
            Unit

        override fun onConnectionStateChange(state: Sign.Model.ConnectionState) = Unit

        override fun onError(error: Sign.Model.Error) {
            Log.d("TAG", "onError: $error")
        }
    }

    SignClient.setDappDelegate(dappDelegate)

    val namespace = "eip155"
    val chains = listOf("eip155:1")
    val methods = listOf(
        "eth_sendTransaction",
        "personal_sign",
        "eth_sign",
        "eth_signTypedData"
    )
    val events = listOf("chainChanged", "accountChanged")
    val namespaces =
        mapOf(namespace to Sign.Model.Namespace.Proposal(chains, methods, events, null))
    val pairing = CoreClient.Pairing.create() ?: return
    val connectParams = Sign.Params.Connect(namespaces, pairing)

    SignClient.connect(connectParams, onSuccess = {
        Log.d("TAG", "connectToWallet: success")
    }, onError = { error ->
        Log.d("TAG", "connectToWallet: $error")
    })
}
@devarogundade devarogundade added the bug Something isn't working label Nov 8, 2022
@KayCm
Copy link

KayCm commented Nov 9, 2022

same issues.
and when connect To Wallet with deeplink,ConnectionStateChange the isAvailable be false.

@jakubuid
Copy link
Contributor

jakubuid commented Nov 9, 2022

Hey @KayCm and @devarogundade, what version of android-core are you using?

@devarogundade
Copy link
Author

Version 1.3.0

@KayCm
Copy link

KayCm commented Nov 10, 2022

Hey @KayCm and @devarogundade, what version of android-core are you using?

implementation("com.walletconnect:auth:1.1.0")
implementation("com.walletconnect:android-core:1.3.0")
implementation("com.walletconnect:sign:2.1.0")

all the newest

@jakubuid
Copy link
Contributor

I cannot reproduce your issue.

Could you please provide the exact user flow steps that you did before getting this error?

Also, please make sure that your app has either a WiFi or cellular Internet connection.

@devarogundade
Copy link
Author

Ok on it

@devarogundade
Copy link
Author

    implementation("com.walletconnect:android-core:1.3.0")
    implementation("com.walletconnect:sign:2.1.0")

@HiltAndroidApp
class BuidlApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        val projectId = "f665.............6a5c"
        val relayUrl = "relay.walletconnect.com"
        val serverUrl = "wss://$relayUrl?projectId=$projectId"
        val connectionType = ConnectionType.AUTOMATIC
        
        val appMetaData = Core.Model.AppMetaData(
            name = "Buidl Player",
            description = "Watch buidl videos with this app",
            url = "https://buidl.netlify.app",
            icons = listOf("https://buidl.netlify.app/logo.png"),
            redirect = "kotlin-dapp-wc:/request"
        )

        CoreClient.initialize(
            relayServerUrl = serverUrl,
            connectionType = connectionType,
            application = this,
            metaData = appMetaData
        )

        val init = Sign.Params.Init(CoreClient)
        SignClient.initialize(init) { error -> Log.d("Application", "onCreate: $error") }
    }

}

package ng.farma.buidlplayer.ui

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.walletconnect.android.CoreClient
import com.walletconnect.sign.client.Sign
import com.walletconnect.sign.client.SignClient
import ng.farma.buidlplayer.databinding.FragmentConnectWalletBinding

class ConnectWalletFragment : Fragment() {

    private lateinit var binding: FragmentConnectWalletBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentConnectWalletBinding.inflate(inflater)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.connectWallet.setOnClickListener { connectToWallet() }
    }

    private fun connectToWallet() {
        SignClient.setDappDelegate(object : SignClient.DappDelegate {
            override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) {
                // Triggered when Dapp receives the session approval from wallet
                Log.d("TAG", "onSessionApproved: $approvedSession")
            }

            override fun onSessionRejected(rejectedSession: Sign.Model.RejectedSession) {
                // Triggered when Dapp receives the session rejection from wallet
                Log.d("TAG", "onSessionRejected: $rejectedSession")
            }

            override fun onSessionUpdate(updatedSession: Sign.Model.UpdatedSession) = Unit
            override fun onSessionExtend(session: Sign.Model.Session) = Unit
            override fun onSessionEvent(sessionEvent: Sign.Model.SessionEvent) = Unit
            override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) = Unit
            override fun onSessionRequestResponse(response: Sign.Model.SessionRequestResponse) =
                Unit

            override fun onConnectionStateChange(state: Sign.Model.ConnectionState) = Unit

            override fun onError(error: Sign.Model.Error) {
                Log.d("TAG", "onError: $error")
            }
        })

        val namespace = "eip155"
        val chains = listOf("eip155:1")
        val methods = listOf(
            "eth_sendTransaction",
            "personal_sign",
            "eth_sign",
            "eth_signTypedData"
        )
        val events = listOf("chainChanged", "accountChanged")
        val namespaces =
            mapOf(namespace to Sign.Model.Namespace.Proposal(chains, methods, events, null))
        val pairing = CoreClient.Pairing.create() ?: return
        val connectParams = Sign.Params.Connect(namespaces, pairing)

        SignClient.connect(connectParams, onSuccess = {
            Log.d("TAG", "connectToWallet: success $connectParams")
        }, onError = { error ->
            Log.d("TAG", "connectToWallet: $error")
        })
    }

    private fun login(address: String) {
        val destination =
            ConnectWalletFragmentDirections.actionConnectWalletFragmentToVideoListFragment(address)
        findNavController().navigate(destination)
    }

}

D/TAG: connectToWallet: success Connect(namespaces={eip155=Proposal(chains=[eip155:1], methods=[eth_sendTransaction, personal_sign, eth_sign, eth_signTypedData], events=[chainChanged, accountChanged], extensions=null)}, pairing=Pairing(topic=6c2492e30a13a32379a73ed9efa48bf2386f4c8826c6f3edf4d136d921687bc0, expiry=1668081152, peerAppMetaData=null, relayProtocol=irn, relayData=null, uri=wc:6c2492e30a13a32379a73ed9efa48bf2386f4c8826c6f3edf4d136d921687bc0@2?relay-protocol=irn&symKey=eb163fe4003768b216ccbd70d5d140215ceb9d2134752ad7513bba0d48769084, isActive=false, registeredMethods=wc_sessionPropose,wc_sessionSettle,wc_sessionRequest,wc_sessionEvent,wc_sessionDelete,wc_sessionExtend,wc_sessionPing,wc_sessionUpdate))

That's all the place is I have used the SDK,
When I click on the connect wallet before is was
"Error(throwable=com.walletconnect.android.internal.common.exception.NoRelayConnectionException: No connection available"
but now its the log message above and no wallet connection is initialted

@jakubuid
Copy link
Contributor

When the onSuccess callback is triggered from the connect method, it means that the session proposal was being sent successfully to the wallet.

As I can see, you print your connectParams inside the onSuccess callback.

Now you should share with your wallet a pairing.uri as a QR code or deeplink and call the pair method on the wallet side.

@KayCm
Copy link

KayCm commented Nov 11, 2022

in official demo
when i use the deeplink open the wallet(tokenpocket)
the log will show this.
D/WalletConnectV2: OnConnectionClosing(shutdownReason=ShutdownReason(code=1000, reason=))
D/WalletConnectV2: OnConnectionClosed(shutdownReason=ShutdownReason(code=1000, reason=))

@jakubuid
Copy link
Contributor

Automatic connection mode works in the way that the connection is closed when the wallet hits the background and and is open again when the wallet if foregrounded.
@KayCm
What's the problem that you're trying to solve?

@KayCm
Copy link

KayCm commented Nov 16, 2022

i think maybe the tokenpocket not support the v2. when i use the v1 it`s work well.
thanks for reply.

@NilayTheAndroidGuy
Copy link

@devarogundade I am also getting "com.walletconnect.android.internal.common.exception.NoRelayConnectionException: No connection available". How did you overcome this to success?

p.s.: I have a very similar code implementation to you. Let me know if you changed anything from your above-mentioned code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants