@@ -8,10 +8,12 @@ import kotlinx.coroutines.flow.MutableStateFlow
88import kotlinx.coroutines.flow.StateFlow
99import kotlinx.coroutines.flow.asStateFlow
1010import kotlinx.coroutines.flow.combine
11+ import kotlinx.coroutines.flow.distinctUntilChanged
1112import kotlinx.coroutines.flow.map
1213import kotlinx.coroutines.flow.update
1314import kotlinx.coroutines.launch
1415import to.bitkit.data.SettingsStore
16+ import to.bitkit.models.ActivityBannerType
1517import to.bitkit.models.Suggestion
1618import to.bitkit.models.TransferType
1719import 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