Skip to content

Commit

Permalink
AND-8879 Fixed blinking on initial staking screen. (#3609)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sateetas authored Oct 29, 2024
1 parent 3c6f64d commit c931c3e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,7 +56,7 @@ internal class StakingBalanceUpdater @AssistedInject constructor(
}
}

suspend fun instantUpdate() {
suspend fun partialUpdate() {
coroutineScope {
listOf(
async {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internal class StakingTransactionSender @AssistedInject constructor(
networkId = cryptoCurrencyStatus.currency.network.id,
).getOrElse { "" }

balanceUpdater.scheduleUpdates()
balanceUpdater.fullUpdate()
onSendSuccess(txUrl)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -207,6 +208,7 @@ internal class StakingViewModel @Inject constructor(
approvalJobHolder.cancel()
feeJobHolder.cancel()
sendTransactionJobHolder.cancel()
stepChangesJobHolder.cancel()
}

override fun onBackClick() {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -822,7 +826,7 @@ internal class StakingViewModel @Inject constructor(
when {
isInitState() -> {
updateInitialData()
onRefreshSwipe(isRefreshing = false)
balanceUpdater.initialUpdate()
}
isAssentState() -> {
getFee()
Expand All @@ -839,6 +843,7 @@ internal class StakingViewModel @Inject constructor(
}
.flowOn(dispatchers.main)
.launchIn(viewModelScope)
.saveIn(stepChangesJobHolder)
}

private fun subscribeOnActionsUpdates() {
Expand Down

0 comments on commit c931c3e

Please sign in to comment.