Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-29 11:42:25 +03:00
commit fbf290c1a1
7 changed files with 32 additions and 16 deletions

View file

@ -300,9 +300,9 @@ internal sealed class AddCustomTokenWarning(val description: TextReference) {
description = TextReference.Res(R.string.custom_token_validation_error_already_added),
)
/** Unsupported Solana token warning */
object UnsupportedSolanaToken : AddCustomTokenWarning(
description = TextReference.Res(R.string.alert_manage_tokens_unsupported_message),
/** Unsupported token warning */
data class UnsupportedToken(val networkName: String) : AddCustomTokenWarning(
description = TextReference.Res(R.string.alert_manage_tokens_unsupported_message, networkName),
)
object WrongDerivationPath : AddCustomTokenWarning(

View file

@ -18,7 +18,7 @@ internal object AddCustomTokenPreviewData {
return setOf(
AddCustomTokenWarning.PotentialScamToken,
AddCustomTokenWarning.TokenAlreadyAdded,
AddCustomTokenWarning.UnsupportedSolanaToken,
AddCustomTokenWarning.UnsupportedToken(networkName = "Solana"),
)
}

View file

@ -486,8 +486,12 @@ internal class AddCustomTokenViewModel @Inject constructor(
}
return buildSet {
if (!isSupportedToken && !isContractAddressFieldEmpty) add(AddCustomTokenWarning.UnsupportedSolanaToken)
if (isCustomTokenAlreadyAdded()) add(AddCustomTokenWarning.TokenAlreadyAdded)
if (!isSupportedToken && !isContractAddressFieldEmpty) {
add(AddCustomTokenWarning.UnsupportedToken(networkSelectorValue.fullName))
}
if (isCustomTokenAlreadyAdded()) {
add(AddCustomTokenWarning.TokenAlreadyAdded)
}
if (foundToken == null && isAnyTokenFieldsFilled() || foundToken?.isActive == false) {
add(AddCustomTokenWarning.PotentialScamToken)
}

View file

@ -5,7 +5,7 @@ package com.tangem.tap.features.tokens.impl.presentation.models
*/
sealed class SupportTokensState {
object SolanaNetworkUnsupported : SupportTokensState()
object NetworkTokensUnsupported : SupportTokensState()
object UnsupportedCurve : SupportTokensState()
object SupportedToken : SupportTokensState()
}

View file

@ -51,11 +51,12 @@ internal class DefaultTokensListRouter : TokensListRouter {
store.dispatchDialogShow(alert)
}
override fun openSolanaTokensNotSupportAlert() {
override fun openNetworkTokensNotSupportAlert(networkName: String) {
store.dispatchDialogShow(
AppDialog.SimpleOkDialogRes(
headerId = R.string.common_warning,
messageId = R.string.alert_manage_tokens_unsupported_message,
args = listOf(networkName),
),
)
}

View file

@ -37,7 +37,7 @@ internal interface TokensListRouter {
fun openUnsupportedNetworkAlert(blockchain: Blockchain)
/**
* Open alert with Solana tokens error
* Open alert with unsupported networks tokens error
*/
fun openSolanaTokensNotSupportAlert()
fun openNetworkTokensNotSupportAlert(networkName: String)
}

View file

@ -4,7 +4,10 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.*
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.*
import com.tangem.blockchain.common.Blockchain
import com.tangem.core.analytics.api.AnalyticsEventHandler
@ -37,7 +40,9 @@ import com.tangem.utils.coroutines.Debouncer
import com.tangem.wallet.R
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
import timber.log.Timber
@ -406,14 +411,20 @@ internal class TokensListViewModel @Inject constructor(
}
} else {
when (isUnsupportedToken(token.blockchain)) {
SupportTokensState.SolanaNetworkUnsupported -> router.openSolanaTokensNotSupportAlert()
SupportTokensState.NetworkTokensUnsupported -> {
router.openNetworkTokensNotSupportAlert(token.blockchain.fullName)
}
SupportTokensState.SupportedToken -> {
analyticsSender.sendWhenTokenAdded(token.token)
changedTokensList.add(token)
toggledNetwork.changeToggleState()
}
SupportTokensState.UnsupportedCurve -> router.openUnsupportedNetworkAlert(token.blockchain)
null -> Timber.e("Something went wrong in isUnsupportedToken (no scanResponse found)")
SupportTokensState.UnsupportedCurve -> {
router.openUnsupportedNetworkAlert(token.blockchain)
}
null -> {
Timber.e("Something went wrong in isUnsupportedToken (no scanResponse found)")
}
}
}
}
@ -428,7 +439,7 @@ internal class TokensListViewModel @Inject constructor(
// refactor this later by moving all this logic in card config
if (blockchain == Blockchain.Solana && !supportedTokens.contains(Blockchain.Solana)) {
return SupportTokensState.SolanaNetworkUnsupported
return SupportTokensState.NetworkTokensUnsupported
}
val canHandleToken = it.scanResponse.card.canHandleToken(
supportedTokens = supportedTokens,