Skip to content

Commit 616bb9d

Browse files
committed
Merge branch 'master' into feat/e2e-test-tags
2 parents 78ab032 + fb17ba5 commit 616bb9d

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class ActivityRepo @Inject constructor(
100100
paymentHashOrTxId: String,
101101
type: ActivityFilter,
102102
txType: PaymentType,
103+
retry: Boolean = true,
103104
): Result<Activity> = withContext(bgDispatcher) {
104105
if (paymentHashOrTxId.isEmpty()) {
105106
return@withContext Result.failure(
@@ -115,7 +116,7 @@ class ActivityRepo @Inject constructor(
115116
).getOrNull()?.firstOrNull { it.matchesPaymentId(paymentHashOrTxId) }
116117

117118
var activity = findActivity()
118-
if (activity == null) {
119+
if (activity == null && retry) {
119120
Logger.warn(
120121
"activity with paymentHashOrTxId:$paymentHashOrTxId not found, trying again after sync",
121122
context = TAG

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fun ContentView(
183183

184184
val pendingTransaction = NewTransactionSheetDetails.load(context)
185185
if (pendingTransaction != null) {
186-
appViewModel.showNewTransactionSheet(pendingTransaction)
186+
appViewModel.showNewTransactionSheet(details = pendingTransaction, event = null)
187187
NewTransactionSheetDetails.clear(context)
188188
}
189189

@@ -329,7 +329,7 @@ fun ContentView(
329329
onComplete = { txSheet ->
330330
appViewModel.hideSheet()
331331
appViewModel.clearClipboardForAutoRead()
332-
txSheet?.let { appViewModel.showNewTransactionSheet(it) }
332+
txSheet?.let { appViewModel.showNewTransactionSheet(details = it, event = null) }
333333
}
334334
)
335335
}

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,16 @@ class AppViewModel @Inject constructor(
191191
viewModelScope.launch {
192192
ldkNodeEventBus.events.collect { event ->
193193
try {
194-
when (event) {
194+
when (event) { // TODO Create individual sheet for each type of event
195195
is Event.PaymentReceived -> {
196196
handleTags(event)
197197
showNewTransactionSheet(
198198
NewTransactionSheetDetails(
199199
type = NewTransactionSheetType.LIGHTNING,
200200
direction = NewTransactionSheetDirection.RECEIVED,
201201
sats = (event.amountMsat / 1000u).toLong(),
202-
)
202+
),
203+
event = event
203204
)
204205
}
205206

@@ -214,7 +215,8 @@ class AppViewModel @Inject constructor(
214215
type = NewTransactionSheetType.LIGHTNING,
215216
direction = NewTransactionSheetDirection.RECEIVED,
216217
sats = (channel.inboundCapacityMsat / 1000u).toLong(),
217-
)
218+
),
219+
event = event
218220
)
219221
} else {
220222
toast(
@@ -240,7 +242,8 @@ class AppViewModel @Inject constructor(
240242
type = NewTransactionSheetType.LIGHTNING,
241243
direction = NewTransactionSheetDirection.SENT,
242244
sats = ((event.feePaidMsat ?: 0u) / 1000u).toLong(),
243-
)
245+
),
246+
event = event
244247
)
245248
}
246249

@@ -1208,10 +1211,28 @@ class AppViewModel @Inject constructor(
12081211
isNewTransactionSheetEnabled = enabled
12091212
}
12101213

1211-
fun showNewTransactionSheet(details: NewTransactionSheetDetails) {
1214+
fun showNewTransactionSheet(
1215+
details: NewTransactionSheetDetails,
1216+
event: Event?,
1217+
) = viewModelScope.launch {
12121218
if (!isNewTransactionSheetEnabled) {
12131219
Logger.debug("NewTransactionSheet display blocked by isNewTransactionSheetEnabled=false", context = TAG)
1214-
return
1220+
return@launch
1221+
}
1222+
1223+
if (event is Event.PaymentReceived) {
1224+
val activity = activityRepo.findActivityByPaymentId(
1225+
paymentHashOrTxId = event.paymentHash,
1226+
type = ActivityFilter.ALL,
1227+
txType = PaymentType.RECEIVED,
1228+
retry = false
1229+
).getOrNull()
1230+
1231+
// TODO Temporary fix while ldk-node bug is not fixed https://github.com/synonymdev/bitkit-android/pull/297
1232+
if (activity != null) {
1233+
Logger.warn("Activity ${activity.rawId()} already exists, skipping sheet", context = TAG)
1234+
return@launch
1235+
}
12151236
}
12161237

12171238
newTransaction = details

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ class BoostTransactionViewModelTest : BaseUnitTest() {
216216
activityRepo.findActivityByPaymentId(
217217
paymentHashOrTxId = any(),
218218
type = any(),
219-
txType = any()
219+
txType = any(),
220+
retry = any(),
220221
)
221222
).thenReturn(Result.success(Activity.Onchain(v1 = newActivity)))
222223

0 commit comments

Comments
 (0)