diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/datastore/RuntimeStateStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/datastore/RuntimeStateStore.kt index 428169c98e..b28130b286 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/datastore/RuntimeStateStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/datastore/RuntimeStateStore.kt @@ -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 { /** Store [value] */ suspend fun store(value: T) + suspend fun update(function: (T) -> T) + companion object { /** @@ -32,6 +35,10 @@ interface RuntimeStateStore { override suspend fun store(value: T) { flow.value = value } + + override suspend fun update(function: (T) -> T) { + flow.update(function) + } } } } \ No newline at end of file diff --git a/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt b/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt index 1b4083ad77..c6e3354caa 100644 --- a/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt +++ b/data/wallets/src/main/java/com/tangem/data/wallets/DefaultWalletsRepository.kt @@ -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, + private val seedPhraseNotificationVisibilityStore: RuntimeStateStore>, private val dispatchers: CoroutineDispatcherProvider, ) : WalletsRepository { @@ -59,7 +60,9 @@ internal class DefaultWalletsRepository( override fun seedPhraseNotificationStatus(userWalletId: UserWalletId): Flow { 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 + } + } + } } \ No newline at end of file diff --git a/data/wallets/src/main/java/com/tangem/data/wallets/di/WalletsDataModule.kt b/data/wallets/src/main/java/com/tangem/data/wallets/di/WalletsDataModule.kt index 20cf86eaa0..778257f353 100644 --- a/data/wallets/src/main/java/com/tangem/data/wallets/di/WalletsDataModule.kt +++ b/data/wallets/src/main/java/com/tangem/data/wallets/di/WalletsDataModule.kt @@ -31,7 +31,7 @@ internal object WalletsDataModule { appPreferencesStore = appPreferencesStore, tangemTechApi = tangemTechApi, userWalletsStore = userWalletsStore, - seedPhraseNotificationVisibilityStore = RuntimeStateStore(defaultValue = false), + seedPhraseNotificationVisibilityStore = RuntimeStateStore(defaultValue = emptyMap()), dispatchers = dispatchers, ) }