From 1a0eaa779a9c24474843c802283ebafd4000d59e Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 27 May 2025 18:04:27 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../tap/di/domain/WalletsDomainModule.kt | 10 ++++ .../data/wallets/DefaultWalletsRepository.kt | 2 +- .../wallet-settings/impl/build.gradle.kts | 1 + .../preview/PreviewWalletSettingsComponent.kt | 2 + .../walletsettings/entity/WalletSettingsUM.kt | 2 + .../model/WalletSettingsModel.kt | 51 ++++++++++++++++++- .../walletsettings/ui/WalletSettingsScreen.kt | 12 +++++ 7 files changed, 77 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt b/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt index 9b80eb5ff0..684a7f0cf7 100644 --- a/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt +++ b/app/src/main/java/com/tangem/tap/di/domain/WalletsDomainModule.kt @@ -268,4 +268,14 @@ internal object WalletsDomainModule { walletsRepository = walletsRepository, ) } + + @Provides + @Singleton + fun providesGetIsNotificationsEnabledUseCase( + walletsRepository: WalletsRepository, + ): GetIsNotificationsEnabledUseCase { + return GetIsNotificationsEnabledUseCase( + walletsRepository = walletsRepository, + ) + } } \ 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 66d01cef74..2e686eac78 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 @@ -244,7 +244,7 @@ internal class DefaultWalletsRepository( override suspend fun isNotificationsEnabled(userWalletId: UserWalletId): Boolean = appPreferencesStore.getObjectMap(PreferencesKeys.NOTIFICATIONS_ENABLED_STATES_KEY) - .map { it[userWalletId.stringValue] } + .map { it[userWalletId.stringValue] == true } .firstOrNull() ?: false override suspend fun setNotificationsEnabled(userWalletId: UserWalletId, isEnabled: Boolean) { diff --git a/features/wallet-settings/impl/build.gradle.kts b/features/wallet-settings/impl/build.gradle.kts index 6f7c482a7f..3cd73b77d8 100644 --- a/features/wallet-settings/impl/build.gradle.kts +++ b/features/wallet-settings/impl/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { implementation(projects.features.manageTokens.api) implementation(projects.features.nft.api) implementation(projects.features.onboardingV2.api) + implementation(projects.features.pushNotifications.api) /* Project - Core */ implementation(projects.core.decompose) diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt index a78e85d068..2df0907822 100644 --- a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/component/preview/PreviewWalletSettingsComponent.kt @@ -36,6 +36,8 @@ internal class PreviewWalletSettingsComponent : WalletSettingsComponent { onCheckedNotificationsChanged = {}, onNotificationsDescriptionClick = {}, ), + requestPushNotificationsPermission = false, + onPushNotificationPermissionGranted = {}, ) @Composable diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt index 749a2ce005..3cadad2268 100644 --- a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/entity/WalletSettingsUM.kt @@ -7,4 +7,6 @@ import kotlinx.collections.immutable.PersistentList internal data class WalletSettingsUM( val popBack: () -> Unit, val items: PersistentList, + val requestPushNotificationsPermission: Boolean = false, + val onPushNotificationPermissionGranted: (Boolean) -> Unit, ) \ No newline at end of file diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt index e7925383d4..7af69bbd73 100644 --- a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/model/WalletSettingsModel.kt @@ -11,6 +11,7 @@ import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.decompose.navigation.Router import com.tangem.core.decompose.ui.UiMessageSender +import com.tangem.core.navigation.settings.SettingsManager import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.message.DialogMessage import com.tangem.core.ui.message.EventMessageAction @@ -62,6 +63,7 @@ internal class WalletSettingsModel @Inject constructor( private val notificationsToggles: NotificationsFeatureToggles, private val getWalletNotificationsEnabledUseCase: GetWalletNotificationsEnabledUseCase, private val setNotificationsEnabledUseCase: SetNotificationsEnabledUseCase, + private val settingsManager: SettingsManager, ) : Model() { val params: WalletSettingsComponent.Params = paramsContainer.require() @@ -71,6 +73,8 @@ internal class WalletSettingsModel @Inject constructor( value = WalletSettingsUM( popBack = router::pop, items = persistentListOf(), + requestPushNotificationsPermission = false, + onPushNotificationPermissionGranted = ::onPushNotificationPermissionGranted, ), ) @@ -193,9 +197,16 @@ internal class WalletSettingsModel @Inject constructor( } private fun onCheckedNotificationsChange(isChecked: Boolean) { - // TODO [REDACTED_JIRA] modelScope.launch { - setNotificationsEnabledUseCase(params.userWalletId, isChecked) + if (isChecked) { + state.update { value -> + value.copy( + requestPushNotificationsPermission = true, + ) + } + } else { + setNotificationsEnabledUseCase(params.userWalletId, false) + } } } @@ -203,6 +214,42 @@ internal class WalletSettingsModel @Inject constructor( // TODO [REDACTED_JIRA] } + private fun openPushSystemSettings() { + settingsManager.openAppSettings() + } + + private fun onPushNotificationPermissionGranted(isGranted: Boolean) { + state.update { value -> + value.copy( + requestPushNotificationsPermission = false, + ) + } + if (isGranted) { + modelScope.launch { + setNotificationsEnabledUseCase(params.userWalletId, true) + } + } else { + val message = DialogMessage( + title = resourceReference(R.string.push_notifications_permission_alert_title), + message = resourceReference(R.string.push_notifications_permission_alert_description), + firstActionBuilder = { + EventMessageAction( + title = resourceReference(R.string.push_notifications_permission_alert_positive_button), + onClick = ::openPushSystemSettings, + ) + }, + secondActionBuilder = { + EventMessageAction( + title = resourceReference(R.string.push_notifications_permission_alert_negative_button), + onClick = { cancelAction() }, + ) + }, + ) + + messageSender.send(message) + } + } + private fun onReferralClick(userWallet: UserWallet) { if (isDemoCardUseCase(userWallet.cardId)) { messageSender.send( diff --git a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt index 84eae80778..f934bc6c3e 100644 --- a/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt +++ b/features/wallet-settings/impl/src/main/kotlin/com/tangem/feature/walletsettings/ui/WalletSettingsScreen.kt @@ -26,10 +26,12 @@ import com.tangem.core.ui.extensions.stringResourceSafe import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.test.TestTags +import com.tangem.core.ui.utils.requestPushPermission import com.tangem.feature.walletsettings.component.preview.PreviewWalletSettingsComponent import com.tangem.feature.walletsettings.entity.WalletSettingsItemUM import com.tangem.feature.walletsettings.entity.WalletSettingsUM import com.tangem.feature.walletsettings.impl.R +import com.tangem.features.pushnotifications.api.utils.getPushPermissionOrNull @Composable internal fun WalletSettingsScreen( @@ -110,6 +112,16 @@ private fun Content(state: WalletSettingsUM, modifier: Modifier = Modifier) { } } } + + val requestPushPermission = requestPushPermission( + onAllow = { state.onPushNotificationPermissionGranted(true) }, + onDeny = { state.onPushNotificationPermissionGranted(false) }, + pushPermission = getPushPermissionOrNull(), + ) + + if (state.requestPushNotificationsPermission) { + requestPushPermission() + } } @Composable