Updated on 2026-08-14
This commit is contained in:
parent
47acce67c1
commit
e326873ac1
4 changed files with 48 additions and 8 deletions
|
|
@ -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 com.tangem.utils.extensions.isPositive
|
||||
import com.tangem.utils.extensions.isZero
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
import timber.log.Timber
|
||||
|
|
@ -87,6 +89,11 @@ internal class TangemPayTxHistoryItemConverter(moshi: Moshi) :
|
|||
currency = Currency.getInstance("usd"),
|
||||
amount = collateral.amount,
|
||||
transactionHash = collateral.transactionHash,
|
||||
type = if (collateral.amount.isPositive() || collateral.amount.isZero()) {
|
||||
TangemPayTxHistoryItem.Type.Deposit
|
||||
} else {
|
||||
TangemPayTxHistoryItem.Type.Withdrawal
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,8 +59,13 @@ sealed class TangemPayTxHistoryItem {
|
|||
override val amount: SerializedBigDecimal,
|
||||
override val currency: SerializedCurrency,
|
||||
val transactionHash: String,
|
||||
val type: Type,
|
||||
) : TangemPayTxHistoryItem()
|
||||
|
||||
enum class Type {
|
||||
Deposit, Withdrawal
|
||||
}
|
||||
|
||||
enum class Status {
|
||||
PENDING,
|
||||
RESERVED,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,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
|
||||
|
|
@ -51,7 +52,10 @@ internal object TangemPayTxHistoryDetailsConverter :
|
|||
|
||||
private fun TangemPayTxHistoryItem.extractIcon(): ImageReference {
|
||||
return when (this) {
|
||||
is TangemPayTxHistoryItem.Collateral -> ImageReference.Res(R.drawable.ic_arrow_up_24)
|
||||
is TangemPayTxHistoryItem.Collateral -> when (this.type) {
|
||||
TangemPayTxHistoryItem.Type.Deposit -> ImageReference.Res(R.drawable.ic_arrow_down_24)
|
||||
TangemPayTxHistoryItem.Type.Withdrawal -> ImageReference.Res(R.drawable.ic_arrow_up_24)
|
||||
}
|
||||
is TangemPayTxHistoryItem.Fee -> ImageReference.Res(R.drawable.ic_percent_24)
|
||||
is TangemPayTxHistoryItem.Payment -> ImageReference.Res(R.drawable.ic_arrow_up_24)
|
||||
is TangemPayTxHistoryItem.Spend -> {
|
||||
|
|
@ -69,7 +73,10 @@ internal object TangemPayTxHistoryDetailsConverter :
|
|||
return when (this) {
|
||||
is TangemPayTxHistoryItem.Spend -> stringReference(this.enrichedMerchantName ?: this.merchantName)
|
||||
is TangemPayTxHistoryItem.Payment -> resourceReference(R.string.tangem_pay_withdrawal)
|
||||
is TangemPayTxHistoryItem.Collateral -> resourceReference(R.string.tangem_pay_withdrawal)
|
||||
is TangemPayTxHistoryItem.Collateral -> when (this.type) {
|
||||
TangemPayTxHistoryItem.Type.Deposit -> resourceReference(R.string.tangem_pay_deposit)
|
||||
TangemPayTxHistoryItem.Type.Withdrawal -> resourceReference(R.string.tangem_pay_withdrawal)
|
||||
}
|
||||
is TangemPayTxHistoryItem.Fee -> {
|
||||
this.description?.let(::stringReference) ?: resourceReference(R.string.tangem_pay_fee_title)
|
||||
}
|
||||
|
|
@ -113,7 +120,11 @@ internal object TangemPayTxHistoryDetailsConverter :
|
|||
amountPrefix + amount
|
||||
}
|
||||
is TangemPayTxHistoryItem.Collateral -> {
|
||||
val amountPrefix = if (this.amount.isZero()) "" else StringsSigns.MINUS
|
||||
val amountPrefix = when {
|
||||
this.amount.isZero() -> ""
|
||||
this.amount.isPositive() -> StringsSigns.PLUS
|
||||
else -> StringsSigns.MINUS
|
||||
}
|
||||
val amount = this.amount.abs().format {
|
||||
fiat(
|
||||
fiatCurrencyCode = this@extractAmount.currency.currencyCode,
|
||||
|
|
@ -131,7 +142,10 @@ internal object TangemPayTxHistoryDetailsConverter :
|
|||
is TangemPayTxHistoryItem.Spend,
|
||||
is TangemPayTxHistoryItem.Payment,
|
||||
-> themedColor { TangemTheme.colors.text.primary1 }
|
||||
is TangemPayTxHistoryItem.Collateral -> themedColor { TangemTheme.colors.text.primary1 }
|
||||
is TangemPayTxHistoryItem.Collateral -> when (this.type) {
|
||||
TangemPayTxHistoryItem.Type.Deposit -> themedColor { TangemTheme.colors.text.accent }
|
||||
TangemPayTxHistoryItem.Type.Withdrawal -> themedColor { TangemTheme.colors.text.primary1 }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ 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
|
||||
|
||||
|
|
@ -96,7 +97,11 @@ internal class TangemPayTxHistoryItemsConverter(
|
|||
private fun convertCollateral(
|
||||
collateral: TangemPayTxHistoryItem.Collateral,
|
||||
): TangemPayTransactionState.Content.Collateral {
|
||||
val amountPrefix = if (collateral.amount.isZero()) "" else StringsSigns.MINUS
|
||||
val amountPrefix = when {
|
||||
collateral.amount.isZero() -> ""
|
||||
collateral.amount.isPositive() -> StringsSigns.PLUS
|
||||
else -> StringsSigns.MINUS
|
||||
}
|
||||
val amount = amountPrefix + collateral.amount.abs().format {
|
||||
fiat(fiatCurrencyCode = collateral.currency.currencyCode, fiatCurrencySymbol = collateral.currency.symbol)
|
||||
}
|
||||
|
|
@ -104,10 +109,19 @@ internal class TangemPayTxHistoryItemsConverter(
|
|||
id = collateral.id,
|
||||
onClick = { txHistoryUiActions.onTransactionClick(collateral) },
|
||||
amount = amount,
|
||||
amountColor = themedColor { TangemTheme.colors.text.primary1 },
|
||||
title = resourceReference(R.string.tangem_pay_withdrawal),
|
||||
amountColor = when (collateral.type) {
|
||||
TangemPayTxHistoryItem.Type.Deposit -> themedColor { TangemTheme.colors.text.accent }
|
||||
TangemPayTxHistoryItem.Type.Withdrawal -> themedColor { TangemTheme.colors.text.primary1 }
|
||||
},
|
||||
title = when (collateral.type) {
|
||||
TangemPayTxHistoryItem.Type.Deposit -> resourceReference(R.string.tangem_pay_deposit)
|
||||
TangemPayTxHistoryItem.Type.Withdrawal -> resourceReference(R.string.tangem_pay_withdrawal)
|
||||
},
|
||||
subtitle = resourceReference(R.string.common_transfer),
|
||||
icon = ImageReference.Res(R.drawable.ic_arrow_up_24),
|
||||
icon = when (collateral.type) {
|
||||
TangemPayTxHistoryItem.Type.Deposit -> ImageReference.Res(R.drawable.ic_arrow_down_24)
|
||||
TangemPayTxHistoryItem.Type.Withdrawal -> ImageReference.Res(R.drawable.ic_arrow_up_24)
|
||||
},
|
||||
time = DateTimeFormatters.formatDate(collateral.date, DateTimeFormatters.timeFormatter),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue