From bffd5e6583384cfcd5a86391f626863c0aa8ece2 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 13:06:46 +0200 Subject: [PATCH 01/12] added mapping from sargon SecurityProblem to Android domain SecurityProblem --- .../android/domain/model/SecurityProblem.kt | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/babylon/wallet/android/domain/model/SecurityProblem.kt b/app/src/main/java/com/babylon/wallet/android/domain/model/SecurityProblem.kt index 0ecdbe8697..65c06a0290 100644 --- a/app/src/main/java/com/babylon/wallet/android/domain/model/SecurityProblem.kt +++ b/app/src/main/java/com/babylon/wallet/android/domain/model/SecurityProblem.kt @@ -4,6 +4,7 @@ package com.babylon.wallet.android.domain.model // https://radixdlt.atlassian.net/wiki/spaces/AT/pages/3392569357/Security-related+Problem+States+in+the+Wallet sealed interface SecurityProblem { + // security problem 3 data class EntitiesNotRecoverable( val accountsNeedBackup: Int, val personasNeedBackup: Int, @@ -11,16 +12,20 @@ sealed interface SecurityProblem { val hiddenPersonasNeedBackup: Int ) : SecurityProblem - data class SeedPhraseNeedRecovery(val isAnyActivePersonaAffected: Boolean) : SecurityProblem - sealed interface CloudBackupNotWorking : SecurityProblem { + // security problem 5 data class ServiceError(val isAnyActivePersonaAffected: Boolean) : CloudBackupNotWorking + + // security problem 6 & 7 data class Disabled( val isAnyActivePersonaAffected: Boolean, val hasManualBackup: Boolean ) : CloudBackupNotWorking } + // security problem 9 + data class SeedPhraseNeedRecovery(val isAnyActivePersonaAffected: Boolean) : SecurityProblem + val hasCloudBackupProblems: Boolean get() = when (this) { is CloudBackupNotWorking.Disabled -> true @@ -36,3 +41,41 @@ sealed interface SecurityProblem { is CloudBackupNotWorking -> false } } + +fun com.radixdlt.sargon.SecurityProblem.toDomainModel( + isAnyActivePersonaAffected: Boolean, + hasManualBackup: Boolean +): SecurityProblem { + return when (this) { + is com.radixdlt.sargon.SecurityProblem.Problem3 -> { + SecurityProblem.EntitiesNotRecoverable( + accountsNeedBackup = this.addresses.accounts.count(), + personasNeedBackup = this.addresses.personas.count(), + hiddenAccountsNeedBackup = this.addresses.hiddenAccounts.count(), + hiddenPersonasNeedBackup = this.addresses.hiddenPersonas.count() + ) + } + com.radixdlt.sargon.SecurityProblem.Problem5 -> { + SecurityProblem.CloudBackupNotWorking.ServiceError( + isAnyActivePersonaAffected = isAnyActivePersonaAffected + ) + } + com.radixdlt.sargon.SecurityProblem.Problem6 -> { + SecurityProblem.CloudBackupNotWorking.Disabled( + isAnyActivePersonaAffected = isAnyActivePersonaAffected, + hasManualBackup = hasManualBackup + ) + } + com.radixdlt.sargon.SecurityProblem.Problem7 -> { + SecurityProblem.CloudBackupNotWorking.Disabled( + isAnyActivePersonaAffected = isAnyActivePersonaAffected, + hasManualBackup = hasManualBackup + ) + } + is com.radixdlt.sargon.SecurityProblem.Problem9 -> { + SecurityProblem.SeedPhraseNeedRecovery( + isAnyActivePersonaAffected = this.addresses.personas.isNotEmpty() + ) + } + } +} From e51e774e6085ca3995ed7d077fa79e0eb854f2f1 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 13:07:59 +0200 Subject: [PATCH 02/12] refactored GetSecurityProblemsUseCase to get security problems from sargon --- .../usecases/GetSecurityProblemsUseCase.kt | 81 ----------- .../GetSecurityProblemsUseCase.kt | 127 ++++++++++++++++++ 2 files changed, 127 insertions(+), 81 deletions(-) delete mode 100644 app/src/main/java/com/babylon/wallet/android/domain/usecases/GetSecurityProblemsUseCase.kt create mode 100644 app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt diff --git a/app/src/main/java/com/babylon/wallet/android/domain/usecases/GetSecurityProblemsUseCase.kt b/app/src/main/java/com/babylon/wallet/android/domain/usecases/GetSecurityProblemsUseCase.kt deleted file mode 100644 index 55140e0d37..0000000000 --- a/app/src/main/java/com/babylon/wallet/android/domain/usecases/GetSecurityProblemsUseCase.kt +++ /dev/null @@ -1,81 +0,0 @@ -package com.babylon.wallet.android.domain.usecases - -import com.babylon.wallet.android.domain.model.SecurityProblem -import com.radixdlt.sargon.extensions.ProfileEntity -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine -import rdx.works.core.domain.cloudbackup.BackupState -import rdx.works.core.sargon.factorSourceId -import rdx.works.core.sargon.isHidden -import rdx.works.core.sargon.isNotHidden -import rdx.works.profile.domain.backup.GetBackupStateUseCase -import javax.inject.Inject - -class GetSecurityProblemsUseCase @Inject constructor( - private val getEntitiesWithSecurityPromptUseCase: GetEntitiesWithSecurityPromptUseCase, - private val getBackupStateUseCase: GetBackupStateUseCase -) { - - operator fun invoke(): Flow> = combine( - getEntitiesWithSecurityPromptUseCase(), - getBackupStateUseCase() - ) { entitiesWithSecurityPrompts, cloudBackupState -> - // personas that need cloud backup - val personasNeedCloudBackup = entitiesWithSecurityPrompts - .filter { it.entity is ProfileEntity.PersonaEntity } - .filter { - it.prompts.contains(SecurityPromptType.CONFIGURATION_BACKUP_PROBLEM) || - it.prompts.contains(SecurityPromptType.WALLET_NOT_RECOVERABLE) || - it.prompts.contains(SecurityPromptType.CONFIGURATION_BACKUP_NOT_UPDATED) - } - val activePersonasNeedCloudBackup = personasNeedCloudBackup.count { it.entity.isNotHidden() } - - // entities that need to write down seed phrase - val entitiesNeedingBackup = entitiesWithSecurityPrompts.filter { it.prompts.contains(SecurityPromptType.WRITE_DOWN_SEED_PHRASE) } - val factorSourceIdsNeedBackup = entitiesNeedingBackup.map { it.entity.securityState.factorSourceId }.toSet() - - // entities that need recovery - val entitiesNeedingRecovery = entitiesWithSecurityPrompts.filter { it.prompts.contains(SecurityPromptType.RECOVERY_REQUIRED) } - val factorSourceIdsNeedRecovery = entitiesNeedingRecovery.map { it.entity.securityState.factorSourceId } - val isAnyActivePersonaNeedRecovery = entitiesNeedingRecovery.any { - it.entity is ProfileEntity.PersonaEntity && it.entity.isNotHidden() - } - - mutableSetOf().apply { - // entities that need cloud backup - if (cloudBackupState is BackupState.CloudBackupDisabled && cloudBackupState.isNotUpdated) { - add( - SecurityProblem.CloudBackupNotWorking.Disabled( - isAnyActivePersonaAffected = activePersonasNeedCloudBackup > 0, - hasManualBackup = cloudBackupState.lastManualBackupTime != null - ) - ) - } else if (cloudBackupState is BackupState.CloudBackupEnabled && cloudBackupState.hasAnyErrors) { - add(SecurityProblem.CloudBackupNotWorking.ServiceError(isAnyActivePersonaAffected = activePersonasNeedCloudBackup > 0)) - } - - // entities that need to write down seed phrase - val accountsNeedBackup = entitiesNeedingBackup.filter { - it.entity is ProfileEntity.AccountEntity && factorSourceIdsNeedBackup.contains(it.entity.securityState.factorSourceId) - } - val personasNeedBackup = entitiesNeedingBackup.filter { - it.entity is ProfileEntity.PersonaEntity && factorSourceIdsNeedBackup.contains(it.entity.securityState.factorSourceId) - } - if (factorSourceIdsNeedBackup.isNotEmpty()) { - add( - SecurityProblem.EntitiesNotRecoverable( - accountsNeedBackup = accountsNeedBackup.count { it.entity.isNotHidden() }, - personasNeedBackup = personasNeedBackup.count { it.entity.isNotHidden() }, - hiddenAccountsNeedBackup = accountsNeedBackup.count { it.entity.isHidden() }, - hiddenPersonasNeedBackup = personasNeedBackup.count { it.entity.isHidden() } - ) - ) - } - - // entities that need recovery - if (factorSourceIdsNeedRecovery.isNotEmpty()) { - add(SecurityProblem.SeedPhraseNeedRecovery(isAnyActivePersonaAffected = isAnyActivePersonaNeedRecovery)) - } - }.toSet() - } -} diff --git a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt new file mode 100644 index 0000000000..942c8c8586 --- /dev/null +++ b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt @@ -0,0 +1,127 @@ +package com.babylon.wallet.android.domain.usecases.securityproblems + +import com.babylon.wallet.android.domain.model.SecurityProblem +import com.babylon.wallet.android.domain.model.toDomainModel +import com.radixdlt.sargon.AddressesOfEntitiesInBadState +import com.radixdlt.sargon.BackupResult +import com.radixdlt.sargon.CheckSecurityProblemsInput +import com.radixdlt.sargon.extensions.ProfileEntity +import com.radixdlt.sargon.os.SargonOsManager +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.combine +import rdx.works.core.domain.cloudbackup.BackupState +import rdx.works.core.sargon.factorSourceId +import rdx.works.core.sargon.isNotHidden +import rdx.works.profile.domain.backup.GetBackupStateUseCase +import javax.inject.Inject + +class GetSecurityProblemsUseCase @Inject constructor( + private val getEntitiesWithSecurityPromptUseCase: GetEntitiesWithSecurityPromptUseCase, + private val getBackupStateUseCase: GetBackupStateUseCase, + private val sargonOsManager: SargonOsManager +) { + + operator fun invoke(): Flow> = combine( + getEntitiesWithSecurityPromptUseCase(), + getBackupStateUseCase() + ) { entitiesWithSecurityPrompts, backupState -> + + // active personas that need cloud backup + val activePersonasNeedCloudBackup = entitiesWithSecurityPrompts + .count { entityWithSecurityPrompt -> + entityWithSecurityPrompt.entity.isNotHidden() && + entityWithSecurityPrompt.entity is ProfileEntity.PersonaEntity && + ( + entityWithSecurityPrompt.prompts.contains(SecurityPromptType.CONFIGURATION_BACKUP_PROBLEM) || + entityWithSecurityPrompt.prompts.contains(SecurityPromptType.WALLET_NOT_RECOVERABLE) || + entityWithSecurityPrompt.prompts.contains(SecurityPromptType.CONFIGURATION_BACKUP_NOT_UPDATED) + ) + } + + sargonOsManager.sargonOs.checkSecurityProblems( + input = CheckSecurityProblemsInput( + isCloudProfileSyncEnabled = backupState.isCloudBackupEnabled, + unrecoverableEntities = findUnrecoverableEntities(entitiesWithSecurityPrompts), + withoutControlEntities = findWithoutControlEntities(entitiesWithSecurityPrompts), + lastCloudBackup = BackupResult( + saveIdentifier = "string", + isCurrent = backupState.isCloudBackupSynced, + isFailed = backupState is BackupState.CloudBackupEnabled && backupState.hasAnyErrors + ), + lastManualBackup = BackupResult( + saveIdentifier = "string", + isCurrent = backupState.isManualBackupSynced, + isFailed = false, + ) + ) + ).map { sargonSecurityProblem -> + sargonSecurityProblem.toDomainModel( + isAnyActivePersonaAffected = activePersonasNeedCloudBackup > 0, + hasManualBackup = backupState.lastManualBackupTime != null + ) + }.toSet() + } + + private fun findUnrecoverableEntities(entitiesWithSecurityPrompts: List): AddressesOfEntitiesInBadState { + // entities that need to write down seed phrase + val entitiesNeedBackup = entitiesWithSecurityPrompts + .filter { entityWithSecurityPrompt -> + entityWithSecurityPrompt.prompts.contains(SecurityPromptType.WRITE_DOWN_SEED_PHRASE) + } + val factorSourceIdsNeedBackup = entitiesNeedBackup.map { entityWithSecurityPrompt -> + entityWithSecurityPrompt.entity.securityState.factorSourceId + }.toSet() + // not hidden and hidden accounts that need to write down seed phrase + val (activeAccountAddressesNeedBackup, hiddenAccountAddressesNeedBackup) = entitiesNeedBackup + .filter { entityWithSecurityPrompt -> + entityWithSecurityPrompt.entity is ProfileEntity.AccountEntity && + factorSourceIdsNeedBackup.contains(entityWithSecurityPrompt.entity.securityState.factorSourceId) + } + .map { entityWithSecurityPrompt -> entityWithSecurityPrompt.entity as ProfileEntity.AccountEntity } + .partition { accountEntity -> accountEntity.isNotHidden() } + .let { partitioned -> + partitioned.first.map { it.accountAddress } to partitioned.second.map { it.accountAddress } + } + // not hidden and hidden personas that need to write down seed phrase + val (activePersonaAddressesNeedBackup, hiddenPersonaAddressesNeedBackup) = entitiesNeedBackup + .filter { entityWithSecurityPrompt -> + entityWithSecurityPrompt.entity is ProfileEntity.PersonaEntity && + factorSourceIdsNeedBackup.contains(entityWithSecurityPrompt.entity.securityState.factorSourceId) + } + .map { entityWithSecurityPrompt -> entityWithSecurityPrompt.entity as ProfileEntity.PersonaEntity } + .partition { personaEntity -> personaEntity.isNotHidden() } + .let { partitioned -> + partitioned.first.map { it.identityAddress } to partitioned.second.map { it.identityAddress } + } + + return AddressesOfEntitiesInBadState( + accounts = activeAccountAddressesNeedBackup, + hiddenAccounts = hiddenAccountAddressesNeedBackup, + personas = activePersonaAddressesNeedBackup, + hiddenPersonas = hiddenPersonaAddressesNeedBackup + ) + } + + private fun findWithoutControlEntities(entitiesWithSecurityPrompts: List): AddressesOfEntitiesInBadState { + // entities that need recovery + val entitiesNeedRecovery = + entitiesWithSecurityPrompts.filter { it.prompts.contains(SecurityPromptType.RECOVERY_REQUIRED) } + val (activeEntitiesNeedRecovery, hiddenEntitiesNeedRecovery) = entitiesNeedRecovery + .partition { it.entity.isNotHidden() } + val activeAccountAddressesNeedRecovery = activeEntitiesNeedRecovery + .mapNotNull { (it.entity as? ProfileEntity.AccountEntity)?.accountAddress } + val activePersonaAddressesNeedRecovery = activeEntitiesNeedRecovery + .mapNotNull { (it.entity as? ProfileEntity.PersonaEntity)?.identityAddress } + val hiddenAccountAddressesNeedRecovery = hiddenEntitiesNeedRecovery + .mapNotNull { (it.entity as? ProfileEntity.AccountEntity)?.accountAddress } + val hiddenPersonaAddressesNeedRecovery = hiddenEntitiesNeedRecovery + .mapNotNull { (it.entity as? ProfileEntity.PersonaEntity)?.identityAddress } + + return AddressesOfEntitiesInBadState( + accounts = activeAccountAddressesNeedRecovery, + hiddenAccounts = hiddenAccountAddressesNeedRecovery, + personas = activePersonaAddressesNeedRecovery, + hiddenPersonas = hiddenPersonaAddressesNeedRecovery + ) + } +} From 8b88ccddb270f11966dd8a49202945639e7a0bcd Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 13:08:55 +0200 Subject: [PATCH 03/12] added two new properties in BackupState --- .../works/core/domain/cloudbackup/BackupState.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/rdx/works/core/domain/cloudbackup/BackupState.kt b/core/src/main/java/rdx/works/core/domain/cloudbackup/BackupState.kt index 849fbb6961..77451138c0 100644 --- a/core/src/main/java/rdx/works/core/domain/cloudbackup/BackupState.kt +++ b/core/src/main/java/rdx/works/core/domain/cloudbackup/BackupState.kt @@ -59,6 +59,20 @@ sealed class BackupState { val isCloudBackupEnabled: Boolean get() = this is CloudBackupEnabled + val isCloudBackupSynced: Boolean + get() = if (lastModifiedProfileTime != null && lastCloudBackupTime != null) { + requireNotNull(lastModifiedProfileTime).isBefore(lastCloudBackupTime) + } else { + false + } + + val isManualBackupSynced: Boolean + get() = if (lastModifiedProfileTime != null && lastManualBackupTime != null) { + requireNotNull(lastModifiedProfileTime).toInstant().isBefore(lastManualBackupTime) + } else { + false + } + val isCloudBackupNotUpdated: Boolean get() { return when (this) { From ef786d6be0d56fc5c1d2fb4f1d34e2f592bf1de1 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 13:10:32 +0200 Subject: [PATCH 04/12] moved security related use cases in securityproblems package --- .../GetEntitiesWithSecurityPromptUseCase.kt | 2 +- .../wallet/android/presentation/account/AccountScreen.kt | 2 +- .../wallet/android/presentation/account/AccountTopBar.kt | 2 +- .../android/presentation/account/AccountViewModel.kt | 6 +++--- .../android/presentation/settings/SettingsViewModel.kt | 2 +- .../presentation/settings/personas/PersonasScreen.kt | 4 ++-- .../presentation/settings/personas/PersonasViewModel.kt | 7 ++++--- .../settings/securitycenter/SecurityCenterViewModel.kt | 2 +- .../securityfactors/SecurityFactorsViewModel.kt | 3 ++- .../troubleshooting/reset/FactoryResetViewModel.kt | 2 +- .../presentation/ui/composables/AccountPromptLabel.kt | 2 +- .../presentation/ui/composables/card/PersonaCard.kt | 2 +- .../wallet/android/presentation/wallet/AccountCardView.kt | 2 +- .../wallet/android/presentation/wallet/WalletScreen.kt | 2 +- .../wallet/android/presentation/wallet/WalletViewModel.kt | 6 +++--- .../usecases/GetEntitiesWithSecurityPromptUseCaseTest.kt | 3 +++ .../wallet/android/presentation/WalletViewModelTest.kt | 2 +- 17 files changed, 28 insertions(+), 23 deletions(-) rename app/src/main/java/com/babylon/wallet/android/domain/usecases/{ => securityproblems}/GetEntitiesWithSecurityPromptUseCase.kt (98%) diff --git a/app/src/main/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCase.kt b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt similarity index 98% rename from app/src/main/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCase.kt rename to app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt index 984e8846f1..7b761a9941 100644 --- a/app/src/main/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCase.kt +++ b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt @@ -1,4 +1,4 @@ -package com.babylon.wallet.android.domain.usecases +package com.babylon.wallet.android.domain.usecases.securityproblems import com.radixdlt.sargon.AddressOfAccountOrPersona import com.radixdlt.sargon.FactorSource diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountScreen.kt b/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountScreen.kt index c8ded21706..423a673efd 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountScreen.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountScreen.kt @@ -55,7 +55,7 @@ import com.babylon.wallet.android.designsystem.theme.gradient import com.babylon.wallet.android.designsystem.theme.plus import com.babylon.wallet.android.domain.model.assets.AccountWithAssets import com.babylon.wallet.android.domain.model.locker.AccountLockerDeposit -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.account.AccountViewModel.Event import com.babylon.wallet.android.presentation.account.AccountViewModel.State import com.babylon.wallet.android.presentation.dialogs.info.GlossaryItem diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountTopBar.kt b/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountTopBar.kt index a82b6497d8..b990de2c0b 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountTopBar.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountTopBar.kt @@ -28,7 +28,7 @@ import androidx.constraintlayout.compose.MotionScene import com.babylon.wallet.android.R import com.babylon.wallet.android.designsystem.composable.RadixSecondaryButton import com.babylon.wallet.android.designsystem.theme.RadixTheme -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.account.AccountViewModel.State import com.babylon.wallet.android.presentation.ui.composables.AccountPromptLabel import com.babylon.wallet.android.presentation.ui.composables.actionableaddress.ActionableAddressView diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountViewModel.kt index 2b0e9676c6..c6fe2aa088 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/account/AccountViewModel.kt @@ -8,14 +8,14 @@ import com.babylon.wallet.android.data.repository.tokenprice.FiatPriceRepository import com.babylon.wallet.android.di.coroutines.DefaultDispatcher import com.babylon.wallet.android.domain.model.assets.AccountWithAssets import com.babylon.wallet.android.domain.model.locker.AccountLockerDeposit -import com.babylon.wallet.android.domain.usecases.GetEntitiesWithSecurityPromptUseCase import com.babylon.wallet.android.domain.usecases.GetNetworkInfoUseCase -import com.babylon.wallet.android.domain.usecases.SecurityPromptType -import com.babylon.wallet.android.domain.usecases.accountPrompts import com.babylon.wallet.android.domain.usecases.assets.GetFiatValueUseCase import com.babylon.wallet.android.domain.usecases.assets.GetNextNFTsPageUseCase import com.babylon.wallet.android.domain.usecases.assets.GetWalletAssetsUseCase import com.babylon.wallet.android.domain.usecases.assets.UpdateLSUsInfo +import com.babylon.wallet.android.domain.usecases.securityproblems.GetEntitiesWithSecurityPromptUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.accountPrompts import com.babylon.wallet.android.domain.usecases.transaction.SendClaimRequestUseCase import com.babylon.wallet.android.presentation.account.delegates.AccountLockersDelegate import com.babylon.wallet.android.presentation.common.OneOffEvent diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/SettingsViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/SettingsViewModel.kt index 283d2fe2d1..5586150fcc 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/SettingsViewModel.kt @@ -5,7 +5,7 @@ import androidx.lifecycle.viewModelScope import com.babylon.wallet.android.BuildConfig.EXPERIMENTAL_FEATURES_ENABLED import com.babylon.wallet.android.di.coroutines.DefaultDispatcher import com.babylon.wallet.android.domain.model.SecurityProblem -import com.babylon.wallet.android.domain.usecases.GetSecurityProblemsUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.GetSecurityProblemsUseCase import com.babylon.wallet.android.presentation.settings.SettingsItem.TopLevelSettings.DebugSettings import com.babylon.wallet.android.presentation.settings.SettingsItem.TopLevelSettings.Personas import com.babylon.wallet.android.presentation.settings.SettingsItem.TopLevelSettings.Preferences diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasScreen.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasScreen.kt index dd2e60d176..40968d5c1b 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasScreen.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasScreen.kt @@ -26,8 +26,8 @@ import com.babylon.wallet.android.R import com.babylon.wallet.android.designsystem.composable.RadixSecondaryButton import com.babylon.wallet.android.designsystem.theme.RadixTheme import com.babylon.wallet.android.designsystem.theme.RadixWalletTheme -import com.babylon.wallet.android.domain.usecases.EntityWithSecurityPrompt -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.EntityWithSecurityPrompt +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.dialogs.info.GlossaryItem import com.babylon.wallet.android.presentation.settings.personas.PersonasViewModel.PersonasEvent import com.babylon.wallet.android.presentation.ui.composables.InfoButton diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt index 3d984db378..7b99888d06 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt @@ -1,9 +1,10 @@ package com.babylon.wallet.android.presentation.settings.personas import androidx.lifecycle.viewModelScope -import com.babylon.wallet.android.domain.usecases.EntityWithSecurityPrompt -import com.babylon.wallet.android.domain.usecases.GetEntitiesWithSecurityPromptUseCase -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.di.coroutines.DefaultDispatcher +import com.babylon.wallet.android.domain.usecases.securityproblems.EntityWithSecurityPrompt +import com.babylon.wallet.android.domain.usecases.securityproblems.GetEntitiesWithSecurityPromptUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.common.OneOffEvent import com.babylon.wallet.android.presentation.common.OneOffEventHandler import com.babylon.wallet.android.presentation.common.OneOffEventHandlerImpl diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/SecurityCenterViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/SecurityCenterViewModel.kt index 3efa6ae378..a3fa8270fd 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/SecurityCenterViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/SecurityCenterViewModel.kt @@ -3,7 +3,7 @@ package com.babylon.wallet.android.presentation.settings.securitycenter import androidx.lifecycle.viewModelScope import com.babylon.wallet.android.di.coroutines.DefaultDispatcher import com.babylon.wallet.android.domain.model.SecurityProblem -import com.babylon.wallet.android.domain.usecases.GetSecurityProblemsUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.GetSecurityProblemsUseCase import com.babylon.wallet.android.presentation.common.StateViewModel import com.babylon.wallet.android.presentation.common.UiState import dagger.hilt.android.lifecycle.HiltViewModel diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt index ce56ac8c55..afd567559a 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt @@ -1,7 +1,8 @@ package com.babylon.wallet.android.presentation.settings.securitycenter.securityfactors import androidx.lifecycle.viewModelScope -import com.babylon.wallet.android.domain.usecases.GetSecurityProblemsUseCase +import com.babylon.wallet.android.di.coroutines.DefaultDispatcher +import com.babylon.wallet.android.domain.usecases.securityproblems.GetSecurityProblemsUseCase import com.babylon.wallet.android.presentation.common.StateViewModel import com.babylon.wallet.android.presentation.common.UiState import com.babylon.wallet.android.presentation.settings.SettingsItem diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt index f2e9dafac4..2d69d8e5a3 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt @@ -3,7 +3,7 @@ package com.babylon.wallet.android.presentation.settings.troubleshooting.reset import androidx.lifecycle.viewModelScope import com.babylon.wallet.android.domain.model.SecurityProblem import com.babylon.wallet.android.domain.usecases.DeleteWalletUseCase -import com.babylon.wallet.android.domain.usecases.GetSecurityProblemsUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.GetSecurityProblemsUseCase import com.babylon.wallet.android.presentation.common.OneOffEvent import com.babylon.wallet.android.presentation.common.OneOffEventHandler import com.babylon.wallet.android.presentation.common.OneOffEventHandlerImpl diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/AccountPromptLabel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/AccountPromptLabel.kt index 15d6a3e095..ec83528b1a 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/AccountPromptLabel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/AccountPromptLabel.kt @@ -13,7 +13,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.babylon.wallet.android.designsystem.R import com.babylon.wallet.android.designsystem.theme.RadixTheme -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.ui.RadixWalletPreviewTheme import com.babylon.wallet.android.presentation.ui.modifier.applyIf import com.babylon.wallet.android.presentation.ui.modifier.throttleClickable diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/card/PersonaCard.kt b/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/card/PersonaCard.kt index 8d54c57e85..aae7d1d7b5 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/card/PersonaCard.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/ui/composables/card/PersonaCard.kt @@ -25,7 +25,7 @@ import androidx.compose.ui.unit.dp import com.babylon.wallet.android.R import com.babylon.wallet.android.designsystem.theme.RadixTheme import com.babylon.wallet.android.designsystem.theme.RadixWalletTheme -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.dapp.authorized.selectpersona.PersonaUiModel import com.babylon.wallet.android.presentation.ui.composables.PromptLabel import com.babylon.wallet.android.presentation.ui.composables.RadixRadioButton diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/wallet/AccountCardView.kt b/app/src/main/java/com/babylon/wallet/android/presentation/wallet/AccountCardView.kt index 0c4143ebd0..21b407bf52 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/wallet/AccountCardView.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/wallet/AccountCardView.kt @@ -27,7 +27,7 @@ import com.babylon.wallet.android.R import com.babylon.wallet.android.designsystem.theme.RadixTheme import com.babylon.wallet.android.designsystem.theme.gradient import com.babylon.wallet.android.domain.model.locker.AccountLockerDeposit -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.LocalBalanceVisibility import com.babylon.wallet.android.presentation.ui.RadixWalletPreviewTheme import com.babylon.wallet.android.presentation.ui.composables.AccountPromptLabel diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletScreen.kt b/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletScreen.kt index 1586190009..4e8371eafd 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletScreen.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletScreen.kt @@ -45,7 +45,7 @@ import com.babylon.wallet.android.designsystem.composable.RadixSecondaryButton import com.babylon.wallet.android.designsystem.theme.RadixTheme import com.babylon.wallet.android.domain.model.assets.AccountWithAssets import com.babylon.wallet.android.domain.model.locker.AccountLockerDeposit -import com.babylon.wallet.android.domain.usecases.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.presentation.ui.RadixWalletPreviewTheme import com.babylon.wallet.android.presentation.ui.composables.HomeCardsCarousel import com.babylon.wallet.android.presentation.ui.composables.RadixSnackbarHost diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletViewModel.kt index 89c02a4730..d8aa1cd7f7 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/wallet/WalletViewModel.kt @@ -10,11 +10,11 @@ import com.babylon.wallet.android.di.coroutines.DefaultDispatcher import com.babylon.wallet.android.domain.model.assets.AccountWithAssets import com.babylon.wallet.android.domain.model.locker.AccountLockerDeposit import com.babylon.wallet.android.domain.usecases.CheckDeletedAccountsOnLedgerUseCase -import com.babylon.wallet.android.domain.usecases.GetEntitiesWithSecurityPromptUseCase -import com.babylon.wallet.android.domain.usecases.SecurityPromptType -import com.babylon.wallet.android.domain.usecases.accountPrompts import com.babylon.wallet.android.domain.usecases.assets.GetFiatValueUseCase import com.babylon.wallet.android.domain.usecases.assets.GetWalletAssetsUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.GetEntitiesWithSecurityPromptUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType +import com.babylon.wallet.android.domain.usecases.securityproblems.accountPrompts import com.babylon.wallet.android.presentation.common.OneOffEvent import com.babylon.wallet.android.presentation.common.OneOffEventHandler import com.babylon.wallet.android.presentation.common.OneOffEventHandlerImpl diff --git a/app/src/test/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCaseTest.kt b/app/src/test/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCaseTest.kt index 862eb3bd56..abcc763744 100644 --- a/app/src/test/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCaseTest.kt +++ b/app/src/test/java/com/babylon/wallet/android/domain/usecases/GetEntitiesWithSecurityPromptUseCaseTest.kt @@ -1,5 +1,8 @@ package com.babylon.wallet.android.domain.usecases +import com.babylon.wallet.android.domain.usecases.securityproblems.EntityWithSecurityPrompt +import com.babylon.wallet.android.domain.usecases.securityproblems.GetEntitiesWithSecurityPromptUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.SecurityPromptType import com.babylon.wallet.android.fakes.FakePreferenceManager import com.babylon.wallet.android.fakes.FakeProfileRepository import com.babylon.wallet.android.presentation.TestDispatcherRule diff --git a/app/src/test/java/com/babylon/wallet/android/presentation/WalletViewModelTest.kt b/app/src/test/java/com/babylon/wallet/android/presentation/WalletViewModelTest.kt index 32332ecd62..cae00dae27 100644 --- a/app/src/test/java/com/babylon/wallet/android/presentation/WalletViewModelTest.kt +++ b/app/src/test/java/com/babylon/wallet/android/presentation/WalletViewModelTest.kt @@ -9,7 +9,7 @@ import com.babylon.wallet.android.data.repository.locker.AccountLockersRepositor import com.babylon.wallet.android.data.repository.p2plink.P2PLinksRepository import com.babylon.wallet.android.domain.model.assets.AccountWithAssets import com.babylon.wallet.android.domain.usecases.CheckDeletedAccountsOnLedgerUseCase -import com.babylon.wallet.android.domain.usecases.GetEntitiesWithSecurityPromptUseCase +import com.babylon.wallet.android.domain.usecases.securityproblems.GetEntitiesWithSecurityPromptUseCase import com.babylon.wallet.android.domain.usecases.assets.GetFiatValueUseCase import com.babylon.wallet.android.domain.usecases.assets.GetWalletAssetsUseCase import com.babylon.wallet.android.domain.utils.AccountLockersObserver From f686638a105d283ade347801da1373e92ae0f9b3 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 13:11:10 +0200 Subject: [PATCH 05/12] added default dispatchers in viewmodels for GetSecurityProblemsUseCase --- .../settings/personas/PersonasViewModel.kt | 9 ++++++-- .../SecurityFactorsViewModel.kt | 12 ++++++---- .../reset/FactoryResetViewModel.kt | 23 ++++++++++++------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt index 7b99888d06..278d97d22a 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt @@ -17,8 +17,10 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch @@ -32,7 +34,8 @@ import javax.inject.Inject class PersonasViewModel @Inject constructor( private val getProfileUseCase: GetProfileUseCase, private val preferencesManager: PreferencesManager, - private val getEntitiesWithSecurityPromptUseCase: GetEntitiesWithSecurityPromptUseCase + private val getEntitiesWithSecurityPromptUseCase: GetEntitiesWithSecurityPromptUseCase, + @DefaultDispatcher defaultDispatcher: CoroutineDispatcher ) : StateViewModel(), OneOffEventHandler by OneOffEventHandlerImpl() { @@ -52,7 +55,9 @@ class PersonasViewModel @Inject constructor( babylonFactorSource = babylonFactorSource ) } - }.collect {} + } + .flowOn(defaultDispatcher) + .collect {} } } diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt index afd567559a..a694ad0f56 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/securitycenter/securityfactors/SecurityFactorsViewModel.kt @@ -10,7 +10,9 @@ import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.persistentSetOf import kotlinx.collections.immutable.toPersistentSet +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import rdx.works.core.sargon.deviceFactorSources @@ -18,11 +20,11 @@ import rdx.works.core.sargon.ledgerFactorSources import rdx.works.profile.domain.GetProfileUseCase import javax.inject.Inject -@Suppress("MagicNumber") @HiltViewModel class SecurityFactorsViewModel @Inject constructor( private val getProfileUseCase: GetProfileUseCase, - private val getSecurityProblemsUseCase: GetSecurityProblemsUseCase + private val getSecurityProblemsUseCase: GetSecurityProblemsUseCase, + @DefaultDispatcher defaultDispatcher: CoroutineDispatcher ) : StateViewModel() { override fun initialState(): SecurityFactorsUiState = SecurityFactorsUiState( @@ -49,9 +51,11 @@ class SecurityFactorsViewModel @Inject constructor( SettingsItem.SecurityFactorsSettingsItem.LedgerHardwareWallets(ledgerFactorSources.size) ) ) - }.collect { securityFactorsUiState -> - _state.update { securityFactorsUiState } } + .flowOn(defaultDispatcher) + .collect { securityFactorsUiState -> + _state.update { securityFactorsUiState } + } } } } diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt index 2d69d8e5a3..f676305a7d 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/troubleshooting/reset/FactoryResetViewModel.kt @@ -1,6 +1,7 @@ package com.babylon.wallet.android.presentation.settings.troubleshooting.reset import androidx.lifecycle.viewModelScope +import com.babylon.wallet.android.di.coroutines.DefaultDispatcher import com.babylon.wallet.android.domain.model.SecurityProblem import com.babylon.wallet.android.domain.usecases.DeleteWalletUseCase import com.babylon.wallet.android.domain.usecases.securityproblems.GetSecurityProblemsUseCase @@ -11,7 +12,9 @@ import com.babylon.wallet.android.presentation.common.StateViewModel import com.babylon.wallet.android.presentation.common.UiMessage import com.babylon.wallet.android.presentation.common.UiState import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Job +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import javax.inject.Inject @@ -19,8 +22,10 @@ import javax.inject.Inject @HiltViewModel class FactoryResetViewModel @Inject constructor( private val deleteWalletUseCase: DeleteWalletUseCase, - private val getSecurityProblemsUseCase: GetSecurityProblemsUseCase -) : StateViewModel(), OneOffEventHandler by OneOffEventHandlerImpl() { + private val getSecurityProblemsUseCase: GetSecurityProblemsUseCase, + @DefaultDispatcher defaultDispatcher: CoroutineDispatcher +) : StateViewModel(), + OneOffEventHandler by OneOffEventHandlerImpl() { private var securityProblemsJob: Job? = null @@ -28,13 +33,15 @@ class FactoryResetViewModel @Inject constructor( init { securityProblemsJob = viewModelScope.launch { - getSecurityProblemsUseCase().collect { problems -> - _state.update { state -> - state.copy( - securityProblems = problems - ) + getSecurityProblemsUseCase() + .flowOn(defaultDispatcher) + .collect { problems -> + _state.update { state -> + state.copy( + securityProblems = problems + ) + } } - } } } From a1e89b4f26105dd99c4778b9cd7c381fe6f395fc Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 13:11:24 +0200 Subject: [PATCH 06/12] documentation --- .../GetEntitiesWithSecurityPromptUseCase.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt index 7b761a9941..c51bb29178 100644 --- a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt +++ b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetEntitiesWithSecurityPromptUseCase.kt @@ -96,9 +96,9 @@ fun List.personaPrompts() = mapNotNull { }.associate { it } enum class SecurityPromptType { - WRITE_DOWN_SEED_PHRASE, - RECOVERY_REQUIRED, - CONFIGURATION_BACKUP_PROBLEM, - WALLET_NOT_RECOVERABLE, - CONFIGURATION_BACKUP_NOT_UPDATED + WRITE_DOWN_SEED_PHRASE, // security problem 3 + RECOVERY_REQUIRED, // security problem 9 + CONFIGURATION_BACKUP_PROBLEM, // security problem 5 + WALLET_NOT_RECOVERABLE, // security problem 6 + CONFIGURATION_BACKUP_NOT_UPDATED // security problem 7 } From 00bbdeff9a19b0e3f61dcfab5aef891d698e68f8 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Fri, 6 Dec 2024 16:47:11 +0200 Subject: [PATCH 07/12] collect, not collect --- .../presentation/settings/personas/PersonasViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt index 278d97d22a..de5de6f88e 100644 --- a/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt +++ b/app/src/main/java/com/babylon/wallet/android/presentation/settings/personas/PersonasViewModel.kt @@ -18,6 +18,7 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOn @@ -57,7 +58,7 @@ class PersonasViewModel @Inject constructor( } } .flowOn(defaultDispatcher) - .collect {} + .collect() } } From 211e801900c2af37e4dcd3368a466ca54e2cb712 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Mon, 9 Dec 2024 10:45:57 +0200 Subject: [PATCH 08/12] added catch in GetSecurityProblemsUseCase --- .../usecases/securityproblems/GetSecurityProblemsUseCase.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt index 942c8c8586..3e2207c9bb 100644 --- a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt +++ b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt @@ -8,11 +8,13 @@ import com.radixdlt.sargon.CheckSecurityProblemsInput import com.radixdlt.sargon.extensions.ProfileEntity import com.radixdlt.sargon.os.SargonOsManager import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.combine import rdx.works.core.domain.cloudbackup.BackupState import rdx.works.core.sargon.factorSourceId import rdx.works.core.sargon.isNotHidden import rdx.works.profile.domain.backup.GetBackupStateUseCase +import timber.log.Timber import javax.inject.Inject class GetSecurityProblemsUseCase @Inject constructor( @@ -60,6 +62,8 @@ class GetSecurityProblemsUseCase @Inject constructor( hasManualBackup = backupState.lastManualBackupTime != null ) }.toSet() + }.catch { exception -> + Timber.e("failed to get security problems: $exception") } private fun findUnrecoverableEntities(entitiesWithSecurityPrompts: List): AddressesOfEntitiesInBadState { From d86bd2a355b056f3fc1cd5e593660702c9b60a3f Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Mon, 9 Dec 2024 10:46:10 +0200 Subject: [PATCH 09/12] updated sargon lib to latest --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f38e99387a..98c1f47bd3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ hiltNavigation = "1.2.0" biometricKtx = "1.2.0-alpha05" coilCompose = "2.6.0" kotlinxSerialization = "1.6.2" -sargon = "1.1.71-61bf5039" +sargon = "1.1.76-f88548ec" okhttpBom = "5.0.0-alpha.12" retrofit = "2.11.0" retrofitKoltinxConverter = "1.0.0" From 3bb6d6ef60bdf43d10950a6fda060f0a91d029a3 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Mon, 9 Dec 2024 13:04:13 +0200 Subject: [PATCH 10/12] added an HostInteractor stub --- .../main/java/rdx/works/core/di/CoreModule.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/src/main/java/rdx/works/core/di/CoreModule.kt b/core/src/main/java/rdx/works/core/di/CoreModule.kt index 3cdb953041..1fcee442ed 100644 --- a/core/src/main/java/rdx/works/core/di/CoreModule.kt +++ b/core/src/main/java/rdx/works/core/di/CoreModule.kt @@ -4,6 +4,14 @@ import android.content.Context import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences import com.radixdlt.sargon.Bios +import com.radixdlt.sargon.CommonException +import com.radixdlt.sargon.HostInteractor +import com.radixdlt.sargon.KeyDerivationRequest +import com.radixdlt.sargon.KeyDerivationResponse +import com.radixdlt.sargon.SignRequestOfSubintent +import com.radixdlt.sargon.SignRequestOfTransactionIntent +import com.radixdlt.sargon.SignWithFactorsOutcomeOfSubintentHash +import com.radixdlt.sargon.SignWithFactorsOutcomeOfTransactionIntentHash import com.radixdlt.sargon.os.SargonOsManager import com.radixdlt.sargon.os.driver.AndroidEventBusDriver import com.radixdlt.sargon.os.driver.AndroidProfileStateChangeDriver @@ -76,7 +84,23 @@ object CoreProvider { @DefaultDispatcher defaultDispatcher: CoroutineDispatcher ): SargonOsManager = SargonOsManager.factory( bios = bios, + hostInteractor = HostInteractorStub(), applicationScope = applicationScope, defaultDispatcher = defaultDispatcher ) } + +private class HostInteractorStub : HostInteractor { + + override suspend fun deriveKeys(request: KeyDerivationRequest): KeyDerivationResponse { + throw CommonException.Unknown() + } + + override suspend fun signSubintents(request: SignRequestOfSubintent): SignWithFactorsOutcomeOfSubintentHash { + throw CommonException.Unknown() + } + + override suspend fun signTransactions(request: SignRequestOfTransactionIntent): SignWithFactorsOutcomeOfTransactionIntentHash { + throw CommonException.Unknown() + } +} From e7e74277032e4b54285784957289738b2dc32053 Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Tue, 10 Dec 2024 14:52:12 +0200 Subject: [PATCH 11/12] removed saveIdentifier from BackupResult and updated sargon lib --- .../usecases/securityproblems/GetSecurityProblemsUseCase.kt | 2 -- gradle/libs.versions.toml | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt index 3e2207c9bb..b2fa983ebb 100644 --- a/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt +++ b/app/src/main/java/com/babylon/wallet/android/domain/usecases/securityproblems/GetSecurityProblemsUseCase.kt @@ -46,12 +46,10 @@ class GetSecurityProblemsUseCase @Inject constructor( unrecoverableEntities = findUnrecoverableEntities(entitiesWithSecurityPrompts), withoutControlEntities = findWithoutControlEntities(entitiesWithSecurityPrompts), lastCloudBackup = BackupResult( - saveIdentifier = "string", isCurrent = backupState.isCloudBackupSynced, isFailed = backupState is BackupState.CloudBackupEnabled && backupState.hasAnyErrors ), lastManualBackup = BackupResult( - saveIdentifier = "string", isCurrent = backupState.isManualBackupSynced, isFailed = false, ) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 98c1f47bd3..a120e05e2d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ hiltNavigation = "1.2.0" biometricKtx = "1.2.0-alpha05" coilCompose = "2.6.0" kotlinxSerialization = "1.6.2" -sargon = "1.1.76-f88548ec" +sargon = "1.1.80-723d183d" okhttpBom = "5.0.0-alpha.12" retrofit = "2.11.0" retrofitKoltinxConverter = "1.0.0" From 4262e639a06bbfbda3f828e4389f7b382d2a679f Mon Sep 17 00:00:00 2001 From: "giannis.tsepas" Date: Tue, 10 Dec 2024 14:53:14 +0200 Subject: [PATCH 12/12] updated HostInteractorStub with new implementation --- core/src/main/java/rdx/works/core/di/CoreModule.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/src/main/java/rdx/works/core/di/CoreModule.kt b/core/src/main/java/rdx/works/core/di/CoreModule.kt index 1fcee442ed..be568341b1 100644 --- a/core/src/main/java/rdx/works/core/di/CoreModule.kt +++ b/core/src/main/java/rdx/works/core/di/CoreModule.kt @@ -3,6 +3,8 @@ package rdx.works.core.di import android.content.Context import androidx.datastore.core.DataStore import androidx.datastore.preferences.core.Preferences +import com.radixdlt.sargon.AuthenticationSigningRequest +import com.radixdlt.sargon.AuthenticationSigningResponse import com.radixdlt.sargon.Bios import com.radixdlt.sargon.CommonException import com.radixdlt.sargon.HostInteractor @@ -96,6 +98,10 @@ private class HostInteractorStub : HostInteractor { throw CommonException.Unknown() } + override suspend fun signAuth(request: AuthenticationSigningRequest): AuthenticationSigningResponse { + throw CommonException.Unknown() + } + override suspend fun signSubintents(request: SignRequestOfSubintent): SignWithFactorsOutcomeOfSubintentHash { throw CommonException.Unknown() }