Updated on 2026-08-14
This commit is contained in:
parent
c003dbb39d
commit
9ea256e557
19 changed files with 166 additions and 9 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue