11package com.flipcash.app.core.ui
22
3+ import androidx.compose.foundation.Image
34import androidx.compose.foundation.clickable
45import androidx.compose.foundation.layout.Arrangement
56import androidx.compose.foundation.layout.PaddingValues
67import androidx.compose.foundation.layout.Row
78import androidx.compose.foundation.layout.Spacer
9+ import androidx.compose.foundation.layout.height
810import androidx.compose.foundation.layout.padding
911import androidx.compose.foundation.layout.size
12+ import androidx.compose.foundation.layout.width
13+ import androidx.compose.foundation.shape.CircleShape
1014import androidx.compose.material.Text
1115import androidx.compose.runtime.Composable
1216import androidx.compose.ui.Alignment
1317import androidx.compose.ui.Modifier
18+ import androidx.compose.ui.draw.clip
19+ import androidx.compose.ui.res.painterResource
1420import androidx.compose.ui.text.TextStyle
1521import androidx.compose.ui.unit.dp
22+ import com.getcode.opencode.compose.LocalExchange
1623import com.getcode.opencode.model.financial.Fiat
1724import com.getcode.opencode.model.financial.Token
1825import com.getcode.opencode.model.financial.TokenWithBalance
@@ -25,6 +32,7 @@ fun TokenBalanceRow(
2532 tokenWithBalance : TokenWithLocalizedBalance ,
2633 modifier : Modifier = Modifier ,
2734 showName : Boolean = true,
35+ showFlag : Boolean = false,
2836 formattedBalance : (Fiat ) -> String = { it.formatted() },
2937 horizontalArrangement : Arrangement .Horizontal = Arrangement .SpaceBetween ,
3038 nameTextStyle : TextStyle = CodeTheme .typography.screenTitle,
@@ -41,6 +49,7 @@ fun TokenBalanceRow(
4149 balanceTextStyle = balanceTextStyle,
4250 modifier = modifier,
4351 showName = showName,
52+ showFlag = showFlag,
4453 horizontalArrangement = horizontalArrangement,
4554 contentPadding = contentPadding,
4655 onClick = onClick
@@ -52,6 +61,7 @@ fun TokenBalanceRow(
5261 tokenWithBalance : TokenWithBalance ,
5362 modifier : Modifier = Modifier ,
5463 showName : Boolean = true,
64+ showFlag : Boolean = false,
5565 formattedBalance : (Fiat ) -> String = { it.formatted() },
5666 horizontalArrangement : Arrangement .Horizontal = Arrangement .SpaceBetween ,
5767 nameTextStyle : TextStyle = CodeTheme .typography.screenTitle,
@@ -64,6 +74,7 @@ fun TokenBalanceRow(
6474 token = token,
6575 balance = balance,
6676 showName = showName,
77+ showFlag = showFlag,
6778 modifier = modifier,
6879 nameTextStyle = nameTextStyle,
6980 balanceTextStyle = balanceTextStyle,
@@ -81,13 +92,15 @@ fun TokenBalanceRow(
8192 balance : Fiat ,
8293 modifier : Modifier = Modifier ,
8394 showName : Boolean = true,
95+ showFlag : Boolean = false,
8496 formattedBalance : (Fiat ) -> String = { it.formatted() },
8597 horizontalArrangement : Arrangement .Horizontal = Arrangement .SpaceBetween ,
8698 nameTextStyle : TextStyle = CodeTheme .typography.screenTitle,
8799 balanceTextStyle : TextStyle = CodeTheme .typography.screenTitle,
88100 contentPadding : PaddingValues = PaddingValues (vertical = CodeTheme .dimens.inset),
89101 onClick : (() -> Unit )? = null,
90102) {
103+ val exchange = LocalExchange .current
91104 Row (
92105 modifier = Modifier
93106 .addIf(onClick != null ) {
@@ -115,10 +128,29 @@ fun TokenBalanceRow(
115128 )
116129 }
117130
118- Text (
119- text = formattedBalance(balance),
120- style = balanceTextStyle,
121- color = CodeTheme .colors.textMain,
122- )
131+ val flag = exchange.getFlagByCurrency(balance.currencyCode.name)
132+ Row (
133+ horizontalArrangement = Arrangement .spacedBy(CodeTheme .dimens.grid.x1),
134+ verticalAlignment = Alignment .CenterVertically ,
135+ ) {
136+ if (showFlag) {
137+ flag?.let {
138+ Image (
139+ modifier = Modifier
140+ .height(CodeTheme .dimens.staticGrid.x3)
141+ .width(CodeTheme .dimens.staticGrid.x3)
142+ .clip(CircleShape ),
143+ painter = painterResource(it),
144+ contentDescription = " "
145+ )
146+ }
147+ }
148+
149+ Text (
150+ text = formattedBalance(balance),
151+ style = balanceTextStyle,
152+ color = CodeTheme .colors.textMain,
153+ )
154+ }
123155 }
124156}
0 commit comments