@@ -177,6 +177,9 @@ class AppViewModel @Inject constructor(
177177 private val _showForgotPinSheet = MutableStateFlow (false )
178178 val showForgotPinSheet = _showForgotPinSheet .asStateFlow()
179179
180+ private val _currentSheet : MutableStateFlow <Sheet ?> = MutableStateFlow (null )
181+ val currentSheet = _currentSheet .asStateFlow()
182+
180183 private val processedPayments = mutableSetOf<String >()
181184
182185 private val timedSheetManager = timedSheetManagerProvider(viewModelScope).apply {
@@ -237,7 +240,12 @@ class AppViewModel @Inject constructor(
237240 viewModelScope.launch {
238241 timedSheetManager.currentSheet.collect { sheetType ->
239242 if (sheetType != null ) {
240- _currentSheet .update { Sheet .TimedSheet (sheetType) }
243+ showSheet(Sheet .TimedSheet (sheetType))
244+ } else {
245+ // Clear the timed sheet when manager sets it to null
246+ _currentSheet .update { current ->
247+ if (current is Sheet .TimedSheet ) null else current
248+ }
241249 }
242250 }
243251 }
@@ -1583,9 +1591,6 @@ class AppViewModel @Inject constructor(
15831591 // endregion
15841592
15851593 // region Sheets
1586- private val _currentSheet : MutableStateFlow <Sheet ?> = MutableStateFlow (null )
1587- val currentSheet = _currentSheet .asStateFlow()
1588-
15891594 fun showSheet (sheetType : Sheet ) {
15901595 viewModelScope.launch {
15911596 _currentSheet .value?.let {
@@ -1597,10 +1602,17 @@ class AppViewModel @Inject constructor(
15971602 }
15981603
15991604 fun hideSheet () {
1600- if (currentSheet.value is Sheet .TimedSheet && timedSheetManager.currentSheet.value != null ) {
1601- dismissTimedSheet()
1602- } else {
1603- _currentSheet .update { null }
1605+ when {
1606+ currentSheet.value is Sheet .TimedSheet -> {
1607+ // Only dismiss if manager still has a sheet (user initiated)
1608+ // If manager already cleared it, just update our state
1609+ if (timedSheetManager.currentSheet.value != null ) {
1610+ dismissTimedSheet()
1611+ } else {
1612+ _currentSheet .update { null }
1613+ }
1614+ }
1615+ else -> _currentSheet .update { null }
16041616 }
16051617 }
16061618
0 commit comments