Updated on 2026-08-14
This commit is contained in:
parent
f5e56b881e
commit
60dde15698
3 changed files with 24 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.datasource.local.datastore
|
|||
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
|
||||
/**
|
||||
* Runtime store
|
||||
|
|
@ -16,6 +17,8 @@ interface RuntimeStateStore<T> {
|
|||
/** Store [value] */
|
||||
suspend fun store(value: T)
|
||||
|
||||
suspend fun update(function: (T) -> T)
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
|
|
@ -32,6 +35,10 @@ interface RuntimeStateStore<T> {
|
|||
override suspend fun store(value: T) {
|
||||
flow.value = value
|
||||
}
|
||||
|
||||
override suspend fun update(function: (T) -> T) {
|
||||
flow.update(function)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,13 +20,14 @@ import com.tangem.utils.coroutines.runCatching
|
|||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
internal class DefaultWalletsRepository(
|
||||
private val appPreferencesStore: AppPreferencesStore,
|
||||
private val tangemTechApi: TangemTechApi,
|
||||
private val userWalletsStore: UserWalletsStore,
|
||||
private val seedPhraseNotificationVisibilityStore: RuntimeStateStore<Boolean>,
|
||||
private val seedPhraseNotificationVisibilityStore: RuntimeStateStore<Map<UserWalletId, Boolean>>,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : WalletsRepository {
|
||||
|
||||
|
|
@ -59,7 +60,9 @@ internal class DefaultWalletsRepository(
|
|||
override fun seedPhraseNotificationStatus(userWalletId: UserWalletId): Flow<Boolean> {
|
||||
return channelFlow {
|
||||
launch {
|
||||
seedPhraseNotificationVisibilityStore.get().collectLatest(::send)
|
||||
seedPhraseNotificationVisibilityStore.get()
|
||||
.map { it.getOrDefault(key = userWalletId, defaultValue = false) }
|
||||
.collectLatest(::send)
|
||||
}
|
||||
|
||||
fetchSeedPhraseNotificationStatus(userWalletId)
|
||||
|
|
@ -81,7 +84,7 @@ internal class DefaultWalletsRepository(
|
|||
)
|
||||
}
|
||||
|
||||
seedPhraseNotificationVisibilityStore.store(value = status)
|
||||
updateNotificationVisibility(id = userWalletId, value = status)
|
||||
}
|
||||
|
||||
override suspend fun notifiedSeedPhraseNotification(userWalletId: UserWalletId) {
|
||||
|
|
@ -101,7 +104,7 @@ internal class DefaultWalletsRepository(
|
|||
).getOrThrow()
|
||||
}
|
||||
|
||||
seedPhraseNotificationVisibilityStore.store(value = false)
|
||||
updateNotificationVisibility(id = userWalletId, value = false)
|
||||
}
|
||||
|
||||
override suspend fun declineSeedPhraseNotification(userWalletId: UserWalletId) {
|
||||
|
|
@ -112,7 +115,7 @@ internal class DefaultWalletsRepository(
|
|||
).getOrThrow()
|
||||
}
|
||||
|
||||
seedPhraseNotificationVisibilityStore.store(value = false)
|
||||
updateNotificationVisibility(id = userWalletId, value = false)
|
||||
}
|
||||
|
||||
override suspend fun markWallet2WasCreated(userWalletId: UserWalletId) {
|
||||
|
|
@ -122,4 +125,12 @@ internal class DefaultWalletsRepository(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun updateNotificationVisibility(id: UserWalletId, value: Boolean) {
|
||||
return seedPhraseNotificationVisibilityStore.update {
|
||||
it.toMutableMap().apply {
|
||||
this[id] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ internal object WalletsDataModule {
|
|||
appPreferencesStore = appPreferencesStore,
|
||||
tangemTechApi = tangemTechApi,
|
||||
userWalletsStore = userWalletsStore,
|
||||
seedPhraseNotificationVisibilityStore = RuntimeStateStore(defaultValue = false),
|
||||
seedPhraseNotificationVisibilityStore = RuntimeStateStore(defaultValue = emptyMap()),
|
||||
dispatchers = dispatchers,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue