Updated on 2026-08-14

This commit is contained in:
Tangem 2023-09-08 16:30:14 +08:00
parent bb7bef8ab7
commit c4ec5774a3
5 changed files with 284 additions and 226 deletions

View file

@ -1,22 +1,21 @@
package com.tangem.feature.wallet.presentation.wallet.state.components
import androidx.compose.runtime.Immutable
import com.tangem.core.ui.components.notifications.NotificationState
import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.WrappedList
import com.tangem.core.ui.res.TangemColorPalette
import com.tangem.feature.wallet.impl.R
/**
* Wallet notification component state
*
* @property state state
* @property config state
*
[REDACTED_AUTHOR]
*/
// TODO: Finalize notification strings [REDACTED_JIRA]
@Immutable
sealed class WalletNotification(open val state: NotificationState) {
sealed class WalletNotification(open val config: NotificationConfig) {
/** Clickable notification */
sealed interface Clickable {
@ -27,41 +26,37 @@ sealed class WalletNotification(open val state: NotificationState) {
/** "Development card" notification */
object DevCard : WalletNotification(
state = NotificationState.Simple(
config = NotificationConfig(
title = TextReference.Res(id = R.string.common_warning),
subtitle = TextReference.Res(id = R.string.alert_developer_card),
iconResId = R.drawable.ic_alert_circle_24,
tint = TangemColorPalette.Amaranth,
),
)
/** "Test card" notification */
object TestCard : WalletNotification(
state = NotificationState.Simple(
config = NotificationConfig(
title = TextReference.Res(id = R.string.common_warning),
subtitle = TextReference.Res(id = R.string.warning_testnet_card_message),
iconResId = R.drawable.ic_alert_circle_24,
tint = TangemColorPalette.Amaranth,
),
)
/** "Demo card" notification */
object DemoCard : WalletNotification(
state = NotificationState.Simple(
config = NotificationConfig(
title = TextReference.Res(id = R.string.common_warning),
subtitle = TextReference.Res(id = R.string.alert_demo_message),
iconResId = R.drawable.ic_alert_circle_24,
tint = TangemColorPalette.Amaranth,
),
)
/** "Card verification failed" notification */
object CardVerificationFailed : WalletNotification(
state = NotificationState.Simple(
config = NotificationConfig(
title = TextReference.Res(id = R.string.warning_failed_to_verify_card_title),
subtitle = TextReference.Res(id = R.string.warning_failed_to_verify_card_message),
iconResId = R.drawable.ic_alert_circle_24,
tint = TangemColorPalette.Amaranth,
),
)
@ -71,14 +66,13 @@ sealed class WalletNotification(open val state: NotificationState) {
* @param count number of remaining signatures
*/
class RemainingSignaturesLeft(count: Int) : WalletNotification(
state = NotificationState.Simple(
config = NotificationConfig(
title = TextReference.Res(id = R.string.common_warning),
subtitle = TextReference.Res(
id = R.string.warning_low_signatures_format,
formatArgs = WrappedList(data = listOf(count)),
),
iconResId = R.drawable.ic_alert_circle_24,
tint = TangemColorPalette.Amaranth,
),
)
@ -88,11 +82,10 @@ sealed class WalletNotification(open val state: NotificationState) {
* @property onClick lambda be invoked when notification's close button is clicked
*/
data class WarningAlreadySignedHashes(override val onClick: () -> Unit) : Clickable, WalletNotification(
state = NotificationState.Closable(
config = NotificationConfig(
title = TextReference.Res(id = R.string.common_warning),
subtitle = TextReference.Res(id = R.string.alert_card_signed_transactions),
iconResId = R.drawable.img_attention_20,
tint = null,
onCloseClick = onClick,
),
)
@ -103,15 +96,13 @@ sealed class WalletNotification(open val state: NotificationState) {
* @property onClick lambda be invoked when notification is clicked
*/
data class CriticalWarningAlreadySignedHashes(override val onClick: () -> Unit) : Clickable, WalletNotification(
state = NotificationState.Clickable(
config = NotificationConfig(
title = TextReference.Res(
id = R.string.warning_important_security_info,
formatArgs = WrappedList(listOf("\u26A0")),
),
subtitle = TextReference.Res(id = R.string.warning_signed_tx_previously),
iconResId = R.drawable.img_attention_20,
onClick = onClick,
tint = null,
),
)
@ -121,20 +112,19 @@ sealed class WalletNotification(open val state: NotificationState) {
* @property onClick lambda be invoked when notification is clicked
*/
data class BackupCard(override val onClick: () -> Unit) : Clickable, WalletNotification(
state = NotificationState.Clickable(
config = NotificationConfig(
title = TextReference.Str(value = "Backup your card"),
subtitle = TextReference.Str(value = ""),
iconResId = R.drawable.img_attention_20,
onClick = onClick,
tint = null,
),
)
/** "Unreachable networks" notification */
object UnreachableNetworks : WalletNotification(
state = NotificationState.Simple(
config = NotificationConfig(
title = TextReference.Str(value = "Some networks are unreachable"),
subtitle = TextReference.Str(value = ""),
iconResId = R.drawable.img_attention_20,
tint = null,
),
)
@ -144,11 +134,10 @@ sealed class WalletNotification(open val state: NotificationState) {
* @property onClick lambda be invoked when notification is clicked
*/
data class LikeTangemApp(override val onClick: () -> Unit) : Clickable, WalletNotification(
state = NotificationState.Clickable(
config = NotificationConfig(
title = TextReference.Str(value = "Like Tangem App?"),
subtitle = TextReference.Str(value = ""),
iconResId = R.drawable.ic_star_24,
onClick = onClick,
tint = TangemColorPalette.Tangerine,
),
)
@ -158,10 +147,10 @@ sealed class WalletNotification(open val state: NotificationState) {
* @property onClick lambda be invoked when notification is clicked
*/
data class ScanCard(override val onClick: () -> Unit) : Clickable, WalletNotification(
state = NotificationState.Clickable(
config = NotificationConfig(
title = TextReference.Str(value = "Scan your card to continue"),
subtitle = TextReference.Str(value = ""),
iconResId = R.drawable.ic_tangem_24,
onClick = onClick,
),
)
@ -171,10 +160,10 @@ sealed class WalletNotification(open val state: NotificationState) {
* @property onClick lambda be invoked when notification is clicked
*/
data class UnlockWallets(override val onClick: () -> Unit) : Clickable, WalletNotification(
state = NotificationState.Clickable(
config = NotificationConfig(
title = TextReference.Str(value = "Unlock needed"),
subtitle = TextReference.Str(value = ""),
iconResId = R.drawable.ic_locked_24,
onClick = onClick,
),
)
}

View file

@ -20,8 +20,8 @@ import kotlinx.collections.immutable.ImmutableList
internal fun LazyListScope.notifications(configs: ImmutableList<WalletNotification>, modifier: Modifier = Modifier) {
items(
items = configs,
key = { it.state.title.hashCode() },
contentType = { it.state::class.java },
itemContent = { Notification(state = it.state, modifier = modifier.animateItemPlacement()) },
key = { it.config.title.hashCode() },
contentType = { it.config::class.java },
itemContent = { Notification(config = it.config, modifier = modifier.animateItemPlacement()) },
)
}