Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-02 12:45:20 +03:00
parent 56590d9345
commit f6c6c5faed
6 changed files with 27 additions and 29 deletions

View file

@ -35,6 +35,7 @@ import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.coroutines.JobHolder
import com.tangem.utils.coroutines.saveIn
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import timber.log.Timber
@ -71,6 +72,7 @@ internal class TokenDetailsViewModel @Inject constructor(
private val marketPriceJobHolder = JobHolder()
private val refreshStateJobHolder = JobHolder()
private val networkStatusAutoUpdateStateJobHolder = JobHolder()
private var cryptoCurrencyStatus: CryptoCurrencyStatus? = null
private var wallet by Delegates.notNull<UserWallet>()
@ -148,7 +150,6 @@ internal class TokenDetailsViewModel @Inject constructor(
getCurrencyStatusUpdatesUseCase(
userWalletId = selectedWallet.walletId,
currencyId = cryptoCurrency.id,
refresh = true,
)
.distinctUntilChanged()
.onEach { either ->
@ -161,6 +162,17 @@ internal class TokenDetailsViewModel @Inject constructor(
.flowOn(dispatchers.io)
.launchIn(viewModelScope)
.saveIn(marketPriceJobHolder)
viewModelScope.launch(dispatchers.io) {
// Wait for blockchain updates pending transactions.
// Immediate update doesn't receive any changes.
delay(NETWORK_STATUS_AUTO_UPDATE_DELAY)
fetchCurrencyStatusUseCase.invoke(
userWalletId = wallet.walletId,
id = cryptoCurrency.id,
refresh = true,
)
}.saveIn(networkStatusAutoUpdateStateJobHolder)
}
private fun updateTxHistory(refresh: Boolean = false) {
@ -377,4 +389,8 @@ internal class TokenDetailsViewModel @Inject constructor(
override fun onCloseRentInfoNotification() {
uiState = stateFactory.getStateWithRemovedRentNotification()
}
companion object {
private const val NETWORK_STATUS_AUTO_UPDATE_DELAY = 1000L
}
}