Commit fbd59915 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

UI: link a new device

Do not ask for password if account does not have one.

Change-Id: I2d52933609d09bdff953615d5f90a7b753f5e8b8
parent 6be74d0d
......@@ -68,7 +68,8 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB
let alert = UIAlertController(title: pin,
message: self.viewModel.explanationMessage,
preferredStyle: .alert)
let action = UIAlertAction(title: L10n.Global.ok, style: .default) { _ in
let action = UIAlertAction(title: L10n.Global.ok,
style: .default) { [unowned self] _ in
self.dismiss(animated: true, completion: nil)
}
alert.addAction(action)
......@@ -79,22 +80,31 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB
let alert = UIAlertController(title: self.viewModel.linkDeviceTitleTitle,
message: nil,
preferredStyle: .alert)
let actionCancel = UIAlertAction(title: L10n.Actions.cancelAction, style: .cancel) { _ in
let actionCancel =
UIAlertAction(title: L10n.Actions.cancelAction,
style: .cancel) { [unowned self] _ in
self.dismiss(animated: true, completion: nil)
}
let actionLink = UIAlertAction(title: L10n.Global.ok, style: .default) { _ in
let actionLink =
UIAlertAction(title: L10n.Global.ok,
style: .default) {[unowned self] _ in
if !self.viewModel.hasPassord {
self.viewModel.linkDevice(with: "")
return
}
if let textFields = alert.textFields {
self.viewModel.linkDevice(with: textFields[0].text)
}
alert.dismiss(animated: false, completion: nil)
}
alert.addAction(actionCancel)
alert.addAction(actionLink)
if self.viewModel.hasPassord {
alert.addTextField { (textField) in
textField.isSecureTextEntry = true
textField.placeholder = L10n.LinkToAccount.passwordLabel
}
}
self.present(alert, animated: true, completion: nil)
}
......@@ -102,7 +112,8 @@ class LinkNewDeviceViewController: UIViewController, StoryboardBased, ViewModelB
let alert = UIAlertController(title: Error,
message: error,
preferredStyle: .alert)
let action = UIAlertAction(title: L10n.Global.ok, style: .cancel) { _ in
let action = UIAlertAction(title: L10n.Global.ok,
style: .cancel) {[unowned self] _ in
self.dismiss(animated: true, completion: nil)
}
alert.addAction(action)
......
......@@ -84,6 +84,11 @@ class LinkNewDeviceViewModel: ViewModel, Stateable {
return self.generatingState.asObservable()
}()
lazy var hasPassord: Bool = {
guard let currentAccount = self.accountService.currentAccount else {return true}
return AccountModelHelper(withAccount: currentAccount).havePassword
}()
let accountService: AccountsService
let disposeBag = DisposeBag()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment