@@ -27,7 +27,9 @@ import androidx.compose.runtime.LaunchedEffect
2727import androidx.compose.runtime.getValue
2828import androidx.compose.runtime.mutableStateOf
2929import androidx.compose.runtime.remember
30+ import androidx.compose.runtime.rememberUpdatedState
3031import androidx.compose.runtime.setValue
32+ import androidx.compose.runtime.snapshotFlow
3133import androidx.compose.ui.Alignment
3234import androidx.compose.ui.Modifier
3335import androidx.compose.ui.layout.ContentScale
@@ -40,6 +42,10 @@ import androidx.compose.ui.tooling.preview.Preview
4042import androidx.compose.ui.unit.dp
4143import androidx.hilt.navigation.compose.hiltViewModel
4244import androidx.lifecycle.compose.collectAsStateWithLifecycle
45+ import kotlinx.coroutines.flow.distinctUntilChanged
46+ import kotlinx.coroutines.flow.filter
47+ import kotlinx.coroutines.flow.first
48+ import kotlinx.coroutines.withTimeoutOrNull
4349import to.bitkit.R
4450import to.bitkit.repositories.CurrencyState
4551import to.bitkit.repositories.WalletState
@@ -66,6 +72,7 @@ import to.bitkit.ui.utils.keyboardAsState
6672import to.bitkit.utils.Logger
6773import to.bitkit.viewmodels.AmountInputViewModel
6874import to.bitkit.viewmodels.previewAmountInputViewModel
75+ import kotlin.time.Duration.Companion.seconds
6976
7077@Suppress(" ViewModelForwarding" )
7178@Composable
@@ -85,6 +92,7 @@ fun EditInvoiceScreen(
8592 var keyboardVisible by remember { mutableStateOf(false ) }
8693 var isSoftKeyboardVisible by keyboardAsState()
8794 val amountInputUiState by amountInputViewModel.uiState.collectAsStateWithLifecycle()
95+ val latestWalletState = rememberUpdatedState(walletUiState)
8896
8997 LaunchedEffect (Unit ) {
9098 editInvoiceVM.editInvoiceEffect.collect { effect ->
@@ -116,7 +124,17 @@ fun EditInvoiceScreen(
116124 }
117125
118126 EditInvoiceVM .EditInvoiceScreenEffects .UpdateInvoice -> {
127+ val previousBolt11 = latestWalletState.value.bolt11
119128 updateInvoice(receiveSats)
129+ val updated = withTimeoutOrNull(5 .seconds) {
130+ snapshotFlow { latestWalletState.value.bolt11 }
131+ .distinctUntilChanged()
132+ .filter { it.isNotEmpty() && it != previousBolt11 }
133+ .first()
134+ }
135+ if (updated == null ) {
136+ Logger .warn(" Timed out waiting for invoice update" , context = " EditInvoiceScreen" )
137+ }
120138 onBack()
121139 }
122140 }
0 commit comments