Skip to content

Commit fbde427

Browse files
committed
chore: setup banner list
1 parent e777f5b commit fbde427

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

app/src/main/java/to/bitkit/models/Suggestion.kt

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,6 @@ enum class Suggestion(
7676
icon = R.drawable.transfer,
7777
dismissible = false
7878
),
79-
80-
/**When the LN channel could not be cooped closed immediately*/
81-
TRANSFER_CLOSING_CHANNEL(
82-
title = R.string.cards__transferClosingChannel__title,
83-
description = R.string.cards__transferClosingChannel__description,
84-
color = Colors.Red24,
85-
icon = R.drawable.transfer,
86-
dismissible = false
87-
),
88-
89-
/**Replaces LIGHTNING when the transfer to spending balance is in progress*/
90-
LIGHTNING_SETTING_UP(
91-
title = R.string.cards__lightningSettingUp__title,
92-
description = R.string.cards__lightningSettingUp__description,
93-
color = Colors.Purple24,
94-
icon = R.drawable.transfer,
95-
dismissible = false
96-
),
9779
LIGHTNING_READY(
9880
title = R.string.cards__lightningReady__title,
9981
description = R.string.cards__lightningReady__description,

app/src/main/java/to/bitkit/ui/screens/wallets/HomeScreen.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.height
1818
import androidx.compose.foundation.layout.padding
1919
import androidx.compose.foundation.layout.size
2020
import androidx.compose.foundation.layout.statusBars
21+
import androidx.compose.foundation.lazy.LazyColumn
2122
import androidx.compose.foundation.lazy.LazyRow
2223
import androidx.compose.foundation.lazy.items
2324
import androidx.compose.foundation.lazy.rememberLazyListState
@@ -236,8 +237,6 @@ fun HomeScreen(
236237
}
237238

238239
Suggestion.TRANSFER_PENDING -> Unit
239-
Suggestion.TRANSFER_CLOSING_CHANNEL -> Unit
240-
Suggestion.LIGHTNING_SETTING_UP -> rootNavController.navigate(Routes.SettingUp)
241240
Suggestion.LIGHTNING_READY -> Unit
242241
Suggestion.NOTIFICATIONS -> {
243242
if (bgPaymentsIntroSeen) {
@@ -479,6 +478,14 @@ private fun Content(
479478
)
480479
}
481480
Spacer(modifier = Modifier.height(32.dp))
481+
482+
LazyColumn {
483+
items(items = homeUiState.banners, key = { banner -> banner.name }) {
484+
// Suggestion.LIGHTNING_SETTING_UP -> rootNavController.navigate(Routes.SettingUp)
485+
486+
}
487+
}
488+
482489
ActivityListSimple(
483490
items = latestActivities,
484491
onAllActivityClick = { rootNavController.navigateToAllActivity() },

app/src/main/java/to/bitkit/ui/screens/wallets/HomeUiState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package to.bitkit.ui.screens.wallets
22

33
import androidx.compose.runtime.Stable
44
import to.bitkit.data.dto.price.PriceDTO
5+
import to.bitkit.models.ActivityBannerType
56
import to.bitkit.models.Suggestion
67
import to.bitkit.models.WidgetType
78
import to.bitkit.models.WidgetWithPosition
@@ -17,6 +18,7 @@ import to.bitkit.ui.screens.widgets.blocks.WeatherModel
1718
@Stable
1819
data class HomeUiState(
1920
val suggestions: List<Suggestion> = listOf(),
21+
val banners: List<ActivityBannerType> = listOf(),
2022
val showWidgets: Boolean = false,
2123
val showWidgetTitles: Boolean = false,
2224
val widgetsWithPosition: List<WidgetWithPosition> = emptyList(),

app/src/main/java/to/bitkit/ui/screens/wallets/HomeViewModel.kt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import kotlinx.coroutines.flow.MutableStateFlow
88
import kotlinx.coroutines.flow.StateFlow
99
import kotlinx.coroutines.flow.asStateFlow
1010
import kotlinx.coroutines.flow.combine
11+
import kotlinx.coroutines.flow.distinctUntilChanged
1112
import kotlinx.coroutines.flow.map
1213
import kotlinx.coroutines.flow.update
1314
import kotlinx.coroutines.launch
1415
import to.bitkit.data.SettingsStore
16+
import to.bitkit.models.ActivityBannerType
1517
import to.bitkit.models.Suggestion
1618
import to.bitkit.models.TransferType
1719
import to.bitkit.models.WidgetType
@@ -88,6 +90,7 @@ class HomeViewModel @Inject constructor(
8890
_uiState.update { newState }
8991
}
9092
}
93+
viewModelScope.launch { createBannersFlow() }
9194
}
9295

9396
private fun setupArticleRotation() {
@@ -212,6 +215,18 @@ class HomeViewModel @Inject constructor(
212215
_uiState.update { it.copy(isEditingWidgets = false) }
213216
}
214217

218+
private suspend fun createBannersFlow() {
219+
transferRepo.activeTransfers
220+
.distinctUntilChanged()
221+
.collect { transfers ->
222+
val banners = listOfNotNull(
223+
ActivityBannerType.SPENDING.takeIf { transfers.any { it.type == TransferType.TO_SPENDING } },
224+
ActivityBannerType.SAVINGS.takeIf { transfers.any { it.type == TransferType.COOP_CLOSE } },
225+
)
226+
_uiState.update { it.copy(banners = banners) }
227+
}
228+
}
229+
215230
private fun createSuggestionsFlow() = combine(
216231
walletRepo.balanceState,
217232
settingsStore.data,
@@ -221,12 +236,6 @@ class HomeViewModel @Inject constructor(
221236
balanceState.totalLightningSats > 0uL -> { // With Lightning
222237
listOfNotNull(
223238
Suggestion.BACK_UP.takeIf { !settings.backupVerified },
224-
Suggestion.LIGHTNING_READY.takeIf {
225-
Suggestion.LIGHTNING_SETTING_UP in _uiState.value.suggestions &&
226-
transfers.all { it.type != TransferType.TO_SPENDING }
227-
},
228-
Suggestion.LIGHTNING_SETTING_UP.takeIf { transfers.any { it.type == TransferType.TO_SPENDING } },
229-
Suggestion.TRANSFER_CLOSING_CHANNEL.takeIf { transfers.any { it.type == TransferType.COOP_CLOSE } },
230239
Suggestion.TRANSFER_PENDING.takeIf { transfers.any { it.type == TransferType.FORCE_CLOSE } },
231240
Suggestion.SECURE.takeIf { !settings.isPinEnabled },
232241
Suggestion.BUY,
@@ -244,8 +253,7 @@ class HomeViewModel @Inject constructor(
244253
Suggestion.BACK_UP.takeIf { !settings.backupVerified },
245254
Suggestion.LIGHTNING.takeIf {
246255
transfers.all { it.type != TransferType.TO_SPENDING }
247-
} ?: Suggestion.LIGHTNING_SETTING_UP,
248-
Suggestion.TRANSFER_CLOSING_CHANNEL.takeIf { transfers.any { it.type == TransferType.COOP_CLOSE } },
256+
},
249257
Suggestion.TRANSFER_PENDING.takeIf { transfers.any { it.type == TransferType.FORCE_CLOSE } },
250258
Suggestion.SECURE.takeIf { !settings.isPinEnabled },
251259
Suggestion.BUY,
@@ -261,7 +269,7 @@ class HomeViewModel @Inject constructor(
261269
Suggestion.BUY,
262270
Suggestion.LIGHTNING.takeIf {
263271
transfers.all { it.type != TransferType.TO_SPENDING }
264-
} ?: Suggestion.LIGHTNING_SETTING_UP,
272+
},
265273
Suggestion.BACK_UP.takeIf { !settings.backupVerified },
266274
Suggestion.SECURE.takeIf { !settings.isPinEnabled },
267275
Suggestion.SUPPORT,

0 commit comments

Comments
 (0)