Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.flipcash.app.directsend

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand All @@ -17,6 +18,7 @@ import com.getcode.navigation.annotatedEntry
import com.getcode.navigation.flow.FlowExitReason
import com.getcode.navigation.flow.FlowHost
import com.getcode.navigation.results.NavResultStateRegistry
import com.getcode.navigation.flow.flowSharedViewModel
import com.getcode.navigation.scenes.LocalBottomSheetDismissDispatcher

@Composable
Expand All @@ -42,12 +44,23 @@ fun SendFlowScreen(resultStateRegistry: NavResultStateRegistry) {

private fun sendEntryProvider(): (NavKey) -> NavEntry<NavKey> = entryProvider {
annotatedEntry<SendStep.PhoneGate> {
SyncStep(it)
PhoneGateLandingScreen()
}
annotatedEntry<SendStep.ContactsGate> {
SyncStep(it)
ContactsPermissionGateScreen()
}
annotatedEntry<SendStep.ContactList> {
SyncStep(it)
ContactListScreen()
}
}

@Composable
private fun SyncStep(step: SendStep) {
val viewModel = flowSharedViewModel<SendFlowViewModel>()
LaunchedEffect(step) {
viewModel.dispatchEvent(SendFlowViewModel.Event.OnStepChanged(step))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal class SendFlowViewModel @Inject constructor(

data class State @OptIn(ExperimentalMaterial3Api::class) constructor(
val steps: List<SendStep> = listOf(SendStep.ContactList),
val currentStep: SendStep? = null,
val searchState: TextFieldState = TextFieldState(),
val isPickerMode: Boolean = false,
val contactSyncState: LoadingSuccessState = LoadingSuccessState(),
Expand All @@ -54,6 +55,7 @@ internal class SendFlowViewModel @Inject constructor(

sealed interface Event {
data class StepsUpdated(val steps: List<SendStep>, val isPickerMode: Boolean) : Event
data class OnStepChanged(val step: SendStep) : Event

data object ContactsGranted : Event
data class ContactsPicked(val contacts: List<PickedContact>) : Event
Expand Down Expand Up @@ -164,6 +166,7 @@ internal class SendFlowViewModel @Inject constructor(

contactCoordinator.state
.filter { it.hasDiscoveredFlipcashContacts && it.flipcashE164s.isNotEmpty() }
.filter { stateFlow.value.currentStep is SendStep.ContactList }
.take(1)
.onEach { contactState ->
val count = contactState.flipcashE164s.size
Expand Down Expand Up @@ -222,6 +225,10 @@ internal class SendFlowViewModel @Inject constructor(
state.copy(steps = event.steps, isPickerMode = event.isPickerMode)
}

is Event.OnStepChanged -> { state ->
state.copy(currentStep = event.step)
}

is Event.ContactsGranted -> { state -> state }
is Event.ContactsPicked -> { state -> state }
is Event.ContactSyncStateUpdated -> { state ->
Expand Down
Loading