Skip to content

Commit

Permalink
Merge pull request #1397 from WalletConnect/fix/no_definition_for_bun…
Browse files Browse the repository at this point in the history
…dle_id

fix: no definition for bundle id
  • Loading branch information
jakubuid authored May 17, 2024
2 parents 4126632 + 8e3c4d1 commit c71498b
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 69 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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ internal fun overrideModule(
pairingController: PairingControllerInterface,
storagePrefix: String,
relayUrl: String,
connectionType: ConnectionType
connectionType: ConnectionType,
bundleId: String
) = module {
val sharedPrefsFile = storagePrefix + SHARED_PREFS_FILE
val keyStoreAlias = storagePrefix + KEY_STORE_ALIAS
Expand All @@ -34,6 +35,6 @@ internal fun overrideModule(
corePairingModule(pairing, pairingController),
coreCryptoModule(sharedPrefsFile, keyStoreAlias),
coreJsonRpcModule(),
coreAndroidNetworkModule(relayUrl, connectionType, "test_version")
coreAndroidNetworkModule(relayUrl, connectionType, "test_version", bundleId = bundleId)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal object TestClient {
Relay = RelayClient(secondaryKoinApp)

// Override of storage instances and depending objects
secondaryKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_secondary", RELAY_URL, ConnectionType.MANUAL))
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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ internal fun overrideModule(
pairingController: PairingControllerInterface,
storagePrefix: String,
relayUrl: String,
connectionType: ConnectionType
connectionType: ConnectionType,
bundleId: String
) = module {
val sharedPrefsFile = storagePrefix + SHARED_PREFS_FILE
val keyStoreAlias = storagePrefix + KEY_STORE_ALIAS
Expand All @@ -33,7 +34,7 @@ internal fun overrideModule(
coreStorageModule(storagePrefix),
corePairingModule(pairing, pairingController),
coreCryptoModule(sharedPrefsFile, keyStoreAlias),
coreAndroidNetworkModule(relayUrl, connectionType, "test_version"),
coreAndroidNetworkModule(relayUrl, connectionType, "test_version", bundleId = bundleId),
coreJsonRpcModule()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal object TestClient {
Relay = RelayClient(dappKoinApp)

// Override of storage instances and depending objects
dappKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_dapp", RELAY_URL, ConnectionType.MANUAL))
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) }
Expand Down Expand Up @@ -111,7 +111,7 @@ internal object TestClient {
Relay = RelayClient(hybridKoinApp)

// Override of storage instances and depending objects
hybridKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_hybrid", RELAY_URL, ConnectionType.MANUAL))
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) }
Expand Down

0 comments on commit c71498b

Please sign in to comment.