Updated on 2026-08-14

This commit is contained in:
Tangem 2026-05-20 12:19:43 +03:00
parent 4578bb824e
commit 0979d1b71b
22 changed files with 565 additions and 0 deletions

View file

@ -0,0 +1,24 @@
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.domain.pushnotificationpreferences"
}
dependencies {
/** Domain */
implementation(projects.domain.models)
/** Other */
implementation(deps.arrow.core)
implementation(deps.kotlin.coroutines)
/** DI */
implementation(deps.hilt.android)
kapt(deps.hilt.kapt)
}

View file

@ -0,0 +1,14 @@
package com.tangem.domain.pushnotificationpreferences
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.pushnotificationpreferences.models.WalletPushNotificationPreferences
import com.tangem.domain.pushnotificationpreferences.repository.WalletPushNotificationPreferencesRepository
import kotlinx.coroutines.flow.Flow
class ObserveWalletPushNotificationPreferencesUseCase(
private val repository: WalletPushNotificationPreferencesRepository,
) {
operator fun invoke(userWalletId: UserWalletId): Flow<WalletPushNotificationPreferences> =
repository.observePreferences(userWalletId)
}

View file

@ -0,0 +1,11 @@
package com.tangem.domain.pushnotificationpreferences
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.pushnotificationpreferences.repository.WalletPushNotificationPreferencesRepository
class PreloadWalletPushNotificationPreferencesUseCase(
private val repository: WalletPushNotificationPreferencesRepository,
) {
suspend operator fun invoke(userWalletId: UserWalletId) = repository.preload(userWalletId)
}

View file

@ -0,0 +1,21 @@
package com.tangem.domain.pushnotificationpreferences
import arrow.core.Either
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.pushnotificationpreferences.models.PushNotificationCategory
import com.tangem.domain.pushnotificationpreferences.repository.WalletPushNotificationPreferencesRepository
class UpdateWalletPushNotificationPreferenceUseCase(
private val repository: WalletPushNotificationPreferencesRepository,
) {
suspend operator fun invoke(
userWalletId: UserWalletId,
category: PushNotificationCategory,
isEnabled: Boolean,
): Either<Throwable, Unit> = repository.updatePreference(
userWalletId = userWalletId,
category = category,
isEnabled = isEnabled,
)
}

View file

@ -0,0 +1,7 @@
package com.tangem.domain.pushnotificationpreferences.models
enum class PushNotificationCategory {
TransactionAlerts,
OffersUpdates,
PriceAlerts,
}

View file

@ -0,0 +1,6 @@
package com.tangem.domain.pushnotificationpreferences.models
data class PushNotificationPreference(
val isEnabled: Boolean,
val isVisible: Boolean,
)

View file

@ -0,0 +1,7 @@
package com.tangem.domain.pushnotificationpreferences.models
data class WalletPushNotificationPreferences(
val transactionAlerts: PushNotificationPreference,
val offersUpdates: PushNotificationPreference,
val priceAlerts: PushNotificationPreference,
)

View file

@ -0,0 +1,23 @@
package com.tangem.domain.pushnotificationpreferences.repository
import arrow.core.Either
import com.tangem.domain.models.wallet.UserWalletId
import com.tangem.domain.pushnotificationpreferences.models.PushNotificationCategory
import com.tangem.domain.pushnotificationpreferences.models.WalletPushNotificationPreferences
import kotlinx.coroutines.flow.Flow
/** Per-wallet push notification preferences. In-memory cache, not persisted. */
interface WalletPushNotificationPreferencesRepository {
/** Warms up the cache for [userWalletId]. No-op if already cached. */
suspend fun preload(userWalletId: UserWalletId)
fun observePreferences(userWalletId: UserWalletId): Flow<WalletPushNotificationPreferences>
/** Updates a single [category]; full-replace PUT under the hood. On failure cache is untouched. */
suspend fun updatePreference(
userWalletId: UserWalletId,
category: PushNotificationCategory,
isEnabled: Boolean,
): Either<Throwable, Unit>
}