From fc173d3a1f68a01c3e2a5c22a2f498c8e051e4a0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 14 Aug 2023 18:05:43 +0300 Subject: [PATCH] Updated on 2026-08-14 --- app/build.gradle.kts | 2 ++ .../tap/di/domain/AppCurrencyDomainModule.kt | 22 +++++++++++++ core/datasource/build.gradle.kts | 1 - data/app-currency/.gitignore | 1 + data/app-currency/build.gradle.kts | 33 +++++++++++++++++++ .../appcurrency/MockAppCurrencyRepository.kt | 23 +++++++++++++ .../appcurrency/di/AppCurrencyDataModule.kt | 20 +++++++++++ data/tokens/build.gradle.kts | 3 +- domain/app-currency/.gitignore | 1 + domain/app-currency/build.gradle.kts | 12 +++++++ domain/app-currency/models/.gitignore | 1 + domain/app-currency/models/build.gradle.kts | 4 +++ .../domain/appcurrency/model/AppCurrency.kt | 16 +++++++++ .../GetSelectedAppCurrencyUseCase.kt | 24 ++++++++++++++ .../error/SelectedAppCurrencyError.kt | 8 +++++ .../repository/AppCurrencyRepository.kt | 13 ++++++++ .../extension/BaseExtensionConfigurations.kt | 10 +++--- settings.gradle.kts | 3 ++ 18 files changed, 190 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/tangem/tap/di/domain/AppCurrencyDomainModule.kt create mode 100644 data/app-currency/.gitignore create mode 100644 data/app-currency/build.gradle.kts create mode 100644 data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/MockAppCurrencyRepository.kt create mode 100644 data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/di/AppCurrencyDataModule.kt create mode 100644 domain/app-currency/.gitignore create mode 100644 domain/app-currency/build.gradle.kts create mode 100644 domain/app-currency/models/.gitignore create mode 100644 domain/app-currency/models/build.gradle.kts create mode 100644 domain/app-currency/models/src/main/kotlin/com/tangem/domain/appcurrency/model/AppCurrency.kt create mode 100644 domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/GetSelectedAppCurrencyUseCase.kt create mode 100644 domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/error/SelectedAppCurrencyError.kt create mode 100644 domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/repository/AppCurrencyRepository.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index de202bea18..473fbff374 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -32,6 +32,7 @@ dependencies { implementation(projects.domain.settings) implementation(projects.domain.tokens) implementation(projects.domain.txhistory) + implementation(projects.domain.appCurrency) implementation(project(":common")) implementation(project(":core:analytics")) @@ -51,6 +52,7 @@ dependencies { implementation(projects.data.settings) implementation(projects.data.tokens) implementation(projects.data.txhistory) + implementation(projects.data.appCurrency) /** Features */ implementation(project(":features:onboarding")) diff --git a/app/src/main/java/com/tangem/tap/di/domain/AppCurrencyDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/AppCurrencyDomainModule.kt new file mode 100644 index 0000000000..c69bca18d1 --- /dev/null +++ b/app/src/main/java/com/tangem/tap/di/domain/AppCurrencyDomainModule.kt @@ -0,0 +1,22 @@ +package com.tangem.tap.di.domain + +import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase +import com.tangem.domain.appcurrency.repository.AppCurrencyRepository +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ViewModelComponent +import dagger.hilt.android.scopes.ViewModelScoped + +@Module +@InstallIn(ViewModelComponent::class) +internal object AppCurrencyDomainModule { + + @Provides + @ViewModelScoped + fun provideGetSelectedAppCurrencyUseCase( + appCurrencyRepository: AppCurrencyRepository, + ): GetSelectedAppCurrencyUseCase { + return GetSelectedAppCurrencyUseCase(appCurrencyRepository) + } +} \ No newline at end of file diff --git a/core/datasource/build.gradle.kts b/core/datasource/build.gradle.kts index bbd2e57c0e..f304966f2a 100644 --- a/core/datasource/build.gradle.kts +++ b/core/datasource/build.gradle.kts @@ -11,7 +11,6 @@ dependencies { /** Project */ implementation(projects.core.utils) implementation(projects.libs.auth) - implementation(projects.domain.core) implementation(projects.domain.tokens.models) implementation(projects.domain.wallets.models) diff --git a/data/app-currency/.gitignore b/data/app-currency/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/data/app-currency/.gitignore @@ -0,0 +1 @@ +/build diff --git a/data/app-currency/build.gradle.kts b/data/app-currency/build.gradle.kts new file mode 100644 index 0000000000..7020b7c452 --- /dev/null +++ b/data/app-currency/build.gradle.kts @@ -0,0 +1,33 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.kapt) + id("configuration") +} + +android { + namespace = "com.tangem.data.appcurrency" +} + +dependencies { + + /** Project - Domain */ + implementation(projects.domain.core) + implementation(projects.domain.appCurrency) + implementation(projects.domain.appCurrency.models) + + /** Project - Data */ + implementation(projects.core.datasource) + implementation(projects.data.common) + + /** Project - Utils */ + implementation(projects.core.utils) + + /** DI */ + implementation(deps.hilt.core) + kapt(deps.hilt.kapt) + + /** Other */ + implementation(deps.kotlin.coroutines) + implementation(deps.timber) +} \ No newline at end of file diff --git a/data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/MockAppCurrencyRepository.kt b/data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/MockAppCurrencyRepository.kt new file mode 100644 index 0000000000..d9c600872c --- /dev/null +++ b/data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/MockAppCurrencyRepository.kt @@ -0,0 +1,23 @@ +package com.tangem.data.appcurrency + +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.appcurrency.repository.AppCurrencyRepository +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf + +internal class MockAppCurrencyRepository : AppCurrencyRepository { + + private val mockAppCurrencies = listOf(AppCurrency(code = "USD", name = "US Dollar", symbol = "$")) + + override fun getSelectedAppCurrency(): Flow { + return flowOf(mockAppCurrencies.first()) + } + + override suspend fun getAvailableAppCurrencies(): List { + return mockAppCurrencies + } + + override suspend fun changeAppCurrency(appCurrency: AppCurrency) { + /* no-op */ + } +} \ No newline at end of file diff --git a/data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/di/AppCurrencyDataModule.kt b/data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/di/AppCurrencyDataModule.kt new file mode 100644 index 0000000000..d7f7ebb36c --- /dev/null +++ b/data/app-currency/src/main/kotlin/com/tangem/data/appcurrency/di/AppCurrencyDataModule.kt @@ -0,0 +1,20 @@ +package com.tangem.data.appcurrency.di + +import com.tangem.data.appcurrency.MockAppCurrencyRepository +import com.tangem.domain.appcurrency.repository.AppCurrencyRepository +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +internal object AppCurrencyDataModule { + + @Provides + @Singleton + fun provideAppCurrencyRepository(): AppCurrencyRepository { + return MockAppCurrencyRepository() + } +} \ No newline at end of file diff --git a/data/tokens/build.gradle.kts b/data/tokens/build.gradle.kts index c908cd02dd..a45be27508 100644 --- a/data/tokens/build.gradle.kts +++ b/data/tokens/build.gradle.kts @@ -13,10 +13,10 @@ dependencies { /** Project - Domain */ implementation(projects.domain.core) + implementation(projects.domain.demo) implementation(projects.domain.models) implementation(projects.domain.tokens) implementation(projects.domain.tokens.models) - implementation(projects.domain.demo) implementation(projects.domain.wallets.models) /** Project - Data */ @@ -37,7 +37,6 @@ dependencies { /** Other */ implementation(deps.kotlin.coroutines) - implementation(deps.arrow.core) implementation(deps.moshi.kotlin) implementation(deps.jodatime) implementation(deps.timber) diff --git a/domain/app-currency/.gitignore b/domain/app-currency/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/domain/app-currency/.gitignore @@ -0,0 +1 @@ +/build diff --git a/domain/app-currency/build.gradle.kts b/domain/app-currency/build.gradle.kts new file mode 100644 index 0000000000..45af2fd004 --- /dev/null +++ b/domain/app-currency/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + alias(deps.plugins.kotlin.jvm) + id("configuration") +} + +dependencies { + + /** Project - Domain */ + implementation(projects.core.utils) + implementation(projects.domain.core) + implementation(projects.domain.appCurrency.models) +} \ No newline at end of file diff --git a/domain/app-currency/models/.gitignore b/domain/app-currency/models/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/domain/app-currency/models/.gitignore @@ -0,0 +1 @@ +/build diff --git a/domain/app-currency/models/build.gradle.kts b/domain/app-currency/models/build.gradle.kts new file mode 100644 index 0000000000..7ff7fb7522 --- /dev/null +++ b/domain/app-currency/models/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + alias(deps.plugins.kotlin.jvm) + id("configuration") +} \ No newline at end of file diff --git a/domain/app-currency/models/src/main/kotlin/com/tangem/domain/appcurrency/model/AppCurrency.kt b/domain/app-currency/models/src/main/kotlin/com/tangem/domain/appcurrency/model/AppCurrency.kt new file mode 100644 index 0000000000..aa8fcb62fc --- /dev/null +++ b/domain/app-currency/models/src/main/kotlin/com/tangem/domain/appcurrency/model/AppCurrency.kt @@ -0,0 +1,16 @@ +package com.tangem.domain.appcurrency.model + +data class AppCurrency( + val code: String, + val name: String, + val symbol: String, +) { + + companion object { + val Default = AppCurrency( + code = "USD", + name = "US Dollar", + symbol = "$", + ) + } +} \ No newline at end of file diff --git a/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/GetSelectedAppCurrencyUseCase.kt b/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/GetSelectedAppCurrencyUseCase.kt new file mode 100644 index 0000000000..4bd3a52e99 --- /dev/null +++ b/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/GetSelectedAppCurrencyUseCase.kt @@ -0,0 +1,24 @@ +package com.tangem.domain.appcurrency + +import arrow.core.Either +import arrow.core.left +import arrow.core.right +import com.tangem.domain.appcurrency.error.SelectedAppCurrencyError +import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.appcurrency.repository.AppCurrencyRepository +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEmpty + +class GetSelectedAppCurrencyUseCase( + private val appCurrencyRepository: AppCurrencyRepository, +) { + + operator fun invoke(): Flow> { + return appCurrencyRepository.getSelectedAppCurrency() + .map> { it.right() } + .catch { emit(SelectedAppCurrencyError.DataError(it).left()) } + .onEmpty { emit(SelectedAppCurrencyError.NoAppCurrencySelected.left()) } + } +} \ No newline at end of file diff --git a/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/error/SelectedAppCurrencyError.kt b/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/error/SelectedAppCurrencyError.kt new file mode 100644 index 0000000000..4fc83d8671 --- /dev/null +++ b/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/error/SelectedAppCurrencyError.kt @@ -0,0 +1,8 @@ +package com.tangem.domain.appcurrency.error + +sealed class SelectedAppCurrencyError { + + object NoAppCurrencySelected : SelectedAppCurrencyError() + + data class DataError(val cause: Throwable) : SelectedAppCurrencyError() +} \ No newline at end of file diff --git a/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/repository/AppCurrencyRepository.kt b/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/repository/AppCurrencyRepository.kt new file mode 100644 index 0000000000..d2dafbc461 --- /dev/null +++ b/domain/app-currency/src/main/kotlin/com/tangem/domain/appcurrency/repository/AppCurrencyRepository.kt @@ -0,0 +1,13 @@ +package com.tangem.domain.appcurrency.repository + +import com.tangem.domain.appcurrency.model.AppCurrency +import kotlinx.coroutines.flow.Flow + +interface AppCurrencyRepository { + + fun getSelectedAppCurrency(): Flow + + suspend fun getAvailableAppCurrencies(): List + + suspend fun changeAppCurrency(appCurrency: AppCurrency) +} \ No newline at end of file diff --git a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt index e148f4849c..3504fee112 100644 --- a/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt +++ b/plugins/configuration/src/main/kotlin/com/tangem/plugin/configuration/configurations/extension/BaseExtensionConfigurations.kt @@ -20,12 +20,14 @@ internal fun BaseExtension.configureCompilerOptions() { internal fun BaseExtension.configureCompose(project: Project) { val useCompose = with(project.path) { contains(":ui") || - contains(":onboarding") || // TODO: divide on api/impl after migrating all onboarding to module - contains(":presentation") || - contains(":app") || // TODO: [REDACTED_JIRA] - contains(":impl") + contains(Regex(pattern = ":onboarding\$")) || // TODO: divide on api/impl after migrating all onboarding to module + contains(Regex(pattern = ":presentation\$")) || + contains(Regex(pattern = ":app\$")) || // TODO: [REDACTED_JIRA] + contains(Regex(pattern = ":impl\$")) } + buildFeatures.compose = useCompose + if (useCompose) { composeOptions { kotlinCompilerExtensionVersion = project.findVersion(alias = "compose-compiler").requiredVersion diff --git a/settings.gradle.kts b/settings.gradle.kts index 8c859f1b92..33ccfc81d6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -108,6 +108,8 @@ include(":domain:wallets") include(":domain:wallets:models") include(":domain:txhistory") include(":domain:txhistory:models") +include(":domain:app-currency") +include(":domain:app-currency:models") // endregion Domain modules // region Data modules @@ -117,4 +119,5 @@ include(":data:tokens") include(":data:source:preferences") include(":data:settings") include(":data:txhistory") +include(":data:app-currency") // endregion Data modules \ No newline at end of file