Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-27 14:00:46 +05:00
commit 53ffcc2918
677 changed files with 33091 additions and 6980 deletions

View file

@ -0,0 +1,25 @@
package com.tangem.data.walletmanager.utils
import com.tangem.domain.models.network.SdkAmount
import com.tangem.domain.models.network.SdkAmountType
import com.tangem.blockchain.common.Amount as BlockchainAmount
import com.tangem.blockchain.common.AmountType as BlockchainAmountType
/** Maps the blockchain SDK [BlockchainAmount] to the serializable domain [SdkAmount]. */
internal fun BlockchainAmount.toDomain(): SdkAmount = SdkAmount(
currencySymbol = currencySymbol,
value = value,
decimals = decimals,
type = type.toDomain(),
)
private fun BlockchainAmountType.toDomain(): SdkAmountType = when (this) {
BlockchainAmountType.Coin -> SdkAmountType.Coin
BlockchainAmountType.Reserve -> SdkAmountType.Reserve
is BlockchainAmountType.FeeResource -> SdkAmountType.FeeResource(name = name)
is BlockchainAmountType.Token -> SdkAmountType.Token(contractAddress = token.contractAddress, id = token.id)
is BlockchainAmountType.TokenYieldSupply -> SdkAmountType.Token(
contractAddress = token.contractAddress,
id = token.id,
)
}

View file

@ -32,6 +32,7 @@ internal class SdkTransactionHistoryItemConverter(
},
type = typeConverter.convert(value),
amount = requireNotNull(value.amount.value) { "Transaction amount value must not be null" },
fee = value.fee.toDomain(),
)
private fun SdkTransactionHistoryItem.SourceType.toDomain(): TxInfo.SourceType = when (this) {

View file

@ -47,6 +47,7 @@ internal class TransactionDataToTxHistoryItemConverter(
},
type = getTransactionType(value),
amount = amount,
fee = value.fee?.amount?.toDomain(),
)
}

View file

@ -0,0 +1,84 @@
package com.tangem.data.walletmanager.utils
import com.google.common.truth.Truth.assertThat
import com.tangem.blockchain.transactionhistory.models.TransactionHistoryItem
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.walletmanager.model.SmartContractMethod
import com.tangem.test.core.ProvideTestModels
import io.mockk.mockk
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class SdkTransactionTypeConverterTest {
private val converter = SdkTransactionTypeConverter(
smartContractMethods = mapOf(
GASLESS_METHOD_ID to SmartContractMethod(info = null, source = null, name = "gaslessTransaction"),
),
yieldSupplyAddresses = emptySet(),
gaslessFeeAddresses = setOf(FEE_RECIPIENT),
)
@ParameterizedTest
@ProvideTestModels
fun convert(model: ConvertModel) {
// Act
val actual = converter.convert(gaslessItem(model.destination))
// Assert
assertThat(actual).isEqualTo(model.expected)
}
private fun provideTestModels() = listOf(
ConvertModel(
destination = singleUser(RECIPIENT),
expected = TxInfo.TransactionType.UnknownOperation,
),
ConvertModel(
destination = singleUser(FEE_RECIPIENT),
expected = TxInfo.TransactionType.GaslessFee,
),
ConvertModel(
destination = singleUser(FEE_RECIPIENT.uppercase()),
expected = TxInfo.TransactionType.GaslessFee,
),
ConvertModel(
destination = TransactionHistoryItem.DestinationType.Multiple(
addressTypes = listOf(
TransactionHistoryItem.AddressType.User(RECIPIENT),
TransactionHistoryItem.AddressType.User(FEE_RECIPIENT),
),
),
expected = TxInfo.TransactionType.UnknownOperation,
),
)
private fun gaslessItem(destination: TransactionHistoryItem.DestinationType) = TransactionHistoryItem(
txHash = "0xhash",
timestamp = 0L,
isOutgoing = true,
destinationType = destination,
sourceType = TransactionHistoryItem.SourceType.Single(SENDER),
status = TransactionHistoryItem.TransactionStatus.Confirmed,
type = TransactionHistoryItem.TransactionType.ContractMethod(id = GASLESS_METHOD_ID),
amount = mockk(),
fee = mockk(),
)
private fun singleUser(address: String) = TransactionHistoryItem.DestinationType.Single(
addressType = TransactionHistoryItem.AddressType.User(address),
)
internal data class ConvertModel(
val destination: TransactionHistoryItem.DestinationType,
val expected: TxInfo.TransactionType,
)
private companion object {
const val GASLESS_METHOD_ID = "0x6234d42b"
const val SENDER = "0x9ffd974772bda94d288240c1b22f367ce75ccd7f"
const val RECIPIENT = "0x2222222222222222222222222222222222222222"
const val FEE_RECIPIENT = "0x1111111111111111111111111111111111111111"
}
}