Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-11 17:35:02 +03:00
parent 91ec85c3eb
commit 43d52e0b60
5 changed files with 30 additions and 12 deletions

View file

@ -569,10 +569,13 @@
<string name="warning_button_ok">Понятно!</string>
<string name="warning_button_really_cool">Очень круто!</string>
<string name="warning_existential_deposit_message">Сеть %1$s использует концепцию экзистенциального депозита. Если баланс вашего счета опустится ниже %2$s, он будет деактивирован, а все оставшиеся средства будут уничтожены.</string>
<string name="warning_existential_deposit_title">Для работы с сетью необходим депозит.</string>
<string name="warning_failed_to_verify_card_message">Эта карта может быть производственным образцом или подделкой</string>
<string name="warning_failed_to_verify_card_title">Проверка подлинности не удалась</string>
<string name="warning_important_security_info">Важная информация о безопасности %s</string>
<string name="warning_low_signatures_format">На этой карте осталось только %s подписей. Вы должны вывести все свои средства.</string>
<string name="warning_network_unreachable_message">В данный момент сеть недоступна. Пожалуйста, попробуйте позже.</string>
<string name="warning_network_unreachable_title">Сеть недоступна.</string>
<string name="warning_rate_app_message">Как вам Tangem?</string>
<string name="warning_rate_app_title">Один вопрос</string>
<string name="warning_signed_tx_previously">Эта карта подписывала транзакции в прошлом</string>

View file

@ -589,10 +589,13 @@
<string name="warning_button_ok">Ok, Got it!</string>
<string name="warning_button_really_cool">Really cool!</string>
<string name="warning_existential_deposit_message">%1$s network has a concept of Existential Deposit. If your account drops below %2$s it will be deactivated and any remaining funds will be destroyed.</string>
<string name="warning_existential_deposit_title">Network requires Existential Deposit</string>
<string name="warning_failed_to_verify_card_message">This card might be a production sample or counterfeit</string>
<string name="warning_failed_to_verify_card_title">Authenticity check failed</string>
<string name="warning_important_security_info">Important security information %s</string>
<string name="warning_low_signatures_format">There are only %s signatures available on this card. You must withdraw all of your funds.</string>
<string name="warning_network_unreachable_message">The network is currently unreachable. Please try again later.</string>
<string name="warning_network_unreachable_title">Network is unreachable</string>
<string name="warning_rate_app_message">How do you like Tangem?</string>
<string name="warning_rate_app_title">One question</string>
<string name="warning_rate_app_title_new">Rate the app</string>

View file

