Updated on 2026-08-14
This commit is contained in:
parent
45f492e541
commit
5b5d38ccc4
2 changed files with 24 additions and 2 deletions
|
|
@ -1,7 +1,9 @@
|
|||
package com.tangem.domain.common.form
|
||||
|
||||
import com.tangem.blockchain.blockchains.ethereum.EthereumAddressService
|
||||
import com.tangem.blockchain.blockchains.solana.SolanaAddressService
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.address.AddressService
|
||||
import com.tangem.common.Validator
|
||||
import com.tangem.domain.AddCustomTokenError
|
||||
|
||||
|
|
@ -25,15 +27,32 @@ class StringIsNotEmptyValidator : CustomTokenValidator<String>() {
|
|||
}
|
||||
|
||||
class TokenContractAddressValidator : CustomTokenValidator<String>() {
|
||||
|
||||
private var blockchain: Blockchain = Blockchain.Unknown
|
||||
|
||||
fun nextValidationFor(blockchain: Blockchain) {
|
||||
this.blockchain = blockchain
|
||||
}
|
||||
|
||||
override fun validate(data: String?): AddCustomTokenError? {
|
||||
if (data == null || data.isEmpty()) return AddCustomTokenError.FieldIsEmpty
|
||||
|
||||
return if (EthereumAddressService().validate(data)) {
|
||||
return if (getAddressService().validate(data)) {
|
||||
null
|
||||
} else {
|
||||
AddCustomTokenError.InvalidContractAddress
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAddressService(): AddressService {
|
||||
return when (blockchain) {
|
||||
Blockchain.Solana, Blockchain.SolanaTestnet -> SolanaAddressService()
|
||||
else -> {
|
||||
if (blockchain.isEvm()) EthereumAddressService()
|
||||
else throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TokenNetworkValidator : CustomTokenValidator<Blockchain>() {
|
||||
|
|
|
|||
|
|
@ -413,7 +413,10 @@ internal class AddCustomTokenHub : BaseStoreHub<AddCustomTokenState>("AddCustomT
|
|||
val decimalsValidator: TokenDecimalsValidator = state.getValidator(Decimals)
|
||||
val networkValidator: TokenNetworkValidator = state.getValidator(Network)
|
||||
return when (this) {
|
||||
ContractAddress -> contractAddressValidator.validate(value as String)
|
||||
ContractAddress -> {
|
||||
contractAddressValidator.nextValidationFor(Network.getFieldValue())
|
||||
contractAddressValidator.validate(value as String)
|
||||
}
|
||||
Network, DerivationPath -> networkValidator.validate(value as Blockchain)
|
||||
Name -> nameValidator.validate(value as String)
|
||||
Symbol -> symbolValidator.validate(value as String)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue