Updated on 2026-08-14
This commit is contained in:
parent
dc097a7815
commit
6901522cf7
6 changed files with 66 additions and 29 deletions
|
|
@ -3,4 +3,11 @@ package com.tangem.datasource.api.common.response
|
|||
fun <T : Any> ApiResponse<T>.getOrThrow(): T = when (this) {
|
||||
is ApiResponse.Error -> throw cause
|
||||
is ApiResponse.Success -> data
|
||||
}
|
||||
|
||||
fun <T : Any, R : Any> ApiResponse<T>.fold(onSuccess: (T) -> R, onError: (ApiResponseError) -> R): R {
|
||||
return when (this) {
|
||||
is ApiResponse.Error -> onError(cause)
|
||||
is ApiResponse.Success -> onSuccess(data)
|
||||
}
|
||||
}
|
||||
|
|
@ -179,7 +179,15 @@ internal class DefaultStakingBalanceStore(
|
|||
cachedBalances: Set<YieldBalance>,
|
||||
runtimeBalances: Set<YieldBalance>,
|
||||
): Set<YieldBalance> {
|
||||
if (runtimeBalances.isEmpty()) return cachedBalances
|
||||
if (runtimeBalances.isEmpty()) {
|
||||
return cachedBalances.mapNotNullTo(hashSetOf()) {
|
||||
when (it) {
|
||||
is YieldBalance.Data -> it.copy(source = StatusSource.ONLY_CACHE)
|
||||
is YieldBalance.Empty -> it.copy(source = StatusSource.ONLY_CACHE)
|
||||
is YieldBalance.Error -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return runtimeBalances
|
||||
.map { runtime ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue