11package com.flipcash.app.cash
22
33import android.os.Parcelable
4+ import androidx.compose.foundation.Image
5+ import androidx.compose.foundation.layout.Arrangement
6+ import androidx.compose.foundation.layout.Box
47import androidx.compose.foundation.layout.Column
8+ import androidx.compose.foundation.layout.Row
59import androidx.compose.foundation.layout.fillMaxSize
10+ import androidx.compose.foundation.layout.fillMaxWidth
11+ import androidx.compose.foundation.layout.width
12+ import androidx.compose.foundation.layout.wrapContentHeight
13+ import androidx.compose.foundation.layout.wrapContentWidth
14+ import androidx.compose.foundation.shape.CircleShape
615import androidx.compose.runtime.Composable
716import androidx.compose.runtime.LaunchedEffect
17+ import androidx.compose.runtime.getValue
818import androidx.compose.ui.Alignment
919import androidx.compose.ui.Modifier
20+ import androidx.compose.ui.draw.clip
21+ import androidx.compose.ui.res.painterResource
1022import androidx.compose.ui.res.stringResource
23+ import androidx.lifecycle.compose.collectAsStateWithLifecycle
1124import cafe.adriel.voyager.core.registry.ScreenRegistry
1225import cafe.adriel.voyager.core.screen.ScreenKey
1326import cafe.adriel.voyager.core.screen.uniqueScreenKey
1427import cafe.adriel.voyager.hilt.getViewModel
1528import cafe.adriel.voyager.navigator.currentOrThrow
1629import com.flipcash.app.cash.internal.CashScreenViewModel
1730import com.flipcash.app.cash.internal.GiveScreenContent
31+ import com.flipcash.app.core.AppRoute
32+ import com.flipcash.app.core.tokens.TokenPurpose
33+ import com.flipcash.app.core.ui.TokenIconWithName
1834import com.flipcash.app.session.LocalSessionController
1935import com.flipcash.features.cash.R
2036import com.getcode.navigation.core.LocalCodeNavigator
2137import com.getcode.navigation.modal.ModalScreen
2238import com.getcode.solana.keys.Mint
39+ import com.getcode.theme.CodeTheme
40+ import com.getcode.ui.components.AppBarDefaults
2341import com.getcode.ui.components.AppBarWithTitle
42+ import com.getcode.ui.core.rememberedClickable
2443import kotlinx.coroutines.flow.filterIsInstance
2544import kotlinx.coroutines.flow.launchIn
2645import kotlinx.coroutines.flow.map
@@ -30,8 +49,8 @@ import kotlinx.parcelize.Parcelize
3049
3150@Parcelize
3251class CashScreen (
33- private val selectedMint : Mint
34- ): ModalScreen, Parcelable {
52+ private val selectedMint : Mint ?
53+ ) : ModalScreen, Parcelable {
3554
3655 @IgnoredOnParcel
3756 override val key: ScreenKey = uniqueScreenKey
@@ -42,6 +61,7 @@ class CashScreen(
4261 val session = LocalSessionController .currentOrThrow
4362
4463 val viewModel = getViewModel<CashScreenViewModel >()
64+ val state by viewModel.stateFlow.collectAsStateWithLifecycle()
4565
4666 LaunchedEffect (viewModel) {
4767 viewModel.eventFlow
@@ -59,16 +79,58 @@ class CashScreen(
5979 ) {
6080 AppBarWithTitle (
6181 isInModal = true ,
62- title = stringResource(R .string.title_enterAmount),
63- titleAlignment = Alignment .CenterHorizontally ,
64- backButton = true ,
65- onBackIconClicked = { navigator.pop() },
82+ title = {
83+ Box (
84+ modifier = Modifier
85+ .fillMaxWidth()
86+ .wrapContentHeight(),
87+ contentAlignment = Alignment .Center
88+ ) {
89+ Row (
90+ modifier = Modifier
91+ .clip(CircleShape )
92+ .rememberedClickable {
93+ navigator.push(
94+ ScreenRegistry .get(
95+ AppRoute .Sheets .TokenSelection (TokenPurpose .Select )
96+ )
97+ )
98+ },
99+ verticalAlignment = Alignment .CenterVertically ,
100+ horizontalArrangement = Arrangement .spacedBy(
101+ space = CodeTheme .dimens.grid.x1,
102+ alignment = Alignment .CenterHorizontally
103+ )
104+ ) {
105+ state.token?.let { (token, _) ->
106+ TokenIconWithName (
107+ token = token,
108+ imageSize = CodeTheme .dimens.staticGrid.x5,
109+ spacing = CodeTheme .dimens.grid.x1,
110+ )
111+
112+ Image (
113+ modifier = Modifier
114+ .width(CodeTheme .dimens.grid.x4),
115+ painter = painterResource(R .drawable.ic_dropdown),
116+ contentDescription = " "
117+ )
118+ }
119+
120+ }
121+ }
122+ },
123+ rightContents = {
124+ AppBarDefaults .Close { navigator.hide() }
125+ }
66126 )
67127 GiveScreenContent (viewModel)
68128 }
69129
70130 LaunchedEffect (viewModel, selectedMint) {
71- viewModel.dispatchEvent(CashScreenViewModel .Event .OnTokenSelected (selectedMint))
131+ selectedMint?.let {
132+ viewModel.dispatchEvent(CashScreenViewModel .Event .OnTokenSelected (it))
133+ }
72134 }
73135
74136 LaunchedEffect (viewModel) {
0 commit comments