Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ABW-3179] Add troubleshooting section and reorganise settings packages to match UI #884

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.babylon.wallet.android.domain.SampleDataProvider
import com.babylon.wallet.android.domain.model.Selectable
import com.babylon.wallet.android.domain.model.toProfileLedgerDeviceModel
import com.babylon.wallet.android.presentation.common.UiMessage
import com.babylon.wallet.android.presentation.settings.preferences.linkedconnectors.AddLinkConnectorViewModel
import com.babylon.wallet.android.presentation.settings.linkedconnectors.AddLinkConnectorViewModel
import com.babylon.wallet.android.presentation.settings.securitycenter.ledgerhardwarewallets.AddLedgerDeviceViewModel
import com.babylon.wallet.android.presentation.settings.securitycenter.ledgerhardwarewallets.ShowLinkConnectorPromptState
import com.babylon.wallet.android.presentation.ui.composables.AddLedgerDeviceScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private fun AccountSettingsContent(
onSettingClick(settingsItem)
}
},
icon = settingsItem.getIcon(),
leadingIcon = settingsItem.getIcon(),
title = stringResource(id = settingsItem.titleRes()),
subtitle = when (settingsItem) {
AccountSettingItem.AccountLabel -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import com.babylon.wallet.android.presentation.onboarding.restore.mnemonics.rest
import com.babylon.wallet.android.presentation.onboarding.restore.withoutbackup.restoreWithoutBackupScreen
import com.babylon.wallet.android.presentation.rootdetection.ROUTE_ROOT_DETECTION
import com.babylon.wallet.android.presentation.rootdetection.RootDetectionContent
import com.babylon.wallet.android.presentation.settings.accountsecurity.accountrecoveryscan.scan.accountRecoveryScan
import com.babylon.wallet.android.presentation.settings.accountsecurity.accountrecoveryscan.scancomplete.recoveryScanComplete
import com.babylon.wallet.android.presentation.settings.personas.createpersona.createPersonaConfirmationScreen
import com.babylon.wallet.android.presentation.settings.personas.createpersona.createPersonaScreen
import com.babylon.wallet.android.presentation.settings.personas.createpersona.personaInfoScreen
Expand All @@ -62,6 +60,8 @@ import com.babylon.wallet.android.presentation.settings.securitycenter.seedphras
import com.babylon.wallet.android.presentation.settings.securitycenter.seedphrases.reveal.revealSeedPhrase
import com.babylon.wallet.android.presentation.settings.securitycenter.seedphrases.seedPhrases
import com.babylon.wallet.android.presentation.settings.settingsNavGraph
import com.babylon.wallet.android.presentation.settings.troubleshooting.accountrecoveryscan.scan.accountRecoveryScan
import com.babylon.wallet.android.presentation.settings.troubleshooting.accountrecoveryscan.scancomplete.recoveryScanComplete
import com.babylon.wallet.android.presentation.status.assets.assetDialog
import com.babylon.wallet.android.presentation.status.assets.fungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.nftAssetDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.babylon.wallet.android.R
import com.babylon.wallet.android.presentation.ui.composables.DSR
import rdx.works.profile.data.model.BackupState

sealed interface SettingsItem {

sealed interface TopLevelSettings {
data object LinkToConnector : TopLevelSettings

data object SecurityCenter : TopLevelSettings
data class SecurityCenter(val needAction: Boolean = false) : TopLevelSettings
data object Personas : TopLevelSettings
data object ApprovedDapps : TopLevelSettings

Expand All @@ -30,7 +29,7 @@ sealed interface SettingsItem {
is Preferences -> R.string.walletSettings_preferences_title
is DebugSettings -> R.string.settings_debugSettings
LinkedConnectors -> R.string.walletSettings_connectors_title
SecurityCenter -> R.string.walletSettings_securityCenter_title
is SecurityCenter -> R.string.walletSettings_securityCenter_title
Troubleshooting -> R.string.walletSettings_troubleshooting_title
}
}
Expand All @@ -44,7 +43,7 @@ sealed interface SettingsItem {
is Preferences -> R.string.walletSettings_preferences_subtitle
is DebugSettings -> R.string.settings_debugSettings
LinkedConnectors -> R.string.walletSettings_connectors_subtitle
SecurityCenter -> R.string.walletSettings_securityCenter_subtitle
is SecurityCenter -> R.string.walletSettings_securityCenter_subtitle
Troubleshooting -> R.string.walletSettings_troubleshooting_subtitle
}
}
Expand All @@ -57,7 +56,7 @@ sealed interface SettingsItem {
is Preferences -> DSR.ic_filter_list
is DebugSettings -> DSR.ic_app_settings
LinkedConnectors -> DSR.ic_desktop_connection
SecurityCenter -> DSR.ic_security_center
is SecurityCenter -> DSR.ic_security_center
Troubleshooting -> DSR.ic_troubleshooting
else -> null
}
Expand Down Expand Up @@ -96,26 +95,40 @@ sealed interface SettingsItem {
}
}

