Skip to content

Commit

Permalink
On delete account screen, add account number validation during input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson authored and pinkisemils committed Sep 11, 2023
1 parent ba70363 commit 1c9a3b0
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -334,7 +343,7 @@ class AccountDeletionContentView: UIView {
} else {
activityIndicator.stopAnimating()
}
deleteButton.isEnabled = isDeleteButtonEnabled && isAccountNumberLengthSatisfied
deleteButton.isEnabled = isDeleteButtonEnabled && isInputValid
statusLabel.text = text
statusLabel.textColor = textColor
}
Expand Down

0 comments on commit 1c9a3b0

Please sign in to comment.