From 65c3ffba952aa83c41dd15b57a93abdfc3de268e Mon Sep 17 00:00:00 2001 From: yevhen1sec Date: Thu, 14 Nov 2024 17:40:22 +0100 Subject: [PATCH 1/2] Remove backup local hint --- .../ui/models/BackupPasswordViewModel.kt | 26 +------------------ .../wallet/ui/models/ImportFileViewModel.kt | 18 ------------- .../wallet/ui/screens/BackupPasswordScreen.kt | 12 --------- .../wallet/ui/screens/ImportFileScreen.kt | 13 ---------- .../repositories/VaultDataStoreRepository.kt | 14 ---------- 5 files changed, 1 insertion(+), 82 deletions(-) diff --git a/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt b/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt index df09e3983..4f168277b 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt @@ -42,7 +42,6 @@ import javax.inject.Inject internal data class BackupPasswordState( val confirmPasswordErrorMessage: UiText? = null, val passwordErrorMessage: UiText? = null, - val hintPasswordErrorMessage: UiText? = null, val isPasswordVisible: Boolean = false, val isConfirmPasswordVisible: Boolean = false, val disableEncryption: Boolean = false, @@ -118,7 +117,7 @@ internal class BackupPasswordViewModel @Inject constructor( fun backupEncryptedVault() { if (shouldEnableEncryption()) { - if (validateConfirmPassword() && validateHint()) { + if (validateConfirmPassword()) { val password = passwordTextFieldState.text.toString() backupVault(password) } @@ -164,18 +163,6 @@ internal class BackupPasswordViewModel @Inject constructor( return errorMessage == null } - private fun validateHint(): Boolean { - val errorMessage = - if (hintPasswordTextFieldState.text.length > HINT_MAX_LENGTH) - UiText.StringResource(R.string.vault_password_hint_to_long) - else null - - uiState.update { - it.copy(hintPasswordErrorMessage = errorMessage) - } - return errorMessage == null - } - fun togglePasswordVisibility() { val isPasswordVisible = !uiState.value.isPasswordVisible uiState.update { @@ -207,7 +194,6 @@ internal class BackupPasswordViewModel @Inject constructor( fun saveContentToUriResult(uri: Uri, content: String) { if (isFileExtensionValid(uri)) { val isSuccess = context.saveContentToUri(uri, content) - if (isSuccess) saveHintToDataStore(uri) completeBackupVault(isSuccess) } else { viewModelScope.launch { @@ -225,16 +211,6 @@ internal class BackupPasswordViewModel @Inject constructor( } } - private fun saveHintToDataStore(uri: Uri) = viewModelScope.launch { - if (hintPasswordTextFieldState.text.isNotEmpty() && passwordTextFieldState.text.isNotEmpty()) { - val fileName = uri.fileName(context) - vaultDataStoreRepository.setBackupHint( - fileName, - hintPasswordTextFieldState.text.toString() - ) - } - } - private fun isFileExtensionValid(uri: Uri) = FILE_ALLOWED_EXTENSIONS.any { it == File(uri.fileName(context)).extension diff --git a/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt b/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt index a17290d4e..1dd9c76eb 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt @@ -38,7 +38,6 @@ internal data class ImportFileState( val password: String? = null, val isPasswordObfuscated: Boolean = true, val passwordErrorHint: UiText? = null, - val passwordHint: UiText? = null, ) internal val FILE_ALLOWED_MIME_TYPES = arrayOf("application/*") @@ -93,12 +92,10 @@ internal class ImportFileViewModel @Inject constructor( saveToDb(fileContent, null) } catch (e: Exception) { Timber.e(e) - val passwordHint = getPasswordHint(fileName) uiModel.update { it.copy( showPasswordPrompt = true, passwordErrorHint = null, - passwordHint = passwordHint, ) } } @@ -106,20 +103,6 @@ internal class ImportFileViewModel @Inject constructor( } } - private suspend fun getPasswordHint(fileName: String?): UiText? { - if (fileName == null) return null - - val passwordHintString = - vaultDataStoreRepository.readBackupHint(vaultFileName = fileName).first() - - if (passwordHintString.isEmpty()) return null - - return UiText.FormattedText( - R.string.import_file_password_hint_text, - listOf(passwordHintString) - ) - } - private suspend fun saveToDb(fileContent: String, password: String?) { try { insertVaultToDb(parseVaultFromString(fileContent, password)) @@ -186,5 +169,4 @@ internal class ImportFileViewModel @Inject constructor( it.copy(isPasswordObfuscated = !passwordVisibility) } } - } \ No newline at end of file diff --git a/app/src/main/java/com/vultisig/wallet/ui/screens/BackupPasswordScreen.kt b/app/src/main/java/com/vultisig/wallet/ui/screens/BackupPasswordScreen.kt index c2542a5ec..359a0a282 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/screens/BackupPasswordScreen.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/screens/BackupPasswordScreen.kt @@ -25,7 +25,6 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavHostController @@ -36,7 +35,6 @@ import com.vultisig.wallet.ui.components.TopBar import com.vultisig.wallet.ui.components.UiAlertDialog import com.vultisig.wallet.ui.components.UiSpacer import com.vultisig.wallet.ui.components.library.form.FormBasicSecureTextField -import com.vultisig.wallet.ui.components.library.form.FormTextFieldCard import com.vultisig.wallet.ui.components.vultiGradient import com.vultisig.wallet.ui.models.BackupPasswordViewModel import com.vultisig.wallet.ui.theme.Theme @@ -194,16 +192,6 @@ internal fun BackupPasswordScreen(navHostController: NavHostController) { ) } }) - UiSpacer(size = 12.dp) - FormTextFieldCard( - title = stringResource( - R.string.backup_password_optional_password_protection_hint - ), - hint = stringResource(R.string.backup_password_screen_hint_field), - error = uiState.hintPasswordErrorMessage, - keyboardType = KeyboardType.Text, - textFieldState = viewModel.hintPasswordTextFieldState, - ) } } } diff --git a/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt b/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt index 8e1d5e977..5281abba4 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt @@ -64,7 +64,6 @@ import com.vultisig.wallet.ui.utils.ActivityResultContractsGetContentWithMimeTyp import com.vultisig.wallet.ui.utils.UiText import com.vultisig.wallet.ui.utils.asString - @Composable internal fun ImportFileScreen( navController: NavHostController, @@ -175,16 +174,6 @@ private fun ImportFileScreen( } ) - if (uiModel.passwordErrorHint != null) { - UiSpacer(size = 8.dp) - Text( - modifier = Modifier.fillMaxWidth(), - text = uiModel.passwordHint?.asString()?: "", - color = appColor.neutral0, - style = menloFamily.body2, - ) - } - TextButton(onClick = onConfirmPasswordClick) { Text( text = stringResource(R.string.import_file_screen_ok), @@ -302,9 +291,7 @@ private fun ImportFileScreen( } } } - } - } diff --git a/data/src/main/kotlin/com/vultisig/wallet/data/repositories/VaultDataStoreRepository.kt b/data/src/main/kotlin/com/vultisig/wallet/data/repositories/VaultDataStoreRepository.kt index 3dccaaa79..0908af2a3 100644 --- a/data/src/main/kotlin/com/vultisig/wallet/data/repositories/VaultDataStoreRepository.kt +++ b/data/src/main/kotlin/com/vultisig/wallet/data/repositories/VaultDataStoreRepository.kt @@ -15,10 +15,6 @@ interface VaultDataStoreRepository { suspend fun readBackupStatus(vaultId: String): Flow - suspend fun setBackupHint(vaultFileName: String, hint: String) - - suspend fun readBackupHint(vaultFileName: String): Flow - suspend fun setFastSignHint(vaultId: String, hint: String) suspend fun readFastSignHint(vaultId: String): Flow @@ -40,15 +36,6 @@ internal class VaultDataStoreRepositoryImpl @Inject constructor( override suspend fun readBackupStatus(vaultId: String): Flow = appDataStore.readData(onVaultBackupStatusKey(vaultId), true) - override suspend fun setBackupHint(vaultFileName: String, hint: String) { - appDataStore.editData { preferences -> - preferences[onVaultBackupHintKey(vaultFileName)] = hint - } - } - - override suspend fun readBackupHint(vaultFileName: String): Flow = - appDataStore.readData(onVaultBackupHintKey(vaultFileName), "") - override suspend fun setFastSignHint(vaultId: String, hint: String) { appDataStore.editData { preferences -> preferences[onVaultFastSignHintKey(vaultId)] = hint @@ -72,7 +59,6 @@ internal class VaultDataStoreRepositoryImpl @Inject constructor( private companion object PreferencesKey { fun onVaultBackupStatusKey(vaultId: String) = booleanPreferencesKey(name = "vault_backup/$vaultId") fun onVaultFastSignHintKey(vaultId: String) = stringPreferencesKey(name = "vault_fast_sign_hint/$vaultId") - fun onVaultBackupHintKey(vaultFileName: String) = stringPreferencesKey(name = "vault_backup_hint/$vaultFileName") fun onGlobalBackupReminderStatusKey() = intPreferencesKey(name = "global_backup_reminder_status") } } From 89f0a4e099871e8b2b4b3577323667d73a924a94 Mon Sep 17 00:00:00 2001 From: yevhen1sec Date: Thu, 14 Nov 2024 17:42:28 +0100 Subject: [PATCH 2/2] code clean --- .../com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt | 2 -- .../java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt | 1 - .../java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt | 1 - 3 files changed, 4 deletions(-) diff --git a/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt b/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt index 4f168277b..f14764cce 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/models/BackupPasswordViewModel.kt @@ -22,7 +22,6 @@ import com.vultisig.wallet.data.models.getVaultPart import com.vultisig.wallet.data.repositories.VaultDataStoreRepository import com.vultisig.wallet.data.repositories.VaultRepository import com.vultisig.wallet.data.usecases.CreateVaultBackupUseCase -import com.vultisig.wallet.data.utils.TextFieldUtils.HINT_MAX_LENGTH import com.vultisig.wallet.ui.navigation.Destination import com.vultisig.wallet.ui.navigation.NavigationOptions import com.vultisig.wallet.ui.navigation.Navigator @@ -63,7 +62,6 @@ internal class BackupPasswordViewModel @Inject constructor( val passwordTextFieldState = TextFieldState() val confirmPasswordTextFieldState = TextFieldState() - val hintPasswordTextFieldState = TextFieldState() private val vaultId: String = requireNotNull(savedStateHandle.get(Destination.BackupPassword.ARG_VAULT_ID)) diff --git a/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt b/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt index 1dd9c76eb..e6c0ed1d5 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/models/ImportFileViewModel.kt @@ -23,7 +23,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt b/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt index 5281abba4..b45df94e3 100644 --- a/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt +++ b/app/src/main/java/com/vultisig/wallet/ui/screens/ImportFileScreen.kt @@ -61,7 +61,6 @@ import com.vultisig.wallet.ui.models.ImportFileState import com.vultisig.wallet.ui.models.ImportFileViewModel import com.vultisig.wallet.ui.theme.Theme import com.vultisig.wallet.ui.utils.ActivityResultContractsGetContentWithMimeTypes -import com.vultisig.wallet.ui.utils.UiText import com.vultisig.wallet.ui.utils.asString @Composable