sealed interface AccountSecurityAndSettingsItem {
data class Backups(val backupState: BackupState) : AccountSecurityAndSettingsItem
data object ImportFromLegacyWallet : AccountSecurityAndSettingsItem
data object AccountRecovery : AccountSecurityAndSettingsItem
sealed interface Troubleshooting {
data object AccountRecovery : Troubleshooting
data object ImportFromLegacyWallet : Troubleshooting
data object ContactSupport : Troubleshooting

data object Discord : Troubleshooting

@StringRes
fun descriptionRes(): Int {
return when (this) {
is Backups -> R.string.accountSecuritySettings_backups_title
ImportFromLegacyWallet -> R.string.accountSecuritySettings_importFromLegacyWallet_title
AccountRecovery -> R.string.accountSecuritySettings_accountRecoveryScan_title
ImportFromLegacyWallet -> R.string.troubleshooting_legacyImport_title
AccountRecovery -> R.string.troubleshooting_accountScan_title
ContactSupport -> R.string.troubleshooting_contactSupport_title
Discord -> R.string.troubleshooting_discord_title
}
}

@StringRes
fun subtitleRes(): Int {
return when (this) {
ImportFromLegacyWallet -> R.string.troubleshooting_legacyImport_subtitle
AccountRecovery -> R.string.troubleshooting_accountScan_subtitle
ContactSupport -> R.string.troubleshooting_contactSupport_subtitle
Discord -> R.string.troubleshooting_discord_subtitle
}
}

@DrawableRes
fun getIcon(): Int? { // add rest of icons
return when (this) {
is Backups -> com.babylon.wallet.android.designsystem.R.drawable.ic_backup
ImportFromLegacyWallet -> com.babylon.wallet.android.designsystem.R.drawable.ic_app_settings
AccountRecovery -> com.babylon.wallet.android.designsystem.R.drawable.ic_app_settings
ImportFromLegacyWallet -> DSR.ic_recovery
AccountRecovery -> DSR.ic_recovery
ContactSupport -> DSR.ic_email
Discord -> DSR.ic_discord
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.babylon.wallet.android.BuildConfig
import com.babylon.wallet.android.presentation.navigation.Screen
import com.babylon.wallet.android.presentation.settings.accountsecurity.accountSecurityNavGraph
import com.babylon.wallet.android.presentation.settings.approveddapps.approvedDAppsScreen
import com.babylon.wallet.android.presentation.settings.approveddapps.dappdetail.dAppDetailScreen
import com.babylon.wallet.android.presentation.settings.debug.debugSettings
import com.babylon.wallet.android.presentation.settings.linkedconnectors.linkedConnectorsScreen
import com.babylon.wallet.android.presentation.settings.personas.createpersona.personasScreen
import com.babylon.wallet.android.presentation.settings.personas.personaedit.personaEditScreen
import com.babylon.wallet.android.presentation.settings.preferences.appSettingsNavGraph
import com.babylon.wallet.android.presentation.settings.preferences.linkedconnectors.linkedConnectorsScreen
import com.babylon.wallet.android.presentation.settings.preferences.preferencesNavGraph
import com.babylon.wallet.android.presentation.settings.preferences.walletPreferencesScreen
import com.babylon.wallet.android.presentation.settings.securitycenter.securityCenter
import com.babylon.wallet.android.presentation.settings.securitycenter.securityCenterNavGraph
import com.babylon.wallet.android.presentation.settings.troubleshooting.troubleshootingNavGraph
import com.babylon.wallet.android.presentation.settings.troubleshooting.troubleshootingSettings
import com.babylon.wallet.android.presentation.status.assets.fungibleAssetDialog
import com.babylon.wallet.android.presentation.status.assets.nftAssetDialog
Expand Down Expand Up @@ -55,10 +56,9 @@ fun NavGraphBuilder.settingsNavGraph(
navController.nftAssetDialog(resourceAddress = resource.address)
}
)
accountSecurityNavGraph(navController)
appSettingsNavGraph(navController)
securityCenter(navController)
troubleshootingSettings(navController)
preferencesNavGraph(navController)
securityCenterNavGraph(navController)
troubleshootingNavGraph(navController)
if (BuildConfig.EXPERIMENTAL_FEATURES_ENABLED) {
debugSettings(navController)
}
Expand Down Expand Up @@ -100,7 +100,7 @@ private fun NavGraphBuilder.settingsAll(navController: NavController) {
navController.linkedConnectorsScreen()
}

SettingsItem.TopLevelSettings.SecurityCenter -> {
is SettingsItem.TopLevelSettings.SecurityCenter -> {
navController.securityCenter()
}
SettingsItem.TopLevelSettings.Troubleshooting -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,18 @@ private fun SettingsContent(
onSettingClick(settingsItem.item)
},
subtitle = stringResource(id = settingsItem.item.subtitleRes()),
icon = settingsItem.item.getIcon(),
title = stringResource(id = settingsItem.item.descriptionRes())
leadingIcon = settingsItem.item.getIcon(),
title = stringResource(id = settingsItem.item.descriptionRes()),
warning = when (settingsItem.item) {
is SettingsItem.TopLevelSettings.SecurityCenter -> {
if (settingsItem.item.needAction) {
stringResource(R.string.securityCenter_problem9_heading)
} else {
null
}
}
else -> null
}
)
}
item {
Expand Down Expand Up @@ -275,7 +285,7 @@ fun SettingsScreenWithoutActiveConnectionPreview() {
state = SettingsUiState(
settings = listOf(
SettingsItem.TopLevelSettings.LinkToConnector,
SettingsItem.TopLevelSettings.SecurityCenter,
SettingsItem.TopLevelSettings.SecurityCenter(),
SettingsItem.TopLevelSettings.ApprovedDapps,
SettingsItem.TopLevelSettings.LinkedConnectors,
SettingsItem.TopLevelSettings.Preferences,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.babylon.wallet.android.presentation.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.babylon.wallet.android.BuildConfig.EXPERIMENTAL_FEATURES_ENABLED
import com.babylon.wallet.android.domain.usecases.GetEntitiesWithSecurityPromptUseCase
import com.babylon.wallet.android.presentation.settings.SettingsItem.TopLevelSettings.DebugSettings
import com.babylon.wallet.android.presentation.settings.SettingsItem.TopLevelSettings.LinkToConnector
import com.babylon.wallet.android.presentation.settings.SettingsItem.TopLevelSettings.Personas
Expand All @@ -15,20 +16,24 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import rdx.works.core.mapWhen
import rdx.works.profile.data.model.Profile
import rdx.works.profile.domain.GetProfileUseCase
import rdx.works.profile.domain.backup.GetBackupStateUseCase
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class SettingsViewModel @Inject constructor(
getProfileUseCase: GetProfileUseCase
getProfileUseCase: GetProfileUseCase,
getEntitiesWithSecurityPromptUseCase: GetEntitiesWithSecurityPromptUseCase,
getBackupStateUseCase: GetBackupStateUseCase
) : ViewModel() {

private val defaultSettings = listOf(
SettingsUiItem.Settings(SettingsItem.TopLevelSettings.SecurityCenter),
SettingsUiItem.Settings(SettingsItem.TopLevelSettings.SecurityCenter()),
SettingsUiItem.Spacer,
SettingsUiItem.Settings(Personas),
SettingsUiItem.Settings(SettingsItem.TopLevelSettings.ApprovedDapps),
Expand All @@ -40,15 +45,25 @@ class SettingsViewModel @Inject constructor(
if (EXPERIMENTAL_FEATURES_ENABLED) SettingsUiItem.Settings(DebugSettings) else null
).mapNotNull { it }

val state: StateFlow<SettingsUiState> = getProfileUseCase().map { profile: Profile ->
val mutated = defaultSettings.toMutableList()
var topIndex = 0
val state: StateFlow<SettingsUiState> = combine(
getProfileUseCase(),
getBackupStateUseCase(),
getEntitiesWithSecurityPromptUseCase()
) { profile: Profile, backupState, entitiesWithSecurityPrompts ->
var mutated = defaultSettings
if (profile.appPreferences.p2pLinks.isEmpty() && !defaultSettings.filterIsInstance<SettingsUiItem.Settings>().map {
it.item
}.contains(LinkToConnector)
) {
mutated.add(topIndex, SettingsUiItem.Settings(LinkToConnector))
topIndex += 1
mutated = listOf(SettingsUiItem.Settings(LinkToConnector)) + mutated
}
val anyEntityHasProblem = entitiesWithSecurityPrompts.isNotEmpty()
val backupHasProblem = backupState.isWarningVisible
if (anyEntityHasProblem || backupHasProblem) {
mutated = mutated.mapWhen(
predicate = { it is SettingsUiItem.Settings && it.item is SettingsItem.TopLevelSettings.SecurityCenter },
mutation = { SettingsUiItem.Settings(SettingsItem.TopLevelSettings.SecurityCenter(true)) }
)
}
SettingsUiState(mutated.toPersistentList())
}.stateIn(
Expand Down
Loading
Loading