Skip to content

Commit a69bab3

Browse files
authored
Merge branch 'master' into feat/spend-unconfirmed
2 parents f3c3e2e + 72a627f commit a69bab3

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

app/src/main/java/to/bitkit/repositories/LightningRepo.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff 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) {

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

app/src/test/java/to/bitkit/ui/sheets/BoostTransactionViewModelTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import app.cash.turbine.test
44
import com.synonym.bitkitcore.Activity
55
import com.synonym.bitkitcore.OnchainActivity
66
import com.synonym.bitkitcore.PaymentType
7+
import kotlinx.coroutines.Job
78
import kotlinx.coroutines.test.runTest
89
import org.junit.Before
910
import 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
}

0 commit comments

Comments
 (0)