Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-13 19:58:22 +03:00
parent 6018cf0b71
commit f7b10f3ed5
31 changed files with 446 additions and 105 deletions

View file

@ -1,10 +1,13 @@
package com.tangem.data.walletmanager.utils
import com.tangem.blockchain.blockchains.ethereum.EthereumTransactionExtras
import com.tangem.blockchain.blockchains.ethereum.tokenmethods.ApprovalERC20TokenCallData
import com.tangem.blockchain.common.*
import com.tangem.blockchain.yieldsupply.providers.ethereum.factory.EthereumYieldSupplyDeployCallData
import com.tangem.blockchain.yieldsupply.providers.ethereum.yield.EthereumYieldSupplyEnterCallData
import com.tangem.blockchain.yieldsupply.providers.ethereum.yield.EthereumYieldSupplyExitCallData
import com.tangem.blockchain.yieldsupply.providers.ethereum.yield.EthereumYieldSupplyInitTokenCallData
import com.tangem.blockchain.yieldsupply.providers.ethereum.yield.EthereumYieldSupplyReactivateTokenCallData
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult.Address
import com.tangem.domain.models.network.TxInfo
import com.tangem.utils.converter.Converter
@ -37,25 +40,12 @@ internal class TransactionDataToTxHistoryItemConverter(
addressType = TxInfo.AddressType.User(value.destinationAddress),
),
sourceType = TxInfo.SourceType.Single(value.sourceAddress),
interactionAddressType = TxInfo.InteractionAddressType.User(
address = if (isOutgoing) value.destinationAddress else value.sourceAddress,
),
interactionAddressType = getInteractionAddressType(value, isOutgoing),
status = when (value.status) {
TransactionStatus.Confirmed -> TxInfo.TransactionStatus.Confirmed
TransactionStatus.Unconfirmed -> TxInfo.TransactionStatus.Unconfirmed
},
type = when (val extras = value.extras) {
is EthereumTransactionExtras -> {
when (extras.callData) {
is EthereumYieldSupplyDeployCallData,
is EthereumYieldSupplyEnterCallData,
-> TxInfo.TransactionType.YieldSupply.Enter
is EthereumYieldSupplyExitCallData -> TxInfo.TransactionType.YieldSupply.Exit
else -> TxInfo.TransactionType.Transfer
}
}
else -> TxInfo.TransactionType.Transfer
},
type = getTransactionType(value.extras),
amount = amount,
)
}
@ -89,4 +79,41 @@ internal class TransactionDataToTxHistoryItemConverter(
return amountToken.contractAddress.equals(feeToken.contractAddress, ignoreCase = true) &&
amountToken.symbol.equals(feeToken.symbol, ignoreCase = true)
}
private fun getInteractionAddressType(
value: TransactionData.Uncompiled,
isOutgoing: Boolean,
): TxInfo.InteractionAddressType = when (val extras = value.extras) {
is EthereumTransactionExtras -> {
when (val callData = extras.callData) {
is ApprovalERC20TokenCallData -> TxInfo.InteractionAddressType.Contract(
address = callData.spenderAddress,
)
else -> TxInfo.InteractionAddressType.User(
address = if (isOutgoing) value.destinationAddress else value.sourceAddress,
)
}
}
else -> TxInfo.InteractionAddressType.User(
address = if (isOutgoing) value.destinationAddress else value.sourceAddress,
)
}
private fun getTransactionType(extras: TransactionExtras?): TxInfo.TransactionType {
return when (extras) {
is EthereumTransactionExtras -> {
when (extras.callData) {
is EthereumYieldSupplyDeployCallData,
is EthereumYieldSupplyReactivateTokenCallData,
is EthereumYieldSupplyInitTokenCallData,
is EthereumYieldSupplyEnterCallData,
-> TxInfo.TransactionType.YieldSupply.Enter
is EthereumYieldSupplyExitCallData -> TxInfo.TransactionType.YieldSupply.Exit
is ApprovalERC20TokenCallData -> TxInfo.TransactionType.Approve
else -> TxInfo.TransactionType.Transfer
}
}
else -> TxInfo.TransactionType.Transfer
}
}
}

