Updated on 2026-08-14
This commit is contained in:
parent
8b0a7f01cf
commit
9c81f9ca51
4 changed files with 27 additions and 22 deletions
|
|
@ -133,15 +133,7 @@ internal class DefaultStakingBalanceStore(
|
|||
stakingIds.any { id -> balance.integrationId == id.integrationId && balance.address == id.address }
|
||||
}
|
||||
|
||||
if (yieldBalance != null) {
|
||||
when (yieldBalance) {
|
||||
is YieldBalance.Data -> yieldBalance.copy(source = StatusSource.CACHE)
|
||||
is YieldBalance.Empty -> yieldBalance.copy(source = StatusSource.CACHE)
|
||||
is YieldBalance.Error -> yieldBalance
|
||||
}
|
||||
} else {
|
||||
it
|
||||
}
|
||||
yieldBalance?.copySealed(source = StatusSource.CACHE) ?: it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -254,7 +246,9 @@ internal class DefaultStakingBalanceStore(
|
|||
val updatedCached = when (cached) {
|
||||
is YieldBalance.Data -> cached.copy(source = StatusSource.ONLY_CACHE)
|
||||
is YieldBalance.Empty -> cached.copy(source = StatusSource.ONLY_CACHE)
|
||||
is YieldBalance.Error -> null
|
||||
is YieldBalance.Error,
|
||||
is YieldBalance.Unsupported,
|
||||
-> null
|
||||
}
|
||||
|
||||
return updatedCached ?: YieldBalance.Error(integrationId = stakingID.address, address = stakingID.integrationId)
|
||||
|
|
|
|||
|
|
@ -45,12 +45,13 @@ internal class DefaultSingleYieldBalanceProducer @AssistedInject constructor(
|
|||
return multiYieldBalanceSupplier(
|
||||
params = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId),
|
||||
)
|
||||
.mapNotNull {
|
||||
val currentStakingIds = getStakingIds()
|
||||
|
||||
it.firstOrNull { balance ->
|
||||
currentStakingIds.contains(balance.getStakingId())
|
||||
.mapNotNull { balances ->
|
||||
val currentStakingIds = getStakingIds().ifEmpty {
|
||||
return@mapNotNull YieldBalance.Unsupported
|
||||
}
|
||||
|
||||
balances.firstOrNull { currentStakingIds.contains(it.getStakingId()) }
|
||||
?: YieldBalance.Unsupported
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.flowOn(dispatchers.default)
|
||||
|
|
|
|||
|
|
@ -184,10 +184,10 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
|||
fun `test if flow doesn't contain network from params`() = runTest {
|
||||
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(solanaId).toDomain()
|
||||
|
||||
val expected = flowOf(setOf(balance))
|
||||
val yieldBalancesFlow = flowOf(setOf(balance))
|
||||
|
||||
val multiParams = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId)
|
||||
every { multiNetworkStatusSupplier(multiParams) } returns expected
|
||||
every { multiNetworkStatusSupplier(multiParams) } returns yieldBalancesFlow
|
||||
coEvery { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) } returns stakingIds
|
||||
|
||||
val actual = producer.produce()
|
||||
|
|
@ -198,17 +198,18 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
|||
|
||||
coVerify { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) }
|
||||
|
||||
Truth.assertThat(values.size).isEqualTo(0)
|
||||
val expected = YieldBalance.Unsupported
|
||||
Truth.assertThat(values.first()).isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test if wallet manager facade returns empty set`() = runTest {
|
||||
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(tonId).toDomain()
|
||||
|
||||
val expected = flowOf(setOf(balance))
|
||||
val yieldBalancesFlow = flowOf(setOf(balance))
|
||||
|
||||
val multiParams = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId)
|
||||
every { multiNetworkStatusSupplier(multiParams) } returns expected
|
||||
every { multiNetworkStatusSupplier(multiParams) } returns yieldBalancesFlow
|
||||
coEvery { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) } returns emptySet()
|
||||
|
||||
val actual = producer.produce()
|
||||
|
|
@ -219,7 +220,8 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
|||
|
||||
coVerify { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) }
|
||||
|
||||
Truth.assertThat(values.size).isEqualTo(0)
|
||||
val expected = YieldBalance.Unsupported
|
||||
Truth.assertThat(values.first()).isEqualTo(expected)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ sealed class YieldBalance {
|
|||
return when (this) {
|
||||
is Data -> copy(source = source)
|
||||
is Empty -> copy(source = source)
|
||||
is Error -> this
|
||||
is Error,
|
||||
is Unsupported,
|
||||
-> this
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +44,12 @@ sealed class YieldBalance {
|
|||
override val source: StatusSource,
|
||||
) : YieldBalance()
|
||||
|
||||
data object Unsupported : YieldBalance() {
|
||||
override val integrationId: String? = null
|
||||
override val address: String? = null
|
||||
override val source: StatusSource = StatusSource.ACTUAL
|
||||
}
|
||||
|
||||
data class Error(override val integrationId: String?, override val address: String?) : YieldBalance() {
|
||||
override val source: StatusSource = StatusSource.ACTUAL
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue