Updated on 2026-08-14
This commit is contained in:
parent
b718f39048
commit
0b0088f613
5 changed files with 54 additions and 19 deletions
13
domain/src/main/java/com/tangem/domain/DomainException.kt
Normal file
13
domain/src/main/java/com/tangem/domain/DomainException.kt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package com.tangem.domain
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
* Must be handled by the module or sent to Crashlytics
|
||||
*/
|
||||
interface DomainInternalException
|
||||
|
||||
sealed class DomainException(message: String?) : Throwable(message), DomainInternalException {
|
||||
data class SelectTokeNetworkException(val networkId: String) : DomainException(
|
||||
"Unknown network [$networkId] should not be included in the network selection dialog."
|
||||
)
|
||||
}
|
||||
|
|
@ -34,7 +34,6 @@ class TokenContractAddressValidator : CustomTokenValidator<String>() {
|
|||
AddCustomTokenError.InvalidContractAddress
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TokenNetworkValidator : CustomTokenValidator<Blockchain>() {
|
||||
|
|
@ -44,6 +43,14 @@ class TokenNetworkValidator : CustomTokenValidator<Blockchain>() {
|
|||
}
|
||||
}
|
||||
|
||||
class TokenNameValidator : CustomTokenValidator<String>() {
|
||||
override fun validate(data: String?): AddCustomTokenError? = StringIsNotEmptyValidator().validate(data)
|
||||
}
|
||||
|
||||
class TokenSymbolValidator : CustomTokenValidator<String>() {
|
||||
override fun validate(data: String?): AddCustomTokenError? = StringIsNotEmptyValidator().validate(data)
|
||||
}
|
||||
|
||||
class TokenDecimalsValidator : CustomTokenValidator<String>() {
|
||||
override fun validate(data: String?): AddCustomTokenError? {
|
||||
val decimal = data?.toIntOrNull() ?: return AddCustomTokenError.FieldIsEmpty
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@ sealed class AddCustomTokenAction : Action {
|
|||
// from user, ui
|
||||
object OnCreate : AddCustomTokenAction()
|
||||
object OnDestroy : AddCustomTokenAction()
|
||||
data class OnTokenFieldChanged(val id: FieldId, val value: Field.Data<String>) : AddCustomTokenAction()
|
||||
data class OnTokenContractAddressChanged(val value: Field.Data<String>) : AddCustomTokenAction()
|
||||
data class OnTokenNetworkChanged(val value: Field.Data<Blockchain>) : AddCustomTokenAction()
|
||||
data class OnTokenNameChanged(val value: Field.Data<String>) : AddCustomTokenAction()
|
||||
data class OnTokenSymbolChanged(val value: Field.Data<String>) : AddCustomTokenAction()
|
||||
data class OnTokenDerivationPathChanged(val value: Field.Data<Blockchain>) : AddCustomTokenAction()
|
||||
data class OnTokenDecimalsChanged(val value: Field.Data<String>) : AddCustomTokenAction()
|
||||
data class OnCustomTokenSelected(val any: Any = Unit) : AddCustomTokenAction()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package com.tangem.domain.features.addCustomToken.redux
|
|||
import android.webkit.ValueCallback
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.common.card.Card
|
||||
import com.tangem.common.services.Result
|
||||
import com.tangem.domain.DomainDialog
|
||||
import com.tangem.domain.DomainException
|
||||
import com.tangem.domain.common.form.*
|
||||
import com.tangem.domain.features.addCustomToken.*
|
||||
import com.tangem.domain.features.addCustomToken.CustomTokenFieldId.*
|
||||
|
|
@ -73,21 +75,29 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
}
|
||||
}
|
||||
is OnTokenNetworkChanged -> {
|
||||
val validator: TokenNetworkValidator = getValidator(Network, hubState)
|
||||
addOrRemoveError(Network, validator.validate(action.value.value))
|
||||
// val validator: TokenNetworkValidator = getValidator(Network, hubState)
|
||||
// addOrRemoveError(Network, validator.validate(action.value.value))
|
||||
|
||||
// dispatchOnMain(OnTokenContractAddressChanged(Field.Data(
|
||||
// getField<TokenField>(ContractAddress, hubState).data.value, false
|
||||
// )))
|
||||
}
|
||||
is OnTokenDerivationPathChanged -> {
|
||||
// val validator: TokenDerivationPathValidator = getValidator(DerivationPath, hubState)
|
||||
// addOrRemoveError(DerivationPath, validator.validate(action.value.value))
|
||||
is OnTokenNameChanged -> {
|
||||
val validator: TokenNameValidator = getValidator(Name, hubState)
|
||||
addOrRemoveError(Name, validator.validate(action.value.value))
|
||||
}
|
||||
is OnTokenSymbolChanged -> {
|
||||
val validator: TokenSymbolValidator = getValidator(Symbol, hubState)
|
||||
addOrRemoveError(Symbol, validator.validate(action.value.value))
|
||||
}
|
||||
is OnTokenDecimalsChanged -> {
|
||||
val validator: TokenDecimalsValidator = getValidator(Decimals, hubState)
|
||||
addOrRemoveError(Decimals, validator.validate(action.value.value))
|
||||
}
|
||||
is OnTokenFieldChanged -> {
|
||||
val validator: StringIsNotEmptyValidator = getValidator(action.id, hubState)
|
||||
addOrRemoveError(action.id as CustomTokenFieldId, validator.validate(action.value.value))
|
||||
}
|
||||
// is OnTokenDerivationPathChanged -> {
|
||||
// val validator: TokenDerivationPathValidator = getValidator(DerivationPath, hubState)
|
||||
// addOrRemoveError(DerivationPath, validator.validate(action.value.value))
|
||||
// }
|
||||
is OnCustomTokenSelected -> {
|
||||
// dispatchOnMain()
|
||||
}
|
||||
|
|
@ -231,8 +241,13 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
field.data = action.value
|
||||
updateFormState(state)
|
||||
}
|
||||
is OnTokenDerivationPathChanged -> {
|
||||
val field: TokenDerivationPathField = getField(DerivationPath, state)
|
||||
is OnTokenNameChanged -> {
|
||||
val field: TokenField = getField(Name, state)
|
||||
field.data = action.value
|
||||
updateFormState(state)
|
||||
}
|
||||
is OnTokenSymbolChanged -> {
|
||||
val field: TokenField = getField(Symbol, state)
|
||||
field.data = action.value
|
||||
updateFormState(state)
|
||||
}
|
||||
|
|
@ -241,8 +256,8 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
field.data = action.value
|
||||
updateFormState(state)
|
||||
}
|
||||
is OnTokenFieldChanged -> {
|
||||
val field: TokenField = getField(action.id, state)
|
||||
is OnTokenDerivationPathChanged -> {
|
||||
val field: TokenDerivationPathField = getField(DerivationPath, state)
|
||||
field.data = action.value
|
||||
updateFormState(state)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,10 +76,9 @@ data class AddCustomTokenState(
|
|||
return mapOf(
|
||||
ContractAddress to TokenContractAddressValidator(),
|
||||
Network to TokenNetworkValidator(),
|
||||
Name to StringIsNotEmptyValidator(),
|
||||
Symbol to StringIsNotEmptyValidator(),
|
||||
Name to TokenNameValidator(),
|
||||
Symbol to TokenSymbolValidator(),
|
||||
Decimals to TokenDecimalsValidator(),
|
||||
// DerivationPath to TokenDerivationPathValidator(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +98,7 @@ data class AddCustomTokenState(
|
|||
val evmBlockchains = Blockchain.values().filter {
|
||||
!it.isTestnet() && it.getChainId() != null
|
||||
}
|
||||
return evmBlockchains
|
||||
return listOf(Blockchain.Unknown) + evmBlockchains
|
||||
}
|
||||
|
||||
private fun createInitialScreenState(): ScreenState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue