-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On delete account screen, add account number validation during input #5069
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -253,9 +253,18 @@ class AccountDeletionContentView: UIView { | |||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
private var isAccountNumberLengthSatisfied: Bool { | ||||||||||||||||||
let length = accountTextField.text?.count ?? 0 | ||||||||||||||||||
return length == 4 | ||||||||||||||||||
private var isInputValid: Bool { | ||||||||||||||||||
guard let input = accountTextField.text, | ||||||||||||||||||
let accountNumber = viewModel?.accountNumber, | ||||||||||||||||||
!accountNumber.isEmpty | ||||||||||||||||||
else { | ||||||||||||||||||
return false | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
let inputLengthIsValid = input.count == 4 | ||||||||||||||||||
let inputMatchesAccountNumber = accountNumber.suffix(4) == input | ||||||||||||||||||
|
||||||||||||||||||
return inputLengthIsValid && inputMatchesAccountNumber | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
weak var delegate: AccountDeletionContentViewDelegate? | ||||||||||||||||||
|
@@ -334,7 +343,7 @@ class AccountDeletionContentView: UIView { | |||||||||||||||||
} else { | ||||||||||||||||||
activityIndicator.stopAnimating() | ||||||||||||||||||
} | ||||||||||||||||||
deleteButton.isEnabled = isDeleteButtonEnabled && isAccountNumberLengthSatisfied | ||||||||||||||||||
deleteButton.isEnabled = isDeleteButtonEnabled && isInputValid | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should Currently it still says the button should be enabled upon failure: mullvadvpn-app/ios/MullvadVPN/View controllers/AccountDeletion/AccountDeletionContentView.swift Lines 221 to 228 in 9cc7a43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to disable the button when loading (to avoid interaction while trying to delete the account), otherwise enabled. |
||||||||||||||||||
statusLabel.text = text | ||||||||||||||||||
statusLabel.textColor = textColor | ||||||||||||||||||
} | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
inputLengthIsValid
really needed?accountNumber.suffix(4) == input
seems to imply thatinput
is indeed 4 characters long when it matchesaccountNumber.suffix(4)
... ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The param in .suffix() specifies a max length, meaning the result could be less than that. In practice the account number - if present - should never be less than 4 digits, so for most (or perhaps all realistic) cases it should work as intended.
Theoretically though, accountNumber.suffix(4) could for some reason return something less than 4 digits, and if so the condition would be incorrect (eg. 3 digit account number matching 3 digit input). It's a safeguard, but perhaps it's not really necessary...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep this is what I assumed that'shy. But okay 👍 sorry for the bother!