Skip to content

Commit ffc0674

Browse files
committed
chore: review
1 parent e0fc9c1 commit ffc0674

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

app/src/main/java/to/bitkit/androidServices/LightningNodeService.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ class LightningNodeService : Service() {
7676
}
7777

7878
private suspend fun handleBackgroundEvent(event: Event) {
79-
if (App.currentActivity?.value != null) return
80-
8179
val command = NotifyPaymentReceived.Command.from(event, includeNotification = true) ?: return
8280

8381
notifyPaymentReceivedHandler(command).onSuccess { result ->
84-
if (result is NotifyPaymentReceived.Result.ShowNotification) {
85-
if (App.currentActivity?.value != null) return@onSuccess
86-
showPaymentNotification(result.details, result.notification)
87-
}
82+
if (result !is NotifyPaymentReceived.Result.ShowNotification) return@onSuccess
83+
if (App.currentActivity?.value != null) return@onSuccess
84+
85+
showPaymentNotification(result.details, result.notification)
8886
}
8987
}
9088

app/src/main/java/to/bitkit/domain/commands/NotifyPaymentReceivedHandler.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import to.bitkit.models.PrimaryDisplay
1919
import to.bitkit.models.formatToModernDisplay
2020
import to.bitkit.repositories.ActivityRepo
2121
import to.bitkit.repositories.CurrencyRepo
22+
import to.bitkit.utils.Logger
2223
import javax.inject.Inject
2324
import javax.inject.Singleton
2425

@@ -34,7 +35,7 @@ class NotifyPaymentReceivedHandler @Inject constructor(
3435
command: NotifyPaymentReceived.Command,
3536
): Result<NotifyPaymentReceived.Result> = withContext(ioDispatcher) {
3637
runCatching {
37-
delay(DELAY_MS)
38+
delay(DELAY_FOR_ACTIVITY_SYNC_MS)
3839

3940
val shouldShow = when (command) {
4041
is NotifyPaymentReceived.Command.Lightning -> true
@@ -62,6 +63,8 @@ class NotifyPaymentReceivedHandler @Inject constructor(
6263
} else {
6364
NotifyPaymentReceived.Result.ShowSheet(details)
6465
}
66+
}.onFailure { e ->
67+
Logger.error("Failed to process payment notification", e, context = TAG)
6568
}
6669
}
6770

@@ -93,6 +96,6 @@ class NotifyPaymentReceivedHandler @Inject constructor(
9396

9497
companion object {
9598
const val TAG = "NotifyPaymentReceivedHandler"
96-
private const val DELAY_MS = 500L
99+
private const val DELAY_FOR_ACTIVITY_SYNC_MS = 500L
97100
}
98101
}

app/src/test/java/to/bitkit/androidServices/LightningNodeServiceTest.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import dagger.hilt.android.testing.BindValue
1111
import dagger.hilt.android.testing.HiltAndroidRule
1212
import dagger.hilt.android.testing.HiltAndroidTest
1313
import dagger.hilt.android.testing.HiltTestApplication
14-
import kotlinx.coroutines.ExperimentalCoroutinesApi
1514
import kotlinx.coroutines.flow.MutableSharedFlow
1615
import kotlinx.coroutines.runBlocking
1716
import org.junit.After
@@ -27,7 +26,6 @@ import org.mockito.kotlin.any
2726
import org.mockito.kotlin.anyOrNull
2827
import org.mockito.kotlin.mock
2928
import org.mockito.kotlin.whenever
30-
import org.mockito.kotlin.wheneverBlocking
3129
import org.robolectric.Robolectric
3230
import org.robolectric.RobolectricTestRunner
3331
import org.robolectric.Shadows
@@ -46,7 +44,6 @@ import to.bitkit.repositories.WalletRepo
4644
import to.bitkit.services.LdkNodeEventBus
4745
import to.bitkit.test.BaseUnitTest
4846

49-
@OptIn(ExperimentalCoroutinesApi::class)
5047
@HiltAndroidTest
5148
@Config(application = HiltTestApplication::class)
5249
@RunWith(RobolectricTestRunner::class)
@@ -98,10 +95,9 @@ class LightningNodeServiceTest : BaseUnitTest() {
9895
title = context.getString(R.string.notification_received_title),
9996
body = "Received ₿ 100 ($0.10)",
10097
)
101-
wheneverBlocking { notifyPaymentReceivedHandler.invoke(any()) }
102-
.thenReturn(
103-
Result.success(NotifyPaymentReceived.Result.ShowNotification(defaultDetails, defaultNotification))
104-
)
98+
whenever(notifyPaymentReceivedHandler.invoke(any())).thenReturn(
99+
Result.success(NotifyPaymentReceived.Result.ShowNotification(defaultDetails, defaultNotification))
100+
)
105101

106102
// Grant permissions for notifications
107103
val app = context as Application

0 commit comments

Comments
 (0)