Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-29 09:18:22 +02:00
parent 4aaaefbd71
commit e6bd9fdabe
3 changed files with 20 additions and 5 deletions

View file

@ -29,7 +29,7 @@ internal class StakingBalanceUpdater @AssistedInject constructor(
@Assisted private val cryptoCurrencyStatus: CryptoCurrencyStatus,
@Assisted private val yield: Yield,
) {
fun scheduleUpdates() {
fun fullUpdate() {
coroutineScope.launch {
listOf(
// we should update network to find pending tx after 1 sec
@ -56,7 +56,7 @@ internal class StakingBalanceUpdater @AssistedInject constructor(
}
}
suspend fun instantUpdate() {
suspend fun partialUpdate() {
coroutineScope {
listOf(
async {
@ -72,6 +72,16 @@ internal class StakingBalanceUpdater @AssistedInject constructor(
}
}
suspend fun initialUpdate() {
coroutineScope {
listOf(
async {
updateStakeBalance()
},
).awaitAll()
}
}
private suspend fun updateNetworkStatuses(delay: Long = BALANCE_UPDATE_DELAY) {
updateDelayedNetworkStatusUseCase(
userWalletId = userWallet.walletId,

View file

@ -227,7 +227,7 @@ internal class StakingTransactionSender @AssistedInject constructor(
networkId = cryptoCurrencyStatus.currency.network.id,
).getOrElse { "" }
balanceUpdater.scheduleUpdates()
balanceUpdater.fullUpdate()
onSendSuccess(txUrl)
},
)

View file

@ -195,6 +195,7 @@ internal class StakingViewModel @Inject constructor(
private var approvalJobHolder: JobHolder = JobHolder()
private var feeJobHolder: JobHolder = JobHolder()
private var sendTransactionJobHolder = JobHolder()
private var stepChangesJobHolder = JobHolder()
init {
subscribeOnSelectedAppCurrency()
@ -207,6 +208,7 @@ internal class StakingViewModel @Inject constructor(
approvalJobHolder.cancel()
feeJobHolder.cancel()
sendTransactionJobHolder.cancel()
stepChangesJobHolder.cancel()
}
override fun onBackClick() {
@ -330,7 +332,7 @@ internal class StakingViewModel @Inject constructor(
override fun onRefreshSwipe(isRefreshing: Boolean) {
stateController.update(SetInitialLoadingStateTransformer(isRefreshing))
coroutineScope.launch {
balanceUpdater.instantUpdate()
balanceUpdater.partialUpdate()
}.invokeOnCompletion {
stateController.update(SetInitialLoadingStateTransformer(false))
}
@ -762,6 +764,8 @@ internal class StakingViewModel @Inject constructor(
.onEach { maybeStatus ->
maybeStatus.fold(
ifRight = { status ->
if (status.value !is CryptoCurrencyStatus.Loaded) return@fold
if (!isInitialInfoAnalyticSent) {
isInitialInfoAnalyticSent = true
val balances = status.value.yieldBalance as? YieldBalance.Data
@ -822,7 +826,7 @@ internal class StakingViewModel @Inject constructor(
when {
isInitState() -> {
updateInitialData()
onRefreshSwipe(isRefreshing = false)
balanceUpdater.initialUpdate()
}
isAssentState() -> {
getFee()
@ -839,6 +843,7 @@ internal class StakingViewModel @Inject constructor(
}
.flowOn(dispatchers.main)
.launchIn(viewModelScope)
.saveIn(stepChangesJobHolder)
}
private fun subscribeOnActionsUpdates() {