Updated on 2026-08-14
This commit is contained in:
parent
972a287b1d
commit
ef6918ce4a
20 changed files with 374 additions and 115 deletions
|
|
@ -24,7 +24,7 @@ internal class SdkTransactionHistoryItemConverter(
|
|||
SdkTransactionHistoryItem.TransactionStatus.Failed -> TxInfo.TransactionStatus.Failed
|
||||
SdkTransactionHistoryItem.TransactionStatus.Unconfirmed -> TxInfo.TransactionStatus.Unconfirmed
|
||||
},
|
||||
type = typeConverter.convert(value.type),
|
||||
type = typeConverter.convert(value.type to value.destinationType.toDomain()),
|
||||
amount = requireNotNull(value.amount.value) { "Transaction amount value must not be null" },
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,27 @@
|
|||
package com.tangem.data.walletmanager.utils
|
||||
|
||||
import com.tangem.blockchain.transactionhistory.models.TransactionHistoryItem.TransactionType
|
||||
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.domain.models.network.TxInfo
|
||||
import com.tangem.domain.walletmanager.model.SmartContractMethod
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
internal class SdkTransactionTypeConverter(
|
||||
private val smartContractMethods: Map<String, SmartContractMethod>,
|
||||
) : Converter<TransactionType, TxInfo.TransactionType> {
|
||||
) : Converter<Pair<TransactionType, TxInfo.DestinationType>, TxInfo.TransactionType> {
|
||||
|
||||
override fun convert(value: TransactionType): TxInfo.TransactionType {
|
||||
return when (value) {
|
||||
override fun convert(value: Pair<TransactionType, TxInfo.DestinationType>): TxInfo.TransactionType {
|
||||
val (type, destination) = value
|
||||
|
||||
return when (type) {
|
||||
is TransactionType.ContractMethod -> {
|
||||
getTransactionType(methodName = smartContractMethods[value.id]?.name)
|
||||
getTransactionType(methodName = smartContractMethods[type.id]?.name, type.callData, destination)
|
||||
}
|
||||
is TransactionType.ContractMethodName -> {
|
||||
getTransactionType(methodName = value.name)
|
||||
getTransactionType(methodName = type.name, type.callData, destination)
|
||||
}
|
||||
is TransactionType.Transfer -> {
|
||||
TxInfo.TransactionType.Transfer
|
||||
|
|
@ -27,7 +33,7 @@ internal class SdkTransactionTypeConverter(
|
|||
TxInfo.TransactionType.Staking.Unstake
|
||||
}
|
||||
is TransactionType.TronStakingTransactionType.VoteWitnessContract -> {
|
||||
TxInfo.TransactionType.Staking.Vote(value.validatorAddress)
|
||||
TxInfo.TransactionType.Staking.Vote(type.validatorAddress)
|
||||
}
|
||||
is TransactionType.TronStakingTransactionType.WithdrawBalanceContract -> {
|
||||
TxInfo.TransactionType.Staking.ClaimRewards
|
||||
|
|
@ -38,7 +44,12 @@ internal class SdkTransactionTypeConverter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getTransactionType(methodName: String?): TxInfo.TransactionType {
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
private fun getTransactionType(
|
||||
methodName: String?,
|
||||
callData: String?,
|
||||
destination: TxInfo.DestinationType,
|
||||
): TxInfo.TransactionType {
|
||||
return when (methodName) {
|
||||
"transfer" -> TxInfo.TransactionType.Transfer
|
||||
"approve" -> TxInfo.TransactionType.Approve
|
||||
|
|
@ -59,11 +70,33 @@ internal class SdkTransactionTypeConverter(
|
|||
"withdrawRewardsPOL",
|
||||
-> TxInfo.TransactionType.Staking.ClaimRewards
|
||||
"redelegate" -> TxInfo.TransactionType.Staking.Restake
|
||||
"supplyEnter" -> TxInfo.TransactionType.YieldSupply.Enter
|
||||
"supplyExit" -> TxInfo.TransactionType.YieldSupply.Exit
|
||||
"yieldSend" -> TxInfo.TransactionType.YieldSupply.Send
|
||||
"enterProtocolByOwner" -> callData?.let { data ->
|
||||
TxInfo.TransactionType.YieldSupply.Enter(
|
||||
EthereumYieldSupplyEnterCallData.decode(data)?.tokenContractAddress.orEmpty(),
|
||||
)
|
||||
}
|
||||
"withdrawAndDeactivate" -> callData?.let { data ->
|
||||
TxInfo.TransactionType.YieldSupply.Exit(
|
||||
EthereumYieldSupplyExitCallData.decode(data)?.tokenContractAddress.orEmpty(),
|
||||
)
|
||||
}
|
||||
"deployYieldModule" -> TxInfo.TransactionType.YieldSupply.DeployContract(
|
||||
(destination as? TxInfo.DestinationType.Single)?.addressType?.address.orEmpty(),
|
||||
)
|
||||
"initYieldToken" -> callData?.let { data ->
|
||||
TxInfo.TransactionType.YieldSupply.InitializeToken(
|
||||
EthereumYieldSupplyInitTokenCallData.decode(data)?.tokenContractAddress.orEmpty(),
|
||||
)
|
||||
}
|
||||
"reactivateToken" -> callData?.let { data ->
|
||||
TxInfo.TransactionType.YieldSupply.ReactivateToken(
|
||||
EthereumYieldSupplyReactivateTokenCallData.decode(data)?.tokenContractAddress.orEmpty(),
|
||||
)
|
||||
}
|
||||
"supplyTopUp" -> TxInfo.TransactionType.YieldSupply.Topup
|
||||
null -> TxInfo.TransactionType.UnknownOperation
|
||||
else -> TxInfo.TransactionType.Operation(name = methodName.replaceFirstChar { it.titlecase() })
|
||||
}
|
||||
} ?: TxInfo.TransactionType.Operation(name = methodName?.replaceFirstChar { it.titlecase() }.orEmpty())
|
||||
}
|
||||
}
|
||||
|
|
@ -45,7 +45,7 @@ internal class TransactionDataToTxHistoryItemConverter(
|
|||
TransactionStatus.Confirmed -> TxInfo.TransactionStatus.Confirmed
|
||||
TransactionStatus.Unconfirmed -> TxInfo.TransactionStatus.Unconfirmed
|
||||
},
|
||||
type = getTransactionType(value.extras),
|
||||
type = getTransactionType(value),
|
||||
amount = amount,
|
||||
)
|
||||
}
|
||||
|
|
@ -99,16 +99,25 @@ internal class TransactionDataToTxHistoryItemConverter(
|
|||
)
|
||||
}
|
||||
|
||||
private fun getTransactionType(extras: TransactionExtras?): TxInfo.TransactionType {
|
||||
return when (extras) {
|
||||
private fun getTransactionType(transactionData: TransactionData.Uncompiled?): TxInfo.TransactionType {
|
||||
return when (val extras = transactionData?.extras) {
|
||||
is EthereumTransactionExtras -> {
|
||||
when (extras.callData) {
|
||||
is EthereumYieldSupplyDeployCallData,
|
||||
is EthereumYieldSupplyReactivateTokenCallData,
|
||||
is EthereumYieldSupplyInitTokenCallData,
|
||||
is EthereumYieldSupplyEnterCallData,
|
||||
-> TxInfo.TransactionType.YieldSupply.Enter
|
||||
is EthereumYieldSupplyExitCallData -> TxInfo.TransactionType.YieldSupply.Exit
|
||||
when (val callData = extras.callData) {
|
||||
is EthereumYieldSupplyDeployCallData -> TxInfo.TransactionType.YieldSupply.DeployContract(
|
||||
transactionData.destinationAddress,
|
||||
)
|
||||
is EthereumYieldSupplyReactivateTokenCallData -> TxInfo.TransactionType.YieldSupply.ReactivateToken(
|
||||
callData.tokenContractAddress,
|
||||
)
|
||||
is EthereumYieldSupplyInitTokenCallData -> TxInfo.TransactionType.YieldSupply.InitializeToken(
|
||||
callData.tokenContractAddress,
|
||||
)
|
||||
is EthereumYieldSupplyEnterCallData -> TxInfo.TransactionType.YieldSupply.Enter(
|
||||
callData.tokenContractAddress,
|
||||
)
|
||||
is EthereumYieldSupplyExitCallData -> TxInfo.TransactionType.YieldSupply.Exit(
|
||||
callData.tokenContractAddress,
|
||||
)
|
||||
is ApprovalERC20TokenCallData -> TxInfo.TransactionType.Approve
|
||||
else -> TxInfo.TransactionType.Transfer
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,10 +174,10 @@ internal class DefaultYieldSupplyRepository(
|
|||
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>.hasYieldEnterTransactions(yieldAddress: String) = any { txInfo ->
|
||||
txInfo.type is TxInfo.TransactionType.YieldSupply.Enter ||
|
||||
txInfo.type == TxInfo.TransactionType.Approve &&
|
||||
(txInfo.interactionAddressType as? TxInfo.InteractionAddressType.Contract)?.address == yieldAddress
|
||||
}
|
||||
|
||||
private fun Set<TxInfo>.hasYieldExitTransactions() = any {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue