Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-20 00:36:08 +05:00
parent 8ca8bf9450
commit de8dde89f6
5 changed files with 101 additions and 84 deletions

View file

@ -24,41 +24,7 @@ internal sealed class TokenDetailsNotification(val config: NotificationConfig) {
iconResId = iconResId,
buttonsState = buttonsState,
),
) {
object NetworksUnreachable : Warning(
title = resourceReference(R.string.warning_network_unreachable_title),
subtitle = resourceReference(R.string.warning_network_unreachable_message),
)
data class NetworkFee(
private val feeInfo: CryptoCurrencyWarning.BalanceNotEnoughForFee,
private val onBuyClick: () -> Unit,
) : Warning(
title = TextReference.Res(
id = R.string.warning_send_blocked_funds_for_fee_title,
formatArgs = wrappedList(feeInfo.blockchainFullName),
),
subtitle = TextReference.Res(
id = R.string.warning_send_blocked_funds_for_fee_message,
formatArgs = wrappedList(
feeInfo.currency.name,
feeInfo.blockchainFullName,
feeInfo.currency.name,
feeInfo.blockchainFullName,
feeInfo.blockchainSymbol,
),
),
iconResId = feeInfo.currency.networkIconResId,
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(
id = R.string.common_buy_currency,
formatArgs = wrappedList(feeInfo.blockchainSymbol),
),
onClick = onBuyClick,
),
)
}
)
sealed class Informational(
title: TextReference,
@ -71,35 +37,76 @@ internal sealed class TokenDetailsNotification(val config: NotificationConfig) {
iconResId = R.drawable.ic_alert_circle_24,
onCloseClick = onCloseClick,
),
) {
data class RentInfo(
private val rentInfo: CryptoCurrencyWarning.Rent,
private val onCloseClick: () -> Unit,
) : Informational(
title = TextReference.Res(R.string.warning_rent_fee_title),
subtitle = TextReference.Res(
id = R.string.warning_solana_rent_fee_message,
formatArgs = wrappedList(rentInfo.rent, rentInfo.exemptionAmount),
),
onCloseClick = onCloseClick,
)
)
data class ExistentialDeposit(
private val existentialInfo: CryptoCurrencyWarning.ExistentialDeposit,
) : Informational(
title = resourceReference(R.string.warning_existential_deposit_title),
subtitle = TextReference.Res(
id = R.string.warning_existential_deposit_message,
formatArgs = wrappedList(existentialInfo.currencyName, existentialInfo.edStringValueWithSymbol),
),
)
object NetworksUnreachable : Warning(
title = resourceReference(R.string.warning_network_unreachable_title),
subtitle = resourceReference(R.string.warning_network_unreachable_message),
)
class NetworksNoAccount(val network: String, val symbol: String, val amount: String) : Informational(
title = resourceReference(R.string.warning_no_account_title),
subtitle = resourceReference(
R.string.no_account_generic,
wrappedList(network, amount, symbol),
data class NetworkFee(
private val feeInfo: CryptoCurrencyWarning.BalanceNotEnoughForFee,
private val onBuyClick: () -> Unit,
) : Warning(
title = TextReference.Res(
id = R.string.warning_send_blocked_funds_for_fee_title,
formatArgs = wrappedList(feeInfo.blockchainFullName),
),
subtitle = TextReference.Res(
id = R.string.warning_send_blocked_funds_for_fee_message,
formatArgs = wrappedList(
feeInfo.currency.name,
feeInfo.blockchainFullName,
feeInfo.currency.name,
feeInfo.blockchainFullName,
feeInfo.blockchainSymbol,
),
)
}
),
iconResId = feeInfo.currency.networkIconResId,
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(
id = R.string.common_buy_currency,
formatArgs = wrappedList(feeInfo.blockchainSymbol),
),
onClick = onBuyClick,
),
)
data class RentInfo(
private val rentInfo: CryptoCurrencyWarning.Rent,
private val onCloseClick: () -> Unit,
) : Informational(
title = TextReference.Res(R.string.warning_rent_fee_title),
subtitle = TextReference.Res(
id = R.string.warning_solana_rent_fee_message,
formatArgs = wrappedList(rentInfo.rent, rentInfo.exemptionAmount),
),
onCloseClick = onCloseClick,
)
data class ExistentialDeposit(
private val existentialInfo: CryptoCurrencyWarning.ExistentialDeposit,
) : Informational(
title = resourceReference(R.string.warning_existential_deposit_title),
subtitle = TextReference.Res(
id = R.string.warning_existential_deposit_message,
formatArgs = wrappedList(existentialInfo.currencyName, existentialInfo.edStringValueWithSymbol),
),
)
class NetworksNoAccount(val network: String, val symbol: String, val amount: String) : Informational(
title = resourceReference(R.string.warning_no_account_title),
subtitle = resourceReference(
id = R.string.no_account_generic,
formatArgs = wrappedList(network, amount, symbol),
),
)
class HasPendingTransactions(val coinSymbol: String) : Informational(
title = resourceReference(R.string.warning_send_blocked_pending_transactions_title),
subtitle = resourceReference(
id = R.string.warning_send_blocked_pending_transactions_message,
formatArgs = wrappedList(coinSymbol),
),
)
}

