Skip to content

Commit da6df73

Browse files
committed
style(tokens): add flag support to TokenBalanceRow/TokenList; show for Give list
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 77a0d61 commit da6df73

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/ui/TokenBalanceRow.kt

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package com.flipcash.app.core.ui
22

3+
import androidx.compose.foundation.Image
34
import androidx.compose.foundation.clickable
45
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.PaddingValues
67
import androidx.compose.foundation.layout.Row
78
import androidx.compose.foundation.layout.Spacer
9+
import androidx.compose.foundation.layout.height
810
import androidx.compose.foundation.layout.padding
911
import androidx.compose.foundation.layout.size
12+
import androidx.compose.foundation.layout.width
13+
import androidx.compose.foundation.shape.CircleShape
1014
import androidx.compose.material.Text
1115
import androidx.compose.runtime.Composable
1216
import androidx.compose.ui.Alignment
1317
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.draw.clip
19+
import androidx.compose.ui.res.painterResource
1420
import androidx.compose.ui.text.TextStyle
1521
import androidx.compose.ui.unit.dp
22+
import com.getcode.opencode.compose.LocalExchange
1623
import com.getcode.opencode.model.financial.Fiat
1724
import com.getcode.opencode.model.financial.Token
1825
import 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
}

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/SelectTokenScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private fun SelectTokenScreenContent(
2828
TokenList(
2929
modifier = Modifier.fillMaxSize(),
3030
tokens = tokens,
31+
showFlags = true,
3132
onTokenSelected = { dispatch(SelectTokenViewModel.Event.OnTokenSelected(it)) }
3233
)
3334
}

apps/flipcash/shared/tokens/src/main/kotlin/TokenList.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.getcode.ui.core.verticalScrollStateGradient
2323
fun TokenList(
2424
tokens: List<TokenWithLocalizedBalance>?,
2525
modifier: Modifier = Modifier,
26+
showFlags: Boolean = false,
2627
emptyState: (@Composable LazyItemScope.() -> Unit)? = null,
2728
onTokenSelected: (Token) -> Unit = { },
2829
) {
@@ -51,7 +52,8 @@ fun TokenList(
5152
modifier = Modifier
5253
.fillParentMaxWidth()
5354
.padding(horizontal = CodeTheme.dimens.inset),
54-
tokenWithBalance = item
55+
tokenWithBalance = item,
56+
showFlag = showFlags,
5557
) { onTokenSelected(item.token) }
5658

5759
Divider(color = CodeTheme.colors.dividerVariant)

0 commit comments

Comments
 (0)