From f6fd1a51fbd9099c0a148b6a4672e7fd7efcf5b9 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 9 Feb 2024 23:26:37 +0100 Subject: [PATCH] Updated on 2026-08-14 --- .../validators/ContractAddressValidator.kt | 6 +-- .../ContractAddressValidatorResult.kt | 2 +- .../viewmodels/AddCustomTokenViewModel.kt | 8 ++-- .../com/tangem/domain/DomainModuleMessage.kt | 39 ------------------- .../tokens/ValidateContractAddressUseCase.kt | 12 +++--- .../tokens/error/AddCustomTokenError.kt | 6 +++ features/manage-tokens/impl/build.gradle.kts | 2 - .../factory/AddCustomTokenStateFactory.kt | 6 +-- 8 files changed, 24 insertions(+), 57 deletions(-) delete mode 100644 domain/legacy/src/main/java/com/tangem/domain/DomainModuleMessage.kt create mode 100644 domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/AddCustomTokenError.kt diff --git a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidator.kt b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidator.kt index 5a8c8bf385..5db91d6354 100644 --- a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidator.kt +++ b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidator.kt @@ -3,7 +3,7 @@ package com.tangem.tap.features.customtoken.impl.presentation.validators import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.address.AddressService import com.tangem.common.card.EllipticCurve -import com.tangem.domain.AddCustomTokenError +import com.tangem.domain.tokens.error.AddCustomTokenError /** * Validator of contract address @@ -15,9 +15,9 @@ object ContractAddressValidator { /** Validate a [address] using [blockchain] */ fun validate(address: String, blockchain: Blockchain): ContractAddressValidatorResult { return when { - address.isEmpty() -> ContractAddressValidatorResult.Error(type = AddCustomTokenError.FieldIsEmpty) + address.isEmpty() -> ContractAddressValidatorResult.Error(type = AddCustomTokenError.FIELD_IS_EMPTY) validateAddress(blockchain, address) -> ContractAddressValidatorResult.Success - else -> ContractAddressValidatorResult.Error(type = AddCustomTokenError.InvalidContractAddress) + else -> ContractAddressValidatorResult.Error(type = AddCustomTokenError.INVALID_CONTRACT_ADDRESS) } } diff --git a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidatorResult.kt b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidatorResult.kt index 417b3821e0..daf1b4d159 100644 --- a/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidatorResult.kt +++ b/app/src/main/java/com/tangem/tap/features/customtoken/impl/presentation/validators/ContractAddressValidatorResult.kt @@ -1,6 +1,6 @@ package com.tangem.tap.features.customtoken.impl.presentation.validators -import com.tangem.domain.AddCustomTokenError +import com.tangem.domain.tokens.error.AddCustomTokenError /** * Result of validation contract address 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 0faab87b40..0825668edb 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 @@ -16,13 +16,13 @@ import com.tangem.blockchain.common.derivation.DerivationStyle import com.tangem.core.analytics.api.AnalyticsEventHandler import com.tangem.crypto.hdWallet.DerivationPath import com.tangem.crypto.hdWallet.HDWalletError -import com.tangem.domain.AddCustomTokenError import com.tangem.domain.common.DerivationStyleProvider import com.tangem.domain.common.extensions.* import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.common.util.derivationStyleProvider import com.tangem.domain.features.addCustomToken.CustomCurrency import com.tangem.domain.tokens.GetCryptoCurrenciesUseCase +import com.tangem.domain.tokens.error.AddCustomTokenError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase import com.tangem.tap.features.customtoken.impl.domain.CustomTokenInteractor @@ -465,7 +465,7 @@ internal class AddCustomTokenViewModel @Inject constructor( address = uiState.form.contractAddressInputField.value, blockchain = networkSelectorValue, ).let { - it is ContractAddressValidatorResult.Error && it.type == AddCustomTokenError.FieldIsEmpty + it is ContractAddressValidatorResult.Error && it.type == AddCustomTokenError.FIELD_IS_EMPTY } val isSupportedToken = if (!isNetworkSelected()) { @@ -621,7 +621,7 @@ internal class AddCustomTokenViewModel @Inject constructor( private fun handleContractAddressErrorValidation(type: AddCustomTokenError) { when { - isNetworkSelected() && type == AddCustomTokenError.InvalidContractAddress -> { + isNetworkSelected() && type == AddCustomTokenError.INVALID_CONTRACT_ADDRESS -> { val isAnotherTokenFieldsFilled = isAnyTokenFieldsFilled() uiState = uiState.copySealed( form = uiState.form.copy( @@ -644,7 +644,7 @@ internal class AddCustomTokenViewModel @Inject constructor( ) } - !isNetworkSelected() || type == AddCustomTokenError.FieldIsEmpty -> { + !isNetworkSelected() || type == AddCustomTokenError.FIELD_IS_EMPTY -> { uiState = uiState.copySealed( form = uiState.form.copy( contractAddressInputField = uiState.form.contractAddressInputField.copy(isError = false), diff --git a/domain/legacy/src/main/java/com/tangem/domain/DomainModuleMessage.kt b/domain/legacy/src/main/java/com/tangem/domain/DomainModuleMessage.kt deleted file mode 100644 index af32f7c703..0000000000 --- a/domain/legacy/src/main/java/com/tangem/domain/DomainModuleMessage.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.tangem.domain - -import com.tangem.common.module.ModuleError -import com.tangem.common.module.ModuleErrorCode -import com.tangem.common.module.ModuleMessage - -/** -[REDACTED_AUTHOR] - * All DomainError descendants must use their own range of codes, but no more than 999 error codes for each. - */ -sealed interface DomainModuleMessage : ModuleMessage - -sealed class DomainModuleError( - subCode: Int, - override val message: String, - override val data: Any?, -) : DomainModuleMessage, ModuleError() { - override val code: Int = ModuleErrorCode.DOMAIN + subCode - - companion object { - // base code used for all errors in the module - internal const val ERROR_CODE_ADD_CUSTOM_TOKEN = 100 -// const val CODE_ANY_OTHER = 200..299, 300..399 etc - } -} - -sealed class AddCustomTokenError( - subCode: Int = 0, - message: String? = null, - data: Any? = null, -) : DomainModuleError( - subCode = ERROR_CODE_ADD_CUSTOM_TOKEN + subCode, - message = message ?: this::class.java.simpleName, - data = data, -) { - - object FieldIsEmpty : AddCustomTokenError() - object InvalidContractAddress : AddCustomTokenError() -} \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt index 5ae4755564..a2c2d2c1b4 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/ValidateContractAddressUseCase.kt @@ -3,26 +3,28 @@ package com.tangem.domain.tokens import arrow.core.Either import arrow.core.raise.catch import arrow.core.raise.either -import com.tangem.domain.AddCustomTokenError +import com.tangem.domain.tokens.error.AddCustomTokenError import com.tangem.domain.tokens.repository.TokensListRepository -class ValidateContractAddressUseCase(private val tokensListRepository: TokensListRepository) { +class ValidateContractAddressUseCase( + private val tokensListRepository: TokensListRepository, +) { operator fun invoke(address: String, networkId: String): Either { return either { catch( block = { - if (address.isEmpty()) raise(AddCustomTokenError.FieldIsEmpty) + if (address.isEmpty()) raise(AddCustomTokenError.FIELD_IS_EMPTY) if (!tokensListRepository.validateAddress( contractAddress = address, networkId = networkId, ) ) { - raise(AddCustomTokenError.InvalidContractAddress) + raise(AddCustomTokenError.INVALID_CONTRACT_ADDRESS) } }, catch = { - AddCustomTokenError.InvalidContractAddress + AddCustomTokenError.INVALID_CONTRACT_ADDRESS }, ) } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/AddCustomTokenError.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/AddCustomTokenError.kt new file mode 100644 index 0000000000..fcbb456b66 --- /dev/null +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/error/AddCustomTokenError.kt @@ -0,0 +1,6 @@ +package com.tangem.domain.tokens.error + +enum class AddCustomTokenError { + FIELD_IS_EMPTY, + INVALID_CONTRACT_ADDRESS, +} \ No newline at end of file diff --git a/features/manage-tokens/impl/build.gradle.kts b/features/manage-tokens/impl/build.gradle.kts index e388043baa..1be0e9701e 100644 --- a/features/manage-tokens/impl/build.gradle.kts +++ b/features/manage-tokens/impl/build.gradle.kts @@ -59,8 +59,6 @@ dependencies { implementation(projects.domain.settings) implementation(projects.domain.tokens) implementation(projects.domain.tokens.models) - implementation(projects.domain.txhistory) - implementation(projects.domain.txhistory.models) implementation(projects.domain.wallets) implementation(projects.domain.wallets.models) implementation(projects.domain.appCurrency) diff --git a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt index 6e51737162..57ce303a3c 100644 --- a/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt +++ b/features/manage-tokens/impl/src/main/java/com/tangem/managetokens/presentation/addcustomtoken/state/factory/AddCustomTokenStateFactory.kt @@ -2,7 +2,7 @@ package com.tangem.managetokens.presentation.addcustomtoken.state.factory import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.event.triggeredEvent -import com.tangem.domain.AddCustomTokenError +import com.tangem.domain.tokens.error.AddCustomTokenError import com.tangem.domain.tokens.model.Network import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId @@ -285,7 +285,7 @@ internal class AddCustomTokenStateFactory( fun handleAddressError(error: AddCustomTokenError): AddCustomTokenState { val uiState = currentStateProvider() return when (error) { - AddCustomTokenError.InvalidContractAddress -> { + AddCustomTokenError.INVALID_CONTRACT_ADDRESS -> { addTokenAddressFieldError(AddCustomTokenWarning.InvalidContractAddress) .copy( addTokenButton = uiState.addTokenButton.copy(isEnabled = false), @@ -294,7 +294,7 @@ internal class AddCustomTokenStateFactory( .toPersistentSet(), ) } - AddCustomTokenError.FieldIsEmpty -> + AddCustomTokenError.FIELD_IS_EMPTY -> removeTokenAddressError() .copy( addTokenButton = uiState.addTokenButton.copy(