Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-16 12:18:53 +05:00
parent c003dbb39d
commit 9ea256e557
19 changed files with 166 additions and 9 deletions

View file

@ -0,0 +1,10 @@
package com.tangem.domain.yield.supply.models
/**
* Represents the availability of yield supply for a given asset.
*/
sealed class YieldSupplyAvailability {
data class Available(val apy: String) : YieldSupplyAvailability()
data object Unavailable : YieldSupplyAvailability()
}

View file

@ -0,0 +1,26 @@
package com.tangem.domain.yield.supply.usecase
import arrow.core.Either
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.yieldSupplyKey
import com.tangem.domain.yield.supply.YieldSupplyRepository
import com.tangem.domain.yield.supply.models.YieldSupplyAvailability
class YieldSupplyGetAvailabilityUseCase(
private val yieldSupplyRepository: YieldSupplyRepository,
) {
suspend operator fun invoke(currency: CryptoCurrency): Either<Throwable, YieldSupplyAvailability> = Either.catch {
val tokenCurrency = currency as? CryptoCurrency.Token ?: return@catch YieldSupplyAvailability.Unavailable
val tokens = yieldSupplyRepository.getCachedMarkets().orEmpty()
val cachedStatus = tokens.firstOrNull { it.yieldSupplyKey == tokenCurrency.yieldSupplyKey() }
val yieldSupplyToken = cachedStatus ?: yieldSupplyRepository.getTokenStatus(tokenCurrency)
if (yieldSupplyToken.isActive) {
YieldSupplyAvailability.Available(yieldSupplyToken.apy.toString())
} else {
YieldSupplyAvailability.Unavailable
}
}
}