-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathHistoryItem.kt
126 lines (106 loc) · 4.17 KB
/
HistoryItem.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package org.p2p.wallet.history.ui.model
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import org.threeten.bp.ZonedDateTime
import org.p2p.core.utils.asNegativeUsdTransaction
import org.p2p.core.utils.asPositiveUsdTransaction
import org.p2p.core.utils.formatToken
import org.p2p.core.utils.scaleSix
import org.p2p.core.utils.toBigDecimalOrZero
import org.p2p.uikit.utils.recycler.RoundedItem
import org.p2p.wallet.bridge.model.BridgeBundle
import org.p2p.wallet.bridge.send.model.BridgeSendTransactionDetails
import org.p2p.wallet.jupiter.model.SwapOpenedFrom
import org.p2p.wallet.utils.emptyString
sealed interface HistoryItem {
val date: ZonedDateTime
val transactionId: String
data class TransactionItem(
override val date: ZonedDateTime,
override val transactionId: String,
val tokenIconUrl: String?,
val sourceIconUrl: String?,
val destinationIconUrl: String?,
val startTitle: String?,
val startSubtitle: String?,
val endTopValue: String?,
@ColorRes val endTopValueTextColor: Int?,
val endBottomValue: String?,
@DrawableRes val iconRes: Int,
val statusIcon: Int?
) : HistoryItem, RoundedItem
data class DateItem(
override val date: ZonedDateTime,
// TODO refactor this
override val transactionId: String = emptyString()
) : HistoryItem
data class MoonpayTransactionItem(
override val date: ZonedDateTime,
override val transactionId: String,
val statusIconRes: Int,
val statusBackgroundRes: Int,
val statusIconColor: Int,
val titleStatus: String,
val subtitleReceiver: String,
val endTopValue: String,
val endBottomValue: String? = null,
) : HistoryItem, RoundedItem
data class UserSendLinksItem(
val linksCount: Int
) : HistoryItem, RoundedItem {
override val date: ZonedDateTime = ZonedDateTime.now()
override val transactionId: String = emptyString()
}
data class SwapBannerItem(
val sourceTokenMintAddress: String,
val destinationTokenMintAddress: String,
val sourceTokenSymbol: String,
val destinationTokenSymbol: String,
val openedFrom: SwapOpenedFrom = SwapOpenedFrom.HISTORY_SCREEN_BANNER
) : HistoryItem {
override val date: ZonedDateTime = ZonedDateTime.now()
override val transactionId: String = emptyString()
}
data class BridgeSendItem(
val id: String,
val sendDetails: BridgeSendTransactionDetails,
val tokenIconUrl: String?
) : HistoryItem, RoundedItem {
override val date: ZonedDateTime = ZonedDateTime.now()
override val transactionId: String = id
fun getFormattedFiatValue(): String {
val totalFiatAmount = sendDetails.amount.amountInUsd.toBigDecimalOrZero()
return totalFiatAmount.asNegativeUsdTransaction()
}
fun getFormattedTotal(scaleMedium: Boolean = false): String {
val totalAmount = sendDetails.amount.amountInToken
val tokenSymbol = sendDetails.amount.symbol
return if (scaleMedium) {
"${totalAmount.scaleSix().formatToken()} $tokenSymbol"
} else {
"${totalAmount.formatToken()} $tokenSymbol"
}
}
}
data class BridgeClaimItem(
val bundleId: String,
val bundle: BridgeBundle,
val tokenIconUrl: String?
) : HistoryItem, RoundedItem {
override val date: ZonedDateTime = ZonedDateTime.now()
override val transactionId: String = bundleId
fun getFormattedFiatValue(): String {
return bundle.resultAmount.amountInUsd.toBigDecimalOrZero()
.asPositiveUsdTransaction()
}
fun getFormattedTotal(scaleMedium: Boolean = false): String {
val totalAmount = bundle.resultAmount.amountInToken
val tokenSymbol = bundle.resultAmount.symbol
return if (scaleMedium) {
"${totalAmount.scaleSix().formatToken()} $tokenSymbol"
} else {
"${totalAmount.formatToken()} $tokenSymbol"
}
}
}
}