Skip to content

Commit

Permalink
Remove Koin definition for bundle_id and inject it directly to compon…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
jakubuid committed May 15, 2024
1 parent ceb3593 commit 7273c19
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ enum class AndroidCommonDITags {
DECRYPT_AUTH_MESSAGE,
DECRYPT_NOTIFY_MESSAGE,
DECRYPT_USE_CASES,
BUNDLE_ID,
ENABLE_ANALYTICS,
ENABLE_AUTHENTICATE
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ fun coreCryptoModule(sharedPrefsFile: String = SHARED_PREFS_FILE, keyStoreAlias:
}
}

single<WCKeyStore> { KeyChain(get()) }
single<WCKeyStore> { KeyChain(sharedPreferences = get()) }

single<ClientIdJwtRepository> { ClientIdJwtRepositoryAndroid(get()) }
single<ClientIdJwtRepository> { ClientIdJwtRepositoryAndroid(keyChain = get()) }

single<KeyManagementRepository> { BouncyCastleKeyManagementRepository(get()) }
single<KeyManagementRepository> { BouncyCastleKeyManagementRepository(keyChain = get()) }

single<Codec> { ChaChaPolyCodec(get()) }
single<Codec> { ChaChaPolyCodec(keyManagementRepository = get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -57,19 +55,15 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType,
"""wc-2/kotlin-${sdkVersion}/android-${Build.VERSION.RELEASE}"""
}

single<PackageName>(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<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value)
.addHeader("Origin", bundleId)
.build()

chain.proceed(updatedRequest)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)) {
Expand All @@ -41,119 +40,119 @@ fun pulseModule() = module {
SendModalCreatedUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendClickAllWalletsUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendClickGetWalletUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendClickWalletHelpUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendClickNetworkHelpUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendClickNetworksUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendConnectErrorUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendConnectSuccessUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendDisconnectErrorUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendDisconnectSuccessUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendModalCloseUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single<SendModalLoadedUseCaseInterface> {
SendModalLoadedUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendModalOpenUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendSelectWalletUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}

single {
SendSwitchNetworkUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = get<PackageName>(named(AndroidCommonDITags.BUNDLE_ID)).value
bundleId = bundleId
)
}
}

0 comments on commit 7273c19

Please sign in to comment.