Updated on 2026-08-14
This commit is contained in:
parent
79eab436df
commit
78720c5cab
20 changed files with 267 additions and 215 deletions
|
|
@ -35,10 +35,7 @@ internal class DefaultSingleYieldBalanceProducer @AssistedInject constructor(
|
|||
) : SingleYieldBalanceProducer {
|
||||
|
||||
override val fallback: YieldBalance by lazy {
|
||||
YieldBalance.Error(
|
||||
integrationId = params.stakingId.integrationId,
|
||||
address = params.stakingId.address,
|
||||
)
|
||||
YieldBalance.Error(stakingId = params.stakingId)
|
||||
}
|
||||
|
||||
override fun produce(): Flow<YieldBalance> {
|
||||
|
|
@ -50,7 +47,7 @@ internal class DefaultSingleYieldBalanceProducer @AssistedInject constructor(
|
|||
.mapNotNull { balances ->
|
||||
val currentStakingId = params.stakingId
|
||||
|
||||
val currentBalances = balances.filter { it.getStakingId() == currentStakingId }
|
||||
val currentBalances = balances.filter { it.stakingId == currentStakingId }
|
||||
|
||||
if (currentBalances.size > 1) {
|
||||
analyticsExceptionHandler.sendException(
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ internal class DefaultYieldsBalancesStore(
|
|||
value = cachedStatuses.map { (stringWalletId, wrappers) ->
|
||||
val key = UserWalletId(stringWalletId)
|
||||
val value = YieldBalanceConverter(isCached = true).convertSet(input = wrappers)
|
||||
.filterNotNull()
|
||||
.toSet()
|
||||
|
||||
key to value
|
||||
}
|
||||
|
|
@ -61,7 +63,7 @@ internal class DefaultYieldsBalancesStore(
|
|||
override suspend fun getSyncOrNull(userWalletId: UserWalletId, stakingId: StakingID): YieldBalance? {
|
||||
return runtimeStore.getSyncOrNull()
|
||||
?.get(userWalletId)
|
||||
?.firstOrNull { stakingId == it.getStakingId() }
|
||||
?.firstOrNull { it.stakingId == stakingId }
|
||||
}
|
||||
|
||||
override suspend fun getAllSyncOrNull(userWalletId: UserWalletId): Set<YieldBalance>? {
|
||||
|
|
@ -96,11 +98,13 @@ internal class DefaultYieldsBalancesStore(
|
|||
|
||||
private suspend fun storeInRuntime(userWalletId: UserWalletId, values: Set<YieldBalanceWrapperDTO>) {
|
||||
val newBalances = YieldBalanceConverter(isCached = false).convertSet(input = values)
|
||||
.filterNotNull()
|
||||
.toSet()
|
||||
|
||||
runtimeStore.update(default = emptyMap()) { saved ->
|
||||
saved.toMutableMap().apply {
|
||||
this[userWalletId] = saved[userWalletId]
|
||||
?.addOrReplace(newBalances) { old, new -> old.getStakingId() == new.getStakingId() }
|
||||
?.addOrReplace(newBalances) { old, new -> old.stakingId == new.stakingId }
|
||||
?: newBalances
|
||||
}
|
||||
}
|
||||
|
|
@ -135,7 +139,7 @@ internal class DefaultYieldsBalancesStore(
|
|||
|
||||
val balances = stakingIds.mapNotNullTo(hashSetOf()) { stakingId ->
|
||||
val balance = portfolioBalances
|
||||
.firstOrNull { stakingId == it.getStakingId() }
|
||||
.firstOrNull { it.stakingId == stakingId }
|
||||
?: ifNotFound(stakingId)
|
||||
?: return@mapNotNullTo null
|
||||
|
||||
|
|
@ -143,7 +147,7 @@ internal class DefaultYieldsBalancesStore(
|
|||
}
|
||||
|
||||
val updatedBalances = portfolioBalances.addOrReplace(items = balances) { old, new ->
|
||||
old.getStakingId() == new.getStakingId()
|
||||
old.stakingId == new.stakingId
|
||||
}
|
||||
|
||||
put(key = userWalletId, value = updatedBalances)
|
||||
|
|
@ -151,9 +155,7 @@ internal class DefaultYieldsBalancesStore(
|
|||
}
|
||||
}
|
||||
|
||||
private fun createErrorYieldBalance(id: StakingID): YieldBalance {
|
||||
return YieldBalance.Error(integrationId = id.integrationId, address = id.address)
|
||||
}
|
||||
private fun createErrorYieldBalance(id: StakingID): YieldBalance = YieldBalance.Error(stakingId = id)
|
||||
|
||||
private fun YieldBalanceWrapperDTO.getStakingId(): StakingID? {
|
||||
val integrationId = integrationId
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ import com.tangem.domain.models.StatusSource
|
|||
import com.tangem.domain.staking.model.stakekit.YieldBalance
|
||||
|
||||
internal fun YieldBalanceWrapperDTO.toDomain(source: StatusSource = StatusSource.CACHE): YieldBalance {
|
||||
return YieldBalanceConverter(source = source).convert(this)
|
||||
return YieldBalanceConverter(source = source).convert(this)!!
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
|||
val producerFlow = producer.produceWithFallback()
|
||||
|
||||
val balance = MockYieldBalanceWrapperDTOFactory.createWithBalance(tonId).toDomain()
|
||||
val updatedBalance = YieldBalance.Error(integrationId = tonId.integrationId, address = tonId.address)
|
||||
val updatedBalance = YieldBalance.Error(stakingId = tonId)
|
||||
|
||||
// Act (first emit)
|
||||
multiFlow.emit(value = setOf(balance))
|
||||
|
|
@ -162,7 +162,7 @@ internal class DefaultSingleYieldBalanceProducerTest {
|
|||
val actual1 = getEmittedValues(flow = producerFlow)
|
||||
|
||||
// Assert (first emit)
|
||||
val fallbackStatus = YieldBalance.Error(integrationId = tonId.integrationId, address = "0x1")
|
||||
val fallbackStatus = YieldBalance.Error(stakingId = tonId.copy(address = "0x1"))
|
||||
|
||||
Truth.assertThat(actual1).hasSize(1)
|
||||
Truth.assertThat(actual1).containsExactly(fallbackStatus)
|
||||
|
|
|
|||
|
|
@ -129,12 +129,7 @@ internal class YieldsBalancesStoreUpdateMethodsTest {
|
|||
store.storeError(userWalletId = userWalletId, stakingIds = setOf(stakingId))
|
||||
|
||||
val runtimeExpected = mapOf(
|
||||
userWalletId to setOf(
|
||||
YieldBalance.Error(
|
||||
integrationId = stakingId.integrationId,
|
||||
address = stakingId.address,
|
||||
),
|
||||
),
|
||||
userWalletId to setOf(YieldBalance.Error(stakingId)),
|
||||
)
|
||||
|
||||
Truth.assertThat(runtimeStore.getSyncOrNull()).isEqualTo(runtimeExpected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue