Skip to content

Commit

Permalink
Merge pull request #1412 from WalletConnect/feat/events_sdk
Browse files Browse the repository at this point in the history
Events SDK
  • Loading branch information
jakubuid authored Jun 5, 2024
2 parents ccc359b + 0d65845 commit 874f57c
Show file tree
Hide file tree
Showing 79 changed files with 1,335 additions and 943 deletions.
1 change: 1 addition & 0 deletions core/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ dependencies {
testImplementation(libs.coroutines.test)
testImplementation(libs.bundles.scarlet.test)
testImplementation(libs.bundles.sqlDelight.test)
testImplementation(libs.koin.test)

androidTestUtil(libs.androidx.testOrchestrator)
androidTestImplementation(libs.bundles.androidxAndroidTest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ private const val KEY_STORE_ALIAS = "wc_keystore_key"

// When called more that once, different `storagePrefix` must be defined.
@JvmSynthetic
internal fun overrideModule(relay: RelayConnectionInterface, pairing: PairingInterface, pairingController: PairingControllerInterface, storagePrefix: String) = module {
internal fun overrideModule(
relay: RelayConnectionInterface,
pairing: PairingInterface,
pairingController: PairingControllerInterface,
storagePrefix: String,
bundleId: String
) = module {
val sharedPrefsFile = storagePrefix + SHARED_PREFS_FILE
val keyStoreAlias = storagePrefix + KEY_STORE_ALIAS

single { relay }

includes(
coreStorageModule(storagePrefix),
coreStorageModule(storagePrefix, bundleId),
corePairingModule(pairing, pairingController),
coreCryptoModule(sharedPrefsFile, keyStoreAlias),
coreJsonRpcModule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal object TestClient {
Relay = RelayClient(secondaryKoinApp)

// Override of storage instances and depending objects
secondaryKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_secondary"))
secondaryKoinApp.modules(overrideModule(Relay, Pairing, PairingController, "test_secondary", 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 @@ -12,9 +12,9 @@ import org.koin.android.ext.koin.androidContext
import org.koin.core.qualifier.named
import org.koin.dsl.module

fun coreStorageModule(storagePrefix: String = String.Empty) = module {
fun coreStorageModule(storagePrefix: String = String.Empty, bundleId: String) = module {

includes(baseStorageModule(storagePrefix))
includes(baseStorageModule(storagePrefix, bundleId))

single<SqlDriver>(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE_DRIVER)) {
AndroidSqliteDriver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface CoreInterface {
relay: RelayConnectionInterface? = null,
keyServerUrl: String? = null,
networkClientTimeout: NetworkClientTimeout? = null,
telemetryEnabled: Boolean = true,
onError: (Core.Model.Error) -> Unit,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.walletconnect.android

import android.app.Application
import com.walletconnect.android.di.coreStorageModule
import com.walletconnect.android.internal.common.di.AndroidCommonDITags
import com.walletconnect.android.internal.common.di.coreAndroidNetworkModule
import com.walletconnect.android.internal.common.di.coreCommonModule
import com.walletconnect.android.internal.common.di.coreCryptoModule
Expand All @@ -17,6 +18,7 @@ import com.walletconnect.android.internal.common.explorer.ExplorerProtocol
import com.walletconnect.android.internal.common.model.AppMetaData
import com.walletconnect.android.internal.common.model.ProjectId
import com.walletconnect.android.internal.common.model.Redirect
import com.walletconnect.android.internal.common.model.TelemetryEnabled
import com.walletconnect.android.internal.common.wcKoinApp
import com.walletconnect.android.pairing.client.PairingInterface
import com.walletconnect.android.pairing.client.PairingProtocol
Expand All @@ -36,6 +38,7 @@ import com.walletconnect.android.verify.client.VerifyClient
import com.walletconnect.android.verify.client.VerifyInterface
import org.koin.android.ext.koin.androidContext
import org.koin.core.KoinApplication
import org.koin.core.qualifier.named
import org.koin.dsl.module

class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInterface {
Expand Down Expand Up @@ -69,6 +72,7 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter
relay: RelayConnectionInterface?,
keyServerUrl: String?,
networkClientTimeout: NetworkClientTimeout?,
telemetryEnabled: Boolean,
onError: (Core.Model.Error) -> Unit
) {
try {
Expand All @@ -78,6 +82,7 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter
require(relayServerUrl.isValidRelayServerUrl()) { "Check the schema and projectId parameter of the Server Url" }
modules(
module { single { ProjectId(relayServerUrl.projectId()) } },
module { single(named(AndroidCommonDITags.TELEMETRY_ENABLED)) { TelemetryEnabled(telemetryEnabled) } },
coreAndroidNetworkModule(relayServerUrl, connectionType.toCommonConnectionType(), BuildConfig.SDK_VERSION, networkClientTimeout, bundleId),
coreCommonModule(),
coreCryptoModule(),
Expand All @@ -88,7 +93,7 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter
}

modules(
coreStorageModule(),
coreStorageModule(bundleId = bundleId),
pushModule(),
module { single { relay ?: Relay } },
module { single { with(metaData) { AppMetaData(name = name, description = description, url = url, icons = icons, redirect = Redirect(redirect)) } } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class AndroidCommonDITags {
DECRYPT_AUTH_MESSAGE,
DECRYPT_NOTIFY_MESSAGE,
DECRYPT_USE_CASES,
ENABLE_ANALYTICS,
ENABLE_AUTHENTICATE
ENABLE_WEB_3_MODAL_ANALYTICS,
ENABLE_AUTHENTICATE,
TELEMETRY_ENABLED,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.squareup.moshi.Moshi
import com.walletconnect.android.di.AndroidBuildVariantDITags
import com.walletconnect.android.internal.common.model.AppMetaDataType
import com.walletconnect.android.internal.common.model.Validation
import com.walletconnect.android.internal.common.storage.events.EventsRepository
import com.walletconnect.android.internal.common.storage.identity.IdentitiesStorageRepository
import com.walletconnect.android.internal.common.storage.metadata.MetadataStorageRepository
import com.walletconnect.android.internal.common.storage.metadata.MetadataStorageRepositoryInterface
Expand All @@ -15,6 +16,7 @@ import com.walletconnect.android.internal.common.storage.push_messages.PushMessa
import com.walletconnect.android.internal.common.storage.rpc.JsonRpcHistory
import com.walletconnect.android.internal.common.storage.verify.VerifyContextStorageRepository
import com.walletconnect.android.sdk.core.AndroidCoreDatabase
import com.walletconnect.android.sdk.storage.data.dao.EventDao
import com.walletconnect.android.sdk.storage.data.dao.MetaData
import com.walletconnect.android.sdk.storage.data.dao.VerifyContext
import com.walletconnect.utils.Empty
Expand All @@ -24,7 +26,7 @@ import org.koin.core.scope.Scope
import org.koin.dsl.module
import com.walletconnect.android.internal.common.scope as wcScope

fun baseStorageModule(storagePrefix: String = String.Empty) = module {
fun baseStorageModule(storagePrefix: String = String.Empty, bundleId: String) = module {

fun Scope.createCoreDB(): AndroidCoreDatabase = AndroidCoreDatabase(
driver = get(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE_DRIVER)),
Expand All @@ -34,6 +36,9 @@ fun baseStorageModule(storagePrefix: String = String.Empty) = module {
),
VerifyContextAdapter = VerifyContext.Adapter(
validationAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_VALIDATION))
),
EventDaoAdapter = EventDao.Adapter(
traceAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_LIST))
)
)

Expand Down Expand Up @@ -101,6 +106,8 @@ fun baseStorageModule(storagePrefix: String = String.Empty) = module {

single { get<AndroidCoreDatabase>(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE)).pushMessageQueries }

single { get<AndroidCoreDatabase>(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE)).eventQueries }

single<MetadataStorageRepositoryInterface> { MetadataStorageRepository(metaDataQueries = get()) }

single<PairingStorageRepositoryInterface> { PairingStorageRepository(pairingQueries = get()) }
Expand All @@ -113,5 +120,7 @@ fun baseStorageModule(storagePrefix: String = String.Empty) = module {

single { PushMessagesRepository(pushMessageQueries = get()) }

single { EventsRepository(eventQueries = get(), bundleId = bundleId, telemetryEnabled = get(named(AndroidCommonDITags.TELEMETRY_ENABLED))) }

single { DatabaseConfig(storagePrefix = storagePrefix) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@ fun coreCommonModule() = module {
.withSubtype(JsonRpcResponse.JsonRpcError::class.java, "error")
}

single<PolymorphicJsonAdapterFactory<Props>> {
PolymorphicJsonAdapterFactory.of(Props::class.java, "type")
.withSubtype(Props.ModalCreated::class.java, "modal_created")
.withSubtype(Props.ModalLoaded::class.java, "modal_loaded")
.withSubtype(Props.ModalOpen::class.java, "modal_open")
.withSubtype(Props.ModalClose::class.java, "modal_close")
.withSubtype(Props.ClickNetworks::class.java, "click_networks")
.withSubtype(Props.ClickAllWallets::class.java, "click_all_wallets")
.withSubtype(Props.SwitchNetwork::class.java, "switch_network")
.withSubtype(Props.SelectWallet::class.java, "select_wallet")
.withSubtype(Props.ConnectSuccess::class.java, "connect_success")
.withSubtype(Props.ConnectError::class.java, "connect_error")
.withSubtype(Props.DisconnectSuccess::class.java, "disconnect_success")
.withSubtype(Props.DisconnectError::class.java, "disconnect_error")
.withSubtype(Props.ClickWalletHelp::class.java, "click_wallet_help")
.withSubtype(Props.ClickNetworkHelp::class.java, "click_network_help")
.withSubtype(Props.ClickGetWallet::class.java, "click_get_wallet")
}

single<Moshi.Builder>(named(AndroidCommonDITags.MOSHI)) {
get<Moshi>(named(FoundationDITags.MOSHI))
.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ fun corePairingModule(pairing: PairingInterface, pairingController: PairingContr
metadataRepository = get(),
pairingRepository = get(),
jsonRpcInteractor = get(),
logger = get(named(AndroidCommonDITags.LOGGER))
logger = get(named(AndroidCommonDITags.LOGGER)),
insertEventUseCase = get(),
sendBatchEventUseCase = get(),
)
}
single { pairing }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
package com.walletconnect.android.internal.common.di

import com.squareup.moshi.Moshi
import com.walletconnect.android.internal.common.model.TelemetryEnabled
import com.walletconnect.android.pulse.data.PulseService
import com.walletconnect.android.pulse.domain.SendClickAllWalletsUseCase
import com.walletconnect.android.pulse.domain.SendClickGetWalletUseCase
import com.walletconnect.android.pulse.domain.SendClickNetworkHelpUseCase
import com.walletconnect.android.pulse.domain.SendClickNetworksUseCase
import com.walletconnect.android.pulse.domain.SendClickWalletHelpUseCase
import com.walletconnect.android.pulse.domain.SendConnectErrorUseCase
import com.walletconnect.android.pulse.domain.SendConnectSuccessUseCase
import com.walletconnect.android.pulse.domain.SendDisconnectErrorUseCase
import com.walletconnect.android.pulse.domain.SendDisconnectSuccessUseCase
import com.walletconnect.android.pulse.domain.SendModalCloseUseCase
import com.walletconnect.android.pulse.domain.SendModalCreatedUseCase
import com.walletconnect.android.pulse.domain.SendModalLoadedUseCase
import com.walletconnect.android.pulse.domain.SendModalLoadedUseCaseInterface
import com.walletconnect.android.pulse.domain.SendModalOpenUseCase
import com.walletconnect.android.pulse.domain.SendSelectWalletUseCase
import com.walletconnect.android.pulse.domain.SendSwitchNetworkUseCase
import com.walletconnect.android.pulse.domain.InsertEventUseCase
import com.walletconnect.android.pulse.domain.SendBatchEventUseCase
import com.walletconnect.android.pulse.domain.SendEventInterface
import com.walletconnect.android.pulse.domain.SendEventUseCase
import org.koin.core.qualifier.named
import org.koin.dsl.module
import retrofit2.Retrofit
Expand All @@ -30,129 +20,35 @@ fun pulseModule(bundleId: String) = module {
Retrofit.Builder()
.baseUrl(get<String>(named(AndroidCommonDITags.PULSE_URL)))
.client(get(named(AndroidCommonDITags.WEB3MODAL_OKHTTP)))
.addConverterFactory(MoshiConverterFactory.create(get(named(AndroidCommonDITags.MOSHI))))
.addConverterFactory(MoshiConverterFactory.create(get<Moshi.Builder>(named(AndroidCommonDITags.MOSHI)).build()))
.build()
}

single { get<Retrofit>(named(AndroidCommonDITags.PULSE_RETROFIT)).create(PulseService::class.java) }

single {
SendModalCreatedUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendClickAllWalletsUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendClickGetWalletUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
get<Retrofit>(named(AndroidCommonDITags.PULSE_RETROFIT)).create(PulseService::class.java)
}

single {
SendClickWalletHelpUseCase(
single<SendEventInterface> {
SendEventUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendClickNetworkHelpUseCase(
SendBatchEventUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
telemetryEnabled = get<TelemetryEnabled>(named(AndroidCommonDITags.TELEMETRY_ENABLED)),
eventsRepository = get(),
)
}

single {
SendClickNetworksUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendConnectErrorUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendConnectSuccessUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendDisconnectErrorUseCase(
pulseService = get(),
InsertEventUseCase(
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendDisconnectSuccessUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendModalCloseUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

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

single {
SendModalOpenUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendSelectWalletUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
)
}

single {
SendSwitchNetworkUseCase(
pulseService = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
bundleId = bundleId
eventsRepository = get(),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.walletconnect.android.internal.common.model

@JvmInline
value class TelemetryEnabled(val value: Boolean)
Loading

0 comments on commit 874f57c

Please sign in to comment.