Updated on 2026-08-14
This commit is contained in:
parent
be2ba06031
commit
455455006d
6 changed files with 137 additions and 79 deletions
|
|
@ -27,7 +27,7 @@ internal class TxHistoryItemToTransactionStateConverter(
|
|||
txHash = value.txHash,
|
||||
amount = value.getAmount(),
|
||||
time = value.timestampInMillis.toTimeFormat(),
|
||||
status = value.status.tiUiStatus(),
|
||||
status = value.status.toUiStatus(),
|
||||
direction = value.extractDirection(),
|
||||
iconRes = value.extractIcon(),
|
||||
title = value.extractTitle(),
|
||||
|
|
@ -41,21 +41,21 @@ internal class TxHistoryItemToTransactionStateConverter(
|
|||
R.drawable.ic_close_24
|
||||
} else {
|
||||
when (type) {
|
||||
is TxInfo.TransactionType.Approve -> R.drawable.ic_doc_24
|
||||
is TxInfo.TransactionType.Staking.Stake,
|
||||
is TxInfo.TransactionType.Staking.Vote,
|
||||
is TxInfo.TransactionType.Staking.Restake,
|
||||
is TransactionType.Approve -> R.drawable.ic_doc_24
|
||||
is TransactionType.Staking.Stake,
|
||||
is TransactionType.Staking.Vote,
|
||||
is TransactionType.Staking.Restake,
|
||||
-> R.drawable.ic_transaction_history_staking_24
|
||||
is TxInfo.TransactionType.Staking.ClaimRewards,
|
||||
is TransactionType.Staking.ClaimRewards,
|
||||
-> R.drawable.ic_transaction_history_claim_rewards_24
|
||||
is TxInfo.TransactionType.Staking.Unstake,
|
||||
is TxInfo.TransactionType.Staking.Withdraw,
|
||||
is TransactionType.Staking.Unstake,
|
||||
is TransactionType.Staking.Withdraw,
|
||||
-> R.drawable.ic_transaction_history_unstaking_24
|
||||
is TxInfo.TransactionType.Operation,
|
||||
is TxInfo.TransactionType.Swap,
|
||||
is TxInfo.TransactionType.Transfer,
|
||||
is TxInfo.TransactionType.YieldSupply,
|
||||
is TxInfo.TransactionType.UnknownOperation,
|
||||
is TransactionType.Operation,
|
||||
is TransactionType.Swap,
|
||||
is TransactionType.Transfer,
|
||||
is TransactionType.YieldSupply,
|
||||
is TransactionType.UnknownOperation,
|
||||
-> if (isOutgoing) R.drawable.ic_arrow_up_24 else R.drawable.ic_arrow_down_24
|
||||
}
|
||||
}
|
||||
|
|
@ -78,43 +78,67 @@ internal class TxHistoryItemToTransactionStateConverter(
|
|||
is TransactionType.UnknownOperation -> resourceReference(R.string.transaction_history_operation)
|
||||
}
|
||||
|
||||
private fun TxInfo.extractSubtitle(): TextReference = when (val interactionAddress = interactionAddressType) {
|
||||
is TxInfo.InteractionAddressType.Contract -> resourceReference(
|
||||
id = R.string.transaction_history_contract_address,
|
||||
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
|
||||
)
|
||||
is TxInfo.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 TxInfo.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 TxInfo.InteractionAddressType.Validator -> resourceReference(
|
||||
id = R.string.transaction_history_transaction_validator,
|
||||
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
|
||||
)
|
||||
null -> {
|
||||
TextReference.EMPTY
|
||||
private fun TxInfo.extractSubtitle(): TextReference {
|
||||
return when (this.type) {
|
||||
is TransactionType.YieldSupply.Enter -> {
|
||||
val amount = amount.format { crypto(symbol = currency.symbol, decimals = currency.decimals) }
|
||||
resourceReference(R.string.yield_module_transaction_enter_subtitle, wrappedList(amount))
|
||||
}
|
||||
is TransactionType.YieldSupply.Topup,
|
||||
-> {
|
||||
val amount = amount.format { crypto(symbol = currency.symbol, decimals = currency.decimals) }
|
||||
resourceReference(R.string.yield_module_transaction_topup_subtitle, wrappedList(amount))
|
||||
}
|
||||
is TransactionType.YieldSupply.Exit -> {
|
||||
val amount = amount.format { crypto(symbol = currency.symbol, decimals = currency.decimals) }
|
||||
resourceReference(R.string.yield_module_transaction_exit_subtitle, wrappedList(amount))
|
||||
}
|
||||
else -> extractSubtitleByAddressType()
|
||||
}
|
||||
}
|
||||
|
||||
private fun TxInfo.extractSubtitleByAddressType(): TextReference =
|
||||
when (val interactionAddress = interactionAddressType) {
|
||||
is TxInfo.InteractionAddressType.Contract -> resourceReference(
|
||||
id = R.string.transaction_history_contract_address,
|
||||
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
|
||||
)
|
||||
is TxInfo.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 TxInfo.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 TxInfo.InteractionAddressType.Validator -> resourceReference(
|
||||
id = R.string.transaction_history_transaction_validator,
|
||||
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
|
||||
)
|
||||
null -> {
|
||||
TextReference.EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
private fun TxInfo.extractDirection() =
|
||||
if (isOutgoing) TransactionState.Content.Direction.OUTGOING else TransactionState.Content.Direction.INCOMING
|
||||
|
||||
@Suppress("ComplexCondition")
|
||||
private fun TxInfo.getAmount(): String {
|
||||
if (type is TxInfo.TransactionType.Staking.Vote ||
|
||||
type == TxInfo.TransactionType.Staking.ClaimRewards ||
|
||||
type == TxInfo.TransactionType.Staking.Withdraw
|
||||
if (type is TransactionType.Staking.Vote ||
|
||||
type == TransactionType.Staking.ClaimRewards ||
|
||||
type == TransactionType.Staking.Withdraw ||
|
||||
type == TransactionType.YieldSupply.Enter ||
|
||||
type == TransactionType.YieldSupply.Exit ||
|
||||
type == TransactionType.YieldSupply.Topup
|
||||
) {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -126,7 +150,7 @@ internal class TxHistoryItemToTransactionStateConverter(
|
|||
return prefix + amount.format { crypto(symbol = currency.symbol, decimals = currency.decimals) }
|
||||
}
|
||||
|
||||
private fun TxInfo.TransactionStatus.tiUiStatus() = when (this) {
|
||||
private fun TxInfo.TransactionStatus.toUiStatus() = when (this) {
|
||||
TxInfo.TransactionStatus.Confirmed -> TransactionState.Content.Status.Confirmed
|
||||
TxInfo.TransactionStatus.Failed -> TransactionState.Content.Status.Failed
|
||||
TxInfo.TransactionStatus.Unconfirmed -> TransactionState.Content.Status.Unconfirmed
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ 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.models.network.TxInfo
|
||||
import com.tangem.domain.models.network.TxInfo.*
|
||||
import com.tangem.domain.models.network.TxInfo.TransactionStatus
|
||||
import com.tangem.domain.models.network.TxInfo.TransactionType
|
||||
import com.tangem.feature.wallet.child.wallet.model.intents.WalletClickIntents
|
||||
import com.tangem.feature.wallet.impl.R
|
||||
import com.tangem.utils.StringsSigns.MINUS
|
||||
|
|
@ -85,36 +86,56 @@ internal class TxHistoryItemStateConverter(
|
|||
is TransactionType.UnknownOperation -> resourceReference(R.string.transaction_history_operation)
|
||||
}
|
||||
|
||||
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 TxInfo.extractSubtitle(): TextReference {
|
||||
return when (this.type) {
|
||||
is TransactionType.YieldSupply.Enter -> {
|
||||
val amount = amount.format { crypto(symbol = symbol, decimals = decimals) }
|
||||
resourceReference(R.string.yield_module_transaction_enter_subtitle, wrappedList(amount))
|
||||
}
|
||||
is TransactionType.YieldSupply.Topup,
|
||||
-> {
|
||||
val amount = amount.format { crypto(symbol = symbol, decimals = decimals) }
|
||||
resourceReference(R.string.yield_module_transaction_topup_subtitle, wrappedList(amount))
|
||||
}
|
||||
is TransactionType.YieldSupply.Exit -> {
|
||||
val amount = amount.format { crypto(symbol = symbol, decimals = decimals) }
|
||||
resourceReference(R.string.yield_module_transaction_exit_subtitle, wrappedList(amount))
|
||||
}
|
||||
else -> extractSubtitleByAddressType()
|
||||
}
|
||||
}
|
||||
|
||||
private fun TxInfo.extractSubtitleByAddressType(): TextReference =
|
||||
when (val interactionAddress = interactionAddressType) {
|
||||
is TxInfo.InteractionAddressType.Contract -> resourceReference(
|
||||
id = R.string.transaction_history_contract_address,
|
||||
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
|
||||
)
|
||||
is TxInfo.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 TxInfo.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 TxInfo.InteractionAddressType.Validator -> resourceReference(
|
||||
id = R.string.transaction_history_transaction_validator,
|
||||
formatArgs = wrappedList(interactionAddress.address.toBriefAddressFormat()),
|
||||
)
|
||||
null -> {
|
||||
TextReference.EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
private fun TxInfo.extractDirection() =
|
||||
if (isOutgoing) TransactionState.Content.Direction.OUTGOING else TransactionState.Content.Direction.INCOMING
|
||||
|
||||
|
|
@ -124,10 +145,14 @@ internal class TxHistoryItemStateConverter(
|
|||
TransactionStatus.Unconfirmed -> TransactionState.Content.Status.Unconfirmed
|
||||
}
|
||||
|
||||
@Suppress("ComplexCondition")
|
||||
private fun TxInfo.getAmount(): String {
|
||||
if (type is TransactionType.Staking.Vote ||
|
||||
type == TransactionType.Staking.ClaimRewards ||
|
||||
type == TransactionType.Staking.Withdraw
|
||||
type == TransactionType.Staking.Withdraw ||
|
||||
type == TransactionType.YieldSupply.Enter ||
|
||||
type == TransactionType.YieldSupply.Exit ||
|
||||
type == TransactionType.YieldSupply.Topup
|
||||
) {
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue