Updated on 2026-08-14

This commit is contained in:
Tangem 2025-11-07 13:52:28 +05:00
parent e25e8e66c7
commit 9def69438e
5 changed files with 44 additions and 62 deletions

View file

@ -4,6 +4,8 @@ import com.squareup.moshi.Moshi
import com.tangem.datasource.api.pay.models.response.TangemPayTxHistoryResponse
import com.tangem.domain.visa.model.TangemPayTxHistoryItem
import com.tangem.utils.converter.Converter
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import timber.log.Timber
import java.util.Currency
@ -30,7 +32,7 @@ internal class TangemPayTxHistoryItemConverter(moshi: Moshi) :
return TangemPayTxHistoryItem.Spend(
id = id,
jsonRepresentation = spendAdapter.toJson(spend),
date = spend.authorizedAt,
date = spend.authorizedAt.withLocalZone(),
amount = spend.amount,
currency = Currency.getInstance(spend.currency),
enrichedMerchantName = spend.enrichedMerchantName,
@ -49,7 +51,7 @@ internal class TangemPayTxHistoryItemConverter(moshi: Moshi) :
return TangemPayTxHistoryItem.Payment(
id = id,
jsonRepresentation = paymentAdapter.toJson(payment),
date = payment.postedAt,
date = payment.postedAt.withLocalZone(),
currency = Currency.getInstance(payment.currency),
amount = payment.amount,
transactionHash = payment.transactionHash,
@ -60,9 +62,10 @@ internal class TangemPayTxHistoryItemConverter(moshi: Moshi) :
return TangemPayTxHistoryItem.Fee(
id = id,
jsonRepresentation = feeAdapter.toJson(fee),
date = fee.postedAt,
date = fee.postedAt.withLocalZone(),
currency = Currency.getInstance(fee.currency),
amount = fee.amount,
description = fee.description,
)
}
@ -77,10 +80,14 @@ internal class TangemPayTxHistoryItemConverter(moshi: Moshi) :
return TangemPayTxHistoryItem.Collateral(
id = id,
jsonRepresentation = collateralAdapter.toJson(collateral),
date = date,
date = date.withLocalZone(),
currency = Currency.getInstance("usd"),
amount = collateral.amount,
transactionHash = collateral.transactionHash,
)
}
private fun DateTime.withLocalZone(): DateTime {
return withZone(DateTimeZone.getDefault())
}
}

View file

@ -45,6 +45,7 @@ sealed class TangemPayTxHistoryItem {
override val date: SerializedDateTime,
override val amount: SerializedBigDecimal,
override val currency: SerializedCurrency,
val description: String?,
) : TangemPayTxHistoryItem()
@Serializable

View file

