Skip to content

Commit

Permalink
Propagate logout errors to the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Jul 31, 2024
1 parent a771eac commit 1b86a4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
)
}
}

Expand Down Expand Up @@ -127,6 +131,8 @@ class AccountViewModel(
UiSideEffect()

data class CopyAccountNumber(val accountNumber: String) : UiSideEffect()

data object GenericError : UiSideEffect()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ class AccountRepository(
suspend fun login(accountNumber: AccountNumber): Either<LoginAccountError, Unit> =
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()
Expand Down

0 comments on commit 1b86a4d

Please sign in to comment.