From 40ffe1755674bfd4fcce7c6485e1b38c07b1b72d Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 26 Nov 2024 15:49:32 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../domain/managetokens/model/AddCustomTokenForm.kt | 8 ++++---- .../managetokens/entity/customtoken/CustomTokenFormUM.kt | 6 ++++++ .../features/managetokens/model/CustomTokenFormModel.kt | 7 ++++--- .../managetokens/utils/CustomCurrencyValidator.kt | 6 +----- .../features/managetokens/utils/mapper/TokenFormMapper.kt | 6 +++++- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/domain/manage-tokens/src/main/kotlin/com/tangem/domain/managetokens/model/AddCustomTokenForm.kt b/domain/manage-tokens/src/main/kotlin/com/tangem/domain/managetokens/model/AddCustomTokenForm.kt index c2cebdb84e..fca536c2c0 100644 --- a/domain/manage-tokens/src/main/kotlin/com/tangem/domain/managetokens/model/AddCustomTokenForm.kt +++ b/domain/manage-tokens/src/main/kotlin/com/tangem/domain/managetokens/model/AddCustomTokenForm.kt @@ -3,10 +3,10 @@ package com.tangem.domain.managetokens.model sealed class AddCustomTokenForm { data class Raw( - val contractAddress: String, - val name: String, - val symbol: String, - val decimals: String, + val contractAddress: String = "", + val name: String = "", + val symbol: String = "", + val decimals: String = "", ) : AddCustomTokenForm() sealed class Validated : AddCustomTokenForm() { diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt index 8f3c97fef8..cf0f8554a8 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/customtoken/CustomTokenFormUM.kt @@ -6,6 +6,7 @@ import com.tangem.core.ui.extensions.TextReference import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.PersistentMap import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.persistentMapOf internal data class CustomTokenFormUM( val networkName: ClickableFieldUM, @@ -29,6 +30,11 @@ internal data class CustomTokenFormUM( SYMBOL, DECIMALS, } + + companion object { + + val Empty = TokenFormUM(fields = persistentMapOf()) + } } data class NotificationUM( diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt index b0b7f781d9..b5f4d3bfc1 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/CustomTokenFormModel.kt @@ -65,7 +65,7 @@ internal class CustomTokenFormModel @Inject constructor( observeTokenFormUpdates() } - createCoin() + validatePrefilledForm() } private fun getInitialState(): CustomTokenFormUM { @@ -148,11 +148,12 @@ internal class CustomTokenFormModel @Inject constructor( } } - private fun createCoin() = modelScope.launch { - customCurrencyValidator.createCoin( + private fun validatePrefilledForm() = modelScope.launch { + customCurrencyValidator.validateForm( userWalletId = params.userWalletId, networkId = params.network.id, derivationPath = getDerivationPath(), + formValues = state.value.tokenForm.mapToDomainModel(), ) } diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/CustomCurrencyValidator.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/CustomCurrencyValidator.kt index d5ba7409da..77a41933ea 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/CustomCurrencyValidator.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/CustomCurrencyValidator.kt @@ -79,16 +79,12 @@ internal class CustomCurrencyValidator @Inject constructor( findToken(userWalletId, networkId, derivationPath, validatedForm) } is AddCustomTokenForm.Validated.Empty -> { - createCoin(userWalletId, networkId, derivationPath) + createCurrency(userWalletId, networkId, derivationPath, validatedForm = null) } } }.saveInAndJoin(validateFormJobHolder) } - suspend fun createCoin(userWalletId: UserWalletId, networkId: Network.ID, derivationPath: Network.DerivationPath) { - createCurrency(userWalletId, networkId, derivationPath, validatedForm = null) - } - private suspend fun findOrCreateCurrency( userWalletId: UserWalletId, networkId: Network.ID, diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/mapper/TokenFormMapper.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/mapper/TokenFormMapper.kt index 6e55316dfb..8a9876d746 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/mapper/TokenFormMapper.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/utils/mapper/TokenFormMapper.kt @@ -3,7 +3,11 @@ package com.tangem.features.managetokens.utils.mapper import com.tangem.domain.managetokens.model.AddCustomTokenForm import com.tangem.features.managetokens.entity.customtoken.CustomTokenFormUM -internal fun CustomTokenFormUM.TokenFormUM.mapToDomainModel(): AddCustomTokenForm.Raw { +internal fun CustomTokenFormUM.TokenFormUM?.mapToDomainModel(): AddCustomTokenForm.Raw { + if (this == null) { + return AddCustomTokenForm.Raw() + } + return AddCustomTokenForm.Raw( contractAddress = fields.getValue(CustomTokenFormUM.TokenFormUM.Field.CONTRACT_ADDRESS).value, symbol = fields.getValue(CustomTokenFormUM.TokenFormUM.Field.SYMBOL).value,