-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathReceiveTokensMapper.kt
106 lines (99 loc) · 3.85 KB
/
ReceiveTokensMapper.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
package org.p2p.wallet.receive.tokenselect
import org.p2p.core.common.DrawableContainer
import org.p2p.core.common.TextContainer
import org.p2p.core.token.TokenMetadata
import org.p2p.core.utils.Constants
import org.p2p.ethereumkit.external.model.ERC20Tokens
import org.p2p.uikit.components.finance_block.MainCellModel
import org.p2p.uikit.components.icon_wrapper.IconWrapperCellModel
import org.p2p.uikit.components.icon_wrapper.TwoIconAngle
import org.p2p.uikit.components.left_side.LeftSideCellModel
import org.p2p.uikit.components.right_side.RightSideCellModel
import org.p2p.uikit.model.AnyCellItem
import org.p2p.uikit.utils.drawable.DrawableCellModel
import org.p2p.uikit.utils.drawable.shape.shapeCircle
import org.p2p.uikit.utils.drawable.shapeDrawable
import org.p2p.uikit.utils.image.ImageViewCellModel
import org.p2p.uikit.utils.image.commonCircleImage
import org.p2p.uikit.utils.text.TextViewCellModel
import org.p2p.wallet.R
import org.p2p.wallet.receive.tokenselect.models.ReceiveTokenPayload
object ReceiveTokensMapper {
fun TokenMetadata.toTokenFinanceCellModel(
solTokenUrl: String,
ethTokenUrl: String
): AnyCellItem {
val isErc20Token = ERC20Tokens.findTokenByMint(mintAddress, ERC20Tokens.MATIC) != null
val isSol = mintAddress == Constants.WRAPPED_SOL_MINT
val replacedName = if (isSol) Constants.SOL_NAME else name
return MainCellModel(
leftSideCellModel = createLeftSideModel(
tokenIconUrl = iconUrl.orEmpty(),
tokenName = replacedName,
tokenSymbol = symbol,
),
rightSideCellModel = createRightSideModel(
firstIconUrl = solTokenUrl,
secondIconUrl = ethTokenUrl,
isErc20Token = isErc20Token
),
payload = ReceiveTokenPayload(
tokenMetadata = this,
isErc20Token = isErc20Token
)
)
}
private fun createLeftSideModel(
tokenIconUrl: String,
tokenName: String,
tokenSymbol: String
): LeftSideCellModel.IconWithText {
val tokenIconImage =
DrawableContainer.Raw(iconUrl = tokenIconUrl)
.let(::commonCircleImage)
.let(IconWrapperCellModel::SingleIcon)
val firstLineText = TextViewCellModel.Raw(
text = TextContainer.Raw(tokenName),
textAppearance = R.style.UiKit_TextAppearance_Regular_Text3
)
val secondLineText = TextViewCellModel.Raw(TextContainer.Raw(tokenSymbol))
return LeftSideCellModel.IconWithText(
icon = tokenIconImage,
firstLineText = firstLineText,
secondLineText = secondLineText
)
}
private fun createRightSideModel(
firstIconUrl: String,
secondIconUrl: String,
isErc20Token: Boolean
): RightSideCellModel {
val solImageCell = ImageViewCellModel(
icon = DrawableContainer.Raw(firstIconUrl),
clippingShape = shapeCircle(),
)
val firstIcon: ImageViewCellModel?
val secondIcon: ImageViewCellModel?
if (isErc20Token) {
firstIcon = ImageViewCellModel(
icon = DrawableContainer.Raw(secondIconUrl),
background = DrawableCellModel(
drawable = shapeDrawable(shape = shapeCircle()),
tint = R.color.icons_rain,
),
clippingShape = shapeCircle(),
)
secondIcon = solImageCell
} else {
firstIcon = solImageCell
secondIcon = null
}
return RightSideCellModel.IconWrapper(
iconWrapper = IconWrapperCellModel.TwoIcon(
first = firstIcon,
second = secondIcon,
angleType = TwoIconAngle.Plus180
)
)
}
}