View file

@ -28,6 +28,7 @@ dependencies {
implementation(projects.domain.yieldSupply.models)
implementation(projects.domain.walletManager)
implementation(projects.domain.legacy)
implementation(projects.domain.txhistory.models)
implementation(projects.libs.blockchainSdk)

View file

@ -12,6 +12,8 @@ import com.tangem.datasource.api.tangemTech.YieldSupplyApi
import com.tangem.datasource.api.tangemTech.models.YieldSupplyChangeTokenStatusBody
import com.tangem.datasource.local.yieldsupply.YieldMarketsStore
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.yield.supply.YieldSupplyRepository
@ -22,6 +24,7 @@ import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.util.concurrent.ConcurrentHashMap
internal class DefaultYieldSupplyRepository(
@ -109,16 +112,21 @@ internal class DefaultYieldSupplyRepository(
override suspend fun saveTokenProtocolStatus(
userWalletId: UserWalletId,
cryptoCurrency: CryptoCurrency,
yieldSupplyEnterStatus: YieldSupplyEnterStatus,
yieldSupplyEnterStatus: YieldSupplyEnterStatus?,
) {
statusMap["${userWalletId}_${cryptoCurrency.id.value}"] = yieldSupplyEnterStatus
val key = getTokenProtocolStatusKey(userWalletId, cryptoCurrency)
if (yieldSupplyEnterStatus != null) {
statusMap[key] = yieldSupplyEnterStatus
} else {
statusMap.remove(key)
}
}
override fun getTokenProtocolStatus(
userWalletId: UserWalletId,
cryptoCurrency: CryptoCurrency,
): YieldSupplyEnterStatus? {
return statusMap["${userWalletId}_${cryptoCurrency.id.value}"]
return statusMap[getTokenProtocolStatusKey(userWalletId, cryptoCurrency)]
}
private fun List<YieldMarketToken>.enrichNetworkIds(): List<YieldMarketToken> {
@ -127,4 +135,44 @@ internal class DefaultYieldSupplyRepository(
token.copy(backendId = chainIdMap[token.chainId])
}
}
override suspend fun getTokenPendingStatus(
userWalletId: UserWalletId,
cryptoCurrencyStatus: CryptoCurrencyStatus,
): YieldSupplyEnterStatus? = try {
val cryptoCurrency = cryptoCurrencyStatus.currency
val walletManager = walletManagersFacade.getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = cryptoCurrency.network.toBlockchain(),
derivationPath = cryptoCurrency.network.derivationPath.value,
) ?: error("Wallet manager not found")
val pendingTxs = cryptoCurrencyStatus.value.pendingTransactions
val yieldAddress = walletManager.calculateYieldModuleAddress()
val hasRecentYieldEnterTxs = pendingTxs.hasYieldEnterTransactions(yieldAddress)
val hasRecentYieldExitTxs = pendingTxs.hasYieldExitTransactions()
when {
hasRecentYieldEnterTxs -> YieldSupplyEnterStatus.Enter
hasRecentYieldExitTxs -> YieldSupplyEnterStatus.Exit
else -> null
}
} catch (e: Exception) {
Timber.e(e, "Failed to get pending yield supply status")
null
}
private fun Set<TxInfo>.hasYieldEnterTransactions(yieldAddress: String) = any {
it.type == TxInfo.TransactionType.YieldSupply.Enter ||
it.type == TxInfo.TransactionType.Approve &&
(it.interactionAddressType as? TxInfo.InteractionAddressType.Contract)?.address == yieldAddress
}
private fun Set<TxInfo>.hasYieldExitTransactions() = any {
it.type == TxInfo.TransactionType.YieldSupply.Exit
}
private fun getTokenProtocolStatusKey(userWalletId: UserWalletId, cryptoCurrency: CryptoCurrency): String =
"${userWalletId}_${cryptoCurrency.id.value}"
}