From f1e218b4414b3c43bf0938b474c7bef69e624bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Thu, 11 Jul 2024 11:12:53 +0200 Subject: [PATCH] Fix account page not opening when offline --- .../mullvadvpn/compose/extensions/UriHandlerExtensions.kt | 2 +- .../net/mullvad/mullvadvpn/viewmodel/AccountViewModel.kt | 8 ++++---- .../net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt | 7 +++---- .../mullvad/mullvadvpn/viewmodel/OutOfTimeViewModel.kt | 7 +++---- .../net/mullvad/mullvadvpn/viewmodel/WelcomeViewModel.kt | 7 +++---- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/UriHandlerExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/UriHandlerExtensions.kt index e8a3706b6687..905823067c4b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/UriHandlerExtensions.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/extensions/UriHandlerExtensions.kt @@ -8,7 +8,7 @@ import net.mullvad.mullvadvpn.lib.common.util.createAccountUri import net.mullvad.mullvadvpn.lib.model.WebsiteAuthToken @Composable -fun UriHandler.createOpenAccountPageHook(): (WebsiteAuthToken) -> Unit { +fun UriHandler.createOpenAccountPageHook(): (WebsiteAuthToken?) -> Unit { val accountUrl = stringResource(id = R.string.account_url) return { token -> this.openUri(createAccountUri(accountUrl, token).toString()) } } 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 7c2635b63a1a..b830d00c607f 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 @@ -68,9 +68,8 @@ class AccountViewModel( fun onManageAccountClick() { viewModelScope.launch { - accountRepository.getWebsiteAuthToken()?.let { wwwAuthToken -> - _uiSideEffect.send(UiSideEffect.OpenAccountManagementPageInBrowser(wwwAuthToken)) - } + val wwwAuthToken = accountRepository.getWebsiteAuthToken() + _uiSideEffect.send(UiSideEffect.OpenAccountManagementPageInBrowser(wwwAuthToken)) } } @@ -124,7 +123,8 @@ class AccountViewModel( sealed class UiSideEffect { data object NavigateToLogin : UiSideEffect() - data class OpenAccountManagementPageInBrowser(val token: WebsiteAuthToken) : UiSideEffect() + data class OpenAccountManagementPageInBrowser(val token: WebsiteAuthToken?) : + UiSideEffect() data class CopyAccountNumber(val accountNumber: String) : UiSideEffect() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt index 037c3243ab84..d1f4b3713b17 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt @@ -161,9 +161,8 @@ class ConnectViewModel( fun onManageAccountClick() { viewModelScope.launch { - accountRepository.getWebsiteAuthToken()?.let { wwwAuthToken -> - _uiSideEffect.send(UiSideEffect.OpenAccountManagementPageInBrowser(wwwAuthToken)) - } + val wwwAuthToken = accountRepository.getWebsiteAuthToken() + _uiSideEffect.send(UiSideEffect.OpenAccountManagementPageInBrowser(wwwAuthToken)) } } @@ -180,7 +179,7 @@ class ConnectViewModel( } sealed interface UiSideEffect { - data class OpenAccountManagementPageInBrowser(val token: WebsiteAuthToken) : UiSideEffect + data class OpenAccountManagementPageInBrowser(val token: WebsiteAuthToken?) : UiSideEffect data object OutOfTime : UiSideEffect diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModel.kt index d2797928534a..b2738a56aef3 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/OutOfTimeViewModel.kt @@ -65,9 +65,8 @@ class OutOfTimeViewModel( fun onSitePaymentClick() { viewModelScope.launch { - accountRepository.getWebsiteAuthToken()?.let { wwwAuthToken -> - _uiSideEffect.send(UiSideEffect.OpenAccountView(wwwAuthToken)) - } + val wwwAuthToken = accountRepository.getWebsiteAuthToken() + _uiSideEffect.send(UiSideEffect.OpenAccountView(wwwAuthToken)) } } @@ -116,7 +115,7 @@ class OutOfTimeViewModel( } sealed interface UiSideEffect { - data class OpenAccountView(val token: WebsiteAuthToken) : UiSideEffect + data class OpenAccountView(val token: WebsiteAuthToken?) : UiSideEffect data object OpenConnectScreen : UiSideEffect } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/WelcomeViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/WelcomeViewModel.kt index f987f16dc9e1..525c6ca54ea4 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/WelcomeViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/WelcomeViewModel.kt @@ -72,9 +72,8 @@ class WelcomeViewModel( fun onSitePaymentClick() { viewModelScope.launch { - accountRepository.getWebsiteAuthToken()?.let { token -> - _uiSideEffect.send(UiSideEffect.OpenAccountView(token)) - } + val wwwAuthToken = accountRepository.getWebsiteAuthToken() + _uiSideEffect.send(UiSideEffect.OpenAccountView(wwwAuthToken)) } } @@ -116,7 +115,7 @@ class WelcomeViewModel( } sealed interface UiSideEffect { - data class OpenAccountView(val token: WebsiteAuthToken) : UiSideEffect + data class OpenAccountView(val token: WebsiteAuthToken?) : UiSideEffect data object OpenConnectScreen : UiSideEffect }