@ -1,6 +1,7 @@
package com.tangem.domain.tokens
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations
@ -23,10 +24,11 @@ class GetCurrencyWarningsUseCase(
suspend operator fun invoke(
userWalletId: UserWalletId,
currency: CryptoCurrency,
currencyStatus: CryptoCurrencyStatus,
derivationPath: Network.DerivationPath,
isSingleWalletWithTokens: Boolean,
): Flow<Set<CryptoCurrencyWarning>> {
val currency = currencyStatus.currency
return combine(
getFeeWarningFlow(
userWalletId = userWalletId,
@ -37,7 +39,8 @@ class GetCurrencyWarningsUseCase(
),
flowOf(walletManagersFacade.getRentInfo(userWalletId, currency.network)),
flowOf(walletManagersFacade.getExistentialDeposit(userWalletId, currency.network)),
) { maybeFeeWarning, maybeRentWarning, maybeEdWarning ->
flowOf(getNetworkUnavailableWarning(currencyStatus)),
) { maybeFeeWarning, maybeRentWarning, maybeEdWarning, maybeNetworkUnavailable ->
setOfNotNull(
maybeRentWarning,
maybeEdWarning?.let {
@ -47,6 +50,7 @@ class GetCurrencyWarningsUseCase(
)
},
maybeFeeWarning,
maybeNetworkUnavailable,
)
}.flowOn(dispatchers.io)
}
@ -96,6 +100,12 @@ class GetCurrencyWarningsUseCase(
}
}
private fun getNetworkUnavailableWarning(currencyStatus: CryptoCurrencyStatus): CryptoCurrencyWarning? {
return (currencyStatus.value as? CryptoCurrencyStatus.Unreachable)?.let {
CryptoCurrencyWarning.SomeNetworksUnreachable
}
}
private fun BigDecimal?.isZero(): Boolean {
return this?.signum() == 0
}

View file

@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.networkIconResId
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
import com.tangem.features.tokendetails.impl.R
@ -33,7 +34,7 @@ sealed class TokenDetailsNotification(
private val existentialInfo: CryptoCurrencyWarning.ExistentialDeposit,
) : TokenDetailsNotification(
config = NotificationConfig(
title = TextReference.Str("Existential Deposit"),
title = resourceReference(R.string.warning_existential_deposit_title),
subtitle = TextReference.Res(
id = R.string.warning_existential_deposit_message,
formatArgs = wrappedList(existentialInfo.currencyName, existentialInfo.edStringValueWithSymbol),
@ -71,8 +72,8 @@ sealed class TokenDetailsNotification(
object NetworksUnreachable : TokenDetailsNotification(
config = NotificationConfig(
title = TextReference.Str("Some networks are unreachable"),
subtitle = TextReference.Str("The problem is on the crypto-network side. It will be fixed soon."),
title = resourceReference(R.string.warning_network_unreachable_title),
subtitle = resourceReference(R.string.warning_network_unreachable_message),
iconResId = R.drawable.img_attention_20,
),
)

View file

@ -21,13 +21,13 @@ import com.tangem.domain.tokens.legacy.TradeCryptoAction
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.models.analytics.TokenReceiveAnalyticsEvent
import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase
import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsCountUseCase
import com.tangem.domain.txhistory.usecase.GetTxHistoryItemsUseCase
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.domain.wallets.usecase.GetExploreUrlUseCase
import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
import com.tangem.feature.tokendetails.presentation.router.InnerTokenDetailsRouter
import com.tangem.feature.tokendetails.presentation.tokendetails.analytics.TokenScreenEvent
@ -81,6 +81,7 @@ internal class TokenDetailsViewModel @Inject constructor(
private val marketPriceJobHolder = JobHolder()
private val refreshStateJobHolder = JobHolder()
private val warningsJobHolder = JobHolder()
private var cryptoCurrencyStatus: CryptoCurrencyStatus? = null
private val selectedAppCurrencyFlow: StateFlow<AppCurrency> = createSelectedAppCurrencyFlow()
@ -102,9 +103,8 @@ internal class TokenDetailsViewModel @Inject constructor(
}
private fun updateContent() {
updateMarketPrice()
subscribeOnCurrencyStatusUpdates()
updateTxHistory(refresh = false, showItemsLoading = true)
updateWarnings()
}
private fun handleBalanceHiding(owner: LifecycleOwner) {
@ -132,22 +132,23 @@ internal class TokenDetailsViewModel @Inject constructor(
.launchIn(viewModelScope)
}
private fun updateWarnings() {
private fun updateWarnings(cryptoCurrencyStatus: CryptoCurrencyStatus) {
viewModelScope.launch(dispatchers.io) {
val wallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch }
getCurrencyWarningsUseCase.invoke(
userWalletId = userWalletId,
currency = cryptoCurrency,
currencyStatus = cryptoCurrencyStatus,
derivationPath = cryptoCurrency.network.derivationPath,
isSingleWalletWithTokens = isSingleWalletWithTokens(wallet),
)
.distinctUntilChanged()
.onEach { uiState = stateFactory.getStateWithNotifications(it) }
.launchIn(viewModelScope)
.saveIn(warningsJobHolder)
}
}
private fun updateMarketPrice() {
private fun subscribeOnCurrencyStatusUpdates() {
viewModelScope.launch(dispatchers.io) {
val wallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch }
getCurrencyStatusUpdatesUseCase(
@ -162,6 +163,7 @@ internal class TokenDetailsViewModel @Inject constructor(
either.onRight { status ->
cryptoCurrencyStatus = status
updateButtons(userWalletId = userWalletId, currencyStatus = status)
updateWarnings(status)
}
}
.flowOn(dispatchers.io)
@ -411,7 +413,6 @@ internal class TokenDetailsViewModel @Inject constructor(
showItemsLoading = uiState.txHistoryState !is TxHistoryState.Content,
)
},
async { updateWarnings() },
).awaitAll()
uiState = stateFactory.getRefreshedState()
}.saveIn(refreshStateJobHolder)