From b6a38918fc85f17aaafd32172c12a4ec2868f758 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 26 Apr 2022 11:32:21 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/domain/common/form/FieldsValidators.kt | 15 +++++++++++---- .../addCustomToken/redux/AddCustomTokenHub.kt | 4 +++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/domain/src/main/java/com/tangem/domain/common/form/FieldsValidators.kt b/domain/src/main/java/com/tangem/domain/common/form/FieldsValidators.kt index 7b5235d365..5da31c0d87 100644 --- a/domain/src/main/java/com/tangem/domain/common/form/FieldsValidators.kt +++ b/domain/src/main/java/com/tangem/domain/common/form/FieldsValidators.kt @@ -1,11 +1,11 @@ package com.tangem.domain.common.form -import com.tangem.blockchain.blockchains.binance.BinanceAddressService import com.tangem.blockchain.blockchains.ethereum.EthereumAddressService import com.tangem.blockchain.blockchains.solana.SolanaAddressService import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.address.AddressService import com.tangem.common.Validator +import com.tangem.common.card.EllipticCurve import com.tangem.domain.AddCustomTokenError import timber.log.Timber @@ -48,10 +48,9 @@ class TokenContractAddressValidator : CustomTokenValidator() { private fun getAddressService(): AddressService { return when (blockchain) { - Blockchain.Unknown -> EthereumAddressService() + Blockchain.Unknown -> successAddressValidator + Blockchain.Binance, Blockchain.BinanceTestnet -> successAddressValidator Blockchain.Solana, Blockchain.SolanaTestnet -> SolanaAddressService() - Blockchain.Binance -> BinanceAddressService() - Blockchain.BinanceTestnet -> BinanceAddressService(true) else -> { if (blockchain.isEvm()) { EthereumAddressService() @@ -62,6 +61,14 @@ class TokenContractAddressValidator : CustomTokenValidator() { } } } + + private val successAddressValidator = object : AddressService() { + override fun makeAddress(walletPublicKey: ByteArray, curve: EllipticCurve?): String { + throw UnsupportedOperationException() + } + + override fun validate(address: String): Boolean = true + } } class TokenNetworkValidator : CustomTokenValidator() { diff --git a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt index af5a758664..55c6e9f760 100644 --- a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt +++ b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenHub.kt @@ -69,7 +69,7 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT val contractAddress = ContractAddress.getFieldValue() validateContractAddressAndNotify(contractAddress) - if (!hubState.tokensAnyFieldsIsFilled()){ + if (!hubState.tokensAnyFieldsIsFilled()) { val isAlreadyAdded = isBlockchainPersistIntoAppSavedTokensList( selectedNetwork = action.blockchainNetwork.value ) @@ -120,6 +120,8 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT } private suspend fun validateContractAddressAndNotify(contractAddress: String): AddCustomTokenError? { + if (!Network.isFilled()) return null + val error = ContractAddress.validateValue(contractAddress) when (error) { null -> {