@ -14,7 +14,7 @@ import com.tangem.features.tangempay.entity.TangemPayTxHistoryDetailsUM
import com.tangem.features.tangempay.entity.TangemPayTxHistoryDetailsUM.ButtonState
import com.tangem.utils.StringsSigns
import com.tangem.utils.converter.Converter
import com.tangem.utils.extensions.isPositive
import com.tangem.utils.extensions.isZero
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -49,13 +49,7 @@ internal object TangemPayTxHistoryDetailsConverter :
return when (this) {
is TangemPayTxHistoryItem.Collateral -> ImageReference.Res(R.drawable.ic_arrow_down_24)
is TangemPayTxHistoryItem.Fee -> ImageReference.Res(R.drawable.ic_percent_24)
is TangemPayTxHistoryItem.Payment -> {
if (this.amount.isPositive()) {
ImageReference.Res(R.drawable.ic_arrow_down_24)
} else {
ImageReference.Res(R.drawable.ic_arrow_up_24)
}
}
is TangemPayTxHistoryItem.Payment -> ImageReference.Res(R.drawable.ic_arrow_up_24)
is TangemPayTxHistoryItem.Spend -> {
val merchantIcon = this.enrichedMerchantIconUrl
if (merchantIcon != null) {
@ -69,14 +63,12 @@ internal object TangemPayTxHistoryDetailsConverter :
private fun TangemPayTxHistoryItem.extractTransactionTitle(): TextReference {
return when (this) {
is TangemPayTxHistoryItem.Fee -> resourceReference(R.string.tangem_pay_fee_title)
is TangemPayTxHistoryItem.Spend -> stringReference(this.enrichedMerchantName ?: this.merchantName)
is TangemPayTxHistoryItem.Payment -> if (this.amount.isPositive()) {
resourceReference(R.string.tangem_pay_deposit)
} else {
resourceReference(R.string.tangem_pay_withdrawal)
}
is TangemPayTxHistoryItem.Payment -> resourceReference(R.string.tangem_pay_withdrawal)
is TangemPayTxHistoryItem.Collateral -> resourceReference(R.string.tangem_pay_deposit)
is TangemPayTxHistoryItem.Fee -> {
this.description?.let(::stringReference) ?: resourceReference(R.string.tangem_pay_fee_title)
}
}
}
@ -92,7 +84,7 @@ internal object TangemPayTxHistoryDetailsConverter :
private fun TangemPayTxHistoryItem.extractAmount(): String {
return when (this) {
is TangemPayTxHistoryItem.Fee,
is TangemPayTxHistoryItem.Spend,
is TangemPayTxHistoryItem.Payment,
-> {
val amount = this.amount.format {
fiat(
@ -102,20 +94,28 @@ internal object TangemPayTxHistoryDetailsConverter :
}
StringsSigns.MINUS + amount
}
is TangemPayTxHistoryItem.Payment,
is TangemPayTxHistoryItem.Collateral,
-> {
is TangemPayTxHistoryItem.Spend -> {
val amountPrefix = when {
this.amount.isZero() -> ""
this.status == TangemPayTxHistoryItem.Status.DECLINED -> ""
else -> StringsSigns.MINUS
}
val amount = this.amount.format {
fiat(
fiatCurrencyCode = this@extractAmount.currency.currencyCode,
fiatCurrencySymbol = this@extractAmount.currency.symbol,
)
}
if (this.amount.isPositive()) {
StringsSigns.PLUS + amount
} else {
StringsSigns.MINUS + amount
amountPrefix + amount
}
is TangemPayTxHistoryItem.Collateral -> {
val amount = this.amount.format {
fiat(
fiatCurrencyCode = this@extractAmount.currency.currencyCode,
fiatCurrencySymbol = this@extractAmount.currency.symbol,
)
}
StringsSigns.PLUS + amount
}
}
}
@ -124,14 +124,8 @@ internal object TangemPayTxHistoryDetailsConverter :
return when (this) {
is TangemPayTxHistoryItem.Fee,
is TangemPayTxHistoryItem.Spend,
is TangemPayTxHistoryItem.Payment,
-> themedColor { TangemTheme.colors.text.primary1 }
is TangemPayTxHistoryItem.Payment -> themedColor {
if (this.amount.isPositive()) {
TangemTheme.colors.text.accent
} else {
TangemTheme.colors.text.primary1
}
}
is TangemPayTxHistoryItem.Collateral -> themedColor { TangemTheme.colors.text.accent }
}
}
@ -203,16 +197,11 @@ internal object TangemPayTxHistoryDetailsConverter :
)
is TangemPayTxHistoryItem.Payment -> persistentListOf(
ButtonState(
text = resourceReference(R.string.tangem_pay_explore_transaction),
onClick = { this.onExplorerClick(this.item.transactionHash) },
text = resourceReference(R.string.tangem_pay_get_help),
onClick = this.onDisputeClick,
),
)
is TangemPayTxHistoryItem.Collateral -> persistentListOf(
ButtonState(
text = resourceReference(R.string.tangem_pay_explore_transaction),
startIcon = ImageReference.Res(R.drawable.ic_explore_20),
onClick = { this.onExplorerClick(this.item.transactionHash) },
),
ButtonState(
text = resourceReference(R.string.tangem_pay_get_help),
onClick = this.onDisputeClick,

View file

@ -14,7 +14,6 @@ import com.tangem.features.tangempay.entity.TangemPayTransactionState
import com.tangem.features.tangempay.utils.TangemPayTxHistoryUiActions
import com.tangem.utils.StringsSigns
import com.tangem.utils.converter.Converter
import com.tangem.utils.extensions.isPositive
import com.tangem.utils.extensions.isZero
import org.joda.time.DateTimeZone
@ -59,27 +58,18 @@ internal class TangemPayTxHistoryItemsConverter(
}
private fun convertPayment(payment: TangemPayTxHistoryItem.Payment): TangemPayTransactionState.Content.Payment {
val isIncome = payment.amount.isPositive()
val amountPrefix = when {
payment.amount.isZero() -> ""
isIncome -> StringsSigns.PLUS
else -> StringsSigns.MINUS
}
val amount = amountPrefix + payment.amount.format {
val amount = StringsSigns.MINUS + payment.amount.format {
fiat(fiatCurrencyCode = payment.currency.currencyCode, fiatCurrencySymbol = payment.currency.symbol)
}
val title = if (payment.amount.isPositive()) "Deposit" else "Withdrawal"
return TangemPayTransactionState.Content.Payment(
id = payment.id,
onClick = { txHistoryUiActions.onTransactionClick(payment) },
amount = amount,
amountColor = themedColor {
if (payment.amount.isPositive()) TangemTheme.colors.text.accent else TangemTheme.colors.text.primary1
},
title = stringReference(title),
amountColor = themedColor { TangemTheme.colors.text.primary1 },
title = resourceReference(R.string.tangem_pay_withdrawal),
subtitle = stringReference("Transfers"),
time = DateTimeFormatters.formatDate(payment.date, DateTimeFormatters.timeFormatter),
icon = ImageReference.Res(if (isIncome) R.drawable.ic_arrow_down_24 else R.drawable.ic_arrow_up_24),
icon = ImageReference.Res(R.drawable.ic_arrow_up_24),
)
}
@ -93,8 +83,8 @@ internal class TangemPayTxHistoryItemsConverter(
onClick = { txHistoryUiActions.onTransactionClick(fee) },
amount = amount,
amountColor = themedColor { TangemTheme.colors.text.primary1 },
title = stringReference("Fee"),
subtitle = stringReference("Service fees"),
title = resourceReference(R.string.tangem_pay_fee_title),
subtitle = fee.description?.let(::stringReference) ?: resourceReference(R.string.tangem_pay_fee_subtitle),
icon = ImageReference.Res(R.drawable.ic_percent_24),
time = DateTimeFormatters.formatDate(fee.date, DateTimeFormatters.timeFormatter),
)

View file

@ -245,7 +245,7 @@ private class TangemPayTxHistoryDetailsUMProvider : CollectionPreviewParameterPr
notification = null,
buttons = persistentListOf(
TangemPayTxHistoryDetailsUM.ButtonState(
text = resourceReference(R.string.tangem_pay_explore_transaction),
text = resourceReference(R.string.tangem_pay_get_help),
onClick = {},
),
),
@ -261,11 +261,6 @@ private class TangemPayTxHistoryDetailsUMProvider : CollectionPreviewParameterPr
labelState = null,
notification = null,
buttons = persistentListOf(
TangemPayTxHistoryDetailsUM.ButtonState(
text = resourceReference(R.string.tangem_pay_explore_transaction),
startIcon = ImageReference.Res(R.drawable.ic_explore_20),
onClick = {},
),
TangemPayTxHistoryDetailsUM.ButtonState(
text = resourceReference(R.string.tangem_pay_get_help),
onClick = {},