fix: prevent staking dashboard infinite loading

- Add maxAttempts parameter to retryUntilDone (default unlimited for
  backward compat), use 5 retries for staking stats fetch
- Catch fetchStakingStats failure in dashboard update system and
  fallback to empty stats instead of hanging forever
- Restore stale scope detection in ComputationalCache so cancelled
  aggregate scopes are recreated instead of returning stale entries
This commit is contained in:
2026-02-26 20:49:12 +03:00
parent 853bbf567e
commit 2374dac2ad
4 changed files with 27 additions and 10 deletions
@@ -39,7 +39,7 @@ class RealStakingStatsDataSource(
stakingAccounts: StakingAccounts,
stakingChains: List<Chain>
): MultiChainStakingStats = withContext(Dispatchers.IO) {
retryUntilDone {
retryUntilDone(maxAttempts = 5) {
val globalConfig = globalConfigDataSource.getGlobalConfig()
val chainsByEndpoint = splitChainsByEndpoint(stakingChains, globalConfig)
@@ -127,9 +127,16 @@ class RealStakingDashboardUpdateSystem(
.onEach { latestOffChainSyncIndex.value = it.index }
.throttleLast(offChainSyncDebounceRate)
.mapLatest { (index, stakingAccounts) ->
val stats = runCatching {
stakingStatsDataSource.fetchStakingStats(stakingAccounts, stakingChains)
}.getOrElse {
Log.d("StakingDashboardUpdateSystem", "Failed to fetch staking stats after retries", it)
emptyMap()
}
MultiChainOffChainSyncResult(
index = index,
multiChainStakingStats = stakingStatsDataSource.fetchStakingStats(stakingAccounts, stakingChains),
multiChainStakingStats = stats,
)
}
}