Updated on 2026-08-14
This commit is contained in:
commit
aabcc23747
3 changed files with 27 additions and 11 deletions
|
|
@ -13,9 +13,8 @@ internal class AddressValidator {
|
|||
suspend fun validateAddress(walletManager: WalletManager, address: String): AddressVerifyAction.Error? {
|
||||
val blockchain = walletManager.wallet.blockchain
|
||||
val wallet = walletManager.wallet
|
||||
return if ((blockchain == Blockchain.Near || blockchain == Blockchain.NearTestnet) &&
|
||||
address.length != NEAR_IMPLICIT_ADDRESS_LENGTH
|
||||
) {
|
||||
|
||||
return if (blockchain.isNear()) {
|
||||
validateNearAddress(walletManager, address)
|
||||
} else {
|
||||
validateAddress(wallet, address)
|
||||
|
|
@ -26,12 +25,28 @@ internal class AddressValidator {
|
|||
walletManager: WalletManager,
|
||||
address: String,
|
||||
): AddressVerifyAction.Error? {
|
||||
val result = (walletManager as? NearWalletManager)?.getAccount(address)
|
||||
return if (result is Result.Success && result.data is NearAccount.Full) {
|
||||
null
|
||||
} else {
|
||||
AddressVerifyAction.Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN
|
||||
// implicit address validation
|
||||
if (address.length == NEAR_IMPLICIT_ADDRESS_LENGTH && hexRegex.matches(address)) {
|
||||
return validateAddress(walletManager.wallet, address)
|
||||
}
|
||||
|
||||
// named address validation
|
||||
if (address.length in NEAR_MIN_ADDRESS_LENGTH until NEAR_IMPLICIT_ADDRESS_LENGTH &&
|
||||
nearAddressRegex.matches(address)
|
||||
) {
|
||||
val result = (walletManager as? NearWalletManager)?.getAccount(address)
|
||||
return if (result is Result.Success && result.data is NearAccount.Full) {
|
||||
null
|
||||
} else {
|
||||
AddressVerifyAction.Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN
|
||||
}
|
||||
}
|
||||
|
||||
return AddressVerifyAction.Error.ADDRESS_INVALID_OR_UNSUPPORTED_BY_BLOCKCHAIN
|
||||
}
|
||||
|
||||
private fun Blockchain.isNear(): Boolean {
|
||||
return this == Blockchain.Near || this == Blockchain.NearTestnet
|
||||
}
|
||||
|
||||
private fun validateAddress(wallet: Wallet, address: String): AddressVerifyAction.Error? {
|
||||
|
|
@ -47,6 +62,9 @@ internal class AddressValidator {
|
|||
}
|
||||
|
||||
companion object {
|
||||
private const val NEAR_MIN_ADDRESS_LENGTH = 2
|
||||
private const val NEAR_IMPLICIT_ADDRESS_LENGTH = 64
|
||||
private val hexRegex = Regex("^[0-9a-f]+$")
|
||||
private val nearAddressRegex = Regex("^(([a-z\\d]+[\\-_])*[a-z\\d]+\\.)*([a-z\\d]+[\\-_])*[a-z\\d]+\$")
|
||||
}
|
||||
}
|
||||
|
|
@ -221,6 +221,4 @@ private val excludedBlockchains = listOf(
|
|||
Blockchain.Ducatus,
|
||||
Blockchain.Telos,
|
||||
Blockchain.TelosTestnet,
|
||||
Blockchain.Near,
|
||||
Blockchain.NearTestnet,
|
||||
)
|
||||
|
|
@ -81,7 +81,7 @@ spr-client = "3.6.2"
|
|||
# endregion Other libraries
|
||||
|
||||
# region Tangem
|
||||
tangemBlockchainSdk = "release-app_5.0-374"
|
||||
tangemBlockchainSdk = "release-app_5.0-378"
|
||||
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
|
||||
tangemCardSdk = "release-app_5.0-309"
|
||||
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue