Updated on 2026-08-14
This commit is contained in:
parent
3c80a53254
commit
5514e3a195
7 changed files with 48 additions and 22 deletions
|
|
@ -8,6 +8,7 @@ import com.tangem.datasource.api.tangemTech.models.YieldSupplyMarketTokenDto
|
|||
import com.tangem.datasource.api.tangemTech.models.YieldTokenChartResponse
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
|
@ -34,6 +35,7 @@ interface YieldSupplyApi {
|
|||
@POST("api/v1/module/activate")
|
||||
suspend fun activateYieldModule(
|
||||
@Body body: YieldSupplyChangeTokenStatusBody,
|
||||
@Header("userWalletId") userWalletId: String,
|
||||
): ApiResponse<YieldModuleStatusResponse>
|
||||
|
||||
@POST("api/v1/module/deactivate")
|
||||
|
|
|
|||
|
|
@ -76,16 +76,20 @@ internal class DefaultYieldSupplyRepository(
|
|||
(walletManager as? YieldSupplyProvider)?.isSupported() ?: false
|
||||
}
|
||||
|
||||
override suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean =
|
||||
withContext(dispatchers.io) {
|
||||
override suspend fun activateProtocol(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencyToken: CryptoCurrency.Token,
|
||||
address: String,
|
||||
): Boolean = withContext(dispatchers.io) {
|
||||
val chainId = Blockchain.fromNetworkId(cryptoCurrencyToken.network.backendId)?.getChainId()
|
||||
?: error("Chain id is required for evm's")
|
||||
yieldSupplyApi.activateYieldModule(
|
||||
YieldSupplyChangeTokenStatusBody(
|
||||
body = YieldSupplyChangeTokenStatusBody(
|
||||
tokenAddress = cryptoCurrencyToken.contractAddress,
|
||||
chainId = chainId,
|
||||
userAddress = address,
|
||||
),
|
||||
userWalletId = userWalletId.stringValue,
|
||||
).getOrThrow().isActive
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,11 @@ interface YieldSupplyRepository {
|
|||
* May throw on network/backend errors or if required chain id cannot be resolved.
|
||||
*/
|
||||
@Throws
|
||||
suspend fun activateProtocol(cryptoCurrencyToken: CryptoCurrency.Token, address: String): Boolean
|
||||
suspend fun activateProtocol(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrencyToken: CryptoCurrency.Token,
|
||||
address: String,
|
||||
): Boolean
|
||||
|
||||
/**
|
||||
* Deactivate yield protocol for the specified token.
|
||||
|
|
|
|||
|
|
@ -2,15 +2,23 @@ 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.YieldSupplyRepository
|
||||
|
||||
class YieldSupplyActivateUseCase(
|
||||
private val yieldSupplyRepository: YieldSupplyRepository,
|
||||
) {
|
||||
|
||||
suspend operator fun invoke(cryptoCurrency: CryptoCurrency, address: String): Either<Throwable, Boolean> =
|
||||
Either.catch {
|
||||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
cryptoCurrency: CryptoCurrency,
|
||||
address: String,
|
||||
): Either<Throwable, Boolean> = Either.catch {
|
||||
val token = cryptoCurrency as? CryptoCurrency.Token ?: error("Token expected")
|
||||
yieldSupplyRepository.activateProtocol(token, address)
|
||||
yieldSupplyRepository.activateProtocol(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrencyToken = token,
|
||||
address = address,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -311,7 +311,11 @@ internal class YieldSupplyModel @Inject constructor(
|
|||
val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value ?: return
|
||||
modelScope.launch(dispatchers.default) {
|
||||
if (cryptoCurrencyStatus.value.yieldSupplyStatus?.isActive == true) {
|
||||
yieldSupplyActivateUseCase(token, address).onRight {
|
||||
yieldSupplyActivateUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
cryptoCurrency = token,
|
||||
address = address,
|
||||
).onRight {
|
||||
lastYieldSupplyStatus = cryptoCurrencyStatus.value.yieldSupplyStatus
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -278,7 +278,11 @@ internal class YieldSupplyStartEarningModel @Inject constructor(
|
|||
|
||||
val address = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value
|
||||
if (address != null) {
|
||||
yieldSupplyActivateUseCase(cryptoCurrency, address)
|
||||
yieldSupplyActivateUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
address = address,
|
||||
)
|
||||
}
|
||||
|
||||
modelScope.launch {
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ internal class YieldSupplyStartEarningFeeContentTransformer(
|
|||
val feeFiat = feeFiatRate?.let(feeValue::multiply)
|
||||
val feeFiatValueText = feeFiat.format { fiat(appCurrency.code, appCurrency.symbol) }
|
||||
|
||||
val estimatedFeeFiat = feeFiatRate?.let(estimatedFeeValue::multiply)
|
||||
val estimatedFeeFiat = estimatedFeeValue
|
||||
val estimatedFeeFiatValueText = estimatedFeeFiat.format { fiat(appCurrency.code, appCurrency.symbol) }
|
||||
|
||||
val tokenCryptoFee = tokenFiatRate?.let { rate ->
|
||||
estimatedFeeFiat?.divide(rate, cryptoCurrency.decimals, RoundingMode.HALF_UP)
|
||||
estimatedFeeFiat.divide(rate, cryptoCurrency.decimals, RoundingMode.HALF_UP)
|
||||
}
|
||||
val tokenCryptoFeeValueText = tokenCryptoFee.format { crypto(cryptoCurrency) }
|
||||
val tokenFiatFeeValueText = estimatedFeeFiat.format { fiat(appCurrency.code, appCurrency.symbol) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue