From b1e7add18eef01be2602f05f374238fbcaea9031 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 28 Apr 2022 23:28:55 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../domain/common/extensions/CardSdk.kt | 12 ++++++++++++ .../addCustomToken/AddCustomTokenService.kt | 4 ++++ .../addCustomToken/redux/AddCustomTokenHub.kt | 5 +++++ .../redux/AddCustomTokenState.kt | 19 ++++++++++++++++--- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt diff --git a/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt b/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt new file mode 100644 index 0000000000..ca37d132ba --- /dev/null +++ b/domain/src/main/java/com/tangem/domain/common/extensions/CardSdk.kt @@ -0,0 +1,12 @@ +package com.tangem.domain.common.extensions + +import com.tangem.common.card.FirmwareVersion + +/** +[REDACTED_AUTHOR] + */ +val FirmwareVersion.Companion.SolanaAvailable + get() = FirmwareVersion(4, 12) + +val FirmwareVersion.Companion.SolanaTokensAvailable + get() = FirmwareVersion(4, 52) \ No newline at end of file diff --git a/domain/src/main/java/com/tangem/domain/features/addCustomToken/AddCustomTokenService.kt b/domain/src/main/java/com/tangem/domain/features/addCustomToken/AddCustomTokenService.kt index fc3b5891ef..ac4ce3a994 100644 --- a/domain/src/main/java/com/tangem/domain/features/addCustomToken/AddCustomTokenService.kt +++ b/domain/src/main/java/com/tangem/domain/features/addCustomToken/AddCustomTokenService.kt @@ -1,6 +1,8 @@ package com.tangem.domain.features.addCustomToken +import com.tangem.blockchain.common.Blockchain import com.tangem.common.services.Result +import com.tangem.domain.common.extensions.toNetworkId import com.tangem.network.api.tangemTech.CoinsResponse import com.tangem.network.api.tangemTech.TangemTechService @@ -24,6 +26,8 @@ class AddCustomTokenService( val networksWithTheSameAddress = coin.networks .filter { it.contractAddress != null || it.decimalCount != null } .filter { it.contractAddress == contractAddress } + //TODO: Solana token + .filter { it.networkId != Blockchain.Solana.toNetworkId() } if (networksWithTheSameAddress.isNotEmpty()) { val newToken = coin.copy(networks = networksWithTheSameAddress) coinsList.add(newToken) 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 74b1061031..b895c985ba 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 @@ -103,6 +103,7 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT null -> { // valid contract address ContractAddress.removeError() + changeBlockchainNetworkList() findTokenAndUpdateFields(contractAddress) } AddCustomTokenError.InvalidContractAddress -> { @@ -126,6 +127,7 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT null -> { // valid contract address ContractAddress.removeError() + changeBlockchainNetworkList() findTokenAndUpdateFields(contractAddress) } else -> { @@ -139,6 +141,7 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT } } + //TODO: Solana token /** * 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 @@ -534,8 +537,10 @@ internal class AddCustomTokenHub : BaseStoreHub("AddCustomT DerivationStyle.LEGACY -> derivationPathState.copy(isVisible = true) null, DerivationStyle.NEW -> derivationPathState.copy(isVisible = false) } + val form = Form(AddCustomTokenState.createFormFields(CustomTokenType.Blockchain)) state.copy( cardDerivationStyle = card.derivationStyle, + form = form, tangemTechServiceManager = tangemTechServiceManager, screenState = state.screenState.copy(derivationPath = derivationPathState) ) 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 7db7052347..5476567b36 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 @@ -2,18 +2,22 @@ package com.tangem.domain.features.addCustomToken.redux import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.DerivationStyle +import com.tangem.common.card.FirmwareVersion import com.tangem.domain.AddCustomTokenError import com.tangem.domain.DomainWrapped +import com.tangem.domain.common.extensions.SolanaAvailable +import com.tangem.domain.common.extensions.SolanaTokensAvailable import com.tangem.domain.common.form.* import com.tangem.domain.features.addCustomToken.* import com.tangem.domain.features.addCustomToken.CustomTokenFieldId.* +import com.tangem.domain.redux.domainStore import org.rekotlin.StateType data class AddCustomTokenState( val appSavedCurrencies: List? = null, val onTokenAddCallback: ((CustomCurrency) -> Unit)? = null, val cardDerivationStyle: DerivationStyle? = null, - val form: Form = Form(createFormFields(CustomTokenType.Blockchain)), + val form: Form = Form(listOf()), val formValidators: Map> = createFormValidators(), val formErrors: Map = emptyMap(), val tokenId: String? = null, @@ -146,7 +150,7 @@ data class AddCustomTokenState( else -> derivationNetwork }.derivationPath(derivationStyle) - private fun createFormFields(type: CustomTokenType): List> { + internal fun createFormFields(type: CustomTokenType): List> { return listOf( TokenField(ContractAddress), TokenBlockchainField(Network, getSupportedNetworks(type)), @@ -176,8 +180,17 @@ data class AddCustomTokenState( 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 + Blockchain.Solana, // not evm ) + //life hack + val fwCardVersion = domainStore.state.globalState.scanResponse?.card?.firmwareVersion + ?: FirmwareVersion(0, 0) + + val solanaUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaAvailable + val solanaTokensUnsupportedByCard = fwCardVersion < FirmwareVersion.SolanaTokensAvailable + if (solanaUnsupportedByCard || solanaTokensUnsupportedByCard) networks.remove(Blockchain.Solana) + + //TODO: Solana if (type == CustomTokenType.Token) networks.remove(Blockchain.Solana) return networks