From 1594412b1395a182ce600a967252c77e9094ca7b Mon Sep 17 00:00:00 2001 From: Ivan Grachyov Date: Sat, 17 Jul 2021 19:05:59 +0300 Subject: [PATCH] Add more menu content --- Encrypted Ink/Agent.swift | 9 +++++++ .../Screens/AccountsListViewController.swift | 24 +++++++++++-------- Encrypted Ink/Views/Alert.swift | 8 +++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Encrypted Ink/Agent.swift b/Encrypted Ink/Agent.swift index 392e9c80..377e6290 100644 --- a/Encrypted Ink/Agent.swift +++ b/Encrypted Ink/Agent.swift @@ -113,12 +113,14 @@ class Agent: NSObject { let menu = NSMenu(title: "Encrypted Ink") let showItem = NSMenuItem(title: "Show Encrypted Ink", action: #selector(didSelectShowMenuItem), keyEquivalent: "") + let howToItem = NSMenuItem(title: "How to WalletConnect?", action: #selector(showInstructionsAlert), keyEquivalent: "") let mailItem = NSMenuItem(title: "Drop us a line…", action: #selector(didSelectMailMenuItem), keyEquivalent: "") let githubItem = NSMenuItem(title: "View on GitHub…", action: #selector(didSelectGitHubMenuItem), keyEquivalent: "") let quitItem = NSMenuItem(title: "Quit", action: #selector(didSelectQuitMenuItem), keyEquivalent: "q") showItem.attributedTitle = NSAttributedString(string: "👀 Show Encrypted Ink", attributes: [.font: NSFont.systemFont(ofSize: 21, weight: .bold)]) showItem.target = self + howToItem.target = self githubItem.target = self mailItem.target = self quitItem.target = self @@ -126,6 +128,8 @@ class Agent: NSObject { menu.delegate = self menu.addItem(showItem) menu.addItem(NSMenuItem.separator()) + menu.addItem(howToItem) + menu.addItem(NSMenuItem.separator()) menu.addItem(githubItem) menu.addItem(mailItem) menu.addItem(NSMenuItem.separator()) @@ -155,6 +159,11 @@ class Agent: NSObject { } } + @objc private func showInstructionsAlert() { + Window.activateWindow(nil) + Alert.showWalletConnectInstructions() + } + @objc private func didSelectMailMenuItem() { if let url = URL(string: "mailto:support@encrypted.ink") { NSWorkspace.shared.open(url) diff --git a/Encrypted Ink/Screens/AccountsListViewController.swift b/Encrypted Ink/Screens/AccountsListViewController.swift index 053bf7f9..27e549fa 100644 --- a/Encrypted Ink/Screens/AccountsListViewController.swift +++ b/Encrypted Ink/Screens/AccountsListViewController.swift @@ -48,9 +48,12 @@ class AccountsListViewController: NSViewController { let menu = NSMenu() menu.delegate = self menu.addItem(NSMenuItem(title: "Copy address", action: #selector(didClickCopyAddress(_:)), keyEquivalent: "")) + menu.addItem(NSMenuItem(title: "View on Zerion", action: #selector(didClickViewOnZerion(_:)), keyEquivalent: "")) menu.addItem(.separator()) menu.addItem(NSMenuItem(title: "Show private key", action: #selector(didClickExportAccount(_:)), keyEquivalent: "")) // TODO: show different texts for secret words export menu.addItem(NSMenuItem(title: "Remove account", action: #selector(didClickRemoveAccount(_:)), keyEquivalent: "")) + menu.addItem(.separator()) + menu.addItem(NSMenuItem(title: "How to WalletConnect?", action: #selector(showInstructionsAlert), keyEquivalent: "")) tableView.menu = menu } @@ -104,6 +107,15 @@ class AccountsListViewController: NSViewController { view.window?.contentViewController = importViewController } + @objc private func didClickViewOnZerion(_ sender: AnyObject) { + let row = tableView.deselectedRow + guard row >= 0 else { return } + let address = accounts[row].address + if let url = URL(string: "https://app.zerion.io/\(address)/overview") { + NSWorkspace.shared.open(url) + } + } + @objc private func didClickCopyAddress(_ sender: AnyObject) { let row = tableView.deselectedRow guard row >= 0 else { return } @@ -160,16 +172,8 @@ class AccountsListViewController: NSViewController { } } - private func showInstructionsAlert() { - let alert = Alert() - alert.messageText = "How to start?" - alert.informativeText = "1. Open your favourite dapp.\n\n2. Press “Copy to clipboard”\nunder WalletConnect QR code.\n\n3. Launch Encrypted Ink." - alert.alertStyle = .informational - alert.addButton(withTitle: "OK") - alert.addButton(withTitle: "Open Zerion") - if alert.runModal() != .alertFirstButtonReturn, let url = URL(string: "https://app.zerion.io") { - NSWorkspace.shared.open(url) - } + @objc private func showInstructionsAlert() { + Alert.showWalletConnectInstructions() } private func removeAccountAtIndex(_ index: Int) { diff --git a/Encrypted Ink/Views/Alert.swift b/Encrypted Ink/Views/Alert.swift index 7f60fb5c..bb6f512c 100644 --- a/Encrypted Ink/Views/Alert.swift +++ b/Encrypted Ink/Views/Alert.swift @@ -12,4 +12,12 @@ class Alert: NSAlert { return super.runModal() } + static func showWalletConnectInstructions() { + let alert = Alert() + alert.messageText = "1 — Open dapp website\n\n2 — Click “Copy to clipboard”\nunder WalletConnect QR code\n\n3 — Open Encrypted Ink" + alert.alertStyle = .informational + alert.addButton(withTitle: "OK") + _ = alert.runModal() + } + }