diff --git a/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt index 17782946ce..1c596a4b4d 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/SettingsDomainModule.kt @@ -91,4 +91,16 @@ internal object SettingsDomainModule { ): UpdateBalanceHidingSettingsUseCase { return UpdateBalanceHidingSettingsUseCase(balanceHidingRepository) } + + @Provides + @ViewModelScoped + fun provideSetWalletsScrollPreviewIsShown(settingsRepository: SettingsRepository): NeverToShowWalletsScrollPreview { + return NeverToShowWalletsScrollPreview(settingsRepository = settingsRepository) + } + + @Provides + @ViewModelScoped + fun provideIsWalletsScrollPreviewEnabled(settingsRepository: SettingsRepository): IsWalletsScrollPreviewEnabled { + return IsWalletsScrollPreviewEnabled(settingsRepository = settingsRepository) + } } \ No newline at end of file diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt b/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt index d81065c147..6eda0886c9 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/preferences/PreferencesKeys.kt @@ -32,6 +32,8 @@ object PreferencesKeys { val SELECTED_APP_CURRENCY_KEY by lazy { stringPreferencesKey(name = "selectedAppCurrency") } val BALANCE_HIDING_SETTINGS_KEY by lazy { stringPreferencesKey(name = "balanceHidingSettings") } + + val WALLETS_SCROLL_PREVIEW_KEY by lazy { booleanPreferencesKey(name = "walletsScrollPreview") } } /** Preferences keys set that should be migrated from "PreferencesDataSource" to a new DataStore */ diff --git a/data/settings/src/main/java/com/tangem/data/settings/DefaultSettingsRepository.kt b/data/settings/src/main/java/com/tangem/data/settings/DefaultSettingsRepository.kt index 0fed0929d9..8d3c6f18bc 100644 --- a/data/settings/src/main/java/com/tangem/data/settings/DefaultSettingsRepository.kt +++ b/data/settings/src/main/java/com/tangem/data/settings/DefaultSettingsRepository.kt @@ -1,16 +1,35 @@ package com.tangem.data.settings import com.tangem.data.source.preferences.PreferencesDataSource +import com.tangem.datasource.local.preferences.AppPreferencesStore +import com.tangem.datasource.local.preferences.PreferencesKeys +import com.tangem.datasource.local.preferences.utils.getSyncOrDefault +import com.tangem.datasource.local.preferences.utils.store import com.tangem.domain.settings.repositories.SettingsRepository import com.tangem.utils.coroutines.CoroutineDispatcherProvider import kotlinx.coroutines.withContext internal class DefaultSettingsRepository( private val preferencesDataSource: PreferencesDataSource, + private val appPreferencesStore: AppPreferencesStore, private val dispatchers: CoroutineDispatcherProvider, ) : SettingsRepository { override suspend fun shouldShowSaveUserWalletScreen(): Boolean { return withContext(dispatchers.io) { preferencesDataSource.shouldShowSaveUserWalletScreen } } + + override suspend fun isWalletScrollPreviewEnabled(): Boolean { + return appPreferencesStore.getSyncOrDefault( + key = PreferencesKeys.WALLETS_SCROLL_PREVIEW_KEY, + default = true, + ) + } + + override suspend fun setWalletScrollPreviewAvailability(isEnabled: Boolean) { + appPreferencesStore.store( + key = PreferencesKeys.WALLETS_SCROLL_PREVIEW_KEY, + value = isEnabled, + ) + } } \ No newline at end of file diff --git a/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt b/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt index 254235cf84..ba83b09d4d 100644 --- a/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt +++ b/data/settings/src/main/java/com/tangem/data/settings/di/SettingsDataModule.kt @@ -21,10 +21,12 @@ internal object SettingsDataModule { @Singleton fun provideSettingsRepository( preferencesDataSource: PreferencesDataSource, + appPreferencesStore: AppPreferencesStore, dispatchers: CoroutineDispatcherProvider, ): SettingsRepository { return DefaultSettingsRepository( preferencesDataSource = preferencesDataSource, + appPreferencesStore = appPreferencesStore, dispatchers = dispatchers, ) } diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/IsWalletsScrollPreviewEnabled.kt b/domain/settings/src/main/java/com/tangem/domain/settings/IsWalletsScrollPreviewEnabled.kt new file mode 100644 index 0000000000..fc45e34aa0 --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/IsWalletsScrollPreviewEnabled.kt @@ -0,0 +1,15 @@ +package com.tangem.domain.settings + +import com.tangem.domain.settings.repositories.SettingsRepository + +/** + * Checks if wallets scroll preview is enabled + * + * @property settingsRepository settings repository + * +[REDACTED_AUTHOR] + */ +class IsWalletsScrollPreviewEnabled(private val settingsRepository: SettingsRepository) { + + suspend operator fun invoke(): Boolean = settingsRepository.isWalletScrollPreviewEnabled() +} \ No newline at end of file diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/NeverToShowWalletsScrollPreview.kt b/domain/settings/src/main/java/com/tangem/domain/settings/NeverToShowWalletsScrollPreview.kt new file mode 100644 index 0000000000..4080a08bc9 --- /dev/null +++ b/domain/settings/src/main/java/com/tangem/domain/settings/NeverToShowWalletsScrollPreview.kt @@ -0,0 +1,17 @@ +package com.tangem.domain.settings + +import com.tangem.domain.settings.repositories.SettingsRepository + +/** + * Never to show wallets scroll preview + * + * @property settingsRepository settings repository + * +[REDACTED_AUTHOR] + */ +class NeverToShowWalletsScrollPreview( + private val settingsRepository: SettingsRepository, +) { + + suspend operator fun invoke() = settingsRepository.setWalletScrollPreviewAvailability(isEnabled = false) +} \ No newline at end of file diff --git a/domain/settings/src/main/java/com/tangem/domain/settings/repositories/SettingsRepository.kt b/domain/settings/src/main/java/com/tangem/domain/settings/repositories/SettingsRepository.kt index cdfe2702da..7dd4507554 100644 --- a/domain/settings/src/main/java/com/tangem/domain/settings/repositories/SettingsRepository.kt +++ b/domain/settings/src/main/java/com/tangem/domain/settings/repositories/SettingsRepository.kt @@ -3,4 +3,8 @@ package com.tangem.domain.settings.repositories interface SettingsRepository { suspend fun shouldShowSaveUserWalletScreen(): Boolean + + suspend fun isWalletScrollPreviewEnabled(): Boolean + + suspend fun setWalletScrollPreviewAvailability(isEnabled: Boolean) } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt index 55d6d6adf8..d5f89f57f5 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCryptoCurrencyActionsUseCase.kt @@ -32,10 +32,7 @@ class GetCryptoCurrencyActionsUseCase( ) { @OptIn(ExperimentalCoroutinesApi::class) - suspend operator fun invoke( - userWallet: UserWallet, - cryptoCurrencyStatus: CryptoCurrencyStatus, - ): Flow { + operator fun invoke(userWallet: UserWallet, cryptoCurrencyStatus: CryptoCurrencyStatus): Flow { val operations = CurrenciesStatusesOperations( currenciesRepository = currenciesRepository, quotesRepository = quotesRepository, @@ -43,19 +40,25 @@ class GetCryptoCurrencyActionsUseCase( userWalletId = userWallet.walletId, ) val networkId = cryptoCurrencyStatus.currency.network.id - val networkFlow = if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) { - operations.getNetworkCoinForSingleWalletWithTokenFlow(networkId) - } else if (!userWallet.isMultiCurrency) { - operations.getPrimaryCurrencyStatusFlow() - } else { - operations.getNetworkCoinFlow(networkId, cryptoCurrencyStatus.currency.network.derivationPath) - } - return networkFlow.mapLatest { maybeCoinStatus -> - createTokenActionsState( - userWalletId = userWallet.walletId, - coinStatus = maybeCoinStatus.getOrNull(), - cryptoCurrencyStatus = cryptoCurrencyStatus, - ) + + return flow { + val networkFlow = if (userWallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) { + operations.getNetworkCoinForSingleWalletWithTokenFlow(networkId) + } else if (!userWallet.isMultiCurrency) { + operations.getPrimaryCurrencyStatusFlow() + } else { + operations.getNetworkCoinFlow(networkId, cryptoCurrencyStatus.currency.network.derivationPath) + } + + val flow = networkFlow.mapLatest { maybeCoinStatus -> + createTokenActionsState( + userWalletId = userWallet.walletId, + coinStatus = maybeCoinStatus.getOrNull(), + cryptoCurrencyStatus = cryptoCurrencyStatus, + ) + } + + emitAll(flow) }.flowOn(dispatchers.io) } diff --git a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SelectWalletUseCase.kt b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SelectWalletUseCase.kt index 4c894e93d2..84303de548 100644 --- a/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SelectWalletUseCase.kt +++ b/domain/wallets/src/main/java/com/tangem/domain/wallets/usecase/SelectWalletUseCase.kt @@ -2,12 +2,13 @@ package com.tangem.domain.wallets.usecase import arrow.core.Either import arrow.core.raise.either -import com.tangem.common.doOnFailure -import com.tangem.common.doOnSuccess +import arrow.core.right +import com.tangem.common.CompletionResult import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.wallets.legacy.WalletsStateHolder import com.tangem.domain.wallets.legacy.ensureUserWalletListManagerNotNull import com.tangem.domain.wallets.models.SelectWalletError +import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId /** @@ -22,16 +23,20 @@ class SelectWalletUseCase( private val reduxStateHolder: ReduxStateHolder, ) { - suspend operator fun invoke(userWalletId: UserWalletId): Either { + suspend operator fun invoke(userWalletId: UserWalletId): Either { return either { val userWalletsListManager = ensureUserWalletListManagerNotNull( walletsStateHolder = walletsStateHolder, raise = { SelectWalletError.DataError }, ) - userWalletsListManager.select(userWalletId) - .doOnFailure { raise(SelectWalletError.UnableToSelectUserWallet) } - .doOnSuccess { reduxStateHolder.onUserWalletSelected(it) } + return when (val result = userWalletsListManager.select(userWalletId)) { + is CompletionResult.Failure -> raise(SelectWalletError.UnableToSelectUserWallet) + is CompletionResult.Success -> { + reduxStateHolder.onUserWalletSelected(result.data) + result.data.right() + } + } } } } \ No newline at end of file