Skip to content

Commit b9a9872

Browse files
committed
refactor: always show amount in payment notifications
1 parent 3ab09d0 commit b9a9872

8 files changed

Lines changed: 5 additions & 69 deletions

File tree

app/src/main/java/to/bitkit/data/SettingsStore.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ data class SettingsData(
142142
val enableSendAmountWarning: Boolean = false,
143143
val backupVerified: Boolean = false,
144144
val notificationsGranted: Boolean = false,
145-
val showNotificationDetails: Boolean = true,
146145
val keepBitkitActiveInBackground: Boolean = false,
147146
val dismissedSuggestions: List<String> = emptyList(),
148147
val balanceWarningIgnoredMillis: Long = 0,

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ class ReceivedNotificationContent @Inject constructor(
2828
suspend fun build(sats: Long): NotificationDetails {
2929
val settings = settingsStore.data.first()
3030
val title = context.getString(R.string.notification__received__title)
31-
val body = if (settings.showNotificationDetails) {
32-
formatAmount(sats, settings)
33-
} else {
34-
context.getString(R.string.notification__received__body_hidden)
35-
}
31+
val body = formatAmount(sats, settings)
3632
return NotificationDetails(title, body)
3733
}
3834

app/src/main/java/to/bitkit/ui/components/NotificationPreview.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package to.bitkit.ui.components
22

3-
import androidx.compose.animation.AnimatedContent
43
import androidx.compose.foundation.Image
54
import androidx.compose.foundation.background
65
import androidx.compose.foundation.layout.Arrangement
@@ -18,7 +17,6 @@ import androidx.compose.ui.Modifier
1817
import androidx.compose.ui.draw.clip
1918
import androidx.compose.ui.draw.rotate
2019
import androidx.compose.ui.res.painterResource
21-
import androidx.compose.ui.res.stringResource
2220
import androidx.compose.ui.tooling.preview.Preview
2321
import androidx.compose.ui.unit.dp
2422
import to.bitkit.R
@@ -34,7 +32,6 @@ fun NotificationPreview(
3432
enabled: Boolean,
3533
title: String,
3634
description: String,
37-
showDetails: Boolean,
3835
modifier: Modifier = Modifier,
3936
time: String = "5m",
4037
) {
@@ -66,13 +63,7 @@ fun NotificationPreview(
6663
Caption(text = time, color = Colors.White64)
6764
}
6865

69-
val bodyText = when (showDetails) {
70-
true -> description
71-
else -> stringResource(R.string.notification__received__body_hidden)
72-
}
73-
AnimatedContent(targetState = bodyText) { text ->
74-
BodyS(text = text, color = Colors.White80)
75-
}
66+
BodyS(text = description, color = Colors.White80)
7667
}
7768

7869
Icon(
@@ -110,14 +101,12 @@ private fun Preview() {
110101
enabled = true,
111102
title = "Payment Received",
112103
description = "₿ 21 000 ($21.00)",
113-
showDetails = true,
114104
modifier = Modifier.fillMaxWidth()
115105
)
116106
NotificationPreview(
117107
enabled = false,
118108
title = "Payment Received",
119109
description = "₿ 21 000 ($21.00)",
120-
showDetails = false,
121110
modifier = Modifier.fillMaxWidth()
122111
)
123112
}

app/src/main/java/to/bitkit/ui/settings/backgroundPayments/BackgroundPaymentsSettings.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ fun BackgroundPaymentsSettings(
3939
) {
4040
val context = LocalContext.current
4141
val notificationsGranted by settingsViewModel.notificationsGranted.collectAsStateWithLifecycle()
42-
val showNotificationDetails by settingsViewModel.showNotificationDetails.collectAsStateWithLifecycle()
4342
val keepActive by settingsViewModel.keepBitkitActiveInBackground.collectAsStateWithLifecycle()
4443

4544
RequestNotificationPermissions(
@@ -49,7 +48,6 @@ fun BackgroundPaymentsSettings(
4948

5049
Content(
5150
hasPermission = notificationsGranted,
52-
showDetails = showNotificationDetails,
5351
keepActive = keepActive,
5452
onBack = onBack,
5553
onSystemSettingsClick = context::openNotificationSettings,
@@ -60,7 +58,6 @@ fun BackgroundPaymentsSettings(
6058
@Composable
6159
private fun Content(
6260
hasPermission: Boolean,
63-
showDetails: Boolean,
6461
keepActive: Boolean,
6562
onBack: () -> Unit,
6663
onSystemSettingsClick: () -> Unit,
@@ -147,7 +144,6 @@ private fun Content(
147144
enabled = hasPermission,
148145
title = stringResource(R.string.notification__received__title),
149146
description = "₿ 21 000 ($21.00)",
150-
showDetails = showDetails,
151147
modifier = Modifier.fillMaxWidth()
152148
)
153149
}
@@ -160,7 +156,6 @@ private fun Preview1() {
160156
AppThemeSurface {
161157
Content(
162158
hasPermission = true,
163-
showDetails = true,
164159
keepActive = true,
165160
onBack = {},
166161
onSystemSettingsClick = {},
@@ -175,7 +170,6 @@ private fun Preview2() {
175170
AppThemeSurface {
176171
Content(
177172
hasPermission = false,
178-
showDetails = false,
179173
keepActive = false,
180174
onBack = {},
181175
onSystemSettingsClick = {},

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ class SettingsViewModel @Inject constructor(
6464
}
6565
}
6666

67-
val showNotificationDetails = settingsStore.data.map { it.showNotificationDetails }
68-
.asStateFlow(initialValue = false)
69-
70-
fun toggleNotificationDetails() {
71-
viewModelScope.launch {
72-
settingsStore.update { it.copy(showNotificationDetails = !it.showNotificationDetails) }
73-
}
74-
}
75-
7667
val keepBitkitActiveInBackground = settingsStore.data.map { it.keepBitkitActiveInBackground }
7768
.asStateFlow(initialValue = false)
7869

app/src/test/java/to/bitkit/domain/commands/NotifyChannelReadyHandlerTest.kt

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class NotifyChannelReadyHandlerTest : BaseUnitTest() {
4646
fun setUp() {
4747
whenever(context.getString(R.string.notification__received__title)).thenReturn("Payment Received")
4848
whenever(context.getString(any(), any())).thenReturn("Received amount")
49-
whenever(settingsStore.data).thenReturn(flowOf(SettingsData(showNotificationDetails = true)))
49+
whenever(settingsStore.data).thenReturn(flowOf(SettingsData()))
5050
whenever(currencyRepo.convertSatsToFiat(any(), anyOrNull())).thenReturn(
5151
Result.success(
5252
ConvertedAmount(
@@ -156,30 +156,6 @@ class NotifyChannelReadyHandlerTest : BaseUnitTest() {
156156
verify(activityRepo).insertActivityFromCjit(cjitEntry, channel)
157157
}
158158

159-
@Test
160-
fun `notification hides details when showNotificationDetails is false`() = test {
161-
val event = mock<Event.ChannelReady> {
162-
on { channelId } doReturn "channel-1"
163-
}
164-
val channel = createChannelDetails().copy(
165-
channelId = "channel-1",
166-
outboundCapacityMsat = 3000_000u,
167-
)
168-
val cjitEntry = IcJitEntry.mock()
169-
whenever(lightningRepo.getChannels()).thenReturn(listOf(channel))
170-
whenever(blocktankRepo.getCjitEntry(channel)).thenReturn(cjitEntry)
171-
whenever(activityRepo.insertActivityFromCjit(any(), any())).thenReturn(Result.success(true))
172-
whenever(settingsStore.data).thenReturn(flowOf(SettingsData(showNotificationDetails = false)))
173-
whenever(context.getString(R.string.notification__received__body_hidden)).thenReturn("Hidden")
174-
175-
val result = sut(NotifyChannelReady.Command(event = event, includeNotification = true))
176-
177-
assertTrue(result.isSuccess)
178-
val showNotification = result.getOrThrow()
179-
assertTrue(showNotification is NotifyChannelReady.Result.ShowNotification)
180-
assertEquals("Hidden", showNotification.notification.body)
181-
}
182-
183159
@Test
184160
fun `returns Duplicate when activity already exists`() = test {
185161
val event = mock<Event.ChannelReady> {

app/src/test/java/to/bitkit/domain/commands/NotifyPaymentReceivedHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class NotifyPaymentReceivedHandlerTest : BaseUnitTest() {
4141
fun setUp() {
4242
whenever(context.getString(R.string.notification__received__title)).thenReturn("Payment Received")
4343
whenever(context.getString(any(), any())).thenReturn("Received amount")
44-
whenever(settingsStore.data).thenReturn(flowOf(SettingsData(showNotificationDetails = true)))
44+
whenever(settingsStore.data).thenReturn(flowOf(SettingsData()))
4545
whenever(currencyRepo.convertSatsToFiat(any(), anyOrNull())).thenReturn(
4646
Result.success(
4747
ConvertedAmount(

app/src/test/java/to/bitkit/domain/commands/ReceivedNotificationContentTest.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,9 @@ class ReceivedNotificationContentTest : BaseUnitTest() {
8989
assertEquals(expected, result.body)
9090
}
9191

92-
@Test
93-
fun `hides the amount when notification details are disabled`() = test {
94-
whenever(settingsStore.data).thenReturn(flowOf(SettingsData(showNotificationDetails = false)))
95-
96-
val result = sut.build(48_064L)
97-
98-
assertEquals(context.getString(R.string.notification__received__body_hidden), result.body)
99-
}
100-
10192
private fun stubSettings(primaryDisplay: PrimaryDisplay) {
10293
whenever(settingsStore.data).thenReturn(
103-
flowOf(SettingsData(showNotificationDetails = true, primaryDisplay = primaryDisplay)),
94+
flowOf(SettingsData(primaryDisplay = primaryDisplay)),
10495
)
10596
}
10697
}

0 commit comments

Comments
 (0)