// // SetPrivateKeyViewController.swift // Malinka // // Created by Nut.Tech on 29.07.2022. // import UIKit import eosswift final class SetPrivateKeyViewController: UIViewController { @IBOutlet weak var warningView: CommonViewWarning! @IBOutlet var headerTitleLabel: UILabel! @IBOutlet private weak var submitBtn: CommonButtonAction! private let accountService = AccountOnboarding.Service.CreateAccount() private let iapService = AccountOnboarding.Service.IAP.shared @IBOutlet var signalView: UIView! @IBOutlet var checkboxButton: UIButton! @IBOutlet private weak var usernameView: CommonViewCopy! @IBOutlet private weak var privateKeyView: CommonViewCopy! var showCreateManual: Bool! var walletService: KeysWalletService! // MARK: - Init // MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() title = L10n.Account.Onboarding.freeTitle checkboxButton.setImage(Asset.checkboxOff.image, for: .normal) usernameView.text = self.walletService.walletName privateKeyView.text = self.walletService.walletPrivateKey warningView.makeCritical() // submitBtn.lzTitle = L10n.Common.Button.pay(iapService.products.first?.localizedPrice() ?? "") submitBtn.lzTitle = L10n.Account.Onboarding.Username.create submitBtn.isEnabled = false if navigationController != nil { navigationItem.leftBarButtonItem = .pop(self) navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default) navigationController?.navigationBar.shadowImage = UIImage() navigationController?.navigationBar.isTranslucent = true } } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if Accounts().current != nil, navigationController == nil { self.dismiss(animated: false) } } @IBAction private func onSubmit(_ : AnyObject?) { if checkboxButton.image(for: .normal) == Asset.checkboxOff.image { UIView.animate(withDuration: 0.3, animations: { self.signalView.alpha = 1 }) DispatchQueue.main.async { UIView.animate(withDuration: 0.3, animations: { self.signalView.alpha = 0 }) } return } //let privateKey = self.privateKey //let publicKey = privateKey.publicKey Loader.show(in: self) // TODO: send wallet registration request Loader.hide(in: self) self.showErrorPopup() } func repeatPurchase(publicKey: EOSPublicKey, privateKey: EOSPrivateKey) { // TODO: repeat wallet registration request (if needed) Loader.hide(in: self) self.showErrorPopup() } @IBAction func onGenerateKeyClicked(_ sender: Any) { // swiftlint:disable force_try self.walletService.generateKey() privateKeyView.text = self.walletService.walletPrivateKey } @IBAction func onUseOwnKeyClicked(_ sender: Any) { let view = AccountOnboardingAddPrivateKey() view.onSubmit = { key in self.walletService.update(key: key) self.privateKeyView.text = self.walletService.walletPrivateKey Popup.hide() Popup.show(title: L10n.Account.Onboarding.Keys.Use.Own.added, views: [ .field(title: L10n.Account.Onboarding.Username.accountNameTitle, text: self.walletService.walletName), .field(title: L10n.Account.Onboarding.Keys.Use.Own.privateKeyAdded, text: key.privateKey) ], submit: L10n.Common.Button.continue, in: self) } Popup.show(content: CommonViewControllerViewPopUp( title: L10n.Account.Onboarding.Enter.Private.key, description: L10n.Account.Onboarding.Keys.Use.Own.description, view: view )) } @IBAction func onCheckbox(_ sender: Any) { signalView.alpha = 0 if checkboxButton.image(for: .normal) == Asset.checkboxOff.image { checkboxButton.setImage(Asset.checkboxOn.image, for: .normal) self.submitBtn.isEnabled = true } else { checkboxButton.setImage(Asset.checkboxOff.image, for: .normal) self.submitBtn.isEnabled = false } } @IBAction func haveWalletPrssed(_: AnyObject?) { let ctrl = UINavigationController(rootViewController: StoryboardScene.Account.manual.instantiate()) self.navigationController?.pushViewController(ctrl, animated: true) } func showErrorPopup() { let views: [UIView] = [ .field(text: L10n.Account.Onboarding.ErrorAlert.title, textStyle: "regular_16"), .field(text: L10n.Account.Onboarding.ErrorAlert.subtitle) ] Popup.show(title: L10n.Account.Onboarding.ErrorAlert.header, views: views, submit: L10n.Common.Button.continue, submitStyle: .primary, in: self) { ctrl in ctrl.dismiss(animated: true, completion: nil) } } }