Skip to content

Commit c8a016f

Browse files
committed
refactor: Extract PaymentDirection.toPaymentType
1 parent fa41721 commit c8a016f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/src/main/java/to/bitkit/services/CoreService.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class ActivityService(
197197

198198
val onchain = OnchainActivity(
199199
id = payment.id,
200-
txType = if (payment.direction == PaymentDirection.OUTBOUND) PaymentType.SENT else PaymentType.RECEIVED,
200+
txType = payment.direction.toPaymentType(),
201201
txId = kind.txid,
202202
value = payment.amountSats ?: 0u,
203203
fee = (payment.feePaidMsat ?: 0u) / 1000u,
@@ -232,7 +232,7 @@ class ActivityService(
232232

233233
val ln = LightningActivity(
234234
id = payment.id,
235-
txType = if (payment.direction == PaymentDirection.OUTBOUND) PaymentType.SENT else PaymentType.RECEIVED,
235+
txType = payment.direction.toPaymentType(),
236236
status = state,
237237
value = payment.amountSats ?: 0u,
238238
fee = null, // TODO
@@ -252,6 +252,7 @@ class ActivityService(
252252
addedCount++
253253
}
254254
}
255+
255256
else -> Unit // Handle spontaneous payments if needed
256257
}
257258
} catch (e: Throwable) {
@@ -267,6 +268,9 @@ class ActivityService(
267268
}
268269
}
269270

271+
private fun PaymentDirection.toPaymentType(): PaymentType =
272+
if (this == PaymentDirection.OUTBOUND) PaymentType.SENT else PaymentType.RECEIVED
273+
270274
suspend fun getActivity(id: String): Activity? {
271275
return ServiceQueue.CORE.background {
272276
getActivityById(id)

0 commit comments

Comments
 (0)