Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-19 16:17:51 +04:00
parent 4c8537529a
commit 33b7a53905
37 changed files with 396 additions and 365 deletions

View file

@ -2,19 +2,19 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers
import com.tangem.core.ui.components.transactions.state.TxHistoryState
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.txhistory.models.TxHistoryStateError
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState
import com.tangem.feature.wallet.presentation.wallet.state.transformers.converter.TxHistoryItemStateConverter
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
import kotlinx.collections.immutable.toImmutableList
import timber.log.Timber
internal class SetTxHistoryCountErrorTransformer(
private val userWallet: UserWallet,
private val error: TxHistoryStateError,
private val pendingTransactions: Set<TxHistoryItem>,
private val pendingTransactions: Set<TxInfo>,
private val clickIntents: WalletClickIntents,
) : WalletStateTransformer(userWallet.walletId) {

View file

@ -9,10 +9,10 @@ import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.utils.toTimeFormat
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryItem.*
import com.tangem.feature.wallet.impl.R
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.network.TxInfo.*
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
import com.tangem.feature.wallet.impl.R
import com.tangem.utils.StringsSigns.MINUS
import com.tangem.utils.StringsSigns.PLUS
import com.tangem.utils.converter.Converter
@ -22,14 +22,14 @@ internal class TxHistoryItemStateConverter(
private val symbol: String,
private val decimals: Int,
private val clickIntents: WalletClickIntents,
) : Converter<TxHistoryItem, TransactionState> {
) : Converter<TxInfo, TransactionState> {
override fun convert(value: TxHistoryItem): TransactionState {
override fun convert(value: TxInfo): TransactionState {
return createTransactionStateItem(item = value)
}
@Suppress("LongMethod")
private fun createTransactionStateItem(item: TxHistoryItem): TransactionState {
private fun createTransactionStateItem(item: TxInfo): TransactionState {
return TransactionState.Content(
txHash = item.txHash,
amount = item.getAmount(),
@ -44,7 +44,7 @@ internal class TxHistoryItemStateConverter(
)
}
private fun TxHistoryItem.extractIcon(): Int = if (status == TransactionStatus.Failed) {
private fun TxInfo.extractIcon(): Int = if (status == TransactionStatus.Failed) {
R.drawable.ic_close_24
} else {
when (type) {
@ -66,7 +66,7 @@ internal class TxHistoryItemStateConverter(
}
}
private fun TxHistoryItem.extractTitle(): TextReference = when (val type = type) {
private fun TxInfo.extractTitle(): TextReference = when (val type = type) {
is TransactionType.Approve -> resourceReference(R.string.common_approval)
is TransactionType.Operation -> stringReference(type.name)
is TransactionType.Swap -> resourceReference(R.string.common_swap)
@ -80,38 +80,37 @@ internal class TxHistoryItemStateConverter(
is TransactionType.UnknownOperation -> resourceReference(R.string.transaction_history_operation)
}
private fun TxHistoryItem.extractSubtitle(): TextReference =
when (val interactionAddress = interactionAddressType) {
is InteractionAddressType.Contract -> resourceReference(
id = R.string.transaction_history_contract_address,
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
)
is InteractionAddressType.Multiple -> resourceReference(
id = if (isOutgoing) {
R.string.transaction_history_transaction_to_address
} else {
R.string.transaction_history_transaction_from_address
},
formatArgs = wrappedList(resourceReference(R.string.transaction_history_multiple_addresses)),
)
is InteractionAddressType.User -> resourceReference(
id = if (isOutgoing) {
R.string.transaction_history_transaction_to_address
} else {
R.string.transaction_history_transaction_from_address
},
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
)
is InteractionAddressType.Validator -> resourceReference(
id = R.string.transaction_history_transaction_validator,
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
)
null -> {
TextReference.EMPTY
}
private fun TxInfo.extractSubtitle(): TextReference = when (val interactionAddress = interactionAddressType) {
is InteractionAddressType.Contract -> resourceReference(
id = R.string.transaction_history_contract_address,
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
)
is InteractionAddressType.Multiple -> resourceReference(
id = if (isOutgoing) {
R.string.transaction_history_transaction_to_address
} else {
R.string.transaction_history_transaction_from_address
},
formatArgs = wrappedList(resourceReference(R.string.transaction_history_multiple_addresses)),
)
is InteractionAddressType.User -> resourceReference(
id = if (isOutgoing) {
R.string.transaction_history_transaction_to_address
} else {
R.string.transaction_history_transaction_from_address
},
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
)
is InteractionAddressType.Validator -> resourceReference(
id = R.string.transaction_history_transaction_validator,
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
)
null -> {
TextReference.EMPTY
}
}
private fun TxHistoryItem.extractDirection() =
private fun TxInfo.extractDirection() =
if (isOutgoing) TransactionState.Content.Direction.OUTGOING else TransactionState.Content.Direction.INCOMING
private fun TransactionStatus.tiUiStatus() = when (this) {
@ -120,7 +119,7 @@ internal class TxHistoryItemStateConverter(
TransactionStatus.Unconfirmed -> TransactionState.Content.Status.Unconfirmed
}
private fun TxHistoryItem.getAmount(): String {
private fun TxInfo.getAmount(): String {
if (type is TransactionType.Staking.Vote ||
type == TransactionType.Staking.ClaimRewards ||
type == TransactionType.Staking.Withdraw

View file

@ -5,9 +5,9 @@ import androidx.paging.cachedIn
import androidx.paging.map
import arrow.core.Either
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.tokens.GetSingleCryptoCurrencyStatusUseCase
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryListError
import com.tangem.domain.txhistory.models.TxHistoryStateError
import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase
@ -27,7 +27,7 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
typealias MaybeTxHistoryCount = Either<TxHistoryStateError, Int>
typealias MaybeTxHistoryItems = Either<TxHistoryListError, Flow<PagingData<TxHistoryItem>>>
typealias MaybeTxHistoryItems = Either<TxHistoryListError, Flow<PagingData<TxInfo>>>
@Suppress("LongParameterList")
internal class TxHistorySubscriber(
@ -40,7 +40,7 @@ internal class TxHistorySubscriber(
private val txHistoryItemsUseCase: GetTxHistoryItemsUseCase,
) : WalletSubscriber() {
override fun create(coroutineScope: CoroutineScope): Flow<PagingData<TxHistoryItem>> {
override fun create(coroutineScope: CoroutineScope): Flow<PagingData<TxInfo>> {
return flow {
getSingleCryptoCurrencyStatusUseCase.collectLatest(userWalletId = userWallet.walletId) { status ->
val maybeTxHistoryItemCount = txHistoryItemsCountUseCase(