1+ package com.flipcash.app.onramp
2+
3+ import android.os.Parcelable
4+ import androidx.compose.foundation.layout.Box
5+ import androidx.compose.foundation.layout.Column
6+ import androidx.compose.foundation.layout.fillMaxSize
7+ import androidx.compose.runtime.Composable
8+ import androidx.compose.runtime.LaunchedEffect
9+ import androidx.compose.runtime.getValue
10+ import androidx.compose.runtime.mutableStateOf
11+ import androidx.compose.runtime.saveable.rememberSaveable
12+ import androidx.compose.runtime.setValue
13+ import androidx.compose.ui.Alignment
14+ import androidx.compose.ui.Modifier
15+ import androidx.compose.ui.res.stringResource
16+ import cafe.adriel.voyager.core.registry.ScreenRegistry
17+ import cafe.adriel.voyager.core.screen.ScreenKey
18+ import cafe.adriel.voyager.core.screen.uniqueScreenKey
19+ import com.flipcash.app.core.NavScreenProvider
20+ import com.flipcash.app.onramp.internal.OnRampViewModel
21+ import com.flipcash.app.onramp.internal.screens.OnRampAmountScreen
22+ import com.flipcash.features.onramp.R
23+ import com.getcode.navigation.core.LocalCodeNavigator
24+ import com.getcode.navigation.extensions.getStackScopedViewModel
25+ import com.getcode.navigation.modal.ModalScreen
26+ import com.getcode.navigation.screens.NamedScreen
27+ import com.getcode.ui.components.AppBarWithTitle
28+ import kotlinx.coroutines.flow.filterIsInstance
29+ import kotlinx.coroutines.flow.launchIn
30+ import kotlinx.coroutines.flow.map
31+ import kotlinx.coroutines.flow.onEach
32+ import kotlinx.parcelize.IgnoredOnParcel
33+ import kotlinx.parcelize.Parcelize
34+
35+ @Parcelize
36+ class OnRampAmountScreen : ModalScreen , NamedScreen , Parcelable {
37+
38+ @IgnoredOnParcel
39+ override val key: ScreenKey = uniqueScreenKey
40+
41+ override val name: String
42+ @Composable get() = stringResource(R .string.title_amountToAdd)
43+
44+ @Composable
45+ override fun ModalContent () {
46+ val navigator = LocalCodeNavigator .current
47+ val viewModel = getStackScopedViewModel<OnRampViewModel >(key = OnRampFlowTracker .key)
48+ var paymentLink by rememberSaveable { mutableStateOf<String ?>(null ) }
49+ Box {
50+ paymentLink?.let {
51+ CoinbaseOnRampWebview (
52+ paymentLinkUrl = it,
53+ onPaymentSuccess = {
54+ paymentLink = null
55+ viewModel.dispatchEvent(OnRampViewModel .Event .OnPaymentSuccess )
56+ },
57+ onPaymentFailure = {
58+ paymentLink = null
59+ viewModel.dispatchEvent(OnRampViewModel .Event .OnPaymentError (it))
60+ }
61+ )
62+ }
63+
64+ Column (
65+ modifier = Modifier .fillMaxSize(),
66+ ) {
67+ AppBarWithTitle (
68+ title = name,
69+ isInModal = true ,
70+ backButton = true ,
71+ onBackIconClicked = { navigator.pop() },
72+ titleAlignment = Alignment .CenterHorizontally ,
73+ )
74+ OnRampAmountScreen (viewModel)
75+ }
76+ }
77+
78+ LaunchedEffect (viewModel) {
79+ viewModel.eventFlow
80+ .filterIsInstance<OnRampViewModel .Event .OnPaymentLinkGenerated >()
81+ .map { it.url }
82+ .onEach {
83+
84+ }.launchIn(this )
85+ }
86+ }
87+ }
0 commit comments