View file

@ -40,7 +40,7 @@ internal class TokenDetailsLoadedBalanceConverter(
return state.copy(
tokenBalanceBlockState = TokenDetailsBalanceBlockState.Error(state.tokenBalanceBlockState.actionButtons),
marketPriceBlockState = MarketPriceBlockState.Error(state.marketPriceBlockState.currencySymbol),
notifications = persistentListOf(TokenDetailsNotification.Warning.NetworksUnreachable),
notifications = persistentListOf(TokenDetailsNotification.NetworksUnreachable),
)
}

View file

@ -19,29 +19,32 @@ internal class TokenDetailsNotificationConverter(
fun removeRentInfo(currentState: TokenDetailsState): ImmutableList<TokenDetailsNotification> {
val newNotifications = currentState.notifications.toMutableList()
newNotifications.removeBy { it is TokenDetailsNotification.Informational.RentInfo }
newNotifications.removeBy { it is TokenDetailsNotification.RentInfo }
return newNotifications.toImmutableList()
}
private fun mapToNotification(warning: CryptoCurrencyWarning): TokenDetailsNotification {
return when (warning) {
is CryptoCurrencyWarning.BalanceNotEnoughForFee -> TokenDetailsNotification.Warning.NetworkFee(
is CryptoCurrencyWarning.BalanceNotEnoughForFee -> TokenDetailsNotification.NetworkFee(
feeInfo = warning,
onBuyClick = clickIntents::onBuyClick,
)
is CryptoCurrencyWarning.ExistentialDeposit -> TokenDetailsNotification.Informational.ExistentialDeposit(
is CryptoCurrencyWarning.ExistentialDeposit -> TokenDetailsNotification.ExistentialDeposit(
existentialInfo = warning,
)
is CryptoCurrencyWarning.Rent -> TokenDetailsNotification.Informational.RentInfo(
is CryptoCurrencyWarning.Rent -> TokenDetailsNotification.RentInfo(
rentInfo = warning,
onCloseClick = clickIntents::onCloseRentInfoNotification,
)
CryptoCurrencyWarning.SomeNetworksUnreachable -> TokenDetailsNotification.Warning.NetworksUnreachable
is CryptoCurrencyWarning.SomeNetworksNoAccount -> TokenDetailsNotification.Informational.NetworksNoAccount(
CryptoCurrencyWarning.SomeNetworksUnreachable -> TokenDetailsNotification.NetworksUnreachable
is CryptoCurrencyWarning.SomeNetworksNoAccount -> TokenDetailsNotification.NetworksNoAccount(
network = warning.amountCurrency.name,
amount = warning.amountToCreateAccount.toString(),
symbol = warning.amountCurrency.symbol,
)
is CryptoCurrencyWarning.HasPendingTransactions -> TokenDetailsNotification.HasPendingTransactions(
coinSymbol = warning.blockchainSymbol,
)
}
}
}