Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-10 14:50:19 +08:00
parent e2791d9b35
commit afcde269ce
24 changed files with 243 additions and 131 deletions

View file

@ -1,16 +1,29 @@
package com.tangem.data.wallets
import com.tangem.data.source.preferences.PreferencesDataSource
import com.tangem.datasource.local.userwallet.ShouldSaveUserWalletStore
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
internal class DefaultWalletsRepository(
private val preferencesDataSource: PreferencesDataSource,
private val shouldSaveUserWalletStore: ShouldSaveUserWalletStore,
private val dispatchers: CoroutineDispatcherProvider,
) : WalletsRepository {
override suspend fun shouldSaveUserWallets(): Boolean {
return withContext(dispatchers.io) { preferencesDataSource.shouldSaveUserWallets }
override suspend fun initialize() {
withContext(dispatchers.io) {
shouldSaveUserWalletStore.getSyncOrNull() ?: shouldSaveUserWalletStore.store(item = false)
}
}
override suspend fun shouldSaveUserWalletsSync(): Boolean {
return withContext(dispatchers.io) { shouldSaveUserWalletStore.getSyncOrNull() ?: false }
}
override fun shouldSaveUserWallets(): Flow<Boolean> = shouldSaveUserWalletStore.get()
override suspend fun saveShouldSaveUserWallets(item: Boolean) {
withContext(dispatchers.io) { shouldSaveUserWalletStore.store(item = item) }
}
}

View file

@ -1,7 +1,7 @@
package com.tangem.data.wallets.di
import com.tangem.data.source.preferences.PreferencesDataSource
import com.tangem.data.wallets.DefaultWalletsRepository
import com.tangem.datasource.local.userwallet.ShouldSaveUserWalletStore
import com.tangem.domain.wallets.repository.WalletsRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
@ -17,11 +17,11 @@ object WalletsDataModule {
@Provides
@Singleton
fun providesWalletsRepository(
preferencesDataSource: PreferencesDataSource,
shouldSaveUserWalletStore: ShouldSaveUserWalletStore,
coroutineDispatcherProvider: CoroutineDispatcherProvider,
): WalletsRepository {
return DefaultWalletsRepository(
preferencesDataSource = preferencesDataSource,
shouldSaveUserWalletStore = shouldSaveUserWalletStore,
dispatchers = coroutineDispatcherProvider,
)
}