From c988d002b6ddc572dd6ef0cffe98c7a9d26cbd48 Mon Sep 17 00:00:00 2001 From: Oleg Koretsky Date: Mon, 10 Jun 2024 13:30:36 +0300 Subject: [PATCH] AND-37 Increase WalletConnect pairing timeout (#71) * Update WalletConnect to 1.32.0 and 2.32.0 The update brings 60s timeout on pairing, which is much better than previously used 2s. * Downgrade WalletConnect to 1.13.0+2.11.0 Further updates require regression testing. Update to 1.32.0+2.32.0 requires fixing opening links from a mobile browser and request spam prevention. * Set WalletConnect network timeout to 40 sec * Update version to 1.1.0-qa.1 * Actualize the changelog * Extend dApp connection failure message --- CHANGELOG.md | 5 ++ app/build.gradle | 16 ++++--- .../main/java/com/concordium/wallet/App.kt | 19 ++++++-- .../wallet/core/arch/BackendEventObserver.kt | 46 ------------------- .../wallet/core/arch/BackendObserver.kt | 46 ------------------- .../wallet/core/arch/EventObserver.kt | 12 ++--- .../recipientlist/RecipientListViewModel.kt | 8 +++- .../ui/walletconnect/WalletConnectView.kt | 10 +++- .../walletconnect/WalletConnectViewModel.kt | 9 ++-- app/src/main/res/values/strings.xml | 2 +- 10 files changed, 53 insertions(+), 120 deletions(-) delete mode 100644 app/src/main/java/com/concordium/wallet/core/arch/BackendEventObserver.kt delete mode 100644 app/src/main/java/com/concordium/wallet/core/arch/BackendObserver.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0610d6aa..0ac8989a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Unreleased] + +### Changed +- Increased WalletConnect pairing timeout to reduce the number of "Could not connect" errors + ## [1.1.0] - 2024-06-07 ### Removed diff --git a/app/build.gradle b/app/build.gradle index 2e4a6df9..8846377d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,9 +22,9 @@ android { // https://semver.org/ def versionMajor = 1 def versionMinor = 1 - def versionPatch = 0 - def versionMeta = "" - def versionCodeIncremental = 1381 + def versionPatch = 1 + def versionMeta = "-qa.1" + def versionCodeIncremental = 1382 compileSdkVersion 34 @@ -187,6 +187,7 @@ android { excludes += ['META-INF/DEPENDENCIES'] excludes += ['META-INF/LICENSE.md'] excludes += ['META-INF/NOTICE.md'] + excludes += ['META-INF/versions/**'] } } buildFeatures { @@ -318,9 +319,12 @@ dependencies { // Generate QR implementation 'com.journeyapps:zxing-android-embedded:4.1.0' - // WalletConnect - implementation "com.walletconnect:android-core:1.5.0" - implementation "com.walletconnect:sign:2.3.0" + // WalletConnect. + // Further updates require regression testing. + // Update to 1.32.0+2.32.0 requires fixing + // opening links from a mobile browser and request spam prevention. + implementation "com.walletconnect:android-core:1.13.0" + implementation "com.walletconnect:sign:2.11.0" // Scarlet Gson adapter required for Spaceseven wallet connection. implementation("com.tinder.scarlet:message-adapter-gson:0.1.12") { diff --git a/app/src/main/java/com/concordium/wallet/App.kt b/app/src/main/java/com/concordium/wallet/App.kt index 001a74ce..a70a3179 100644 --- a/app/src/main/java/com/concordium/wallet/App.kt +++ b/app/src/main/java/com/concordium/wallet/App.kt @@ -9,8 +9,10 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics import com.walletconnect.android.Core import com.walletconnect.android.CoreClient import com.walletconnect.android.relay.ConnectionType +import com.walletconnect.android.relay.NetworkClientTimeout import com.walletconnect.sign.client.Sign import com.walletconnect.sign.client.SignClient +import java.util.concurrent.TimeUnit class App : Application() { @@ -42,7 +44,7 @@ class App : Application() { } private fun initWalletConnect() { - println("LC -> CALL INIT") + println("WalletConnect -> CALL INIT") // Account - oleg.koretsky, project – CryptoX Android val projectId = "f6dea1cab6223d05f64c0c418527368b" @@ -58,13 +60,20 @@ class App : Application() { CoreClient.initialize( relayServerUrl = relayServerUrl, connectionType = ConnectionType.AUTOMATIC, + networkClientTimeout = NetworkClientTimeout(40, TimeUnit.SECONDS), application = this, - metaData = appMetaData + metaData = appMetaData, + onError = { error -> + println("WalletConnect -> CORE ERROR ${error.throwable.stackTraceToString()}") + } ) - SignClient.initialize(Sign.Params.Init(core = CoreClient)) { modelError -> - println("LC -> INIT ERROR ${modelError.throwable.stackTraceToString()}") - } + SignClient.initialize( + init = Sign.Params.Init(core = CoreClient), + onError = { error -> + println("WalletConnect -> SIGN ERROR ${error.throwable.stackTraceToString()}") + } + ) } private fun initFirebase() { diff --git a/app/src/main/java/com/concordium/wallet/core/arch/BackendEventObserver.kt b/app/src/main/java/com/concordium/wallet/core/arch/BackendEventObserver.kt deleted file mode 100644 index 1acf2443..00000000 --- a/app/src/main/java/com/concordium/wallet/core/arch/BackendEventObserver.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.concordium.wallet.core.arch - -import androidx.lifecycle.Observer -import com.concordium.wallet.core.backend.BackendEventResource - -/** - * This class has the responsibility to return more specific callbacks for a BackendEventResource. - * It is used instead of an Observer when calling observe on a LiveData object. - * As it operates on an event resource it only results in a callback, if the event has not already been handled. - * @param - */ - -open class BackendEventObserver : Observer> { - - override fun onChanged(backendResource: BackendEventResource?) { - onDone() - if (backendResource != null) { - if (backendResource.handleIfNotHandled()) { - val exception = backendResource.exception - if (exception != null) { - onException(exception) - } else { - val data = backendResource.data - if (data != null) { - onSuccess(data) - } - } - } - return - } - // custom exception - onException(Exception("No backend resource set")) - } - - @Suppress("UNUSED_PARAMETER") - open fun onDone() { - } - - @Suppress("UNUSED_PARAMETER") - open fun onSuccess(data: T) { - } - - @Suppress("UNUSED_PARAMETER") - open fun onException(e: Exception) { - } -} \ No newline at end of file diff --git a/app/src/main/java/com/concordium/wallet/core/arch/BackendObserver.kt b/app/src/main/java/com/concordium/wallet/core/arch/BackendObserver.kt deleted file mode 100644 index 9624ff06..00000000 --- a/app/src/main/java/com/concordium/wallet/core/arch/BackendObserver.kt +++ /dev/null @@ -1,46 +0,0 @@ -package com.concordium.wallet.core.arch - -import androidx.lifecycle.Observer -import com.concordium.wallet.core.backend.BackendResource - -/** - * This class has the responsibility to return more specific callbacks for a BackendEventResource. - * It is used instead of an Observer when calling observe on a LiveData object. - * @param - */ - -class BackendObserver : Observer> { - - override fun onChanged(backendResource: BackendResource?) { - onDone() - if (backendResource != null) { - val exception = backendResource.exception - if (exception != null) { - onException(exception) - } else { - val data = backendResource.data - if (data != null) { - onSuccess(data) - } - } - return - } - // custom exception - onException(Exception("No backend resource set")) - } - - fun onDone() { - } - - @Suppress("UNUSED_PARAMETER") - fun onSuccess(data: T) { - } - - @Suppress("UNUSED_PARAMETER") - fun onError(error: Error) { - } - - @Suppress("UNUSED_PARAMETER") - fun onException(e: Exception) { - } -} \ No newline at end of file diff --git a/app/src/main/java/com/concordium/wallet/core/arch/EventObserver.kt b/app/src/main/java/com/concordium/wallet/core/arch/EventObserver.kt index 04434aab..b9efc350 100644 --- a/app/src/main/java/com/concordium/wallet/core/arch/EventObserver.kt +++ b/app/src/main/java/com/concordium/wallet/core/arch/EventObserver.kt @@ -10,16 +10,14 @@ import androidx.lifecycle.Observer open class EventObserver : Observer> { - override fun onChanged(event: Event?) { - if (event != null) { - val value = event.contentIfNotHandled - if (value != null) { - onUnhandledEvent(value) - } + override fun onChanged(value: Event) { + val notHandledValue = value.contentIfNotHandled + if (notHandledValue != null) { + onUnhandledEvent(notHandledValue) } } @Suppress("UNUSED_PARAMETER") open fun onUnhandledEvent(value: T) { } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/concordium/wallet/ui/recipient/recipientlist/RecipientListViewModel.kt b/app/src/main/java/com/concordium/wallet/ui/recipient/recipientlist/RecipientListViewModel.kt index cc03cad8..6d2d997b 100644 --- a/app/src/main/java/com/concordium/wallet/ui/recipient/recipientlist/RecipientListViewModel.kt +++ b/app/src/main/java/com/concordium/wallet/ui/recipient/recipientlist/RecipientListViewModel.kt @@ -1,7 +1,11 @@ package com.concordium.wallet.ui.recipient.recipientlist import android.app.Application -import androidx.lifecycle.* +import androidx.lifecycle.AndroidViewModel +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.switchMap +import androidx.lifecycle.viewModelScope import com.concordium.wallet.data.RecipientRepository import com.concordium.wallet.data.room.Account import com.concordium.wallet.data.room.Recipient @@ -19,7 +23,7 @@ class RecipientListViewModel(application: Application) : AndroidViewModel(applic private val allRecipientsLiveData: LiveData> val recipientListLiveData: LiveData> - get() = Transformations.switchMap(allRecipientsLiveData) { allRecipients -> + get() = allRecipientsLiveData.switchMap { allRecipients -> val filteredRecipientsLiveData = MutableLiveData>() val recipientsToShowLiveData = when { selectRecipientMode -> { diff --git a/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectView.kt b/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectView.kt index 524eaf03..c108b49c 100644 --- a/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectView.kt +++ b/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectView.kt @@ -200,7 +200,15 @@ class WalletConnectView( R.string.wallet_connect_error_not_seed_phrase_wallet } - Toast.makeText(activity, errorRes, Toast.LENGTH_SHORT).show() + val duration = when (event.error) { + WalletConnectViewModel.Error.ConnectionFailed -> + Toast.LENGTH_LONG + + else -> + Toast.LENGTH_SHORT + } + + Toast.makeText(activity, errorRes, duration).show() } is WalletConnectViewModel.Event.ShowDetailsDialog -> { diff --git a/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectViewModel.kt b/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectViewModel.kt index 2b8b7a98..83c9479a 100644 --- a/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectViewModel.kt +++ b/app/src/main/java/com/concordium/wallet/ui/walletconnect/WalletConnectViewModel.kt @@ -324,17 +324,15 @@ private constructor( mutableStateFlow.tryEmit(State.WaitingForSessionRequest) } - override fun onSessionProposal( - sessionProposal: Sign.Model.SessionProposal, - ) = viewModelScope.launch { + override fun onSessionProposal(sessionProposal: Sign.Model.SessionProposal) = viewModelScope.launch { defaultWalletDelegate.onSessionProposal(sessionProposal) // Find a single allowed namespace and chain. val singleNamespaceEntry = sessionProposal.requiredNamespaces.entries.find { (_, namespace) -> - namespace.chains.any { chain -> + namespace.chains?.any { chain -> allowedChains.contains(chain) - } + } == true } val singleNamespaceChain = singleNamespaceEntry?.value?.chains?.find { chain -> allowedChains.contains(chain) @@ -432,7 +430,6 @@ private constructor( accounts = listOf("$sessionProposalNamespaceChain:$accountAddress"), methods = sessionProposalNamespace.methods, events = sessionProposalNamespace.events, - extensions = null, ) ), ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4555d6d6..5f2b49de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -437,7 +437,7 @@ Database cleared Okay Cancel - Could not connect to dApp + dApp connection failed. Please, refresh the page and try again The WalletConnect request is invalid Unexpected cryptography error Could not load the required data