diff --git a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt index 34944cf67a..d725069217 100644 --- a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/viewmodels/AddCustomTokenViewModel.kt @@ -370,6 +370,8 @@ internal class AddCustomTokenViewModel @Inject constructor( viewModelScope.launch(dispatchers.main) { runCatching(dispatchers.io) { val tokenAddress = convertTokenAddress(selectedNetwork, address) + ?: error("TokenAddress is invalid") + featureInteractor.findToken(address = tokenAddress, blockchain = selectedNetwork) } .onSuccess { token -> @@ -602,7 +604,8 @@ internal class AddCustomTokenViewModel @Inject constructor( val contractAddress = convertTokenAddress( blockchain = networkSelectorValue, address = uiState.form.contractAddressInputField.value, - ) + ) ?: return false // invalid address can't be "already added" + return currentCryptoCurrencies .filterIsInstance() .any { token -> @@ -859,7 +862,8 @@ internal class AddCustomTokenViewModel @Inject constructor( val contractAddress = convertTokenAddress( blockchain = blockchain, address = foundToken?.network?.contractAddress ?: uiState.form.contractAddressInputField.value, - ) + ) ?: error("Contract address is invalid") // impossible to add a token with invalid address + CustomCurrency.CustomToken( token = Token( name = uiState.form.tokenNameInputField.value, @@ -897,7 +901,8 @@ internal class AddCustomTokenViewModel @Inject constructor( } } - private fun convertTokenAddress(blockchain: Blockchain, address: String): String { + /** Convert [address] to single address for specific [blockchain] or return null if invalid */ + private fun convertTokenAddress(blockchain: Blockchain, address: String): String? { return when (blockchain) { Blockchain.Hedera, Blockchain.HederaTestnet -> hederaAddressConverter.convertToTokenId(address) Blockchain.Cardano -> { diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index a821c9080b..3123d85dbb 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -87,7 +87,7 @@ markdown = "0.7.2" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "release-app_5.12-694" +tangemBlockchainSdk = "release-app_5.12-697" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds tangemCardSdk = "release-app_5.12-369" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^