Skip to content

Commit

Permalink
move crash reporting to core module
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-rdx committed Jan 10, 2024
1 parent b02b1d3 commit 8ff29bc
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 17 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {
id 'kotlinx-serialization'
id 'kotlin-parcelize'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}

apply from: "$rootDir/config/jacoco.gradle"
Expand Down Expand Up @@ -208,7 +207,6 @@ dependencies {
//Timber
implementation libs.timber

implementation libs.firebaseCrashlytics
// ML Kit
implementation libs.barcode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import com.babylon.wallet.android.presentation.dapp.authorized.selectpersona.toU
import com.babylon.wallet.android.presentation.model.getPersonaDataForFieldKinds
import com.babylon.wallet.android.utils.AppEvent
import com.babylon.wallet.android.utils.AppEventBus
import com.babylon.wallet.android.utils.logNonFatalException
import com.babylon.wallet.android.utils.toISO8601String
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import rdx.works.core.logNonFatalException
import rdx.works.profile.data.model.pernetwork.Network
import rdx.works.profile.data.model.pernetwork.Network.AuthorizedDapp.AuthorizedPersonaSimple
import rdx.works.profile.data.model.pernetwork.PersonaData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import com.babylon.wallet.android.presentation.dapp.authorized.selectpersona.toU
import com.babylon.wallet.android.presentation.model.toPersonaData
import com.babylon.wallet.android.utils.AppEvent
import com.babylon.wallet.android.utils.AppEventBus
import com.babylon.wallet.android.utils.logNonFatalException
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import rdx.works.core.logNonFatalException
import rdx.works.profile.data.model.pernetwork.Network
import rdx.works.profile.data.model.pernetwork.PersonaData
import rdx.works.profile.domain.GetProfileUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import com.babylon.wallet.android.BuildConfig
import com.babylon.wallet.android.presentation.common.StateViewModel
import com.babylon.wallet.android.presentation.common.UiState
import com.babylon.wallet.android.presentation.settings.SettingsItem
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.persistentSetOf
Expand All @@ -15,6 +13,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import rdx.works.core.deleteCrashlyticsUnsentReports
import rdx.works.core.enableCrashlytics
import rdx.works.core.mapWhen
import rdx.works.core.preferences.PreferencesManager
import rdx.works.profile.domain.GetProfileUseCase
Expand Down Expand Up @@ -55,9 +55,9 @@ class AppSettingsViewModel @Inject constructor(
viewModelScope.launch {
preferencesManager.isCrashReportingEnabled.collect { enabled ->
if (enabled) {
Firebase.crashlytics.deleteUnsentReports()
deleteCrashlyticsUnsentReports()
}
Firebase.crashlytics.setCrashlyticsCollectionEnabled(enabled)
enableCrashlytics(enabled)
_state.updateSetting<SettingsItem.AppSettingsItem.CrashReporting> {
SettingsItem.AppSettingsItem.CrashReporting(enabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import com.babylon.wallet.android.presentation.transaction.TransactionReviewView
import com.babylon.wallet.android.utils.AppEvent
import com.babylon.wallet.android.utils.AppEventBus
import com.babylon.wallet.android.utils.ExceptionMessageProvider
import com.babylon.wallet.android.utils.logNonFatalException
import com.radixdlt.ret.TransactionManifest
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import rdx.works.core.logNonFatalException
import rdx.works.profile.derivation.model.NetworkId
import rdx.works.profile.domain.gateway.GetCurrentGatewayUseCase
import timber.log.Timber
Expand Down

This file was deleted.

2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'kotlinx-serialization'
id 'com.google.firebase.crashlytics'
}

android {
Expand Down Expand Up @@ -39,6 +40,7 @@ dependencies {
implementation libs.ktorCore
implementation libs.zxing
implementation libs.kotlinxSerialization
implementation libs.firebaseCrashlytics

// Datastore
implementation libs.datastorePreferences
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/rdx/works/core/CrashlyticsExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package rdx.works.core

import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase

fun logNonFatalException(throwable: Throwable) {
Firebase.crashlytics.recordException(throwable)
}

fun deleteCrashlyticsUnsentReports() {
Firebase.crashlytics.deleteUnsentReports()
}

fun enableCrashlytics(enabled: Boolean) {
Firebase.crashlytics.setCrashlyticsCollectionEnabled(enabled)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.flow.retryWhen
import rdx.works.core.KeySpec
import rdx.works.core.decrypt
import rdx.works.core.encrypt
import rdx.works.core.logNonFatalException
import rdx.works.profile.di.ProfileDataStore
import rdx.works.profile.di.coroutines.IoDispatcher
import rdx.works.profile.domain.ProfileException
Expand Down Expand Up @@ -137,6 +138,7 @@ class EncryptedPreferencesManager @Inject constructor(

private fun Flow<Preferences>.catchIOException() = catch { exception ->
if (exception is IOException) {
logNonFatalException(exception)
emit(emptyPreferences())
} else {
throw exception
Expand Down

0 comments on commit 8ff29bc

Please sign in to comment.