Skip to content

Commit

Permalink
Add payment verification to Connect Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun authored and albin-mullvad committed Nov 27, 2023
1 parent f2add33 commit 993c14d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ val uiModule = module {
viewModel {
ChangelogViewModel(get(), BuildConfig.VERSION_CODE, BuildConfig.ALWAYS_SHOW_CHANGELOG)
}
viewModel { ConnectViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { ConnectViewModel(get(), get(), get(), get(), get(), get(), get()) }
viewModel { DeviceListViewModel(get(), get()) }
viewModel { DeviceRevokedViewModel(get(), get()) }
viewModel { LoginViewModel(get(), get(), get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface PaymentUseCase {

suspend fun resetPurchaseResult()

suspend fun verifyPurchases()
suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit = {})
}

class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : PaymentUseCase {
Expand All @@ -42,11 +42,12 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay
_purchaseResult.emit(null)
}

override suspend fun verifyPurchases() {
override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) {
paymentRepository.verifyPurchases().collect {
if (it == VerificationResult.Success) {
// Update the payment availability after a successful verification.
queryPaymentAvailability()
onSuccessfulVerification()
}
}
}
Expand All @@ -68,7 +69,7 @@ class EmptyPaymentUseCase : PaymentUseCase {
// No op
}

override suspend fun verifyPurchases() {
override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) {
// No op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionState
import net.mullvad.mullvadvpn.ui.serviceconnection.authTokenCache
import net.mullvad.mullvadvpn.ui.serviceconnection.connectionProxy
import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase
import net.mullvad.mullvadvpn.usecase.PaymentUseCase
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
import net.mullvad.mullvadvpn.util.callbackFlowFromNotifier
import net.mullvad.mullvadvpn.util.combine
Expand All @@ -49,7 +50,8 @@ class ConnectViewModel(
private val deviceRepository: DeviceRepository,
private val inAppNotificationController: InAppNotificationController,
private val newDeviceNotificationUseCase: NewDeviceNotificationUseCase,
private val relayListUseCase: RelayListUseCase
private val relayListUseCase: RelayListUseCase,
private val paymentUseCase: PaymentUseCase
) : ViewModel() {
private val _uiSideEffect = MutableSharedFlow<UiSideEffect>(extraBufferCapacity = 1)
val uiSideEffect = _uiSideEffect.asSharedFlow()
Expand Down Expand Up @@ -137,6 +139,9 @@ class ConnectViewModel(
// The create account cache is no longer needed as we have successfully reached the connect
// screen
accountRepository.clearCreatedAccountCache()
viewModelScope.launch {
paymentUseCase.verifyPurchases { accountRepository.fetchAccountExpiry() }
}
}

private fun LocationInfoCache.locationCallbackFlow() = callbackFlow {
Expand Down

0 comments on commit 993c14d

Please sign in to comment.