diff --git a/core/config-toggles/build.gradle.kts b/core/config-toggles/build.gradle.kts index 55ba623cd7..30a1f408aa 100644 --- a/core/config-toggles/build.gradle.kts +++ b/core/config-toggles/build.gradle.kts @@ -1,4 +1,5 @@ import com.tangem.plugin.configuration.configurations.TogglesGenerator +import io.gitlab.arturbosch.detekt.Detekt plugins { alias(deps.plugins.android.library) @@ -58,6 +59,10 @@ tasks.named("preBuild") { dependsOn(generateToggles) } +tasks.withType().configureEach { + exclude { it.file.absolutePath.contains("/build/generated/") } +} + tasks.withType().configureEach { useJUnitPlatform() } diff --git a/core/config-toggles/src/main/assets/configs/feature_toggles_config.json b/core/config-toggles/src/main/assets/configs/feature_toggles_config.json index 7e831f6919..13eea8afdb 100644 --- a/core/config-toggles/src/main/assets/configs/feature_toggles_config.json +++ b/core/config-toggles/src/main/assets/configs/feature_toggles_config.json @@ -70,5 +70,9 @@ { "name": "SWAP_AB_ENABLED", "version": "undefined" + }, + { + "name": "TWI_1403_PUSH_NOTIFICATION_SETTINGS_ENABLED", + "version": "undefined" } ] diff --git a/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt b/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt new file mode 100644 index 0000000000..949c85c8ac --- /dev/null +++ b/core/config-toggles/src/test/kotlin/com/tangem/core/configtoggle/feature/FeatureTogglesNamingConventionTest.kt @@ -0,0 +1,61 @@ +package com.tangem.core.configtoggle.feature + +import com.google.common.truth.Truth +import com.squareup.moshi.Moshi +import com.squareup.moshi.Types +import com.tangem.core.configtoggle.storage.ConfigToggle +import org.junit.jupiter.api.Test +import java.io.File + +internal class FeatureTogglesNamingConventionTest { + + @Test + fun `all new feature toggles must follow AND_id or TWI_id naming`() { + val toggles = parseToggles(CONFIG_FILE) + + val invalid = toggles + .map(ConfigToggle::name) + .filterNot { it in EXCLUDED_TOGGLES_LIST } + .filterNot(VALID_NAME_PATTERN::matches) + + Truth.assertWithMessage( + """New feature toggles must match pattern ${VALID_NAME_PATTERN.pattern} — AND_ (Android ticket, e.g. AND_15312_PUSH_NOTIFICATION_SETTINGS_ENABLED) or TWI_ (idea ticket, e.g. TWI_1403_PUSH_NOTIFICATION_SETTINGS_ENABLED). + |Either rename these or, only if you have an explicit reason, add them to LEGACY_EXCLUDED.""".trimMargin(), + ).that(invalid).isEmpty() + } + + private fun parseToggles(file: File): List { + val moshi = Moshi.Builder().build() + val listType = Types.newParameterizedType(List::class.java, ConfigToggle::class.java) + val adapter = moshi.adapter>(listType) + return requireNotNull(adapter.fromJson(file.readText())) { "Failed to parse $file" } + } + + private companion object { + val VALID_NAME_PATTERN = Regex("""^(AND|TWI)_\d+(?:_[A-Z0-9]+)+$""") + + val CONFIG_FILE = File("src/main/assets/configs/feature_toggles_config.json") + + /** Toggles created before the AND_/TWI_ naming convention. Do NOT add new entries. */ + val EXCLUDED_TOGGLES_LIST = setOf( + "ADDRESS_SYNC_ENABLED", + "ADD_AND_MANAGE_TOKENS_ENABLED", + "APP_REDESIGN_ENABLED", + "ASSETS_DISCOVERY_ENABLED", + "DYNAMIC_ADDRESSES_ENABLED", + "GASLESS_APPROVAL_ENABLED", + "HEDERA_ERC20_ENABLED", + "NEW_CARD_SCANNING_ENABLED", + "SOLANA_SCALED_UI_AMOUNT_ENABLED", + "SOLANA_TX_HISTORY_ENABLED", + "STAKING_ETH_ENABLED", + "SWAP_AB_ENABLED", + "SWAP_INTEGRATED_APPROVE", + "SWAP_SWITCH_TO_TRANSFER_ENABLED", + "USEDESK_ENABLED", + "VIRTUAL_ACCOUNTS_ENABLED", + "VISA_ONBOARDING_ENABLED", + "WALLET_CONNECT_BITCOIN_ENABLED", + ) + } +} \ No newline at end of file diff --git a/features/push-notification-settings/api/build.gradle.kts b/features/push-notification-settings/api/build.gradle.kts new file mode 100644 index 0000000000..b81ea7349e --- /dev/null +++ b/features/push-notification-settings/api/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + id("configuration") +} + +android { + namespace = "com.tangem.features.pushnotificationsettings.api" +} \ No newline at end of file diff --git a/features/push-notification-settings/api/src/main/kotlin/com/tangem/features/pushnotificationsettings/PushNotificationSettingsFeatureToggles.kt b/features/push-notification-settings/api/src/main/kotlin/com/tangem/features/pushnotificationsettings/PushNotificationSettingsFeatureToggles.kt new file mode 100644 index 0000000000..857edf2f63 --- /dev/null +++ b/features/push-notification-settings/api/src/main/kotlin/com/tangem/features/pushnotificationsettings/PushNotificationSettingsFeatureToggles.kt @@ -0,0 +1,5 @@ +package com.tangem.features.pushnotificationsettings + +interface PushNotificationSettingsFeatureToggles { + val isPushNotificationSettingsEnabled: Boolean +} \ No newline at end of file diff --git a/features/push-notification-settings/impl/build.gradle.kts b/features/push-notification-settings/impl/build.gradle.kts new file mode 100644 index 0000000000..c593bf8504 --- /dev/null +++ b/features/push-notification-settings/impl/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + alias(deps.plugins.android.library) + alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.kapt) + alias(deps.plugins.hilt.android) + id("configuration") +} + +android { + namespace = "com.tangem.features.pushnotificationsettings.impl" +} + +dependencies { + /** Api */ + implementation(projects.features.pushNotificationSettings.api) + + /** Core modules */ + implementation(projects.core.configToggles) + + /** Compose */ + implementation(deps.compose.runtime) + + /** DI */ + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) +} \ No newline at end of file diff --git a/features/push-notification-settings/impl/src/main/kotlin/com/tangem/features/pushnotificationsettings/DefaultPushNotificationSettingsFeatureToggles.kt b/features/push-notification-settings/impl/src/main/kotlin/com/tangem/features/pushnotificationsettings/DefaultPushNotificationSettingsFeatureToggles.kt new file mode 100644 index 0000000000..329e322724 --- /dev/null +++ b/features/push-notification-settings/impl/src/main/kotlin/com/tangem/features/pushnotificationsettings/DefaultPushNotificationSettingsFeatureToggles.kt @@ -0,0 +1,12 @@ +package com.tangem.features.pushnotificationsettings + +import com.tangem.core.configtoggle.FeatureToggles +import com.tangem.core.configtoggle.feature.FeatureTogglesManager + +internal class DefaultPushNotificationSettingsFeatureToggles( + private val featureTogglesManager: FeatureTogglesManager, +) : PushNotificationSettingsFeatureToggles { + + override val isPushNotificationSettingsEnabled: Boolean + get() = featureTogglesManager.isFeatureEnabled(FeatureToggles.TWI_1403_PUSH_NOTIFICATION_SETTINGS_ENABLED) +} \ No newline at end of file diff --git a/features/push-notification-settings/impl/src/main/kotlin/com/tangem/features/pushnotificationsettings/di/PushNotificationSettingsFeatureModule.kt b/features/push-notification-settings/impl/src/main/kotlin/com/tangem/features/pushnotificationsettings/di/PushNotificationSettingsFeatureModule.kt new file mode 100644 index 0000000000..2bf5fb205e --- /dev/null +++ b/features/push-notification-settings/impl/src/main/kotlin/com/tangem/features/pushnotificationsettings/di/PushNotificationSettingsFeatureModule.kt @@ -0,0 +1,23 @@ +package com.tangem.features.pushnotificationsettings.di + +import com.tangem.core.configtoggle.feature.FeatureTogglesManager +import com.tangem.features.pushnotificationsettings.DefaultPushNotificationSettingsFeatureToggles +import com.tangem.features.pushnotificationsettings.PushNotificationSettingsFeatureToggles +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 PushNotificationSettingsFeatureModule { + + @Provides + @Singleton + fun providePushNotificationSettingsFeatureToggles( + featureTogglesManager: FeatureTogglesManager, + ): PushNotificationSettingsFeatureToggles { + return DefaultPushNotificationSettingsFeatureToggles(featureTogglesManager) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 1a2ca11f1d..64a025b52b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -244,6 +244,9 @@ include(":features:push-notifications:impl") include(":features:wallet-settings:api") include(":features:wallet-settings:impl") +include(":features:push-notification-settings:api") +include(":features:push-notification-settings:impl") + include(":features:markets:api") include(":features:markets:impl")