From 2ab17518cff4f49f068b1b7979dff15aab77de1a Mon Sep 17 00:00:00 2001 From: Ivan Grachyov Date: Sun, 13 Jun 2021 07:12:39 +0300 Subject: [PATCH] Show error screen on failed connection attempt --- Encrypted Ink/Agent.swift | 18 +++++++++++++----- .../Screens/ErrorViewController.swift | 12 +++++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Encrypted Ink/Agent.swift b/Encrypted Ink/Agent.swift index 57441733..e3fdbe75 100644 --- a/Encrypted Ink/Agent.swift +++ b/Encrypted Ink/Agent.swift @@ -46,11 +46,19 @@ class Agent { } } - func connectWalletWithLink(_ link: String, account: Account) { - WalletConnect.shared.connect(link: link, address: account.address) { connected in - Window.closeAll() - Window.activateSafari() - // TODO: show error if failed to connect + func showErrorMessage(_ message: String) { + let windowController = Window.showNew() + windowController.contentViewController = ErrorViewController.withMessage(message) + } + + private func connectWalletWithLink(_ link: String, account: Account) { + WalletConnect.shared.connect(link: link, address: account.address) { [weak self] connected in + if connected { + Window.closeAll() + Window.activateSafari() + } else { + self?.showErrorMessage("Failed to connect") + } } let windowController = Window.showNew() diff --git a/Encrypted Ink/Screens/ErrorViewController.swift b/Encrypted Ink/Screens/ErrorViewController.swift index 38eed22a..0a150ba9 100644 --- a/Encrypted Ink/Screens/ErrorViewController.swift +++ b/Encrypted Ink/Screens/ErrorViewController.swift @@ -4,14 +4,24 @@ import Cocoa class ErrorViewController: NSViewController { + static func withMessage(_ message: String) -> ErrorViewController { + let new = instantiate(ErrorViewController.self) + new.message = message + return new + } + + private var message = "" + @IBOutlet weak var titleLabel: NSTextField! override func viewDidLoad() { super.viewDidLoad() + // TODO: show message text } @IBAction func actionButtonTapped(_ sender: Any) { - + Window.closeAll() + Window.activateSafari() } }