File tree Expand file tree Collapse file tree 4 files changed +27
-13
lines changed
test/java/to/bitkit/ui/sheets Expand file tree Collapse file tree 4 files changed +27
-13
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,12 @@ class LightningRepo @Inject constructor(
334334 Result .success(Unit )
335335 }
336336
337+ fun syncAsync () = scope.launch {
338+ sync().onFailure { error ->
339+ Logger .warn(" Sync failed" , e = error, context = TAG )
340+ }
341+ }
342+
337343 /* * Clear pending sync flag. Called when manual pull-to-refresh takes priority. */
338344 fun clearPendingSync () {
339345 syncPending.set(false )
Original file line number Diff line number Diff line change @@ -209,20 +209,16 @@ class BoostTransactionViewModel @Inject constructor(
209209
210210 private suspend fun handleBoostSuccess (newTxId : Txid , isRBF : Boolean ) {
211211 Logger .debug(" Boost successful. newTxId: $newTxId " , context = TAG )
212- updateActivity(newTxId = newTxId, isRBF = isRBF).fold(
213- onSuccess = {
214- lightningRepo.sync()
215- activityRepo.syncActivities()
216- _uiState .update { it.copy(boosting = false ) }
217- setBoostTransactionEffect(BoostTransactionEffects .OnBoostSuccess )
218- },
219- onFailure = { error ->
220- // Boost succeeded but activity update failed - still consider it successful
212+ updateActivity(newTxId = newTxId, isRBF = isRBF)
213+ .onFailure { error ->
221214 Logger .warn(" Boost successful but activity update failed" , e = error, context = TAG )
222- _uiState .update { it.copy(boosting = false ) }
223- setBoostTransactionEffect(BoostTransactionEffects .OnBoostSuccess )
224215 }
225- )
216+
217+ _uiState .update { it.copy(boosting = false ) }
218+ setBoostTransactionEffect(BoostTransactionEffects .OnBoostSuccess )
219+
220+ // Fire-and-forget sync to keep UI responsive even if LDK sync hangs.
221+ lightningRepo.syncAsync()
226222 }
227223
228224 fun onChangeAmount (increase : Boolean ) {
Original file line number Diff line number Diff line change @@ -311,8 +311,17 @@ class AppViewModel @Inject constructor(
311311 }
312312
313313 private suspend fun handleOnchainTransactionReplaced (event : Event .OnchainTransactionReplaced ) {
314+ // If the replaced transaction was just boosted via RBF from within the app, we already show a
315+ // dedicated boost success toast; suppress the generic "transaction replaced" toast to avoid
316+ // flakiness/noise (notably in E2E flows).
317+ val shouldSuppressReplacedToast = activityRepo
318+ .getOnchainActivityByTxId(event.txid)
319+ ?.let { it.isBoosted && it.txType == PaymentType .SENT } == true
320+
314321 activityRepo.handleOnchainTransactionReplaced(event.txid, event.conflicts)
315- notifyTransactionReplaced(event)
322+ if (! shouldSuppressReplacedToast) {
323+ notifyTransactionReplaced(event)
324+ }
316325 }
317326
318327 private suspend fun handlePaymentFailed (event : Event .PaymentFailed ) {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import app.cash.turbine.test
44import com.synonym.bitkitcore.Activity
55import com.synonym.bitkitcore.OnchainActivity
66import com.synonym.bitkitcore.PaymentType
7+ import kotlinx.coroutines.Job
78import kotlinx.coroutines.test.runTest
89import org.junit.Before
910import org.junit.Test
@@ -62,6 +63,7 @@ class BoostTransactionViewModelTest : BaseUnitTest() {
6263 activityRepo = activityRepo
6364 )
6465 wheneverBlocking { lightningRepo.listSpendableOutputs() }.thenReturn(Result .success(emptyList()))
66+ whenever(lightningRepo.syncAsync()).thenReturn(Job ())
6567 }
6668
6769 @Test
@@ -224,6 +226,7 @@ class BoostTransactionViewModelTest : BaseUnitTest() {
224226 }
225227
226228 verify(lightningRepo).accelerateByCpfp(any(), any(), any())
229+ verify(lightningRepo).syncAsync()
227230 verify(activityRepo).updateActivity(any(), any(), any())
228231 verify(activityRepo, never()).deleteActivity(any())
229232 }
You can’t perform that action at this time.
0 commit comments