Updated on 2026-08-14
This commit is contained in:
parent
1166f7e8bf
commit
84cf236d5f
20 changed files with 258 additions and 10 deletions
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue