Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-26 15:49:32 +04:00
parent f6a56e1657
commit 40ffe17556
5 changed files with 20 additions and 13 deletions

View file

@ -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() {

View file

@ -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(

View file

@ -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(),
)
}

View file

@ -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,

View file

@ -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,