Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-01 12:27:58 +05:00
parent 1166f7e8bf
commit 84cf236d5f
20 changed files with 258 additions and 10 deletions

View file

@ -0,0 +1,26 @@
package com.tangem.domain.yield.supply.usecase
import com.tangem.domain.yield.supply.YieldSupplyMarketRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
/**
* Emits a map of APY values per token.
*
* Return map:
* - key: token contract address
* - value: APY as string
*/
class YieldSupplyApyFlowUseCase(
private val yieldSupplyMarketRepository: YieldSupplyMarketRepository,
) {
operator fun invoke(): Flow<Map<String, String>> {
return yieldSupplyMarketRepository.getMarketsFlow()
.map { yieldMarketTokenList ->
yieldMarketTokenList.filter { it.isActive }.associate {
it.tokenAddress to it.apy.toString()
}
}
}
}

View file

@ -0,0 +1,25 @@
package com.tangem.domain.yield.supply.usecase
import arrow.core.Either
import com.tangem.domain.yield.supply.YieldSupplyMarketRepository
import kotlin.collections.filter
/**
* Updates and returns a map of APY values per token.
*
* Return map:
* - key: token contract address
* - value: APY as string
*/
class YieldSupplyApyUpdateUseCase(
private val yieldSupplyMarketRepository: YieldSupplyMarketRepository,
) {
suspend operator fun invoke(): Either<Throwable, Map<String, String>> = Either.catch {
yieldSupplyMarketRepository.updateMarkets()
.filter { it.isActive }
.associate {
it.tokenAddress to it.apy.toString()
}
}
}