From 681161c832d35c416cd334fa7486eb1d50fc7728 Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 18 Jun 2024 11:22:40 +0200 Subject: [PATCH 1/7] Add connection restart --- .../com/walletconnect/android/CoreProtocol.kt | 5 +- .../connection/ManualConnectionLifecycle.kt | 29 ++-- .../internal/common/di/AndroidCommonDITags.kt | 4 +- .../internal/common/di/CoreNetworkModule.kt | 32 ++-- .../android/relay/RelayClient.kt | 147 ++++++++++-------- .../android/relay/RelayConnectionInterface.kt | 2 + .../walletconnect/android/utils/Extensions.kt | 8 - .../android/internal/RelayClientTests.kt | 6 +- .../foundation/di/FoundationNetworkModule.kt | 6 - .../foundation/network/BaseRelayClient.kt | 129 +++++++-------- .../network/data/ConnectionController.kt | 25 --- .../network/data/ConnectionEvent.kt | 5 - .../sample/wallet/Web3WalletApplication.kt | 6 +- .../ConnectionDetailsRoute.kt | 18 ++- 14 files changed, 202 insertions(+), 220 deletions(-) delete mode 100644 foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionController.kt delete mode 100644 foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionEvent.kt diff --git a/core/android/src/main/kotlin/com/walletconnect/android/CoreProtocol.kt b/core/android/src/main/kotlin/com/walletconnect/android/CoreProtocol.kt index 2b507ffe1e..dbea781cab 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/CoreProtocol.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/CoreProtocol.kt @@ -33,7 +33,6 @@ import com.walletconnect.android.relay.RelayConnectionInterface import com.walletconnect.android.utils.isValidRelayServerUrl import com.walletconnect.android.utils.plantTimber import com.walletconnect.android.utils.projectId -import com.walletconnect.android.utils.toCommonConnectionType import com.walletconnect.android.verify.client.VerifyClient import com.walletconnect.android.verify.client.VerifyInterface import org.koin.android.ext.koin.androidContext @@ -83,13 +82,13 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter modules( module { single { ProjectId(relayServerUrl.projectId()) } }, module { single(named(AndroidCommonDITags.TELEMETRY_ENABLED)) { TelemetryEnabled(telemetryEnabled) } }, - coreAndroidNetworkModule(relayServerUrl, connectionType.toCommonConnectionType(), BuildConfig.SDK_VERSION, networkClientTimeout, bundleId), + coreAndroidNetworkModule(relayServerUrl, connectionType, BuildConfig.SDK_VERSION, networkClientTimeout, bundleId), coreCommonModule(), coreCryptoModule(), ) if (relay == null) { - Relay.initialize { error -> onError(Core.Model.Error(error)) } + Relay.initialize(connectionType) { error -> onError(Core.Model.Error(error)) } } modules( diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/connection/ManualConnectionLifecycle.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/connection/ManualConnectionLifecycle.kt index 4b116ec039..395a04df70 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/connection/ManualConnectionLifecycle.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/connection/ManualConnectionLifecycle.kt @@ -4,27 +4,20 @@ package com.walletconnect.android.internal.common.connection import com.tinder.scarlet.Lifecycle import com.tinder.scarlet.lifecycle.LifecycleRegistry -import com.walletconnect.android.internal.common.scope -import com.walletconnect.foundation.network.data.ConnectionController -import com.walletconnect.foundation.network.data.ConnectionEvent -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach internal class ManualConnectionLifecycle( - connectionController: ConnectionController, - private val lifecycleRegistry: LifecycleRegistry, + private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(), ) : Lifecycle by lifecycleRegistry { + fun connect() { + lifecycleRegistry.onNext(Lifecycle.State.Started) + } + + fun disconnect() { + lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason()) + } - init { - if (connectionController is ConnectionController.Manual) { - connectionController.connectionEventFlow - .onEach { event -> - when (event) { - ConnectionEvent.CONNECT -> lifecycleRegistry.onNext(Lifecycle.State.Started) - ConnectionEvent.DISCONNECT -> lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason()) - } - } - .launchIn(scope) - } + fun restart() { + lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason()) + lifecycleRegistry.onNext(Lifecycle.State.Started) } } \ No newline at end of file diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt index 4a52f2104c..041401257e 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt @@ -10,8 +10,8 @@ enum class AndroidCommonDITags { RELAY_SERVICE, SCARLET, MSG_ADAPTER, - CONNECTION_CONTROLLER, - LIFECYCLE, + MANUAL_CONNECTION_LIFECYCLE, + AUTOMATIC_CONNECTION_LIFECYCLE, LOGGER, CONNECTIVITY_STATE, PUSH_RETROFIT, diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreNetworkModule.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreNetworkModule.kt index 780813993c..62b4e35a4f 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreNetworkModule.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreNetworkModule.kt @@ -4,8 +4,8 @@ import android.net.Uri import android.os.Build import com.pandulapeter.beagle.logOkHttp.BeagleOkHttpLogger import com.squareup.moshi.Moshi +import com.tinder.scarlet.Lifecycle import com.tinder.scarlet.Scarlet -import com.tinder.scarlet.lifecycle.LifecycleRegistry import com.tinder.scarlet.lifecycle.android.AndroidLifecycle import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter import com.tinder.scarlet.retry.LinearBackoffStrategy @@ -16,7 +16,6 @@ import com.walletconnect.android.internal.common.connection.ManualConnectionLife import com.walletconnect.android.internal.common.jwt.clientid.GenerateJwtStoreClientIdUseCase import com.walletconnect.android.relay.ConnectionType import com.walletconnect.android.relay.NetworkClientTimeout -import com.walletconnect.foundation.network.data.ConnectionController import com.walletconnect.foundation.network.data.adapter.FlowStreamAdapter import com.walletconnect.foundation.network.data.service.RelayService import okhttp3.Authenticator @@ -26,6 +25,7 @@ import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import org.koin.android.ext.koin.androidApplication import org.koin.core.qualifier.named +import org.koin.core.scope.Scope import org.koin.dsl.module import java.io.IOException import java.net.SocketTimeoutException @@ -93,6 +93,7 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, request = request.newBuilder().url(newHttpUrl).build() return@Interceptor chain.proceed(request) } + else -> { throw e } @@ -143,20 +144,12 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, single(named(AndroidCommonDITags.MSG_ADAPTER)) { MoshiMessageAdapter.Factory(get(named(AndroidCommonDITags.MOSHI)).build()) } - single(named(AndroidCommonDITags.CONNECTION_CONTROLLER)) { - if (connectionType == ConnectionType.MANUAL) { - ConnectionController.Manual() - } else { - ConnectionController.Automatic - } + single(named(AndroidCommonDITags.MANUAL_CONNECTION_LIFECYCLE)) { + ManualConnectionLifecycle() } - single(named(AndroidCommonDITags.LIFECYCLE)) { - if (connectionType == ConnectionType.MANUAL) { - ManualConnectionLifecycle(get(named(AndroidCommonDITags.CONNECTION_CONTROLLER)), LifecycleRegistry()) - } else { - AndroidLifecycle.ofApplicationForeground(androidApplication()) - } + single(named(AndroidCommonDITags.AUTOMATIC_CONNECTION_LIFECYCLE)) { + AndroidLifecycle.ofApplicationForeground(androidApplication()) } single { LinearBackoffStrategy(TimeUnit.SECONDS.toMillis(DEFAULT_BACKOFF_SECONDS)) } @@ -167,7 +160,7 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, Scarlet.Builder() .backoffStrategy(get()) .webSocketFactory(get(named(AndroidCommonDITags.OK_HTTP)).newWebSocketFactory(get(named(AndroidCommonDITags.RELAY_URL)))) - .lifecycle(get(named(AndroidCommonDITags.LIFECYCLE))) + .lifecycle(getLifecycle(connectionType)) .addMessageAdapterFactory(get(named(AndroidCommonDITags.MSG_ADAPTER))) .addStreamAdapterFactory(get()) .build() @@ -180,4 +173,11 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, single(named(AndroidCommonDITags.CONNECTIVITY_STATE)) { ConnectivityState(androidApplication()) } -} \ No newline at end of file +} + +private fun Scope.getLifecycle(connectionType: ConnectionType) = + if (connectionType == ConnectionType.MANUAL) { + get(named(AndroidCommonDITags.MANUAL_CONNECTION_LIFECYCLE)) + } else { + get(named(AndroidCommonDITags.AUTOMATIC_CONNECTION_LIFECYCLE)) + } \ No newline at end of file diff --git a/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayClient.kt b/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayClient.kt index b752cfcf85..dd39a8e986 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayClient.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayClient.kt @@ -4,13 +4,13 @@ package com.walletconnect.android.relay import com.walletconnect.android.Core import com.walletconnect.android.internal.common.connection.ConnectivityState +import com.walletconnect.android.internal.common.connection.ManualConnectionLifecycle import com.walletconnect.android.internal.common.di.AndroidCommonDITags import com.walletconnect.android.internal.common.exception.WRONG_CONNECTION_TYPE import com.walletconnect.android.internal.common.scope import com.walletconnect.android.internal.common.wcKoinApp import com.walletconnect.android.utils.toWalletConnectException import com.walletconnect.foundation.network.BaseRelayClient -import com.walletconnect.foundation.network.data.ConnectionController import com.walletconnect.foundation.network.model.Relay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -24,80 +24,95 @@ import org.koin.core.KoinApplication import org.koin.core.qualifier.named class RelayClient(private val koinApp: KoinApplication = wcKoinApp) : BaseRelayClient(), RelayConnectionInterface { - private val connectionController: ConnectionController by lazy { koinApp.koin.get(named(AndroidCommonDITags.CONNECTION_CONTROLLER)) } - private val networkState: ConnectivityState by lazy { koinApp.koin.get(named(AndroidCommonDITags.CONNECTIVITY_STATE)) } - override val isNetworkAvailable: StateFlow by lazy { networkState.isAvailable } - private val _wssConnectionState: MutableStateFlow = MutableStateFlow(WSSConnectionState.Disconnected.ConnectionClosed()) - override val wssConnectionState: StateFlow = _wssConnectionState + private val manualConnection: ManualConnectionLifecycle by lazy { koinApp.koin.get(named(AndroidCommonDITags.MANUAL_CONNECTION_LIFECYCLE)) } + private val networkState: ConnectivityState by lazy { koinApp.koin.get(named(AndroidCommonDITags.CONNECTIVITY_STATE)) } + override val isNetworkAvailable: StateFlow by lazy { networkState.isAvailable } + private val _wssConnectionState: MutableStateFlow = MutableStateFlow(WSSConnectionState.Disconnected.ConnectionClosed()) + override val wssConnectionState: StateFlow = _wssConnectionState + private lateinit var connectionType: ConnectionType - @JvmSynthetic - fun initialize(onError: (Throwable) -> Unit) { - logger = koinApp.koin.get(named(AndroidCommonDITags.LOGGER)) - relayService = koinApp.koin.get(named(AndroidCommonDITags.RELAY_SERVICE)) - collectConnectionInitializationErrors { error -> onError(error) } - monitorConnectionState() - observeResults() - } + @JvmSynthetic + fun initialize(connectionType: ConnectionType, onError: (Throwable) -> Unit) { + this.connectionType = connectionType + logger = koinApp.koin.get(named(AndroidCommonDITags.LOGGER)) + relayService = koinApp.koin.get(named(AndroidCommonDITags.RELAY_SERVICE)) + collectConnectionInitializationErrors { error -> onError(error) } + monitorConnectionState() + observeResults() + } - private fun collectConnectionInitializationErrors(onError: (Throwable) -> Unit) { - scope.launch { - supervisorScope { - eventsFlow - .takeWhile { event -> - if (event is Relay.Model.Event.OnConnectionFailed) { - onError(event.throwable.toWalletConnectException) - } + private fun collectConnectionInitializationErrors(onError: (Throwable) -> Unit) { + scope.launch { + supervisorScope { + eventsFlow + .takeWhile { event -> + if (event is Relay.Model.Event.OnConnectionFailed) { + onError(event.throwable.toWalletConnectException) + } - event !is Relay.Model.Event.OnConnectionOpened<*> - }.collect() - } - } - } + event !is Relay.Model.Event.OnConnectionOpened<*> + }.collect() + } + } + } - private fun monitorConnectionState() { - eventsFlow - .onEach { event: Relay.Model.Event -> setIsWSSConnectionOpened(event) } - .launchIn(scope) - } + private fun monitorConnectionState() { + eventsFlow + .onEach { event: Relay.Model.Event -> setIsWSSConnectionOpened(event) } + .launchIn(scope) + } - private fun setIsWSSConnectionOpened(event: Relay.Model.Event) { - when { - event is Relay.Model.Event.OnConnectionOpened<*> && _wssConnectionState.value is WSSConnectionState.Disconnected -> - _wssConnectionState.value = WSSConnectionState.Connected + private fun setIsWSSConnectionOpened(event: Relay.Model.Event) { + when { + event is Relay.Model.Event.OnConnectionOpened<*> && _wssConnectionState.value is WSSConnectionState.Disconnected -> + _wssConnectionState.value = WSSConnectionState.Connected - event is Relay.Model.Event.OnConnectionFailed && _wssConnectionState.value is WSSConnectionState.Connected -> - _wssConnectionState.value = WSSConnectionState.Disconnected.ConnectionFailed(event.throwable) + event is Relay.Model.Event.OnConnectionFailed && _wssConnectionState.value is WSSConnectionState.Connected -> + _wssConnectionState.value = WSSConnectionState.Disconnected.ConnectionFailed(event.throwable) - event is Relay.Model.Event.OnConnectionClosed && _wssConnectionState.value is WSSConnectionState.Connected -> - _wssConnectionState.value = WSSConnectionState.Disconnected.ConnectionClosed("Connection closed: ${event.shutdownReason.reason} ${event.shutdownReason.code}") - } - } + event is Relay.Model.Event.OnConnectionClosed && _wssConnectionState.value is WSSConnectionState.Connected -> + _wssConnectionState.value = WSSConnectionState.Disconnected.ConnectionClosed("Connection closed: ${event.shutdownReason.reason} ${event.shutdownReason.code}") + } + } - override fun connect(onErrorModel: (Core.Model.Error) -> Unit, onError: (String) -> Unit) { - when (connectionController) { - is ConnectionController.Automatic -> onError(WRONG_CONNECTION_TYPE) - is ConnectionController.Manual -> (connectionController as ConnectionController.Manual).connect() - } - } + override fun connect(onError: (Core.Model.Error) -> Unit) { + when (connectionType) { + ConnectionType.AUTOMATIC -> onError(Core.Model.Error(IllegalStateException(WRONG_CONNECTION_TYPE))) + ConnectionType.MANUAL -> manualConnection.connect() + } + } - override fun connect(onError: (Core.Model.Error) -> Unit) { - when (connectionController) { - is ConnectionController.Automatic -> onError(Core.Model.Error(IllegalStateException(WRONG_CONNECTION_TYPE))) - is ConnectionController.Manual -> (connectionController as ConnectionController.Manual).connect() - } - } + override fun disconnect(onError: (Core.Model.Error) -> Unit) { + when (connectionType) { + ConnectionType.AUTOMATIC -> onError(Core.Model.Error(IllegalStateException(WRONG_CONNECTION_TYPE))) + ConnectionType.MANUAL -> manualConnection.disconnect() + } + } - override fun disconnect(onErrorModel: (Core.Model.Error) -> Unit, onError: (String) -> Unit) { - when (connectionController) { - is ConnectionController.Automatic -> onError(WRONG_CONNECTION_TYPE) - is ConnectionController.Manual -> (connectionController as ConnectionController.Manual).disconnect() - } - } + override fun restart(onError: (Core.Model.Error) -> Unit) { + try { + when (connectionType) { + ConnectionType.AUTOMATIC -> onError(Core.Model.Error(IllegalStateException(WRONG_CONNECTION_TYPE))) + ConnectionType.MANUAL -> manualConnection.restart() + } + } catch (e: Exception) { + onError(Core.Model.Error(e)) + } + } - override fun disconnect(onError: (Core.Model.Error) -> Unit) { - when (connectionController) { - is ConnectionController.Automatic -> onError(Core.Model.Error(IllegalStateException(WRONG_CONNECTION_TYPE))) - is ConnectionController.Manual -> (connectionController as ConnectionController.Manual).disconnect() - } - } + @Deprecated("This has become deprecate in favor of the onError returning Core.Model.Error", replaceWith = ReplaceWith("this.connect(onErrorModel)")) + override fun connect(onErrorModel: (Core.Model.Error) -> Unit, onError: (String) -> Unit) { + when (connectionType) { + ConnectionType.AUTOMATIC -> onError(WRONG_CONNECTION_TYPE) + ConnectionType.MANUAL -> manualConnection.connect() + } + } + + @Deprecated("This has become deprecate in favor of the onError returning Core.Model.Error", replaceWith = ReplaceWith("this.disconnect(onErrorModel)")) + override fun disconnect(onErrorModel: (Core.Model.Error) -> Unit, onError: (String) -> Unit) { + when (connectionType) { + ConnectionType.AUTOMATIC -> onError(WRONG_CONNECTION_TYPE) + ConnectionType.MANUAL -> manualConnection.disconnect() + } + } } \ No newline at end of file diff --git a/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayConnectionInterface.kt b/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayConnectionInterface.kt index 8a9719443e..c3f13d6b94 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayConnectionInterface.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/relay/RelayConnectionInterface.kt @@ -14,4 +14,6 @@ interface RelayConnectionInterface : RelayInterface { @Deprecated("This has become deprecate in favor of the onError returning Core.Model.Error", ReplaceWith("this.disconnect(onErrorModel)")) fun disconnect(onErrorModel: (Core.Model.Error) -> Unit = {}, onError: (String) -> Unit) fun disconnect(onError: (Core.Model.Error) -> Unit) + + fun restart(onError: (Core.Model.Error) -> Unit) } \ No newline at end of file diff --git a/core/android/src/main/kotlin/com/walletconnect/android/utils/Extensions.kt b/core/android/src/main/kotlin/com/walletconnect/android/utils/Extensions.kt index 6a31649601..73fce140b8 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/utils/Extensions.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/utils/Extensions.kt @@ -10,7 +10,6 @@ import com.walletconnect.android.internal.common.exception.ProjectIdDoesNotExist import com.walletconnect.android.internal.common.exception.UnableToConnectToWebsocketException import com.walletconnect.android.internal.common.exception.WalletConnectException import com.walletconnect.android.internal.common.model.AppMetaData -import com.walletconnect.android.relay.ConnectionType import com.walletconnect.utils.Empty import java.net.HttpURLConnection @@ -19,13 +18,6 @@ internal fun String.strippedUrl() = Uri.parse(this).run { this@run.scheme + "://" + this@run.authority } -@JvmSynthetic -internal fun ConnectionType.toCommonConnectionType(): ConnectionType = - when (this) { - ConnectionType.AUTOMATIC -> ConnectionType.AUTOMATIC - ConnectionType.MANUAL -> ConnectionType.MANUAL - } - @JvmSynthetic internal fun String.isValidRelayServerUrl(): Boolean { return this.isNotBlank() && Uri.parse(this)?.let { relayUrl -> diff --git a/core/android/src/test/kotlin/com/walletconnect/android/internal/RelayClientTests.kt b/core/android/src/test/kotlin/com/walletconnect/android/internal/RelayClientTests.kt index 6f5c991f43..c978a77fc4 100644 --- a/core/android/src/test/kotlin/com/walletconnect/android/internal/RelayClientTests.kt +++ b/core/android/src/test/kotlin/com/walletconnect/android/internal/RelayClientTests.kt @@ -4,8 +4,8 @@ import com.tinder.scarlet.WebSocket import com.walletconnect.android.internal.common.connection.ConnectivityState import com.walletconnect.android.internal.common.di.AndroidCommonDITags import com.walletconnect.android.internal.common.scope +import com.walletconnect.android.relay.ConnectionType import com.walletconnect.android.relay.RelayClient -import com.walletconnect.foundation.network.data.ConnectionController import com.walletconnect.foundation.network.data.service.RelayService import com.walletconnect.foundation.util.Logger import io.mockk.clearAllMocks @@ -35,7 +35,6 @@ class RelayClientTests { private lateinit var relayClient: RelayClient private val mockRelayService = mockk(relaxed = true) private val mockLogger = mockk(relaxed = true) - private val mockConnectionController = mockk(relaxed = true) private val mockNetworkState = mockk(relaxed = true) private val testDispatcher = StandardTestDispatcher() private val testScope = TestScope(testDispatcher) @@ -47,7 +46,6 @@ class RelayClientTests { modules(module { single(named(AndroidCommonDITags.RELAY_SERVICE)) { mockRelayService } single(named(AndroidCommonDITags.LOGGER)) { mockLogger } - single(named(AndroidCommonDITags.CONNECTION_CONTROLLER)) { mockConnectionController } single(named(AndroidCommonDITags.CONNECTIVITY_STATE)) { mockNetworkState } }) } @@ -73,7 +71,7 @@ class RelayClientTests { emit(WebSocket.Event.OnConnectionFailed(Throwable("Network failure2"))) } - relayClient.initialize { error -> + relayClient.initialize(ConnectionType.MANUAL) { error -> assertEquals( "Error while connecting, please check your Internet connection or contact support: java.lang.Throwable: Network failure", error.message diff --git a/foundation/src/main/kotlin/com/walletconnect/foundation/di/FoundationNetworkModule.kt b/foundation/src/main/kotlin/com/walletconnect/foundation/di/FoundationNetworkModule.kt index f1e51de476..2b24be1e16 100644 --- a/foundation/src/main/kotlin/com/walletconnect/foundation/di/FoundationNetworkModule.kt +++ b/foundation/src/main/kotlin/com/walletconnect/foundation/di/FoundationNetworkModule.kt @@ -5,7 +5,6 @@ import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter import com.tinder.scarlet.retry.LinearBackoffStrategy import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory import com.walletconnect.foundation.network.BaseRelayClient -import com.walletconnect.foundation.network.data.ConnectionController import com.walletconnect.foundation.network.data.adapter.FlowStreamAdapter import com.walletconnect.foundation.network.data.service.RelayService import okhttp3.Interceptor @@ -48,11 +47,6 @@ fun networkModule(serverUrl: String, sdkVersion: String, jwt: String): Module = single { LinearBackoffStrategy(TimeUnit.SECONDS.toMillis(DEFAULT_BACKOFF_SECONDS)) } - single() { - - ConnectionController.Manual() - } - single(named(FoundationDITags.SCARLET)) { Scarlet.Builder() .backoffStrategy(get()) diff --git a/foundation/src/main/kotlin/com/walletconnect/foundation/network/BaseRelayClient.kt b/foundation/src/main/kotlin/com/walletconnect/foundation/network/BaseRelayClient.kt index d1d0e9f70c..0b673229b1 100644 --- a/foundation/src/main/kotlin/com/walletconnect/foundation/network/BaseRelayClient.kt +++ b/foundation/src/main/kotlin/com/walletconnect/foundation/network/BaseRelayClient.kt @@ -36,15 +36,15 @@ import org.koin.core.KoinApplication @OptIn(ExperimentalCoroutinesApi::class) abstract class BaseRelayClient : RelayInterface { - private var foundationKoinApp: KoinApplication = KoinApplication.init() - lateinit var relayService: RelayService - protected var logger: Logger - private val resultState: MutableSharedFlow = MutableSharedFlow() - - init { - foundationKoinApp.run { modules(foundationCommonModule()) } - logger = foundationKoinApp.koin.get() - } + private var foundationKoinApp: KoinApplication = KoinApplication.init() + lateinit var relayService: RelayService + protected var logger: Logger + private val resultState: MutableSharedFlow = MutableSharedFlow() + + init { + foundationKoinApp.run { modules(foundationCommonModule()) } + logger = foundationKoinApp.koin.get() + } fun observeResults() { scope.launch { @@ -63,26 +63,29 @@ abstract class BaseRelayClient : RelayInterface { } } - override val eventsFlow: SharedFlow by lazy { - relayService - .observeWebSocketEvent() - .map { event -> event.toRelayEvent() } - .shareIn(scope, SharingStarted.Lazily, REPLAY) - } + override val eventsFlow: SharedFlow by lazy { + relayService + .observeWebSocketEvent() + .map { event -> + logger.log(event.toString()) + event.toRelayEvent() + } + .shareIn(scope, SharingStarted.Lazily, REPLAY) + } - override val subscriptionRequest: Flow by lazy { - relayService.observeSubscriptionRequest() - .map { request -> request.toRelay() } - .onEach { relayRequest -> supervisorScope { publishSubscriptionAcknowledgement(relayRequest.id) } } - } + override val subscriptionRequest: Flow by lazy { + relayService.observeSubscriptionRequest() + .map { request -> request.toRelay() } + .onEach { relayRequest -> supervisorScope { publishSubscriptionAcknowledgement(relayRequest.id) } } + } @ExperimentalCoroutinesApi override fun publish( - topic: String, - message: String, - params: Relay.Model.IrnParams, - id: Long?, - onResult: (Result) -> Unit, + topic: String, + message: String, + params: Relay.Model.IrnParams, + id: Long?, + onResult: (Result) -> Unit, ) { val (tag, ttl, prompt) = params val publishParams = RelayDTO.Publish.Request.Params(Topic(topic), message, Ttl(ttl), tag, prompt) @@ -97,15 +100,15 @@ abstract class BaseRelayClient : RelayInterface { try { withTimeout(RESULT_TIMEOUT) { resultState - .filterIsInstance() - .filter { relayResult -> relayResult.id == id } - .first { publishResult -> - when (publishResult) { - is RelayDTO.Publish.Result.Acknowledgement -> onResult(Result.success(publishResult.toRelay())) - is RelayDTO.Publish.Result.JsonRpcError -> onResult(Result.failure(Throwable(publishResult.error.errorMessage))) - } - true + .filterIsInstance() + .filter { relayResult -> relayResult.id == id } + .first { publishResult -> + when (publishResult) { + is RelayDTO.Publish.Result.Acknowledgement -> onResult(Result.success(publishResult.toRelay())) + is RelayDTO.Publish.Result.JsonRpcError -> onResult(Result.failure(Throwable(publishResult.error.errorMessage))) } + true + } } } catch (e: TimeoutCancellationException) { onResult(Result.failure(e)) @@ -130,15 +133,15 @@ abstract class BaseRelayClient : RelayInterface { try { withTimeout(RESULT_TIMEOUT) { resultState - .filterIsInstance() - .filter { relayResult -> relayResult.id == id } - .first { subscribeResult -> - when (subscribeResult) { - is RelayDTO.Subscribe.Result.Acknowledgement -> onResult(Result.success(subscribeResult.toRelay())) - is RelayDTO.Subscribe.Result.JsonRpcError -> onResult(Result.failure(Throwable(subscribeResult.error.errorMessage))) - } - true + .filterIsInstance() + .filter { relayResult -> relayResult.id == id } + .first { subscribeResult -> + when (subscribeResult) { + is RelayDTO.Subscribe.Result.Acknowledgement -> onResult(Result.success(subscribeResult.toRelay())) + is RelayDTO.Subscribe.Result.JsonRpcError -> onResult(Result.failure(Throwable(subscribeResult.error.errorMessage))) } + true + } } } catch (e: TimeoutCancellationException) { onResult(Result.failure(e)) @@ -163,15 +166,15 @@ abstract class BaseRelayClient : RelayInterface { try { withTimeout(RESULT_TIMEOUT) { resultState - .filterIsInstance() - .filter { relayResult -> relayResult.id == id } - .first { batchSubscribeResult -> - when (batchSubscribeResult) { - is RelayDTO.BatchSubscribe.Result.Acknowledgement -> onResult(Result.success(batchSubscribeResult.toRelay())) - is RelayDTO.BatchSubscribe.Result.JsonRpcError -> onResult(Result.failure(Throwable(batchSubscribeResult.error.errorMessage))) - } - true + .filterIsInstance() + .filter { relayResult -> relayResult.id == id } + .first { batchSubscribeResult -> + when (batchSubscribeResult) { + is RelayDTO.BatchSubscribe.Result.Acknowledgement -> onResult(Result.success(batchSubscribeResult.toRelay())) + is RelayDTO.BatchSubscribe.Result.JsonRpcError -> onResult(Result.failure(Throwable(batchSubscribeResult.error.errorMessage))) } + true + } } } catch (e: TimeoutCancellationException) { onResult(Result.failure(e)) @@ -185,14 +188,14 @@ abstract class BaseRelayClient : RelayInterface { @ExperimentalCoroutinesApi override fun unsubscribe( - topic: String, - subscriptionId: String, - id: Long?, - onResult: (Result) -> Unit, + topic: String, + subscriptionId: String, + id: Long?, + onResult: (Result) -> Unit, ) { val unsubscribeRequest = RelayDTO.Unsubscribe.Request( - id = id ?: generateClientToServerId(), - params = RelayDTO.Unsubscribe.Request.Params(Topic(topic), SubscriptionId(subscriptionId)) + id = id ?: generateClientToServerId(), + params = RelayDTO.Unsubscribe.Request.Params(Topic(topic), SubscriptionId(subscriptionId)) ) observeUnsubscribeResult(unsubscribeRequest.id, onResult) @@ -204,15 +207,15 @@ abstract class BaseRelayClient : RelayInterface { try { withTimeout(RESULT_TIMEOUT) { resultState - .filterIsInstance() - .filter { relayResult -> relayResult.id == id } - .first { unsubscribeResult -> - when (unsubscribeResult) { - is RelayDTO.Unsubscribe.Result.Acknowledgement -> onResult(Result.success(unsubscribeResult.toRelay())) - is RelayDTO.Unsubscribe.Result.JsonRpcError -> onResult(Result.failure(Throwable(unsubscribeResult.error.errorMessage))) - } - true + .filterIsInstance() + .filter { relayResult -> relayResult.id == id } + .first { unsubscribeResult -> + when (unsubscribeResult) { + is RelayDTO.Unsubscribe.Result.Acknowledgement -> onResult(Result.success(unsubscribeResult.toRelay())) + is RelayDTO.Unsubscribe.Result.JsonRpcError -> onResult(Result.failure(Throwable(unsubscribeResult.error.errorMessage))) } + true + } } } catch (e: TimeoutCancellationException) { onResult(Result.failure(e)) diff --git a/foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionController.kt b/foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionController.kt deleted file mode 100644 index 54414bd48b..0000000000 --- a/foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionController.kt +++ /dev/null @@ -1,25 +0,0 @@ -@file:JvmSynthetic - -package com.walletconnect.foundation.network.data - -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow - -sealed class ConnectionController { - - class Manual : ConnectionController() { - private val _connectionEvent: MutableStateFlow = MutableStateFlow(ConnectionEvent.DISCONNECT) - val connectionEventFlow: StateFlow = _connectionEvent.asStateFlow() - - fun connect() { - _connectionEvent.value = ConnectionEvent.CONNECT - } - - fun disconnect() { - _connectionEvent.value = ConnectionEvent.DISCONNECT - } - } - - object Automatic : ConnectionController() -} \ No newline at end of file diff --git a/foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionEvent.kt b/foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionEvent.kt deleted file mode 100644 index 29c9ee0b11..0000000000 --- a/foundation/src/main/kotlin/com/walletconnect/foundation/network/data/ConnectionEvent.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.walletconnect.foundation.network.data - -enum class ConnectionEvent { - CONNECT, DISCONNECT -} \ No newline at end of file diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt index 21f438e966..dec31aa6be 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt @@ -59,7 +59,7 @@ class Web3WalletApplication : Application() { EthAccountDelegate.application = this - val projectId = BuildConfig.PROJECT_ID + val projectId = "a7f155fbc59c18b6ad4fb5650067dd41" //BuildConfig.PROJECT_ID //todo: remove val serverUrl = "wss://$RELAY_URL?projectId=$projectId" val appMetaData = Core.Model.AppMetaData( name = "Kotlin Wallet", @@ -71,12 +71,12 @@ class Web3WalletApplication : Application() { CoreClient.initialize( relayServerUrl = serverUrl, - connectionType = ConnectionType.AUTOMATIC, + connectionType = ConnectionType.MANUAL, application = this, metaData = appMetaData, onError = { error -> Firebase.crashlytics.recordException(error.throwable) - logger.error(error.throwable.stackTraceToString()) + println(error.throwable.stackTraceToString()) scope.launch { connectionStateFlow.emit(ConnectionState.Error(error.throwable.message ?: "")) } diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt index 8b66ff166f..a2f8541034 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt @@ -50,6 +50,7 @@ import com.google.accompanist.pager.rememberPagerState import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.ktx.Firebase import com.skydoves.landscapist.glide.GlideImage +import com.walletconnect.android.CoreClient import com.walletconnect.sample.common.ui.themedColor import com.walletconnect.sample.wallet.R import com.walletconnect.sample.wallet.ui.common.Content @@ -155,6 +156,13 @@ fun ConnectionDetailsRoute(navController: NavController, connectionId: Int?, con } } } + }, + onRestart = { + CoreClient.Relay.restart { error -> + composableScope.launch(Dispatchers.Main) { + Toast.makeText(context, error.throwable.message, Toast.LENGTH_SHORT).show() + } + } } ) Spacer(modifier = Modifier.height(16.dp)) @@ -317,7 +325,7 @@ fun Connection(connectionUI: ConnectionUI) { } @Composable -fun TopButtons(navController: NavController, isEmitAndUpdateVisible: Boolean, isEmitLoading: Boolean, isUpdateLoading: Boolean, onEmit: () -> Unit, onUpdate: () -> Unit) { +fun TopButtons(navController: NavController, isEmitAndUpdateVisible: Boolean, isEmitLoading: Boolean, isUpdateLoading: Boolean, onEmit: () -> Unit, onUpdate: () -> Unit, onRestart: () -> Unit) { val color = Color(0xFF3496ff) val style = TextStyle(fontWeight = FontWeight.SemiBold, fontSize = 17.sp, color = color) Row( @@ -376,6 +384,14 @@ fun TopButtons(navController: NavController, isEmitAndUpdateVisible: Boolean, is ) } } + + Text( + modifier = Modifier + .clip(RoundedCornerShape(5.dp)) + .clickable { onRestart() } + .padding(horizontal = 5.dp, vertical = 5.dp), + text = "Restart", style = style + ) } } } \ No newline at end of file From 36009304086449ec3ae4e03279ba316f29846455 Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 18 Jun 2024 14:38:24 +0200 Subject: [PATCH 2/7] Fix testing --- build.gradle.kts | 2 +- buildSrc/src/main/kotlin/Versions.kt | 24 +++++++++---------- .../android/test/utils/TestClient.kt | 2 +- .../notify/test/utils/TestClient.kt | 2 +- .../sign/test/utils/TestClient.kt | 4 ++-- sample/wallet/build.gradle.kts | 2 +- .../sample/wallet/Web3WalletApplication.kt | 4 +++- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f5a59cbcc4..34233c501b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -101,7 +101,7 @@ task("clean") { nexusPublishing { repositories { -// project.version = "-SNAPSHOT" + project.version = "-SNAPSHOT" sonatype { stagingProfileId.set(System.getenv("SONATYPE_STAGING_PROFILE_ID")) username.set(System.getenv("OSSRH_USERNAME")) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index fa1dc23aab..c8767e96b1 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -5,21 +5,21 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID" const val KEY_SDK_NAME = "SDK_NAME" //Latest versions -const val BOM_VERSION = "1.32.1" -const val FOUNDATION_VERSION = "1.17.2" -const val CORE_VERSION = "1.32.0" -const val SIGN_VERSION = "2.32.0" -const val AUTH_VERSION = "1.28.3" -const val CHAT_VERSION = "1.0.0-beta30" -const val NOTIFY_VERSION = "1.3.4" -const val WEB_3_WALLET_VERSION = "1.32.1" -const val WEB_3_MODAL_VERSION = "1.5.4" -const val WC_MODAL_VERSION = "1.5.4" -const val MODAL_CORE_VERSION = "1.5.4" +const val BOM_VERSION = "1.32.1-SNAPSHOT" +const val FOUNDATION_VERSION = "1.17.2-SNAPSHOT" +const val CORE_VERSION = "1.32.0-SNAPSHOT" +const val SIGN_VERSION = "2.32.0-SNAPSHOT" +const val AUTH_VERSION = "1.28.3-SNAPSHOT" +const val CHAT_VERSION = "1.0.0-beta30-SNAPSHOT" +const val NOTIFY_VERSION = "1.3.4-SNAPSHOT" +const val WEB_3_WALLET_VERSION = "1.32.1-SNAPSHOT" +const val WEB_3_MODAL_VERSION = "1.5.4-SNAPSHOT" +const val WC_MODAL_VERSION = "1.5.4-SNAPSHOT" +const val MODAL_CORE_VERSION = "1.5.4-SNAPSHOT" val jvmVersion = JavaVersion.VERSION_11 const val MIN_SDK: Int = 23 const val TARGET_SDK: Int = 34 const val COMPILE_SDK: Int = TARGET_SDK -val SAMPLE_VERSION_CODE = BOM_VERSION.replace(".", "").toInt() +val SAMPLE_VERSION_CODE = BOM_VERSION.replace("-SNAPSHOT", "").replace(".", "").toInt() const val SAMPLE_VERSION_NAME = BOM_VERSION \ No newline at end of file diff --git a/core/android/src/androidTest/kotlin/com/walletconnect/android/test/utils/TestClient.kt b/core/android/src/androidTest/kotlin/com/walletconnect/android/test/utils/TestClient.kt index 86865d856e..e1b4ffa772 100644 --- a/core/android/src/androidTest/kotlin/com/walletconnect/android/test/utils/TestClient.kt +++ b/core/android/src/androidTest/kotlin/com/walletconnect/android/test/utils/TestClient.kt @@ -81,7 +81,7 @@ internal object TestClient { secondaryKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_secondary", app.packageName)) // Necessary reinit of Relay, Pairing and PairingController - Relay.initialize { Timber.e(it) } + Relay.initialize(ConnectionType.MANUAL) { Timber.e(it) } Pairing.initialize() PairingController.initialize() diff --git a/protocol/notify/src/androidTest/kotlin/com/walletconnect/notify/test/utils/TestClient.kt b/protocol/notify/src/androidTest/kotlin/com/walletconnect/notify/test/utils/TestClient.kt index 1ad9992735..8a6dd1e859 100644 --- a/protocol/notify/src/androidTest/kotlin/com/walletconnect/notify/test/utils/TestClient.kt +++ b/protocol/notify/src/androidTest/kotlin/com/walletconnect/notify/test/utils/TestClient.kt @@ -108,7 +108,7 @@ internal object TestClient { secondaryKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_secondary", RELAY_URL, ConnectionType.MANUAL, app.packageName)) // Necessary reinit of Relay, Pairing and PairingController - Relay.initialize { Timber.e(it) } + Relay.initialize(ConnectionType.MANUAL) { Timber.e(it) } Pairing.initialize() PairingController.initialize() diff --git a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt index 860d19f146..7ccb1843e9 100644 --- a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt +++ b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt @@ -73,7 +73,7 @@ internal object TestClient { dappKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_dapp", RELAY_URL, ConnectionType.MANUAL, app.packageName)) // Necessary reinit of Relay, Pairing and PairingController - Relay.initialize { Timber.e(it) } + Relay.initialize(ConnectionType.MANUAL) { Timber.e(it) } Pairing.initialize() PairingController.initialize() @@ -114,7 +114,7 @@ internal object TestClient { hybridKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_hybrid", RELAY_URL, ConnectionType.MANUAL, app.packageName)) // Necessary reinit of Relay, Pairing and PairingController - Relay.initialize { Timber.e(it) } + Relay.initialize(ConnectionType.MANUAL) { Timber.e(it) } Pairing.initialize() PairingController.initialize() diff --git a/sample/wallet/build.gradle.kts b/sample/wallet/build.gradle.kts index 292f49687a..86c5572ec2 100644 --- a/sample/wallet/build.gradle.kts +++ b/sample/wallet/build.gradle.kts @@ -21,7 +21,7 @@ android { vectorDrawables { useSupportLibrary = true } - buildConfigField("String", "PROJECT_ID", "\"${System.getenv("WC_CLOUD_PROJECT_ID") ?: ""}\"") + buildConfigField("String", "PROJECT_ID", "\"${System.getenv("WC_CLOUD_PROJECT_ID") ?: "a7f155fbc59c18b6ad4fb5650067dd41"}\"") //todo: check getenv buildConfigField("String", "BOM_VERSION", "\"${BOM_VERSION}\"") } diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt index dec31aa6be..78e66410e5 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/Web3WalletApplication.kt @@ -59,7 +59,7 @@ class Web3WalletApplication : Application() { EthAccountDelegate.application = this - val projectId = "a7f155fbc59c18b6ad4fb5650067dd41" //BuildConfig.PROJECT_ID //todo: remove + val projectId = BuildConfig.PROJECT_ID val serverUrl = "wss://$RELAY_URL?projectId=$projectId" val appMetaData = Core.Model.AppMetaData( name = "Kotlin Wallet", @@ -109,6 +109,8 @@ class Web3WalletApplication : Application() { FirebaseAppDistribution.getInstance().updateIfNewReleaseAvailable() + CoreClient.Relay.restart { } + registerAccount() initializeBeagle() From c9eaa1ca2e509ff19eaecaf64f991f524a71855e Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 13 Aug 2024 09:13:35 +0200 Subject: [PATCH 3/7] Fix get accounts exception --- .../connection_details/ConnectionDetailsRoute.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt index 8cb93de4d6..6edbf2b933 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/composable_routes/connection_details/ConnectionDetailsRoute.kt @@ -200,7 +200,12 @@ fun ConnectionDetailsRoute(navController: NavController, connectionId: Int?, con onSwitch = { when (uiConnection.type) { is ConnectionType.Sign -> { - val (namespace, reference, _) = connectionsViewModel.displayedAccounts[1].split(":") + val (namespace, reference, _) = try { + connectionsViewModel.displayedAccounts[1].split(":") + } catch (e: Exception) { + connectionsViewModel.displayedAccounts[0].split(":") + } + val chainId = "$namespace:$reference" val accountsToChange = connectionsViewModel.getAccountsToChange() Web3Wallet.emitSessionEvent(Wallet.Params.SessionEmit(uiConnection.type.topic, Wallet.Model.SessionEvent("accountsChanged", accountsToChange), chainId), From 7d790d2b2d34bfea9a69e2a8f0a4c6e4d772abbb Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 13 Aug 2024 09:33:41 +0200 Subject: [PATCH 4/7] Update token --- .github/workflows/ci_github_release.yml | 4 ++-- .github/workflows/ci_release_articacts.yml | 2 +- build.gradle.kts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_github_release.yml b/.github/workflows/ci_github_release.yml index a4191b810d..0aa38def10 100644 --- a/.github/workflows/ci_github_release.yml +++ b/.github/workflows/ci_github_release.yml @@ -19,12 +19,12 @@ jobs: with: config-name: release-drafter.yml env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.PUSH_GITHUB_TOKEN }} - name: Create GitHub Release uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.PUSH_GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} diff --git a/.github/workflows/ci_release_articacts.yml b/.github/workflows/ci_release_articacts.yml index 6162de0ee2..e4a4c4a1f5 100644 --- a/.github/workflows/ci_release_articacts.yml +++ b/.github/workflows/ci_release_articacts.yml @@ -86,6 +86,6 @@ jobs: ./gradlew closeAndReleaseMultipleRepositories - name: Push Tag env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.PUSH_GITHUB_TOKEN }} run: | ./gradlew pushTagToMain diff --git a/build.gradle.kts b/build.gradle.kts index dc80237f14..08b0181e1c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -335,7 +335,7 @@ tasks.register("createTag") { tasks.register("pushTagToMain") { val tagName = "BOM_$BOM_VERSION" val repoUrl = "https://github.com/WalletConnect/WalletConnectKotlinV2.git" - val token = System.getenv("PUSH_GITHUB_TOKEN") ?: throw GradleException("GITHUB_TOKEN environment variable is not set") + val token = System.getenv("PUSH_GITHUB_TOKEN") ?: throw GradleException("PUSH_GITHUB_TOKEN environment variable is not set") dependsOn("createTag") val authenticatedRepoUrl = repoUrl.replace("https://", "https://$token:@") commandLine("git", "push", authenticatedRepoUrl, tagName, "refs/heads/main") From f1c54eed29662707b85df1e804edfb43e7324b52 Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 13 Aug 2024 10:56:03 +0200 Subject: [PATCH 5/7] Test fixing --- .../kotlin/com/walletconnect/sign/test/utils/TestClient.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt index d7f492b92c..44a913edfc 100644 --- a/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt +++ b/protocol/sign/src/androidTest/kotlin/com/walletconnect/sign/test/utils/TestClient.kt @@ -166,7 +166,7 @@ internal object TestClient { ) // Necessary reinit of Relay, Pairing and PairingController - Relay.initialize { Timber.e(it) } + Relay.initialize(ConnectionType.MANUAL) { Timber.e(it) } Pairing.initialize() PairingController.initialize() From cd4ae2746413031a0981280e8d59ef23428d7ea2 Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 13 Aug 2024 10:59:55 +0200 Subject: [PATCH 6/7] Clean up --- build.gradle.kts | 2 +- sample/wallet/build.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e7e32485c1..dc80237f14 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -110,7 +110,7 @@ task("clean") { nexusPublishing { repositories { - project.version = "-SNAPSHOT" +// project.version = "-SNAPSHOT" sonatype { stagingProfileId.set(System.getenv("SONATYPE_STAGING_PROFILE_ID")) username.set(System.getenv("OSSRH_USERNAME")) diff --git a/sample/wallet/build.gradle.kts b/sample/wallet/build.gradle.kts index 3940633e89..f1a8072ee9 100644 --- a/sample/wallet/build.gradle.kts +++ b/sample/wallet/build.gradle.kts @@ -21,7 +21,7 @@ android { vectorDrawables { useSupportLibrary = true } - buildConfigField("String", "PROJECT_ID", "\"${System.getenv("WC_CLOUD_PROJECT_ID") ?: "a7f155fbc59c18b6ad4fb5650067dd41"}\"") //todo: check getenv + buildConfigField("String", "PROJECT_ID", "\"${System.getenv("WC_CLOUD_PROJECT_ID") ?: ""}\"") buildConfigField("String", "BOM_VERSION", "\"${BOM_VERSION}\"") } From d569de55f44179c3ec036bc09aea8c654fdcce34 Mon Sep 17 00:00:00 2001 From: kubel Date: Tue, 13 Aug 2024 11:44:13 +0200 Subject: [PATCH 7/7] Version bump --- ReadMe.md | 1 + buildSrc/src/main/kotlin/Versions.kt | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index a23f99af23..1ff62ea1cf 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -23,6 +23,7 @@ dependencies { | BOM | [Core SDK](core/android) | [Sign SDK](protocol/sign) | [Auth SDK](protocol/auth) | [Chat SDK](protocol/chat) | [Notify SDK](protocol/notify) | [web3wallet](product/web3wallet) | [web3modal](product/web3modal) | [WalletConnectModal](product/walletconnectmodal) | |-----------------------------------------------------------------------------------------|--------------------------|---------------------------|---------------------------|---------------------------|:------------------------------|----------------------------------|--------------------------------|--------------------------------------------------| +| 1.34.1 | 1.34.1 | 2.34.1 | 1.28.7 | 1.0.0.beta34 | 1.3.8 | 1.34.1 | 1.6.3 | 1.5.8 | | 1.34.0 | 1.34.0 | 2.34.0 | 1.28.6 | 1.0.0.beta33 | 1.3.7 | 1.34.0 | 1.6.2 | 1.5.7 | | 1.33.1 | 1.33.1 | 2.33.1 | 1.28.5 | 1.0.0.beta32 | 1.3.6 | 1.33.1 | 1.6.1 | 1.5.6 | | 1.33.0 | 1.33.0 | 2.33.0 | 1.28.4 | 1.0.0.beta31 | 1.3.5 | 1.33.0 | 1.6.0 | 1.5.5 | diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index ac76aec636..a4f820d29e 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -5,17 +5,17 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID" const val KEY_SDK_NAME = "SDK_NAME" //Latest versions -const val BOM_VERSION = "1.34.0" -const val FOUNDATION_VERSION = "1.18.0" -const val CORE_VERSION = "1.34.0" -const val SIGN_VERSION = "2.34.0" -const val AUTH_VERSION = "1.28.6" -const val CHAT_VERSION = "1.0.0-beta33" -const val NOTIFY_VERSION = "1.3.7" -const val WEB_3_WALLET_VERSION = "1.34.0" -const val WEB_3_MODAL_VERSION = "1.6.2" -const val WC_MODAL_VERSION = "1.5.7" -const val MODAL_CORE_VERSION = "1.6.2" +const val BOM_VERSION = "1.34.1" +const val FOUNDATION_VERSION = "1.18.1" +const val CORE_VERSION = "1.34.1" +const val SIGN_VERSION = "2.34.1" +const val AUTH_VERSION = "1.28.7" +const val CHAT_VERSION = "1.0.0-beta34" +const val NOTIFY_VERSION = "1.3.8" +const val WEB_3_WALLET_VERSION = "1.34.1" +const val WEB_3_MODAL_VERSION = "1.6.3" +const val WC_MODAL_VERSION = "1.5.8" +const val MODAL_CORE_VERSION = "1.6.3" //Artifact ids const val ANDROID_BOM = "android-bom"