diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt index 8329c11ec91a..a561123cfb87 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreen.kt @@ -57,6 +57,7 @@ import net.mullvad.mullvadvpn.compose.transitions.SlideInFromBottomTransition import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect import net.mullvad.mullvadvpn.compose.util.SecureScreenWhileInView import net.mullvad.mullvadvpn.compose.util.createCopyToClipboardHandle +import net.mullvad.mullvadvpn.compose.util.showSnackbarImmediately import net.mullvad.mullvadvpn.lib.model.AccountNumber import net.mullvad.mullvadvpn.lib.payment.model.PaymentProduct import net.mullvad.mullvadvpn.lib.payment.model.PaymentStatus @@ -164,6 +165,7 @@ fun AccountScreen( val snackbarHostState = remember { SnackbarHostState() } val copyTextString = stringResource(id = R.string.copied_mullvad_account_number) + val errorString = stringResource(id = R.string.error_occurred) val copyToClipboard = createCopyToClipboardHandle(snackbarHostState = snackbarHostState) val openAccountPage = LocalUriHandler.current.createOpenAccountPageHook() LaunchedEffectCollect(uiSideEffect) { sideEffect -> @@ -173,6 +175,8 @@ fun AccountScreen( openAccountPage(sideEffect.token) is AccountViewModel.UiSideEffect.CopyAccountNumber -> launch { copyToClipboard(sideEffect.accountNumber, copyTextString) } + AccountViewModel.UiSideEffect.GenericError -> + snackbarHostState.showSnackbarImmediately(message = errorString) } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/AccountViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/AccountViewModel.kt index b830d00c607f..f8f66563e8f9 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/AccountViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/AccountViewModel.kt @@ -75,8 +75,12 @@ class AccountViewModel( fun onLogoutClick() { viewModelScope.launch { - accountRepository.logout() - _uiSideEffect.send(UiSideEffect.NavigateToLogin) + accountRepository + .logout() + .fold( + { _uiSideEffect.send(UiSideEffect.GenericError) }, + { _uiSideEffect.send(UiSideEffect.NavigateToLogin) } + ) } } @@ -127,6 +131,8 @@ class AccountViewModel( UiSideEffect() data class CopyAccountNumber(val accountNumber: String) : UiSideEffect() + + data object GenericError : UiSideEffect() } } diff --git a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt index a71dbe8efbd0..82f70e8140a7 100644 --- a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt +++ b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt @@ -54,10 +54,8 @@ class AccountRepository( suspend fun login(accountNumber: AccountNumber): Either = managementService.loginAccount(accountNumber) - suspend fun logout() { - managementService.logoutAccount() - _isNewAccount.update { false } - } + suspend fun logout() = + managementService.logoutAccount().onRight { _isNewAccount.update { false } } suspend fun fetchAccountHistory(): AccountNumber? = managementService.getAccountHistory().getOrNull()