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 }
|
stakingIds.any { id -> balance.integrationId == id.integrationId && balance.address == id.address }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yieldBalance != null) {
|
yieldBalance?.copySealed(source = StatusSource.CACHE) ?: it
|
||||||
when (yieldBalance) {
|
|
||||||
is YieldBalance.Data -> yieldBalance.copy(source = StatusSource.CACHE)
|
|
||||||
is YieldBalance.Empty -> yieldBalance.copy(source = StatusSource.CACHE)
|
|
||||||
is YieldBalance.Error -> yieldBalance
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
it
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -254,7 +246,9 @@ internal class DefaultStakingBalanceStore(
|
||||||
val updatedCached = when (cached) {
|
val updatedCached = when (cached) {
|
||||||
is YieldBalance.Data -> cached.copy(source = StatusSource.ONLY_CACHE)
|
is YieldBalance.Data -> cached.copy(source = StatusSource.ONLY_CACHE)
|
||||||
is YieldBalance.Empty -> 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)
|
return updatedCached ?: YieldBalance.Error(integrationId = stakingID.address, address = stakingID.integrationId)
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,13 @@ internal class DefaultSingleYieldBalanceProducer @AssistedInject constructor(
|
||||||
return multiYieldBalanceSupplier(
|
return multiYieldBalanceSupplier(
|
||||||
params = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId),
|
params = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId),
|
||||||
)
|
)
|
||||||
.mapNotNull {
|
.mapNotNull { balances ->
|
||||||
val currentStakingIds = getStakingIds()
|
val currentStakingIds = getStakingIds().ifEmpty {
|
||||||
|
return@mapNotNull YieldBalance.Unsupported
|
||||||
it.firstOrNull { balance ->
|
|
||||||
currentStakingIds.contains(balance.getStakingId())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
balances.firstOrNull { currentStakingIds.contains(it.getStakingId()) }
|
||||||
|
?: YieldBalance.Unsupported
|
||||||
}
|
}
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.flowOn(dispatchers.default)
|
.flowOn(dispatchers.default)
|
||||||
|
|
|
||||||
|
|
@ -184,10 +184,10 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
||||||
fun `test if flow doesn't contain network from params`() = runTest {
|
fun `test if flow doesn't contain network from params`() = runTest {
|
||||||
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(solanaId).toDomain()
|
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(solanaId).toDomain()
|
||||||
|
|
||||||
val expected = flowOf(setOf(balance))
|
val yieldBalancesFlow = flowOf(setOf(balance))
|
||||||
|
|
||||||
val multiParams = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId)
|
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
|
coEvery { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) } returns stakingIds
|
||||||
|
|
||||||
val actual = producer.produce()
|
val actual = producer.produce()
|
||||||
|
|
@ -198,17 +198,18 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
||||||
|
|
||||||
coVerify { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) }
|
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
|
@Test
|
||||||
fun `test if wallet manager facade returns empty set`() = runTest {
|
fun `test if wallet manager facade returns empty set`() = runTest {
|
||||||
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(tonId).toDomain()
|
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(tonId).toDomain()
|
||||||
|
|
||||||
val expected = flowOf(setOf(balance))
|
val yieldBalancesFlow = flowOf(setOf(balance))
|
||||||
|
|
||||||
val multiParams = MultiYieldBalanceProducer.Params(userWalletId = params.userWalletId)
|
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()
|
coEvery { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) } returns emptySet()
|
||||||
|
|
||||||
val actual = producer.produce()
|
val actual = producer.produce()
|
||||||
|
|
@ -219,7 +220,8 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
||||||
|
|
||||||
coVerify { stakingIdFactory.create(params.userWalletId, params.currencyId, params.network) }
|
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 {
|
private companion object {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ sealed class YieldBalance {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is Data -> copy(source = source)
|
is Data -> copy(source = source)
|
||||||
is Empty -> 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,
|
override val source: StatusSource,
|
||||||
) : YieldBalance()
|
) : 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() {
|
data class Error(override val integrationId: String?, override val address: String?) : YieldBalance() {
|
||||||
override val source: StatusSource = StatusSource.ACTUAL
|
override val source: StatusSource = StatusSource.ACTUAL
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue