Skip to content

Commit 6bbab66

Browse files
committed
fix: wait for updated bolt11 before closing receive sheet
1 parent 3124ac0 commit 6bbab66

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

app/src/main/java/to/bitkit/ui/screens/wallets/receive/EditInvoiceScreen.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import androidx.compose.runtime.LaunchedEffect
2727
import androidx.compose.runtime.getValue
2828
import androidx.compose.runtime.mutableStateOf
2929
import androidx.compose.runtime.remember
30+
import androidx.compose.runtime.rememberUpdatedState
3031
import androidx.compose.runtime.setValue
32+
import androidx.compose.runtime.snapshotFlow
3133
import androidx.compose.ui.Alignment
3234
import androidx.compose.ui.Modifier
3335
import androidx.compose.ui.layout.ContentScale
@@ -40,6 +42,10 @@ import androidx.compose.ui.tooling.preview.Preview
4042
import androidx.compose.ui.unit.dp
4143
import androidx.hilt.navigation.compose.hiltViewModel
4244
import 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
4349
import to.bitkit.R
4450
import to.bitkit.repositories.CurrencyState
4551
import to.bitkit.repositories.WalletState
@@ -66,6 +72,7 @@ import to.bitkit.ui.utils.keyboardAsState
6672
import to.bitkit.utils.Logger
6773
import to.bitkit.viewmodels.AmountInputViewModel
6874
import 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

Comments
 (0)