|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
|
|
import UIKit |
|
|
|
|
import Eureka |
|
|
|
|
import OnePasswordExtension |
|
|
|
|
|
|
|
|
|
protocol ImportWalletViewControllerDelegate: class { |
|
|
|
|
func didImportAccount(account: Account, in viewController: ImportWalletViewController) |
|
|
|
@ -17,6 +18,14 @@ class ImportWalletViewController: FormViewController { |
|
|
|
|
static let password = "password" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var keystoreRow: TextAreaRow? { |
|
|
|
|
return form.rowBy(tag: Values.keystore) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var passwordRow: TextFloatLabelRow? { |
|
|
|
|
return form.rowBy(tag: Values.password) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
weak var delegate: ImportWalletViewControllerDelegate? |
|
|
|
|
|
|
|
|
|
override func viewDidLoad() { |
|
|
|
@ -24,6 +33,15 @@ class ImportWalletViewController: FormViewController { |
|
|
|
|
|
|
|
|
|
title = viewModel.title |
|
|
|
|
|
|
|
|
|
if OnePasswordExtension.shared().isAppExtensionAvailable() { |
|
|
|
|
self.navigationItem.rightBarButtonItem = UIBarButtonItem( |
|
|
|
|
image: R.image.onepasswordButton(), |
|
|
|
|
style: .done, |
|
|
|
|
target: self, |
|
|
|
|
action: #selector(onePasswordImport) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
form = Section() |
|
|
|
|
|
|
|
|
|
<<< AppFormAppearance.textArea(tag: Values.keystore) { |
|
|
|
@ -57,9 +75,6 @@ class ImportWalletViewController: FormViewController { |
|
|
|
|
|
|
|
|
|
func importWallet() { |
|
|
|
|
|
|
|
|
|
let keystoreRow: TextAreaRow? = form.rowBy(tag: Values.keystore) |
|
|
|
|
let passwordRow: TextFloatLabelRow? = form.rowBy(tag: Values.password) |
|
|
|
|
|
|
|
|
|
let input = keystoreRow?.value ?? "" |
|
|
|
|
let password = passwordRow?.value ?? "" |
|
|
|
|
|
|
|
|
@ -71,4 +86,31 @@ class ImportWalletViewController: FormViewController { |
|
|
|
|
displayError(error: error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func onePasswordImport() { |
|
|
|
|
|
|
|
|
|
OnePasswordExtension().findLogin( |
|
|
|
|
forURLString: OnePasswordConfig.url, |
|
|
|
|
for: self, |
|
|
|
|
sender: nil |
|
|
|
|
) { [weak self] results, error in |
|
|
|
|
guard let `self` = self else { return } |
|
|
|
|
if let error = error { |
|
|
|
|
return self.displayError(error: error) |
|
|
|
|
} |
|
|
|
|
guard let password = results?[AppExtensionPasswordKey] as? String else { return } |
|
|
|
|
|
|
|
|
|
let result = OnePasswordConverter.fromPassword(password: password) |
|
|
|
|
|
|
|
|
|
switch result { |
|
|
|
|
case .success(let password, let keystore): |
|
|
|
|
self.keystoreRow?.value = keystore |
|
|
|
|
self.keystoreRow?.reload() |
|
|
|
|
self.passwordRow?.value = password |
|
|
|
|
self.passwordRow?.reload() |
|
|
|
|
case .failure(let error): |
|
|
|
|
self.displayError(error: error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|