Updated on 2026-08-14

This commit is contained in:
Tangem 2024-02-27 18:51:25 +00:00
parent 451e0ed797
commit e637ebdba0
7 changed files with 67 additions and 13 deletions

View file

@ -74,23 +74,40 @@ class ResponseCryptoCurrenciesFactory {
): CryptoCurrency.Coin? {
val network = getNetwork(blockchain, responseToken.derivationPath, derivationStyleProvider) ?: return null
// workaround: Dischain was renamed but backend still returns the old name,
// get name and symbol from enum Blockchain until backend renamed
// [REDACTED_JIRA]
val name = if (blockchain == Blockchain.Dischain) blockchain.fullName else responseToken.name
val symbol = if (blockchain == Blockchain.Dischain) blockchain.currency else responseToken.symbol
return CryptoCurrency.Coin(
id = getCoinId(network, blockchain.toCoinId()),
network = network,
name = name,
symbol = symbol,
name = blockchain.getNameForCoin(responseToken),
symbol = blockchain.getSymbolForCoin(responseToken),
decimals = responseToken.decimals,
iconUrl = getCoinIconUrl(blockchain),
isCustom = isCustomCoin(network),
)
}
private fun Blockchain.getNameForCoin(responseToken: UserTokensResponse.Token): String {
return when (this) {
// workaround: Dischain was renamed but backend still returns the old name,
// get name and symbol from enum Blockchain until backend renamed
// [REDACTED_JIRA]
Blockchain.Dischain,
Blockchain.Arbitrum,
-> this.fullName
else -> responseToken.name
}
}
private fun Blockchain.getSymbolForCoin(responseToken: UserTokensResponse.Token): String {
return when (this) {
// workaround: Dischain was renamed but backend still returns the old name,
// get name and symbol from enum Blockchain until backend renamed
// [REDACTED_JIRA]
Blockchain.Dischain,
-> this.currency
else -> responseToken.symbol
}
}
private fun createToken(
blockchain: Blockchain,
sdkToken: Token,

View file

@ -24,7 +24,7 @@ sealed class CryptoCurrencyWarning {
val feeCurrencySymbol: String,
) : CryptoCurrencyWarning()
object SomeNetworksUnreachable : CryptoCurrencyWarning()
data object SomeNetworksUnreachable : CryptoCurrencyWarning()
data class SomeNetworksNoAccount(
val amountToCreateAccount: BigDecimal,

View file

@ -1,9 +1,11 @@
package com.tangem.features.send.impl.presentation.state.fee
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.core.ui.extensions.networkIconResId
import com.tangem.core.ui.utils.parseToBigDecimal
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.domain.tokens.GetBalanceNotEnoughForFeeWarningUseCase
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
@ -90,6 +92,7 @@ internal class FeeNotificationFactory(
ifRight = { it },
) ?: return
val mergeFeeNetworkName = cryptoCurrencyStatus.shouldMergeFeeNetworkName()
when (warning) {
is CryptoCurrencyWarning.BalanceNotEnoughForFee -> {
add(
@ -99,6 +102,7 @@ internal class FeeNotificationFactory(
currencyName = cryptoCurrencyStatus.currency.name,
feeName = warning.coinCurrency.name,
feeSymbol = warning.coinCurrency.symbol,
mergeFeeNetworkName = mergeFeeNetworkName,
onClick = {
clickIntents.onTokenDetailsClick(
userWalletId = userWalletId,
@ -117,6 +121,7 @@ internal class FeeNotificationFactory(
feeName = warning.feeCurrencyName,
feeSymbol = warning.feeCurrencySymbol,
networkName = warning.networkName,
mergeFeeNetworkName = mergeFeeNetworkName,
onClick = currency?.let {
{
clickIntents.onTokenDetailsClick(
@ -132,6 +137,11 @@ internal class FeeNotificationFactory(
}
}
// workaround for networks that users have misunderstanding
private fun CryptoCurrencyStatus.shouldMergeFeeNetworkName(): Boolean {
return Blockchain.fromNetworkId(this.currency.network.backendId) == Blockchain.Arbitrum
}
companion object {
private val FEE_MAX_DIFF = BigDecimal(5)
private const val HIGH_FEE_DIFF_DECIMALS = 0

View file

@ -56,6 +56,7 @@ sealed class SendFeeNotification(val config: NotificationConfig) {
val feeName: String,
val feeSymbol: String,
val networkName: String,
val mergeFeeNetworkName: Boolean = false,
val onClick: (() -> Unit)? = null,
) : Error(
title = resourceReference(
@ -69,7 +70,16 @@ sealed class SendFeeNotification(val config: NotificationConfig) {
iconResId = networkIconId,
buttonsState = onClick?.let {
NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(R.string.common_buy_currency, wrappedList(feeName)),
text = resourceReference(
R.string.common_buy_currency,
wrappedList(
if (mergeFeeNetworkName) {
"$currencyName ($feeSymbol)"
} else {
feeName
},
),
),
onClick = onClick,
)
},

View file

@ -99,6 +99,7 @@ internal sealed class TokenDetailsNotification(val config: NotificationConfig) {
private val networkName: String,
private val feeCurrencyName: String,
private val feeCurrencySymbol: String,
val mergeFeeNetworkName: Boolean = false,
private val onBuyClick: () -> Unit,
) : Warning(
title = TextReference.Res(
@ -120,7 +121,13 @@ internal sealed class TokenDetailsNotification(val config: NotificationConfig) {
NotificationConfig.ButtonsState.SecondaryButtonConfig(
text = resourceReference(
id = R.string.common_buy_currency,
formatArgs = wrappedList(feeCurrencySymbol),
formatArgs = wrappedList(
if (mergeFeeNetworkName) {
"$feeCurrencyName ($feeCurrencySymbol)"
} else {
feeCurrencySymbol
},
),
),
onClick = onBuyClick,
),

View file

@ -1,5 +1,8 @@
package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory
import com.tangem.blockchain.common.Blockchain
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification
@ -28,9 +31,10 @@ internal class TokenDetailsNotificationConverter(
return when (warning) {
is CryptoCurrencyWarning.BalanceNotEnoughForFee -> NetworkFeeWithBuyButton(
currency = warning.tokenCurrency,
networkName = warning.coinCurrency.name,
networkName = warning.coinCurrency.network.name,
feeCurrencyName = warning.coinCurrency.name,
feeCurrencySymbol = warning.coinCurrency.symbol,
mergeFeeNetworkName = warning.coinCurrency.shouldMergeFeeNetworkName(),
onBuyClick = { clickIntents.onBuyCoinClick(warning.coinCurrency) },
)
is CryptoCurrencyWarning.CustomTokenNotEnoughForFee -> {
@ -41,6 +45,7 @@ internal class TokenDetailsNotificationConverter(
networkName = feeCurrency.network.name,
feeCurrencyName = warning.feeCurrencyName,
feeCurrencySymbol = warning.feeCurrencySymbol,
mergeFeeNetworkName = warning.currency.shouldMergeFeeNetworkName(),
onBuyClick = { clickIntents.onBuyCoinClick(feeCurrency) },
)
} else {
@ -75,4 +80,9 @@ internal class TokenDetailsNotificationConverter(
)
}
}
// workaround for networks that users have misunderstanding
private fun CryptoCurrency.shouldMergeFeeNetworkName(): Boolean {
return Blockchain.fromNetworkId(this.network.backendId) == Blockchain.Arbitrum
}
}

View file

@ -85,7 +85,7 @@ web3j = "4.10.1"
# endregion Other libraries
# region Tangem
tangemBlockchainSdk = "develop-497"
tangemBlockchainSdk = "develop-503"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "develop-324"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^