Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-12 17:40:19 +04:00
parent 90c64f8982
commit 3bca437ea4
3 changed files with 34 additions and 2 deletions

View file

@ -83,11 +83,20 @@ internal class DefaultSingleNetworkStatusFetcher @Inject constructor(
val statusValue = status.value
if (statusValue is NetworkStatus.Unreachable) {
networksStatusesStore.storeError(
val prevStatus = networksStatusesStore.getSyncOrNull(
userWalletId = params.userWalletId,
network = params.network,
value = statusValue,
)
if (prevStatus?.value is NetworkStatus.MissedDerivation) {
networksStatusesStore.storeUnreachableStatus(userWalletId = params.userWalletId, value = status)
} else {
networksStatusesStore.storeError(
userWalletId = params.userWalletId,
network = params.network,
value = statusValue,
)
}
} else {
networksStatusesStore.storeSuccess(userWalletId = params.userWalletId, value = status)
}

View file

@ -55,6 +55,12 @@ internal class DefaultNetworksStatusesStoreV2(
return runtimeStore.get().mapNotNull { it[userWalletId.stringValue] }
}
override suspend fun getSyncOrNull(userWalletId: UserWalletId, network: Network): SimpleNetworkStatus? {
val simpleStatusId = SimpleNetworkStatus.Id(network = network)
return runtimeStore.getSyncOrNull()?.get(userWalletId.stringValue)?.firstOrNull { it.id == simpleStatusId }
}
override suspend fun refresh(userWalletId: UserWalletId, network: Network) {
refresh(userWalletId = userWalletId, networks = setOf(network))
}
@ -116,6 +122,17 @@ internal class DefaultNetworksStatusesStoreV2(
)
}
override suspend fun storeUnreachableStatus(userWalletId: UserWalletId, value: NetworkStatus) {
if (value.value !is NetworkStatus.Unreachable) {
val message = "Use storeError method to save unreachable status"
Timber.d(message)
error(message)
}
storeInRuntime(userWalletId = userWalletId, status = value)
}
private suspend fun updateInRuntime(
userWalletId: UserWalletId,
networks: Set<Network>,

View file

@ -12,6 +12,9 @@ internal interface NetworksStatusesStoreV2 {
/** Get statuses by [userWalletId] */
fun get(userWalletId: UserWalletId): Flow<Set<SimpleNetworkStatus>>
/** Get status of [network] by [userWalletId] synchronously or null */
suspend fun getSyncOrNull(userWalletId: UserWalletId, network: Network): SimpleNetworkStatus?
/** Refresh status of [network] by [userWalletId] */
suspend fun refresh(userWalletId: UserWalletId, network: Network)
@ -28,6 +31,9 @@ internal interface NetworksStatusesStoreV2 {
*/
suspend fun storeError(userWalletId: UserWalletId, network: Network, value: NetworkStatus.Unreachable? = null)
/** Store unreachable [value] by [userWalletId] */
suspend fun storeUnreachableStatus(userWalletId: UserWalletId, value: NetworkStatus)
/** Store error for [networks] by [userWalletId] */
suspend fun storeError(userWalletId: UserWalletId, networks: Set<Network>)
}