Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-24 20:11:17 +05:00
parent 744185dfa5
commit be2ba06031
4 changed files with 31 additions and 19 deletions

View file

@ -23,20 +23,22 @@ internal class DefaultStakingYieldsStore(
return withTimeoutOrNull(timeout = YIELDS_WAITING_TIMEOUT, block = { get().firstOrNull() })
}
override suspend fun store(items: List<YieldDTO>) {
dataStore.updateData { data ->
val updatedItems = data.toMutableList()
items.forEach { newItem ->
val existingItemIndex = data.indexOfFirst { it.id == newItem.id }
if (existingItemIndex != -1) {
// Update existing item
updatedItems[existingItemIndex] = newItem
} else {
// Add new item
updatedItems.add(newItem)
override suspend fun store(items: List<YieldDTO>, force: Boolean) {
if (force) {
dataStore.updateData { items }
} else {
dataStore.updateData { data ->
val updatedItems = data.toMutableList()
items.forEach { newItem ->
val existingItemIndex = data.indexOfFirst { it.id == newItem.id }
if (existingItemIndex != -1) {
updatedItems[existingItemIndex] = newItem
} else {
updatedItems.add(newItem)
}
}
updatedItems
}
updatedItems
}
}

View file

@ -11,5 +11,5 @@ interface StakingYieldsStore {
suspend fun getSyncWithTimeout(): List<YieldDTO>?
suspend fun store(items: List<YieldDTO>)
suspend fun store(items: List<YieldDTO>, force: Boolean = false)
}

View file

@ -107,7 +107,9 @@ internal class DefaultStakingRepository(
}
}
}
stakingYieldsStore.store(yields)
val shouldRewriteCache = yieldsResponses.all { it is ApiResponse.Success }
stakingYieldsStore.store(yields, shouldRewriteCache)
}
}
@ -488,6 +490,13 @@ internal class DefaultStakingRepository(
}
private fun findPrefetchedYield(yields: List<Yield>, currencyId: CryptoCurrency.RawID, symbol: String): Yield? {
if (!stakingFeatureToggles.isCardanoStakingEnabled && symbol.equals(
Blockchain.Cardano.currency,
ignoreCase = true,
)
) {
return null
}
return yields.find { yield ->
yield.tokens.any { it.coinGeckoId == currencyId.value && it.symbol == symbol }
}

View file

@ -1105,14 +1105,15 @@ internal class TokenDetailsModel @Inject constructor(
private fun openStaking() {
modelScope.launch {
val yield = getYieldUseCase.invoke(
getYieldUseCase.invoke(
cryptoCurrencyId = cryptoCurrency.id,
symbol = cryptoCurrency.symbol,
).getOrElse {
error("Staking is unavailable for ${cryptoCurrency.name}")
).onRight { yield ->
router.openStaking(userWalletId, cryptoCurrency, yield.id)
}.onLeft {
Timber.e("Staking is unavailable for ${cryptoCurrency.name}")
uiMessageSender.send(SnackbarMessage(resourceReference(R.string.staking_error_no_validators_title)))
}
router.openStaking(userWalletId, cryptoCurrency, yield.id)
}
}