From 7273c1924e28cc9513fc1c9bf6e1f6c92abf2947 Mon Sep 17 00:00:00 2001 From: kubel Date: Wed, 15 May 2024 16:02:30 +0200 Subject: [PATCH] Remove Koin definition for bundle_id and inject it directly to components --- .idea/codeStyles/codeStyleConfig.xml | 2 +- .../com/walletconnect/android/CoreProtocol.kt | 65 ++++++++++--------- .../internal/common/di/AndroidCommonDITags.kt | 1 - .../internal/common/di/CoreCryptoModule.kt | 8 +-- .../internal/common/di/CoreNetworkModule.kt | 12 +--- .../android/internal/common/di/PulseModule.kt | 33 +++++----- 6 files changed, 59 insertions(+), 62 deletions(-) diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml index 79ee123c2..a55e7a179 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,5 +1,5 @@ - \ No newline at end of file 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 6720fa226..0cad4d346 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/CoreProtocol.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/CoreProtocol.kt @@ -71,39 +71,44 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter networkClientTimeout: NetworkClientTimeout?, onError: (Core.Model.Error) -> Unit ) { - with(koinApp) { - androidContext(application) - require(relayServerUrl.isValidRelayServerUrl()) { "Check the schema and projectId parameter of the Server Url" } - modules( - coreAndroidNetworkModule(relayServerUrl, connectionType.toCommonConnectionType(), BuildConfig.SDK_VERSION, networkClientTimeout), - coreCommonModule(), - coreCryptoModule(), - ) + try { + val bundleId: String = application.packageName + with(koinApp) { + androidContext(application) + require(relayServerUrl.isValidRelayServerUrl()) { "Check the schema and projectId parameter of the Server Url" } + modules( + module { single { ProjectId(relayServerUrl.projectId()) } }, + coreAndroidNetworkModule(relayServerUrl, connectionType.toCommonConnectionType(), BuildConfig.SDK_VERSION, networkClientTimeout, bundleId), + coreCommonModule(), + coreCryptoModule(), + ) - if (relay == null) { - Relay.initialize { error -> onError(Core.Model.Error(error)) } + if (relay == null) { + Relay.initialize { error -> onError(Core.Model.Error(error)) } + } + + modules( + coreStorageModule(), + pushModule(), + module { single { relay ?: Relay } }, + module { single { with(metaData) { AppMetaData(name = name, description = description, url = url, icons = icons, redirect = Redirect(redirect)) } } }, + module { single { Echo } }, + module { single { Push } }, + module { single { Verify } }, + coreJsonRpcModule(), + corePairingModule(Pairing, PairingController), + keyServerModule(keyServerUrl), + explorerModule(), + web3ModalModule(), + pulseModule(bundleId) + ) } - modules( - module { single { ProjectId(relayServerUrl.projectId()) } }, - coreStorageModule(), - pushModule(), - module { single { relay ?: Relay } }, - module { single { with(metaData) { AppMetaData(name = name, description = description, url = url, icons = icons, redirect = Redirect(redirect)) } } }, - module { single { Echo } }, - module { single { Push } }, - module { single { Verify } }, - coreJsonRpcModule(), - corePairingModule(Pairing, PairingController), - keyServerModule(keyServerUrl), - explorerModule(), - web3ModalModule(), - pulseModule() - ) + Verify.initialize() + Pairing.initialize() + PairingController.initialize() + } catch (e: Exception) { + onError(Core.Model.Error(e)) } - - Verify.initialize() - Pairing.initialize() - PairingController.initialize() } } \ 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 f0d39001e..735d30527 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 @@ -39,7 +39,6 @@ enum class AndroidCommonDITags { DECRYPT_AUTH_MESSAGE, DECRYPT_NOTIFY_MESSAGE, DECRYPT_USE_CASES, - BUNDLE_ID, ENABLE_ANALYTICS, ENABLE_AUTHENTICATE } \ No newline at end of file diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreCryptoModule.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreCryptoModule.kt index fab7b47d4..26dc9649d 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreCryptoModule.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/CoreCryptoModule.kt @@ -92,11 +92,11 @@ fun coreCryptoModule(sharedPrefsFile: String = SHARED_PREFS_FILE, keyStoreAlias: } } - single { KeyChain(get()) } + single { KeyChain(sharedPreferences = get()) } - single { ClientIdJwtRepositoryAndroid(get()) } + single { ClientIdJwtRepositoryAndroid(keyChain = get()) } - single { BouncyCastleKeyManagementRepository(get()) } + single { BouncyCastleKeyManagementRepository(keyChain = get()) } - single { ChaChaPolyCodec(get()) } + single { ChaChaPolyCodec(keyManagementRepository = get()) } } \ No newline at end of file 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 be2aee56d..780813993 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 @@ -14,7 +14,6 @@ import com.walletconnect.android.BuildConfig import com.walletconnect.android.internal.common.connection.ConnectivityState import com.walletconnect.android.internal.common.connection.ManualConnectionLifecycle import com.walletconnect.android.internal.common.jwt.clientid.GenerateJwtStoreClientIdUseCase -import com.walletconnect.android.internal.common.model.PackageName import com.walletconnect.android.relay.ConnectionType import com.walletconnect.android.relay.NetworkClientTimeout import com.walletconnect.foundation.network.data.ConnectionController @@ -26,7 +25,6 @@ import okhttp3.OkHttpClient import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import org.koin.android.ext.koin.androidApplication -import org.koin.android.ext.koin.androidContext import org.koin.core.qualifier.named import org.koin.dsl.module import java.io.IOException @@ -39,7 +37,7 @@ private const val DEFAULT_BACKOFF_SECONDS = 5L @Suppress("LocalVariableName") @JvmSynthetic -fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, sdkVersion: String, timeout: NetworkClientTimeout? = null) = module { +fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, sdkVersion: String, timeout: NetworkClientTimeout? = null, bundleId: String) = module { val networkClientTimeout = timeout ?: NetworkClientTimeout.getDefaultTimeout() SERVER_URL = serverUrl @@ -57,19 +55,15 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType, """wc-2/kotlin-${sdkVersion}/android-${Build.VERSION.RELEASE}""" } - single(named(AndroidCommonDITags.BUNDLE_ID)) { - PackageName(androidContext().packageName) - } - single { - GenerateJwtStoreClientIdUseCase(get(), get()) + GenerateJwtStoreClientIdUseCase(clientIdJwtRepository = get(), sharedPreferences = get()) } single(named(AndroidCommonDITags.SHARED_INTERCEPTOR)) { Interceptor { chain -> val updatedRequest = chain.request().newBuilder() .addHeader("User-Agent", get(named(AndroidCommonDITags.USER_AGENT))) - .addHeader("Origin", get(named(AndroidCommonDITags.BUNDLE_ID)).value) + .addHeader("Origin", bundleId) .build() chain.proceed(updatedRequest) diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/PulseModule.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/PulseModule.kt index 154d6bbdb..6d25eddfc 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/PulseModule.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/PulseModule.kt @@ -1,6 +1,5 @@ package com.walletconnect.android.internal.common.di -import com.walletconnect.android.internal.common.model.PackageName import com.walletconnect.android.pulse.data.PulseService import com.walletconnect.android.pulse.domain.SendClickAllWalletsUseCase import com.walletconnect.android.pulse.domain.SendClickGetWalletUseCase @@ -24,7 +23,7 @@ import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory @JvmSynthetic -fun pulseModule() = module { +fun pulseModule(bundleId: String) = module { single(named(AndroidCommonDITags.PULSE_URL)) { "https://pulse.walletconnect.org" } single(named(AndroidCommonDITags.PULSE_RETROFIT)) { @@ -41,7 +40,7 @@ fun pulseModule() = module { SendModalCreatedUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -49,7 +48,7 @@ fun pulseModule() = module { SendClickAllWalletsUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -57,7 +56,7 @@ fun pulseModule() = module { SendClickGetWalletUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -65,7 +64,7 @@ fun pulseModule() = module { SendClickWalletHelpUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -73,7 +72,7 @@ fun pulseModule() = module { SendClickNetworkHelpUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -81,7 +80,7 @@ fun pulseModule() = module { SendClickNetworksUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -89,7 +88,7 @@ fun pulseModule() = module { SendConnectErrorUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -97,7 +96,7 @@ fun pulseModule() = module { SendConnectSuccessUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -105,7 +104,7 @@ fun pulseModule() = module { SendDisconnectErrorUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -113,7 +112,7 @@ fun pulseModule() = module { SendDisconnectSuccessUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -121,7 +120,7 @@ fun pulseModule() = module { SendModalCloseUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -129,7 +128,7 @@ fun pulseModule() = module { SendModalLoadedUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -137,7 +136,7 @@ fun pulseModule() = module { SendModalOpenUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -145,7 +144,7 @@ fun pulseModule() = module { SendSelectWalletUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } @@ -153,7 +152,7 @@ fun pulseModule() = module { SendSwitchNetworkUseCase( pulseService = get(), logger = get(named(AndroidCommonDITags.LOGGER)), - bundleId = get(named(AndroidCommonDITags.BUNDLE_ID)).value + bundleId = bundleId ) } } \ No newline at end of file