diff --git a/android/app/src/main/java/updated/mysterium/vpn/notification/PaymentStatusService.kt b/android/app/src/main/java/updated/mysterium/vpn/notification/PaymentStatusService.kt index 63ded3806..e6f576ed1 100644 --- a/android/app/src/main/java/updated/mysterium/vpn/notification/PaymentStatusService.kt +++ b/android/app/src/main/java/updated/mysterium/vpn/notification/PaymentStatusService.kt @@ -12,6 +12,7 @@ import org.koin.core.component.KoinComponent import org.koin.core.component.inject import updated.mysterium.vpn.model.payment.PaymentStatus import updated.mysterium.vpn.network.provider.usecase.UseCaseProvider +import updated.mysterium.vpn.ui.balance.BalanceViewModel class PaymentStatusService : Service(), KoinComponent { @@ -22,6 +23,7 @@ class PaymentStatusService : Service(), KoinComponent { private val useCaseProvider: UseCaseProvider by inject() private val notificationManager: AppNotificationManager by inject() private val paymentUseCase = useCaseProvider.payment() + private val balanceViewModel: BalanceViewModel by inject() override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { bindPaymentCallback() @@ -48,6 +50,7 @@ class PaymentStatusService : Service(), KoinComponent { ) { if (paymentStatus == PaymentStatus.STATUS_PAID) { notificationManager.showSuccessPaymentNotification(amount, currency) + balanceViewModel.forceBalanceUpdate() } else { notificationManager.showFailedPaymentNotification() } diff --git a/android/app/src/main/java/updated/mysterium/vpn/ui/balance/BalanceViewModel.kt b/android/app/src/main/java/updated/mysterium/vpn/ui/balance/BalanceViewModel.kt index cb92f1ae9..4a98468b6 100644 --- a/android/app/src/main/java/updated/mysterium/vpn/ui/balance/BalanceViewModel.kt +++ b/android/app/src/main/java/updated/mysterium/vpn/ui/balance/BalanceViewModel.kt @@ -55,20 +55,18 @@ class BalanceViewModel(useCaseProvider: UseCaseProvider) : ViewModel() { } } - fun getCurrentBalance() = liveDataResult { - if (balanceRequest == null) { - val handler = CoroutineExceptionHandler { _, exception -> - Log.e(TAG, exception.localizedMessage ?: exception.toString()) - } - viewModelScope.launch(Dispatchers.IO + handler) { + fun forceBalanceUpdate() { + val handler = CoroutineExceptionHandler { _, exception -> + Log.e(TAG, exception.localizedMessage ?: exception.toString()) + } + viewModelScope.launch(Dispatchers.IO + handler) { + if (balanceRequest == null) { initBalanceRequest() } + balanceRequest?.let { + _balanceLiveData.postValue(balanceUseCase.forceBalanceUpdate(it).balance) + } } - var balance = 0.0 - balanceRequest?.let { - balance = balanceUseCase.getBalance(it) - } - balance } private suspend fun startDeferredNode(coreService: CompletableDeferred) {