Skip to content

Commit 22ea407

Browse files
committed
fix: keep timed sheets behind transaction sheet
1 parent 503cc0d commit 22ea407

File tree

6 files changed

+36
-40
lines changed

6 files changed

+36
-40
lines changed

app/src/main/java/to/bitkit/models/NewTransactionSheetDetails.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ data class NewTransactionSheetDetails(
1111
val paymentHashOrTxId: String? = null,
1212
val sats: Long = 0,
1313
val isLoadingDetails: Boolean = false,
14-
)
14+
) {
15+
companion object {
16+
val EMPTY = NewTransactionSheetDetails(
17+
type = NewTransactionSheetType.LIGHTNING,
18+
direction = NewTransactionSheetDirection.RECEIVED,
19+
)
20+
}
21+
}
1522

1623
@Serializable
1724
enum class NewTransactionSheetType {

app/src/main/java/to/bitkit/ui/MainActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import kotlinx.coroutines.launch
3030
import kotlinx.serialization.Serializable
3131
import to.bitkit.androidServices.LightningNodeService
3232
import to.bitkit.androidServices.LightningNodeService.Companion.CHANNEL_ID_NODE
33+
import to.bitkit.models.NewTransactionSheetDetails
3334
import to.bitkit.ui.components.AuthCheckView
3435
import to.bitkit.ui.components.InactivityTracker
3536
import to.bitkit.ui.components.IsOnlineTracker
@@ -168,8 +169,8 @@ class MainActivity : FragmentActivity() {
168169
}
169170
)
170171

171-
val showNewTransaction by appViewModel.showNewTransaction.collectAsStateWithLifecycle()
172-
if (showNewTransaction) {
172+
val transactionSheetDetails by appViewModel.transactionSheet.collectAsStateWithLifecycle()
173+
if (transactionSheetDetails != NewTransactionSheetDetails.EMPTY) {
173174
NewTransactionSheet(
174175
appViewModel = appViewModel,
175176
currencyViewModel = currencyViewModel,

app/src/main/java/to/bitkit/ui/screens/transfer/SettingUpScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ fun SettingUpScreen(
6969

7070
// Effect to disable new transaction sheet for channel purchase
7171
DisposableEffect(Unit) {
72-
app.setNewTransactionSheetEnabled(false)
72+
app.enabledTransactionSheet(false)
7373
onDispose {
74-
app.setNewTransactionSheetEnabled(true)
74+
app.enabledTransactionSheet(true)
7575
}
7676
}
7777

app/src/main/java/to/bitkit/ui/sheets/GiftSheet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fun GiftSheet(
3333

3434
val onSuccessState = rememberUpdatedState { details: NewTransactionSheetDetails ->
3535
appViewModel.hideSheet()
36-
appViewModel.showNewTransactionSheet(details)
36+
appViewModel.showTransactionSheet(details)
3737
}
3838

3939
LaunchedEffect(Unit) {

app/src/main/java/to/bitkit/ui/sheets/NewTransactionSheet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fun NewTransactionSheet(
5757
modifier: Modifier = Modifier,
5858
) {
5959
val currencies by currencyViewModel.uiState.collectAsState()
60-
val newTransaction by appViewModel.newTransaction.collectAsState()
60+
val details by appViewModel.transactionSheet.collectAsState()
6161

6262
CompositionLocalProvider(
6363
LocalCurrencyViewModel provides currencyViewModel,
@@ -68,7 +68,7 @@ fun NewTransactionSheet(
6868
onDismissRequest = { appViewModel.hideNewTransactionSheet() },
6969
) {
7070
NewTransactionSheetView(
71-
details = newTransaction,
71+
details = details,
7272
onCloseClick = { appViewModel.hideNewTransactionSheet() },
7373
onDetailClick = {
7474
appViewModel.onClickActivityDetail()

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import kotlinx.coroutines.delay
3737
import kotlinx.coroutines.flow.MutableSharedFlow
3838
import kotlinx.coroutines.flow.MutableStateFlow
3939
import kotlinx.coroutines.flow.SharingStarted
40-
import kotlinx.coroutines.flow.StateFlow
4140
import kotlinx.coroutines.flow.asSharedFlow
4241
import kotlinx.coroutines.flow.asStateFlow
4342
import 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

Comments
 (0)