Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-27 18:04:27 +05:00
parent 7868e94865
commit 1a0eaa779a
7 changed files with 77 additions and 3 deletions

View file

@ -268,4 +268,14 @@ internal object WalletsDomainModule {
walletsRepository = walletsRepository,
)
}
@Provides
@Singleton
fun providesGetIsNotificationsEnabledUseCase(
walletsRepository: WalletsRepository,
): GetIsNotificationsEnabledUseCase {
return GetIsNotificationsEnabledUseCase(
walletsRepository = walletsRepository,
)
}
}

View file

@ -244,7 +244,7 @@ internal class DefaultWalletsRepository(
override suspend fun isNotificationsEnabled(userWalletId: UserWalletId): Boolean =
appPreferencesStore.getObjectMap<Boolean>(PreferencesKeys.NOTIFICATIONS_ENABLED_STATES_KEY)
.map { it[userWalletId.stringValue] }
.map { it[userWalletId.stringValue] == true }
.firstOrNull() ?: false
override suspend fun setNotificationsEnabled(userWalletId: UserWalletId, isEnabled: Boolean) {

View file

@ -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)

View file

@ -36,6 +36,8 @@ internal class PreviewWalletSettingsComponent : WalletSettingsComponent {
onCheckedNotificationsChanged = {},
onNotificationsDescriptionClick = {},
),
requestPushNotificationsPermission = false,
onPushNotificationPermissionGranted = {},
)
@Composable

View file

@ -7,4 +7,6 @@ import kotlinx.collections.immutable.PersistentList
internal data class WalletSettingsUM(
val popBack: () -> Unit,
val items: PersistentList<WalletSettingsItemUM>,
val requestPushNotificationsPermission: Boolean = false,
val onPushNotificationPermissionGranted: (Boolean) -> Unit,
)

View file

@ -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(

View file

@ -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