diff --git a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt index f2ded85944..62f4f714b1 100644 --- a/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt +++ b/app/src/main/java/com/tangem/tap/features/wallet/models/PendingTransaction.kt @@ -6,12 +6,21 @@ import com.tangem.tap.common.extensions.toFormattedString import java.math.BigDecimal data class PendingTransaction( - val address: String?, - val amount: BigDecimal?, - val amountUi: String?, - val currency: String, - val type: PendingTransactionType -) + val transactionData: TransactionData, + val type: PendingTransactionType, +) { + val address: String? = when (type) { + PendingTransactionType.Incoming -> transactionData.destinationAddress + PendingTransactionType.Outgoing -> transactionData.sourceAddress + PendingTransactionType.Unknown -> null + } + + val amountValue: BigDecimal? = transactionData.amount.value + + val amountValueUi: String? = amountValue?.toFormattedString(transactionData.amount.decimals) + + val currency: String = transactionData.amount.currencySymbol +} enum class PendingTransactionType { Incoming, Outgoing, Unknown } @@ -19,29 +28,11 @@ fun TransactionData.toPendingTransaction(walletAddress: String): PendingTransact if (this.status == TransactionStatus.Confirmed) return null val type: PendingTransactionType = when { - this.sourceAddress == walletAddress -> { - PendingTransactionType.Outgoing - } - this.destinationAddress == walletAddress -> { - PendingTransactionType.Incoming - } - else -> { - PendingTransactionType.Unknown - } + this.sourceAddress == walletAddress -> PendingTransactionType.Outgoing + this.destinationAddress == walletAddress -> PendingTransactionType.Incoming + else -> PendingTransactionType.Unknown } - val address = if (this.sourceAddress == walletAddress) { - this.destinationAddress - } else { - this.sourceAddress - } - - return PendingTransaction( - if (address == "unknown") null else address, - this.amount.value, - this.amount.value?.toFormattedString(amount.decimals), - this.amount.currencySymbol, - type - ) + return PendingTransaction(this, type) } fun List.toPendingTransactions(walletAddress: String): List {