From badb0d0f77ea7e71c0d00a858e8f881a0689296f Mon Sep 17 00:00:00 2001 From: Iliyan Germanov Date: Mon, 3 Jan 2022 14:47:39 +0200 Subject: [PATCH] Implement option to delete all user data --- .../java/com/ivy/wallet/network/RestClient.kt | 1 + .../ivy/wallet/network/service/NukeService.kt | 8 +++ .../ivy/wallet/ui/settings/SettingsScreen.kt | 57 ++++++++++++++++--- .../wallet/ui/settings/SettingsViewModel.kt | 11 ++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/ivy/wallet/network/service/NukeService.kt diff --git a/app/src/main/java/com/ivy/wallet/network/RestClient.kt b/app/src/main/java/com/ivy/wallet/network/RestClient.kt index 9f268f1668..71ad4e3eee 100644 --- a/app/src/main/java/com/ivy/wallet/network/RestClient.kt +++ b/app/src/main/java/com/ivy/wallet/network/RestClient.kt @@ -211,4 +211,5 @@ class RestClient private constructor( retrofit.create(BankIntegrationsService::class.java) } val githubService: GithubService by lazy { retrofit.create(GithubService::class.java) } + val nukeService: NukeService by lazy { retrofit.create(NukeService::class.java) } } \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/network/service/NukeService.kt b/app/src/main/java/com/ivy/wallet/network/service/NukeService.kt new file mode 100644 index 0000000000..4cd7928d00 --- /dev/null +++ b/app/src/main/java/com/ivy/wallet/network/service/NukeService.kt @@ -0,0 +1,8 @@ +package com.ivy.wallet.network.service + +import retrofit2.http.POST + +interface NukeService { + @POST("wallet/nuke/delete-all-user-data") + suspend fun deleteAllUserData() +} \ No newline at end of file diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt index 87e44f484c..339d1cbf58 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsScreen.kt @@ -41,10 +41,7 @@ import com.ivy.wallet.ui.theme.components.IvyButton import com.ivy.wallet.ui.theme.components.IvyIcon import com.ivy.wallet.ui.theme.components.IvySwitch import com.ivy.wallet.ui.theme.components.IvyToolbar -import com.ivy.wallet.ui.theme.modal.ChooseStartDateOfMonthModal -import com.ivy.wallet.ui.theme.modal.CurrencyModal -import com.ivy.wallet.ui.theme.modal.NameModal -import com.ivy.wallet.ui.theme.modal.RequestFeatureModal +import com.ivy.wallet.ui.theme.modal.* import java.util.* @ExperimentalFoundationApi @@ -93,7 +90,8 @@ fun BoxWithConstraintsScope.SettingsScreen(screen: Screen.Settings) { title = title, body = body ) - } + }, + onDeleteAllUserData = viewModel::deleteAllUserData ) } @@ -119,12 +117,16 @@ private fun BoxWithConstraintsScope.UI( onExportToCSV: () -> Unit = {}, onSetLockApp: (Boolean) -> Unit = {}, onSetStartDateOfMonth: (Int) -> Unit = {}, - onRequestFeature: (String, String) -> Unit = { _, _ -> } + onRequestFeature: (String, String) -> Unit = { _, _ -> }, + onDeleteAllUserData: () -> Unit = {} ) { var currencyModalVisible by remember { mutableStateOf(false) } var nameModalVisible by remember { mutableStateOf(false) } var chooseStartDateOfMonthVisible by remember { mutableStateOf(false) } var requestFeatureModalVisible by remember { mutableStateOf(false) } + var deleteAllDataModalVisible by remember { mutableStateOf(false) } + var deleteAllDataModalFinalVisible by remember { mutableStateOf(false) } + LazyColumn( modifier = Modifier .fillMaxSize() @@ -289,6 +291,23 @@ private fun BoxWithConstraintsScope.UI( TCAndPrivacyPolicy() } + item { + SettingsSectionDivider( + text = "Danger zone", + color = Red + ) + + Spacer(Modifier.height(16.dp)) + + SettingsPrimaryButton( + icon = R.drawable.ic_delete, + text = "Delete all user data", + backgroundGradient = Gradient.solid(Red) + ) { + deleteAllDataModalVisible = true + } + } + item { Spacer(modifier = Modifier.height(120.dp)) //last item spacer } @@ -326,6 +345,27 @@ private fun BoxWithConstraintsScope.UI( }, onSubmit = onRequestFeature ) + + DeleteModal( + title = "Delete all user data?", + description = "WARNING! This action will delete all data for ${user?.email ?: "your account"} PERMANENTLY and you won't be able to recover it.", + visible = deleteAllDataModalVisible, + dismiss = { deleteAllDataModalVisible = false }, + onDelete = { + deleteAllDataModalVisible = false + deleteAllDataModalFinalVisible = true + } + ) + + DeleteModal( + title = "Confirm permanent deletion for '${user?.email ?: "all of your data"}'", + description = "FINAL WARNING! After clicking \"Delete\" your data will be gone forever.", + visible = deleteAllDataModalFinalVisible, + dismiss = { deleteAllDataModalFinalVisible = false }, + onDelete = { + onDeleteAllUserData() + } + ) } @Composable @@ -946,7 +986,8 @@ private fun CurrencyButton( @Composable private fun SettingsSectionDivider( - text: String + text: String, + color: Color = Gray ) { Spacer(Modifier.height(32.dp)) @@ -954,7 +995,7 @@ private fun SettingsSectionDivider( modifier = Modifier.padding(start = 32.dp), text = text, style = Typo.body2.style( - color = Gray, + color = color, fontWeight = FontWeight.Bold ) ) diff --git a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt index ef48a4ba07..48ef09ebbd 100644 --- a/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/ivy/wallet/ui/settings/SettingsViewModel.kt @@ -273,4 +273,15 @@ class SettingsViewModel @Inject constructor( TestIdlingResource.decrement() } } + + fun deleteAllUserData() { + viewModelScope.launch { + try { + restClient.nukeService.deleteAllUserData() + } catch (e: Exception) { + e.printStackTrace() + } + logout() + } + } } \ No newline at end of file