From 4e49562a24e041b718340634d68dddcbb93d1015 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 22 Apr 2022 23:53:24 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../addCustomToken/redux/AddCustomTokenHub.kt | 90 +++++++++---------- .../redux/AddCustomTokenState.kt | 2 +- 2 files changed, 42 insertions(+), 50 deletions(-) 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 c526237f5a..5d21995d73 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 @@ -59,48 +59,23 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT } is OnDestroy -> cancelAll() is OnTokenContractAddressChanged -> { - val address = action.contractAddress.value + val contractAddress = action.contractAddress.value - when (val error = ContractAddress.validateValue(address)) { - null -> { - // valid contract address - ContractAddress.removeError() - updateTokenDetailFields(false) - changeBlockchainNetworkList() - checkAndUpdateAddButton() - manageFoundTokenChanges(requestInfoAboutToken(address)) - } - AddCustomTokenError.FieldIsEmpty -> { - // empty contract address - ContractAddress.removeError() - clearTokenDetailsFields() - updateTokenDetailFields(false) - changeBlockchainNetworkList() - checkAndUpdateAddButton() - } - AddCustomTokenError.InvalidContractAddress -> { - ContractAddress.addError(error) - updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled()) - changeBlockchainNetworkList() - checkAndUpdateAddButton() - } - } + validateContractAddressAndNotify(contractAddress) } is OnTokenNetworkChanged -> { if (!action.blockchainNetwork.isUserInput) return val contractAddress = ContractAddress.getFieldValue() - val error = ContractAddress.validateValue(contractAddress) - if (error == null && contractAddress.isNotEmpty()) { - // token branch - manageFoundTokenChanges(requestInfoAboutToken(contractAddress)) - } else { - // blockchain branch - val isAlreadyAdded = isBlockchainPersistIntoAppSavedTokensList( - selectedNetwork = action.blockchainNetwork.value - ) - updateWarningAlreadyAdded(isAlreadyAdded) - checkAndUpdateAddButton() + when (validateContractAddressAndNotify(contractAddress)) { + is AddCustomTokenError.InvalidContractAddress -> { + val isAlreadyAdded = isBlockchainPersistIntoAppSavedTokensList( + selectedNetwork = action.blockchainNetwork.value + ) + updateWarningAlreadyAdded(isAlreadyAdded) + checkAndUpdateAddButton() + } + else -> {} } } is OnTokenDerivationPathChanged -> { @@ -118,19 +93,7 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT updateWarningAlreadyAdded(isAlreadyAdded) checkAndUpdateAddButton() } - is OnTokenNameChanged -> { -// changeBlockchainNetworkList() -// updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled()) - checkAndUpdateAddButton() - } - is OnTokenSymbolChanged -> { -// changeBlockchainNetworkList() -// updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled()) - checkAndUpdateAddButton() - } - is OnTokenDecimalsChanged -> { -// changeBlockchainNetworkList() -// updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled()) + is OnTokenNameChanged, is OnTokenSymbolChanged, is OnTokenDecimalsChanged -> { checkAndUpdateAddButton() } is OnAddCustomTokenClicked -> { @@ -157,6 +120,35 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT } } + private suspend fun validateContractAddressAndNotify(contractAddress: String): AddCustomTokenError? { + val error = ContractAddress.validateValue(contractAddress) + when (error) { + null -> { + // valid contract address + ContractAddress.removeError() + updateTokenDetailFields(false) + changeBlockchainNetworkList() + checkAndUpdateAddButton() + manageFoundTokenChanges(requestInfoAboutToken(contractAddress)) + } + AddCustomTokenError.FieldIsEmpty -> { + // empty contract address + ContractAddress.removeError() + clearTokenDetailsFields() + updateTokenDetailFields(false) + changeBlockchainNetworkList() + checkAndUpdateAddButton() + } + AddCustomTokenError.InvalidContractAddress -> { + ContractAddress.addError(error) + updateTokenDetailFields(hubState.tokensAnyFieldsIsFilled()) + changeBlockchainNetworkList() + checkAndUpdateAddButton() + } + } + return error + } + /** * This feature is only needed until Solana coins are added. * While they are not there - this function excludes the Solana blockchain if the user has diff --git a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt index 77177b013c..7db7052347 100644 --- a/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt +++ b/domain/src/main/java/com/tangem/domain/features/addCustomToken/redux/AddCustomTokenState.kt @@ -172,10 +172,10 @@ data class AddCustomTokenState( Blockchain.Unknown, Blockchain.Ethereum, Blockchain.BSC, - Blockchain.Binance, // not evm Blockchain.Polygon, Blockchain.Avalanche, Blockchain.Fantom, + Blockchain.Binance, // not evm Blockchain.Solana, // not evm. Should be unsupported for coins until they are added to the Blockchain SDK ) if (type == CustomTokenType.Token) networks.remove(Blockchain.Solana)