@@ -4,13 +4,17 @@ import androidx.compose.foundation.background
44import androidx.compose.foundation.layout.Arrangement
55import androidx.compose.foundation.layout.Box
66import androidx.compose.foundation.layout.Column
7+ import androidx.compose.foundation.layout.PaddingValues
78import androidx.compose.foundation.layout.Spacer
89import androidx.compose.foundation.layout.WindowInsets
10+ import androidx.compose.foundation.layout.asPaddingValues
911import androidx.compose.foundation.layout.fillMaxWidth
1012import androidx.compose.foundation.layout.navigationBars
1113import androidx.compose.foundation.layout.padding
1214import androidx.compose.foundation.layout.windowInsetsPadding
1315import androidx.compose.foundation.lazy.LazyColumn
16+ import androidx.compose.foundation.lazy.items
17+ import androidx.compose.foundation.lazy.itemsIndexed
1418import androidx.compose.foundation.lazy.rememberLazyListState
1519import androidx.compose.material.Divider
1620import androidx.compose.material.Text
@@ -24,45 +28,32 @@ import androidx.compose.ui.platform.LocalContext
2428import androidx.compose.ui.res.stringResource
2529import androidx.compose.ui.text.style.TextAlign
2630import androidx.compose.ui.tooling.preview.Preview
27- import androidx.paging.LoadState
28- import androidx.paging.PagingData
29- import androidx.paging.compose.LazyPagingItems
30- import androidx.paging.compose.collectAsLazyPagingItems
31- import androidx.paging.compose.itemKey
3231import com.flipcash.app.balance.internal.components.BalanceHeader
33- import com.flipcash.app.balance.internal.components.FeedItem
34- import com.flipcash.app.core.feed.ActivityFeedMessage
32+ import com.flipcash.app.core.ui.TokenBalanceRow
3533import com.flipcash.app.onramp.AddCashRow
3634import com.flipcash.app.theme.FlipcashDesignSystem
3735import com.flipcash.features.balance.R
3836import com.getcode.opencode.compose.ExchangeStub
3937import com.getcode.opencode.compose.LocalExchange
4038import com.getcode.opencode.model.financial.CurrencyCode
41- import com.getcode.opencode.model.financial.LocalFiat
4239import com.getcode.opencode.model.financial.Rate
43- import com.getcode.opencode.model.financial.toFiat
40+ import com.getcode.solana.keys.base58
4441import com.getcode.theme.CodeTheme
4542import com.getcode.ui.core.verticalScrollStateGradient
46- import com.getcode.ui.theme.ButtonState
47- import com.getcode.ui.theme.CodeButton
48- import kotlinx.coroutines.flow.flowOf
4943
5044@Composable
5145internal fun BalanceScreen (viewModel : BalanceViewModel ) {
5246 val state by viewModel.stateFlow.collectAsState()
53- val feed = viewModel.feed.collectAsLazyPagingItems()
5447
5548 BalanceScreenContent (
5649 state = state,
57- feed = feed,
5850 dispatchEvent = viewModel::dispatchEvent
5951 )
6052}
6153
6254@Composable
6355private fun BalanceScreenContent (
6456 state : BalanceViewModel .State ,
65- feed : LazyPagingItems <ActivityFeedMessage >,
6657 dispatchEvent : (BalanceViewModel .Event ) -> Unit
6758) {
6859 Column {
@@ -85,20 +76,18 @@ private fun BalanceScreenContent(
8576 onWithdraw = { dispatchEvent(BalanceViewModel .Event .OnWithdrawClicked ) },
8677 )
8778
88- FeedList (
79+ TokenList (
8980 modifier = Modifier .weight(1f ),
9081 state = state,
91- feed = feed,
9282 dispatchEvent = dispatchEvent
9383 )
9484 }
9585}
9686
9787@Composable
98- private fun FeedList (
88+ private fun TokenList (
9989 modifier : Modifier = Modifier ,
10090 state : BalanceViewModel .State ,
101- feed : LazyPagingItems <ActivityFeedMessage >,
10291 dispatchEvent : (BalanceViewModel .Event ) -> Unit
10392) {
10493 val listState = rememberLazyListState()
@@ -109,16 +98,23 @@ private fun FeedList(
10998 color = CodeTheme .colors.background,
11099 showAtEnd = true
111100 ),
101+ contentPadding = PaddingValues (
102+ bottom = WindowInsets .navigationBars.asPaddingValues().calculateBottomPadding()
103+ ),
112104 state = listState
113105 ) {
114- if (feed.itemCount == 0 && feed.loadState.append is LoadState . NotLoading ) {
106+ if (state.balances != null && state.balances.isEmpty() ) {
115107 item {
116108 Box (
117- modifier = Modifier .fillParentMaxSize().padding(bottom = CodeTheme .dimens.inset),
109+ modifier = Modifier
110+ .fillParentMaxSize()
111+ .padding(bottom = CodeTheme .dimens.inset),
118112 contentAlignment = Alignment .Center
119113 ) {
120114 Column (
121- modifier = Modifier .fillMaxWidth().padding(horizontal = CodeTheme .dimens.inset),
115+ modifier = Modifier
116+ .fillMaxWidth()
117+ .padding(horizontal = CodeTheme .dimens.inset),
122118 verticalArrangement = Arrangement .spacedBy(CodeTheme .dimens.grid.x12),
123119 horizontalAlignment = Alignment .CenterHorizontally
124120 ) {
@@ -132,25 +128,16 @@ private fun FeedList(
132128 }
133129 }
134130 } else {
135- items(feed.itemCount, key = feed.itemKey { item -> item.id }) { index ->
136- val message = feed[index] ? : return @items
137- FeedItem (
138- modifier = Modifier
139- .fillParentMaxWidth()
140- .animateItem(),
141- message = message,
142- canViewDetails = state.canViewDetails,
143- isExpanded = state.expandedItem == message.id,
144- dispatch = dispatchEvent
145- )
131+ itemsIndexed(
132+ state.balances.orEmpty(),
133+ key = { index, item -> item.token.address.base58() }) { index, item ->
134+ TokenBalanceRow (
135+ modifier = Modifier .fillParentMaxWidth()
136+ .padding(horizontal = CodeTheme .dimens.inset),
137+ tokenWithBalance = item
138+ ) { }
146139
147- if (index < feed.itemCount - 1 ) {
148- Divider (color = CodeTheme .colors.dividerVariant)
149- }
150- }
151-
152- item {
153- Spacer (Modifier .windowInsetsPadding(WindowInsets .navigationBars))
140+ Divider (color = CodeTheme .colors.dividerVariant)
154141 }
155142 }
156143 }
@@ -177,7 +164,6 @@ private fun Preview_BalanceScreen_Empty() {
177164 state = BalanceViewModel .State (
178165 balances = emptyList()
179166 ),
180- feed = flowOf(PagingData .empty<ActivityFeedMessage >()).collectAsLazyPagingItems(),
181167 dispatchEvent = {}
182168 )
183169 }
0 commit comments