Updated on 2026-08-14
This commit is contained in:
parent
1d06981060
commit
7b5a62d593
10 changed files with 82 additions and 20 deletions
|
|
@ -0,0 +1,12 @@
|
|||
package com.tangem.domain.yield.supply
|
||||
|
||||
sealed class YieldSupplyError : Throwable() {
|
||||
|
||||
abstract val code: Int
|
||||
|
||||
data class DataError(
|
||||
val throwable: Throwable,
|
||||
) : YieldSupplyError() {
|
||||
override val code: Int = -1
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.tangem.domain.yield.supply
|
||||
|
||||
interface YieldSupplyErrorResolver {
|
||||
fun resolve(throwable: Throwable): YieldSupplyError
|
||||
}
|
||||
|
|
@ -3,19 +3,22 @@ package com.tangem.domain.yield.supply.usecase
|
|||
import arrow.core.Either
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.yield.supply.YieldSupplyError
|
||||
import com.tangem.domain.yield.supply.YieldSupplyErrorResolver
|
||||
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
|
||||
|
||||
class YieldSupplyGetContractAddressUseCase(
|
||||
private val yieldSupplyTransactionRepository: YieldSupplyTransactionRepository,
|
||||
private val yieldSupplyErrorResolver: YieldSupplyErrorResolver,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency.Token,
|
||||
): Either<Throwable, String?> = Either.catch {
|
||||
): Either<YieldSupplyError, String?> = Either.catch {
|
||||
yieldSupplyTransactionRepository.getYieldContractAddress(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
)
|
||||
}
|
||||
}.mapLeft(yieldSupplyErrorResolver::resolve)
|
||||
}
|
||||
|
|
@ -3,22 +3,25 @@ package com.tangem.domain.yield.supply.usecase
|
|||
import arrow.core.Either
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.yield.supply.YieldSupplyError
|
||||
import com.tangem.domain.yield.supply.YieldSupplyErrorResolver
|
||||
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
|
||||
import java.math.BigDecimal
|
||||
|
||||
class YieldSupplyGetProtocolBalanceUseCase(
|
||||
private val yieldSupplyTransactionRepository: YieldSupplyTransactionRepository,
|
||||
private val yieldSupplyErrorResolver: YieldSupplyErrorResolver,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
): Either<Throwable, BigDecimal?> = Either.catch {
|
||||
): Either<YieldSupplyError, BigDecimal?> = Either.catch {
|
||||
requireNotNull(cryptoCurrency as CryptoCurrency.Token)
|
||||
|
||||
yieldSupplyTransactionRepository.getProtocolBalance(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
)
|
||||
}
|
||||
}.mapLeft(yieldSupplyErrorResolver::resolve)
|
||||
}
|
||||
|
|
@ -4,22 +4,25 @@ import arrow.core.Either
|
|||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.yield.supply.YieldSupplyError
|
||||
import com.tangem.domain.yield.supply.YieldSupplyErrorResolver
|
||||
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
|
||||
import java.math.BigDecimal
|
||||
|
||||
class YieldSupplyStartEarningUseCase(
|
||||
private val yieldSupplyTransactionRepository: YieldSupplyTransactionRepository,
|
||||
private val yieldSupplyErrorResolver: YieldSupplyErrorResolver,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
maxNetworkFee: BigDecimal,
|
||||
): Either<Throwable, List<TransactionData.Uncompiled>> = Either.catch {
|
||||
): Either<YieldSupplyError, List<TransactionData.Uncompiled>> = Either.catch {
|
||||
yieldSupplyTransactionRepository.createEnterTransactions(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
maxNetworkFee = maxNetworkFee,
|
||||
)
|
||||
}
|
||||
}.mapLeft(yieldSupplyErrorResolver::resolve)
|
||||
}
|
||||
|
|
@ -5,21 +5,24 @@ import com.tangem.blockchain.common.TransactionData
|
|||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.yield.supply.YieldSupplyError
|
||||
import com.tangem.domain.yield.supply.YieldSupplyErrorResolver
|
||||
import com.tangem.domain.yield.supply.YieldSupplyTransactionRepository
|
||||
|
||||
class YieldSupplyStopEarningUseCase(
|
||||
private val yieldSupplyTransactionRepository: YieldSupplyTransactionRepository,
|
||||
private val yieldSupplyErrorResolver: YieldSupplyErrorResolver,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
fee: Fee?,
|
||||
): Either<Throwable, TransactionData.Uncompiled> = Either.catch {
|
||||
): Either<YieldSupplyError, TransactionData.Uncompiled> = Either.catch {
|
||||
yieldSupplyTransactionRepository.createExitTransaction(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
fee = null,
|
||||
)
|
||||
}
|
||||
}.mapLeft(yieldSupplyErrorResolver::resolve)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue