diff --git a/MoppApp/MoppApp/LocalizationKeys.swift b/MoppApp/MoppApp/LocalizationKeys.swift index e049054d7..d890cfc6e 100644 --- a/MoppApp/MoppApp/LocalizationKeys.swift +++ b/MoppApp/MoppApp/LocalizationKeys.swift @@ -169,6 +169,8 @@ enum LocKey : String case nfcTitle = "nfc-title" case nfcCANTitle = "nfc-can-title" case nfcDeviceNoSupport = "nfc-device-no-support" + case nfcCanLocation = "nfc-can-location" + case nfcIncorrectLength = "nfc-incorrect-length" case nfcHoldNear = "nfc-hold-near" case nfcMultipleCards = "nfc-multiple-cards" case nfcInvalidTag = "nfc-invalid-tag" diff --git a/MoppApp/MoppApp/NFCEditViewController.swift b/MoppApp/MoppApp/NFCEditViewController.swift index 1c0973b8a..8902dda47 100644 --- a/MoppApp/MoppApp/NFCEditViewController.swift +++ b/MoppApp/MoppApp/NFCEditViewController.swift @@ -35,7 +35,7 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning { @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var canTextLabel: UILabel! @IBOutlet weak var pinTextLabel: UILabel! - @IBOutlet weak var canTextErrorLabel: UILabel! + @IBOutlet weak var canTextInfoLabel: ScaledLabel! @IBOutlet weak var pinTextErrorLabel: UILabel! @IBOutlet weak var cancelButton: MoppButton! @IBOutlet weak var signButton: MoppButton! @@ -56,8 +56,8 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning { pinTextLabel.text = L(.pin2TextfieldLabel) pinTextLabel.isHidden = notAvailable - canTextErrorLabel.text = "" - canTextErrorLabel.isHidden = true + setCANDefaultText() + pinTextErrorLabel.text = "" pinTextErrorLabel.isHidden = true @@ -84,6 +84,20 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning { tapGR.addTarget(self, action: #selector(cancelAction)) view.addGestureRecognizer(tapGR) } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + if let canNumber = canTextField.text { + if !canNumber.isEmpty && canNumber.count != 6 { + setCANErrorText() + } else { + setCANDefaultText() + } + } else { + setCANDefaultText() + } + } @objc func dismissKeyboard(_ notification: NSNotification) { pinTextField.resignFirstResponder() @@ -196,6 +210,18 @@ class NFCEditViewController : MoppViewController, TokenFlowSigning { override func keyboardWillHide(notification: NSNotification) { hideKeyboard(scrollView: scrollView) } + + func setCANDefaultText() { + canTextInfoLabel.text = L(.nfcCanLocation) + canTextInfoLabel.isHidden = false + canTextInfoLabel.textColor = UIColor.moppText + } + + func setCANErrorText() { + canTextInfoLabel.text = L(.nfcIncorrectLength) + canTextInfoLabel.isHidden = false + canTextInfoLabel.textColor = UIColor.moppError + } } extension NFCEditViewController : UITextFieldDelegate { @@ -226,12 +252,17 @@ extension NFCEditViewController : UITextFieldDelegate { func textFieldDidEndEditing(_ textField: UITextField) { if textField.accessibilityIdentifier == "nfcCanField" { if let can = textField.text { + if !can.isEmpty && can.count != 6 { + setCANErrorText() + } else { + setCANDefaultText() + } do { let symKey = try EncryptedDataUtil.getSymmetricKey(fileName: NFCEditViewController.nfcCANKeyFilename) if let encryptedKey = EncryptedDataUtil.encryptSecret(can, with: symKey) { _ = KeychainUtil.save(key: NFCEditViewController.nfcCANKey, info: encryptedKey, withPasscodeSetOnly: true) } else { - printLog("Encryption failed for 'can' string") + printLog("Encryption failed for 'CAN' string") } } catch { do { @@ -249,8 +280,7 @@ extension NFCEditViewController : UITextFieldDelegate { } } else { KeychainUtil.remove(key: NFCEditViewController.nfcCANKey) - canTextErrorLabel.text = "" - canTextErrorLabel.isHidden = true + setCANDefaultText() removeViewBorder(view: textField) UIAccessibility.post(notification: .layoutChanged, argument: canTextField) } diff --git a/MoppApp/MoppApp/TokenFlow.storyboard b/MoppApp/MoppApp/TokenFlow.storyboard index ca025fa8c..7b45bda3f 100644 --- a/MoppApp/MoppApp/TokenFlow.storyboard +++ b/MoppApp/MoppApp/TokenFlow.storyboard @@ -3,7 +3,7 @@ - + @@ -1418,7 +1418,7 @@ - +