Updated on 2026-08-14

This commit is contained in:
Tangem 2024-06-21 21:35:19 +05:00
parent 0b671b4ac1
commit 1d75e884c8
15 changed files with 340 additions and 23 deletions

View file

@ -0,0 +1,25 @@
package com.tangem.domain.staking
import arrow.core.Either
import com.tangem.domain.staking.repositories.StakingRepository
import com.tangem.domain.tokens.model.NetworkStatus
import com.tangem.domain.wallets.models.UserWalletId
class FetchStakingYieldBalanceUseCase(
private val stakingRepository: StakingRepository,
) {
suspend operator fun invoke(
userWalletId: UserWalletId,
networkStatus: NetworkStatus,
integrationId: String,
refresh: Boolean = false,
): Either<Throwable, Unit> = Either.catch {
stakingRepository.fetchSingleYieldBalance(
userWalletId = userWalletId,
networkStatus = networkStatus,
integrationId = integrationId,
refresh = refresh,
)
}
}

View file

@ -0,0 +1,30 @@
package com.tangem.domain.staking
import arrow.core.Either
import arrow.core.left
import arrow.core.right
import com.tangem.domain.core.utils.EitherFlow
import com.tangem.domain.staking.model.YieldBalance
import com.tangem.domain.staking.repositories.StakingRepository
import com.tangem.domain.tokens.model.NetworkStatus
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.map
class GetStakingYieldBalanceUseCase(
private val stakingRepository: StakingRepository,
) {
operator fun invoke(
userWalletId: UserWalletId,
networkStatus: NetworkStatus,
integrationId: String,
): EitherFlow<Throwable, List<YieldBalance>> {
return stakingRepository.getSingleYieldBalanceFlow(
userWalletId = userWalletId,
networkStatus = networkStatus,
integrationId = integrationId,
).map<List<YieldBalance>, Either<Throwable, List<YieldBalance>>> { it.right() }
.catch { emit(it.left()) }
}
}

View file

@ -1,9 +1,10 @@
package com.tangem.domain.staking.repositories
import com.tangem.domain.staking.model.StakingAvailability
import com.tangem.domain.staking.model.StakingEntryInfo
import com.tangem.domain.staking.model.Yield
import com.tangem.domain.staking.model.*
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.NetworkStatus
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
interface StakingRepository {
@ -19,4 +20,30 @@ interface StakingRepository {
cryptoCurrencyId: CryptoCurrency.ID,
symbol: String,
): StakingAvailability
suspend fun fetchSingleYieldBalance(
userWalletId: UserWalletId,
networkStatus: NetworkStatus,
integrationId: String,
refresh: Boolean = false,
)
fun getSingleYieldBalanceFlow(
userWalletId: UserWalletId,
networkStatus: NetworkStatus,
integrationId: String,
): Flow<List<YieldBalance>>
suspend fun fetchMultiYieldBalance(
userWalletId: UserWalletId,
networks: Set<NetworkStatus>,
integrationId: String,
refresh: Boolean = false,
)
fun getMultiYieldBalanceFlow(
userWalletId: UserWalletId,
networks: Set<NetworkStatus>,
integrationId: String,
): Flow<List<YieldBalanceList>>
}