@@ -37,7 +37,6 @@ import kotlinx.coroutines.delay
3737import kotlinx.coroutines.flow.MutableSharedFlow
3838import kotlinx.coroutines.flow.MutableStateFlow
3939import kotlinx.coroutines.flow.SharingStarted
40- import kotlinx.coroutines.flow.StateFlow
4140import kotlinx.coroutines.flow.asSharedFlow
4241import kotlinx.coroutines.flow.asStateFlow
4342import kotlinx.coroutines.flow.first
@@ -316,7 +315,7 @@ class AppViewModel @Inject constructor(
316315 val cjitEntry = channel?.let { blocktankRepo.getCjitEntry(it) }
317316 if (cjitEntry != null ) {
318317 val amount = channel.amountOnClose.toLong()
319- showNewTransactionSheet (
318+ showTransactionSheet (
320319 NewTransactionSheetDetails (
321320 type = NewTransactionSheetType .LIGHTNING ,
322321 direction = NewTransactionSheetDirection .RECEIVED ,
@@ -359,7 +358,7 @@ class AppViewModel @Inject constructor(
359358 val result = notifyPaymentReceivedHandler(command).getOrNull()
360359 if (result !is NotifyPaymentReceived .Result .ShowSheet ) return
361360
362- showNewTransactionSheet (result.sheet)
361+ showTransactionSheet (result.sheet)
363362 }
364363
365364 private fun notifyTransactionUnconfirmed () = toast(
@@ -1223,10 +1222,10 @@ class AppViewModel @Inject constructor(
12231222 }
12241223
12251224 fun onClickActivityDetail () {
1226- val activityType = _newTransaction .value.type.toActivityFilter()
1227- val txType = _newTransaction .value.direction.toTxType()
1228- val paymentHashOrTxId = _newTransaction .value.paymentHashOrTxId ? : return
1229- _newTransaction .update { it.copy(isLoadingDetails = true ) }
1225+ val activityType = _transactionSheet .value.type.toActivityFilter()
1226+ val txType = _transactionSheet .value.direction.toTxType()
1227+ val paymentHashOrTxId = _transactionSheet .value.paymentHashOrTxId ? : return
1228+ _transactionSheet .update { it.copy(isLoadingDetails = true ) }
12301229 viewModelScope.launch {
12311230 activityRepo.findActivityByPaymentId(
12321231 paymentHashOrTxId = paymentHashOrTxId,
@@ -1235,13 +1234,13 @@ class AppViewModel @Inject constructor(
12351234 retry = true
12361235 ).onSuccess { activity ->
12371236 hideNewTransactionSheet()
1238- _newTransaction .update { it.copy(isLoadingDetails = false ) }
1237+ _transactionSheet .update { it.copy(isLoadingDetails = false ) }
12391238 val nextRoute = Routes .ActivityDetail (activity.rawId())
12401239 mainScreenEffect(MainScreenEffect .Navigate (nextRoute))
12411240 }.onFailure { e ->
12421241 Logger .error(msg = " Activity not found" , context = TAG )
12431242 toast(e)
1244- _newTransaction .update { it.copy(isLoadingDetails = false ) }
1243+ _transactionSheet .update { it.copy(isLoadingDetails = false ) }
12451244 }
12461245 }
12471246 }
@@ -1446,18 +1445,10 @@ class AppViewModel @Inject constructor(
14461445 // endregion
14471446
14481447 // region TxSheet
1449- private var _isNewTransactionSheetEnabled = true
1450- private val _showNewTransaction = MutableStateFlow (false )
1451- val showNewTransaction: StateFlow <Boolean > = _showNewTransaction .asStateFlow()
1448+ private var _isTransactionSheetEnabled = true
14521449
1453- private val _newTransaction = MutableStateFlow (
1454- NewTransactionSheetDetails (
1455- type = NewTransactionSheetType .LIGHTNING ,
1456- direction = NewTransactionSheetDirection .RECEIVED ,
1457- )
1458- )
1459-
1460- val newTransaction = _newTransaction .asStateFlow()
1450+ private val _transactionSheet = MutableStateFlow (NewTransactionSheetDetails .EMPTY )
1451+ val transactionSheet = _transactionSheet .asStateFlow()
14611452
14621453 private val _successSendUiState = MutableStateFlow (
14631454 NewTransactionSheetDetails (
@@ -1468,32 +1459,31 @@ class AppViewModel @Inject constructor(
14681459
14691460 val successSendUiState = _successSendUiState .asStateFlow()
14701461
1471- fun setNewTransactionSheetEnabled (enabled : Boolean ) {
1472- _isNewTransactionSheetEnabled = enabled
1462+ fun enabledTransactionSheet (enabled : Boolean ) {
1463+ _isTransactionSheetEnabled = enabled
14731464 }
14741465
1475- fun showNewTransactionSheet (
1466+ fun showTransactionSheet (
14761467 details : NewTransactionSheetDetails ,
14771468 ) = viewModelScope.launch {
14781469 if (backupRepo.isRestoring.value) return @launch
14791470
1480- if (! _isNewTransactionSheetEnabled ) {
1471+ if (! _isTransactionSheetEnabled ) {
14811472 Logger .verbose(" NewTransactionSheet blocked by isNewTransactionSheetEnabled=false" , context = TAG )
14821473 return @launch
14831474 }
14841475
1485- hideSheet()
1486-
1487- _showNewTransaction .update { true }
1488- _newTransaction .update { details }
1476+ _transactionSheet .update { details }
14891477 }
14901478
1491- fun hideNewTransactionSheet () = _showNewTransaction .update { false }
1479+ fun hideNewTransactionSheet () {
1480+ _transactionSheet .update { NewTransactionSheetDetails .EMPTY }
1481+ }
14921482
14931483 fun consumePaymentReceivedInBackground () = viewModelScope.launch(bgDispatcher) {
14941484 val details = cacheStore.data.first().backgroundReceive ? : return @launch
14951485 cacheStore.clearBackgroundReceive()
1496- showNewTransactionSheet (details)
1486+ showTransactionSheet (details)
14971487 }
14981488 // endregion
14991489
@@ -1714,8 +1704,6 @@ class AppViewModel @Inject constructor(
17141704 return
17151705 }
17161706
1717- if (backupRepo.isRestoring.value) return
1718-
17191707 timedSheetsScope?.cancel()
17201708 timedSheetsScope = CoroutineScope (bgDispatcher + SupervisorJob ())
17211709 timedSheetsScope?.launch {
0 commit comments