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