/// <summary> /// Checks if the address is valid once the text is changed. /// </summary> private void CheckAddress() { string address = addressField.Text.ToLower(); bool invalidEthereumAddress = !AddressUtils.IsValidEthereumAddress(address); bool isRestrictedAddress = restrictedAddressManager.IsRestrictedAddress(address); addressField.Error = invalidEthereumAddress || isRestrictedAddress; if (invalidEthereumAddress) { addressField.errorMessage.text = "Invalid address"; } else if (isRestrictedAddress) { addressField.errorMessage.text = "Restricted address"; } if (!addressField.Error) { CheckIfSavedContact(address); } else { contactName.text = string.Empty; } }
/// <summary> /// Checks to see if the text is a valid ethereum address /// </summary> /// <param name="address"> The current string in the address input field </param> private void AddressChanged(string address) { string updatedAddress = addressInputField.Text.ToLower(); bool realEthereumAddress = AddressUtils.IsValidEthereumAddress(updatedAddress); bool overridingOtherContactAddresses = contactsManager.ContactList.Contains(updatedAddress) && (!AddingContact ? updatedAddress != PreviousAddress : true); bool isRestrictedAddress = restrictedAddressManager.IsRestrictedAddress(updatedAddress); addressInputField.Error = !realEthereumAddress || overridingOtherContactAddresses || isRestrictedAddress; if (!realEthereumAddress) { addressInputField.errorMessage.text = "Invalid address"; } else if (overridingOtherContactAddresses) { addressInputField.errorMessage.text = "Address in use"; } else if (isRestrictedAddress) { addressInputField.errorMessage.text = "Restricted address"; } SetMainButtonInteractable(); }
/// <summary> /// Method called every time the text in the input field changed. /// Sets the button to interactable if the text is a valid ethereum address. /// </summary> private void OnAddressChanged() { isInvalidAddress = !AddressUtils.IsValidEthereumAddress(addressField.Text); if (isInvalidAddress) { CheckInvalidAddress(); } else { CheckValidAddress(); } }