2021-11-30 15:56:00 +03:00
|
|
|
// Copyright © 2021 Tokenary. All rights reserved.
|
2021-06-12 19:16:23 +03:00
|
|
|
|
|
|
|
import Cocoa
|
2021-06-13 13:13:47 +03:00
|
|
|
import WalletConnect
|
2021-11-29 22:24:05 +03:00
|
|
|
import SafariServices
|
2021-06-13 15:30:19 +03:00
|
|
|
import LocalAuthentication
|
2022-05-07 23:10:08 +03:00
|
|
|
import WalletCore
|
2021-06-12 19:16:23 +03:00
|
|
|
|
2021-06-19 14:07:57 +03:00
|
|
|
class Agent: NSObject {
|
2021-11-22 13:11:34 +03:00
|
|
|
|
|
|
|
enum ExternalRequest {
|
|
|
|
case wcSession(WCSession)
|
|
|
|
case safari(SafariRequest)
|
|
|
|
}
|
|
|
|
|
2021-06-13 06:30:20 +03:00
|
|
|
static let shared = Agent()
|
2021-06-12 19:16:23 +03:00
|
|
|
|
2021-11-22 13:11:34 +03:00
|
|
|
private let walletConnect = WalletConnect.shared
|
|
|
|
|
2021-06-19 14:07:57 +03:00
|
|
|
private override init() { super.init() }
|
2021-06-13 13:13:47 +03:00
|
|
|
private var statusBarItem: NSStatusItem!
|
2021-11-30 20:46:02 +03:00
|
|
|
private lazy var hasPassword = Keychain.shared.password != nil
|
2021-06-19 19:22:18 +03:00
|
|
|
private var didEnterPasswordOnStart = false
|
2021-07-30 02:36:24 +03:00
|
|
|
|
|
|
|
private var didStartInitialLAEvaluation = false
|
|
|
|
private var didCompleteInitialLAEvaluation = false
|
2021-11-22 13:11:34 +03:00
|
|
|
private var initialExternalRequest: ExternalRequest?
|
2021-07-30 02:36:24 +03:00
|
|
|
|
2021-06-23 22:15:56 +03:00
|
|
|
var statusBarButtonIsBlocked = false
|
2021-06-13 06:30:20 +03:00
|
|
|
|
2021-06-12 19:16:23 +03:00
|
|
|
func start() {
|
2021-06-29 21:25:23 +03:00
|
|
|
checkPasteboardAndOpen()
|
2021-06-28 16:20:08 +03:00
|
|
|
setupStatusBarItem()
|
2021-06-13 05:45:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func reopen() {
|
2021-06-29 21:25:23 +03:00
|
|
|
checkPasteboardAndOpen()
|
2021-06-13 05:45:54 +03:00
|
|
|
}
|
|
|
|
|
2021-11-22 13:11:34 +03:00
|
|
|
func showInitialScreen(externalRequest: ExternalRequest?) {
|
2021-07-30 02:36:24 +03:00
|
|
|
let isEvaluatingInitialLA = didStartInitialLAEvaluation && !didCompleteInitialLAEvaluation
|
|
|
|
guard !isEvaluatingInitialLA else {
|
2021-11-22 13:11:34 +03:00
|
|
|
if externalRequest != nil {
|
|
|
|
initialExternalRequest = externalRequest
|
2021-07-30 02:36:24 +03:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-19 00:38:05 +03:00
|
|
|
guard hasPassword else {
|
|
|
|
let welcomeViewController = WelcomeViewController.new { [weak self] createdPassword in
|
|
|
|
guard createdPassword else { return }
|
2021-06-19 19:22:18 +03:00
|
|
|
self?.didEnterPasswordOnStart = true
|
2021-07-30 02:36:24 +03:00
|
|
|
self?.didCompleteInitialLAEvaluation = true
|
2021-06-19 00:38:05 +03:00
|
|
|
self?.hasPassword = true
|
2021-11-22 13:11:34 +03:00
|
|
|
self?.showInitialScreen(externalRequest: externalRequest)
|
2021-06-19 00:38:05 +03:00
|
|
|
}
|
2022-08-01 16:39:07 +03:00
|
|
|
let windowController = Window.showNew(closeOthers: true)
|
2021-06-19 00:38:05 +03:00
|
|
|
windowController.contentViewController = welcomeViewController
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-19 19:22:18 +03:00
|
|
|
guard didEnterPasswordOnStart else {
|
2022-08-01 17:09:41 +03:00
|
|
|
askAuthentication(on: nil, browser: nil, onStart: true, reason: .start) { [weak self] success in
|
2021-06-19 19:22:18 +03:00
|
|
|
if success {
|
|
|
|
self?.didEnterPasswordOnStart = true
|
2021-11-22 13:11:34 +03:00
|
|
|
self?.showInitialScreen(externalRequest: externalRequest)
|
|
|
|
self?.walletConnect.restartSessions()
|
2021-06-19 19:22:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-11-22 13:11:34 +03:00
|
|
|
let request = externalRequest ?? initialExternalRequest
|
|
|
|
initialExternalRequest = nil
|
|
|
|
|
|
|
|
if case let .safari(request) = request {
|
|
|
|
processSafariRequest(request)
|
2021-07-30 02:36:24 +03:00
|
|
|
} else {
|
2021-11-22 13:11:34 +03:00
|
|
|
let accountsList = instantiate(AccountsListViewController.self)
|
|
|
|
|
2022-08-15 15:39:48 +03:00
|
|
|
if case let .wcSession(session) = request, let completion = onSelectedWallet(session: session) {
|
2022-08-19 13:15:34 +03:00
|
|
|
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: nil,
|
|
|
|
coinType: .ethereum,
|
|
|
|
selectedAccounts: Set(),
|
|
|
|
initiallyConnectedProviders: Set(),
|
|
|
|
completion: completion)
|
2021-11-22 13:11:34 +03:00
|
|
|
}
|
|
|
|
|
2022-08-15 15:39:48 +03:00
|
|
|
let windowController = Window.showNew(closeOthers: accountsList.accountSelectionConfiguration == nil)
|
2021-11-22 13:11:34 +03:00
|
|
|
windowController.contentViewController = accountsList
|
2021-07-30 02:36:24 +03:00
|
|
|
}
|
2021-06-12 19:16:23 +03:00
|
|
|
}
|
|
|
|
|
2022-08-01 17:09:41 +03:00
|
|
|
func showApprove(windowController: NSWindowController, browser: Browser?, transaction: Transaction, chain: EthereumChain, peerMeta: PeerMeta?, completion: @escaping (Transaction?) -> Void) {
|
2022-08-01 16:39:07 +03:00
|
|
|
let window = windowController.window
|
|
|
|
let approveViewController = ApproveTransactionViewController.with(transaction: transaction, chain: chain, peerMeta: peerMeta) { [weak self, weak window] transaction in
|
2021-06-28 16:15:53 +03:00
|
|
|
if transaction != nil {
|
2022-08-01 17:09:41 +03:00
|
|
|
self?.askAuthentication(on: window, browser: browser, onStart: false, reason: .sendTransaction) { success in
|
2021-06-28 16:15:53 +03:00
|
|
|
completion(success ? transaction : nil)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
completion(nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
windowController.contentViewController = approveViewController
|
|
|
|
}
|
|
|
|
|
2022-08-01 17:09:41 +03:00
|
|
|
func showApprove(windowController: NSWindowController, browser: Browser?, subject: ApprovalSubject, meta: String, peerMeta: PeerMeta?, completion: @escaping (Bool) -> Void) {
|
2022-08-01 16:39:07 +03:00
|
|
|
let window = windowController.window
|
|
|
|
let approveViewController = ApproveViewController.with(subject: subject, meta: meta, peerMeta: peerMeta) { [weak self, weak window] result in
|
2021-06-13 15:30:19 +03:00
|
|
|
if result {
|
2022-08-01 17:09:41 +03:00
|
|
|
self?.askAuthentication(on: window, getBackTo: window?.contentViewController, browser: browser, onStart: false, reason: subject.asAuthenticationReason) { success in
|
2021-06-19 19:22:18 +03:00
|
|
|
completion(success)
|
2022-08-01 16:39:07 +03:00
|
|
|
(window?.contentViewController as? ApproveViewController)?.enableWaiting()
|
2021-06-19 19:22:18 +03:00
|
|
|
}
|
2021-06-13 15:30:19 +03:00
|
|
|
} else {
|
|
|
|
completion(result)
|
|
|
|
}
|
2021-06-13 09:32:07 +03:00
|
|
|
}
|
|
|
|
windowController.contentViewController = approveViewController
|
|
|
|
}
|
|
|
|
|
2022-08-17 16:18:48 +03:00
|
|
|
func getWalletSelectionCompletionIfShouldSelect() -> ((EthereumChain?, SpecificWalletAccount?) -> Void)? {
|
2021-06-17 23:56:42 +03:00
|
|
|
let session = getSessionFromPasteboard()
|
2021-08-01 19:42:27 +03:00
|
|
|
return onSelectedWallet(session: session)
|
2021-06-17 23:56:42 +03:00
|
|
|
}
|
|
|
|
|
2021-06-19 14:07:57 +03:00
|
|
|
lazy private var statusBarMenu: NSMenu = {
|
2021-11-30 15:56:00 +03:00
|
|
|
let menu = NSMenu(title: Strings.tokenary)
|
2021-06-29 21:21:21 +03:00
|
|
|
|
2021-11-30 15:56:00 +03:00
|
|
|
let showItem = NSMenuItem(title: Strings.showTokenary, action: #selector(didSelectShowMenuItem), keyEquivalent: "")
|
2021-12-09 17:42:45 +03:00
|
|
|
let safariItem = NSMenuItem(title: Strings.enableSafariExtension.withEllipsis, action: #selector(enableSafariExtension), keyEquivalent: "")
|
|
|
|
let mailItem = NSMenuItem(title: Strings.dropUsALine.withEllipsis, action: #selector(didSelectMailMenuItem), keyEquivalent: "")
|
|
|
|
let githubItem = NSMenuItem(title: Strings.viewOnGithub.withEllipsis, action: #selector(didSelectGitHubMenuItem), keyEquivalent: "")
|
|
|
|
let twitterItem = NSMenuItem(title: Strings.viewOnTwitter.withEllipsis, action: #selector(didSelectTwitterMenuItem), keyEquivalent: "")
|
2021-08-29 21:56:32 +03:00
|
|
|
let quitItem = NSMenuItem(title: Strings.quit, action: #selector(didSelectQuitMenuItem), keyEquivalent: "q")
|
2021-11-30 15:56:00 +03:00
|
|
|
showItem.attributedTitle = NSAttributedString(string: "👀 " + Strings.showTokenary, attributes: [.font: NSFont.systemFont(ofSize: 15, weight: .semibold)])
|
2021-06-29 21:21:21 +03:00
|
|
|
|
|
|
|
showItem.target = self
|
2021-11-29 22:24:05 +03:00
|
|
|
safariItem.target = self
|
2021-07-06 19:59:45 +03:00
|
|
|
githubItem.target = self
|
2021-07-30 02:47:14 +03:00
|
|
|
twitterItem.target = self
|
2021-07-06 19:59:45 +03:00
|
|
|
mailItem.target = self
|
2021-06-19 14:07:57 +03:00
|
|
|
quitItem.target = self
|
2021-07-06 19:59:45 +03:00
|
|
|
|
2021-06-19 14:07:57 +03:00
|
|
|
menu.delegate = self
|
2021-06-29 21:21:21 +03:00
|
|
|
menu.addItem(showItem)
|
2021-07-06 19:59:45 +03:00
|
|
|
menu.addItem(NSMenuItem.separator())
|
2021-11-29 22:24:05 +03:00
|
|
|
menu.addItem(safariItem)
|
2021-07-17 19:05:59 +03:00
|
|
|
menu.addItem(NSMenuItem.separator())
|
2021-07-30 02:47:14 +03:00
|
|
|
menu.addItem(twitterItem)
|
2021-07-06 19:59:45 +03:00
|
|
|
menu.addItem(githubItem)
|
|
|
|
menu.addItem(mailItem)
|
|
|
|
menu.addItem(NSMenuItem.separator())
|
2021-06-19 14:07:57 +03:00
|
|
|
menu.addItem(quitItem)
|
|
|
|
return menu
|
|
|
|
}()
|
|
|
|
|
2021-06-23 22:21:23 +03:00
|
|
|
func warnBeforeQuitting(updateStatusBarAfterwards: Bool = false) {
|
2021-06-19 15:08:41 +03:00
|
|
|
Window.activateWindow(nil)
|
2021-06-23 22:15:56 +03:00
|
|
|
let alert = Alert()
|
2021-11-30 15:56:00 +03:00
|
|
|
alert.messageText = Strings.quitTokenary
|
2021-08-29 21:56:32 +03:00
|
|
|
alert.informativeText = Strings.youWontBeAbleToSignRequests
|
2021-06-19 15:08:41 +03:00
|
|
|
alert.alertStyle = .warning
|
2021-08-26 21:17:23 +03:00
|
|
|
alert.addButton(withTitle: Strings.ok)
|
|
|
|
alert.addButton(withTitle: Strings.cancel)
|
2022-08-02 14:28:10 +03:00
|
|
|
|
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
if alert.runModal() == .alertFirstButtonReturn {
|
|
|
|
NSApp.terminate(nil)
|
|
|
|
}
|
|
|
|
if updateStatusBarAfterwards {
|
|
|
|
self?.setupStatusBarItem()
|
|
|
|
}
|
2021-06-23 22:21:23 +03:00
|
|
|
}
|
2021-06-19 14:07:57 +03:00
|
|
|
}
|
|
|
|
|
2021-07-30 02:47:14 +03:00
|
|
|
@objc private func didSelectTwitterMenuItem() {
|
2021-12-09 17:42:45 +03:00
|
|
|
NSWorkspace.shared.open(URL.twitter)
|
2021-07-30 02:47:14 +03:00
|
|
|
}
|
|
|
|
|
2021-07-06 19:59:45 +03:00
|
|
|
@objc private func didSelectGitHubMenuItem() {
|
2021-12-09 17:42:45 +03:00
|
|
|
NSWorkspace.shared.open(URL.github)
|
2021-07-06 19:59:45 +03:00
|
|
|
}
|
|
|
|
|
2021-11-30 21:37:27 +03:00
|
|
|
@objc func enableSafariExtension() {
|
|
|
|
SFSafariApplication.showPreferencesForExtension(withIdentifier: Identifiers.safariExtensionBundle)
|
2021-07-17 19:05:59 +03:00
|
|
|
}
|
|
|
|
|
2021-07-06 19:59:45 +03:00
|
|
|
@objc private func didSelectMailMenuItem() {
|
2021-12-09 17:42:45 +03:00
|
|
|
NSWorkspace.shared.open(URL.email)
|
2021-07-06 19:59:45 +03:00
|
|
|
}
|
|
|
|
|
2021-06-29 21:21:21 +03:00
|
|
|
@objc private func didSelectShowMenuItem() {
|
2021-06-29 21:25:23 +03:00
|
|
|
checkPasteboardAndOpen()
|
2021-06-29 21:21:21 +03:00
|
|
|
}
|
|
|
|
|
2021-06-23 21:28:52 +03:00
|
|
|
@objc private func didSelectQuitMenuItem() {
|
|
|
|
warnBeforeQuitting()
|
|
|
|
}
|
|
|
|
|
2021-06-19 14:07:57 +03:00
|
|
|
func setupStatusBarItem() {
|
|
|
|
let statusBar = NSStatusBar.system
|
|
|
|
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength)
|
2022-05-07 23:10:08 +03:00
|
|
|
statusBarItem.button?.image = Images.statusBarIcon
|
2021-06-19 14:07:57 +03:00
|
|
|
statusBarItem.button?.target = self
|
|
|
|
statusBarItem.button?.action = #selector(statusBarButtonClicked(sender:))
|
|
|
|
statusBarItem.button?.sendAction(on: [.leftMouseUp, .rightMouseUp])
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc private func statusBarButtonClicked(sender: NSStatusBarButton) {
|
2021-06-29 21:21:21 +03:00
|
|
|
guard !statusBarButtonIsBlocked, let event = NSApp.currentEvent, event.type == .rightMouseUp || event.type == .leftMouseUp else { return }
|
2021-06-29 21:25:23 +03:00
|
|
|
|
|
|
|
if let session = getSessionFromPasteboard() {
|
2021-11-22 13:11:34 +03:00
|
|
|
showInitialScreen(externalRequest: .wcSession(session))
|
2021-06-29 21:25:23 +03:00
|
|
|
} else {
|
|
|
|
statusBarItem.menu = statusBarMenu
|
|
|
|
statusBarItem.button?.performClick(nil)
|
|
|
|
}
|
2021-06-19 14:07:57 +03:00
|
|
|
}
|
|
|
|
|
2022-08-17 16:18:48 +03:00
|
|
|
private func onSelectedWallet(session: WCSession?) -> ((EthereumChain?, SpecificWalletAccount?) -> Void)? {
|
2021-06-17 23:11:03 +03:00
|
|
|
guard let session = session else { return nil }
|
2022-08-17 16:18:48 +03:00
|
|
|
return { [weak self] chain, specificWalletAccount in
|
|
|
|
guard let chain = chain, let specificWalletAccount = specificWalletAccount, specificWalletAccount.account.coin == .ethereum else {
|
2022-08-01 16:39:07 +03:00
|
|
|
Window.closeAllAndActivateBrowser(specific: nil)
|
2022-05-07 23:10:08 +03:00
|
|
|
return
|
|
|
|
}
|
2022-08-17 16:18:48 +03:00
|
|
|
self?.connectWallet(session: session, chainId: chain.id, walletId: specificWalletAccount.walletId)
|
2021-06-17 23:11:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func getSessionFromPasteboard() -> WCSession? {
|
2021-06-13 13:13:47 +03:00
|
|
|
let pasteboard = NSPasteboard.general
|
|
|
|
let link = pasteboard.string(forType: .string) ?? ""
|
2021-11-22 13:11:34 +03:00
|
|
|
let session = walletConnect.sessionWithLink(link)
|
2021-06-15 23:52:33 +03:00
|
|
|
if session != nil {
|
|
|
|
pasteboard.clearContents()
|
|
|
|
}
|
2021-06-17 23:11:03 +03:00
|
|
|
return session
|
|
|
|
}
|
|
|
|
|
2021-06-29 21:25:23 +03:00
|
|
|
private func checkPasteboardAndOpen() {
|
2021-11-22 13:11:34 +03:00
|
|
|
let request: ExternalRequest?
|
|
|
|
|
|
|
|
if let session = getSessionFromPasteboard() {
|
|
|
|
request = .wcSession(session)
|
|
|
|
} else {
|
|
|
|
request = .none
|
|
|
|
}
|
|
|
|
|
|
|
|
showInitialScreen(externalRequest: request)
|
2021-06-15 23:52:33 +03:00
|
|
|
}
|
|
|
|
|
2022-08-01 17:09:41 +03:00
|
|
|
func askAuthentication(on: NSWindow?, getBackTo: NSViewController? = nil, browser: Browser?, onStart: Bool, reason: AuthenticationReason, completion: @escaping (Bool) -> Void) {
|
2021-06-13 15:30:19 +03:00
|
|
|
let context = LAContext()
|
2021-06-13 15:39:31 +03:00
|
|
|
var error: NSError?
|
2021-06-19 19:22:18 +03:00
|
|
|
let policy = LAPolicy.deviceOwnerAuthenticationWithBiometrics
|
|
|
|
let canDoLocalAuthentication = context.canEvaluatePolicy(policy, error: &error)
|
2021-06-13 15:39:31 +03:00
|
|
|
|
2021-06-25 00:43:21 +03:00
|
|
|
func showPasswordScreen() {
|
2022-08-01 16:39:07 +03:00
|
|
|
let window = on ?? Window.showNew(closeOthers: onStart).window
|
2021-06-25 00:43:21 +03:00
|
|
|
let passwordViewController = PasswordViewController.with(mode: .enter, reason: reason) { [weak window] success in
|
2021-06-19 19:22:18 +03:00
|
|
|
if let getBackTo = getBackTo {
|
2021-06-25 00:43:21 +03:00
|
|
|
window?.contentViewController = getBackTo
|
2022-08-01 17:09:41 +03:00
|
|
|
} else if let browser = browser {
|
|
|
|
Window.closeWindowAndActivateNext(idToClose: window?.windowNumber, specificBrowser: browser)
|
2021-06-19 19:22:18 +03:00
|
|
|
} else {
|
2022-08-01 17:09:41 +03:00
|
|
|
Window.closeWindow(idToClose: window?.windowNumber)
|
2021-06-19 19:22:18 +03:00
|
|
|
}
|
2021-06-13 15:30:19 +03:00
|
|
|
completion(success)
|
|
|
|
}
|
2021-06-25 00:43:21 +03:00
|
|
|
window?.contentViewController = passwordViewController
|
2021-06-19 19:22:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if canDoLocalAuthentication {
|
2021-08-26 21:17:23 +03:00
|
|
|
context.localizedCancelTitle = Strings.cancel
|
2021-07-30 02:36:24 +03:00
|
|
|
didStartInitialLAEvaluation = true
|
2021-08-01 23:29:56 +03:00
|
|
|
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason.title) { [weak self] success, _ in
|
2021-06-19 19:22:18 +03:00
|
|
|
DispatchQueue.main.async {
|
2021-07-30 02:36:24 +03:00
|
|
|
self?.didCompleteInitialLAEvaluation = true
|
2021-06-25 00:43:21 +03:00
|
|
|
if !success, onStart, self?.didEnterPasswordOnStart == false {
|
|
|
|
showPasswordScreen()
|
2021-06-19 20:15:46 +03:00
|
|
|
}
|
2021-06-19 19:22:18 +03:00
|
|
|
completion(success)
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 00:43:21 +03:00
|
|
|
} else {
|
|
|
|
showPasswordScreen()
|
2021-06-13 15:30:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 15:58:04 +03:00
|
|
|
private func connectWallet(session: WCSession, chainId: Int, walletId: String) {
|
2022-08-01 16:39:07 +03:00
|
|
|
let windowController = Window.showNew(closeOthers: true)
|
2021-07-09 20:13:59 +03:00
|
|
|
let window = windowController.window
|
2021-08-27 23:50:55 +03:00
|
|
|
windowController.contentViewController = WaitingViewController.withReason(Strings.connecting)
|
2021-07-09 20:04:26 +03:00
|
|
|
|
2022-08-17 15:58:04 +03:00
|
|
|
walletConnect.connect(session: session, chainId: chainId, walletId: walletId) { [weak window] _ in
|
2021-07-09 20:13:59 +03:00
|
|
|
if window?.isVisible == true {
|
2022-08-01 16:39:07 +03:00
|
|
|
Window.closeAllAndActivateBrowser(specific: nil)
|
2021-06-13 07:12:39 +03:00
|
|
|
}
|
2021-06-13 06:30:20 +03:00
|
|
|
}
|
|
|
|
}
|
2022-08-01 16:39:07 +03:00
|
|
|
|
2021-11-22 13:11:34 +03:00
|
|
|
private func processSafariRequest(_ safariRequest: SafariRequest) {
|
2022-08-01 16:39:07 +03:00
|
|
|
var windowNumber: Int?
|
2022-02-12 21:30:05 +03:00
|
|
|
let action = DappRequestProcessor.processSafariRequest(safariRequest) {
|
2022-08-01 16:39:07 +03:00
|
|
|
Window.closeWindowAndActivateNext(idToClose: windowNumber, specificBrowser: .safari)
|
2021-12-14 15:26:00 +03:00
|
|
|
}
|
2022-02-12 21:30:05 +03:00
|
|
|
|
|
|
|
switch action {
|
|
|
|
case .none:
|
|
|
|
break
|
2022-08-01 16:39:07 +03:00
|
|
|
case .selectAccount(let accountAction), .switchAccount(let accountAction):
|
|
|
|
let closeOtherWindows: Bool
|
|
|
|
if case .selectAccount = action {
|
|
|
|
closeOtherWindows = false
|
|
|
|
} else {
|
|
|
|
closeOtherWindows = true
|
|
|
|
}
|
|
|
|
|
|
|
|
let windowController = Window.showNew(closeOthers: closeOtherWindows)
|
|
|
|
windowNumber = windowController.window?.windowNumber
|
2021-11-22 13:11:34 +03:00
|
|
|
let accountsList = instantiate(AccountsListViewController.self)
|
2022-08-18 19:53:44 +03:00
|
|
|
let coinType = CoinType.correspondingToWeb3Provider(accountAction.provider)
|
2022-08-17 17:54:12 +03:00
|
|
|
accountsList.accountSelectionConfiguration = AccountSelectionConfiguration(peer: safariRequest.peerMeta,
|
2022-08-18 19:53:44 +03:00
|
|
|
coinType: coinType,
|
|
|
|
selectedAccounts: Set(accountAction.preselectedAccounts),
|
2022-08-19 13:15:34 +03:00
|
|
|
initiallyConnectedProviders: accountAction.initiallyConnectedProviders,
|
2022-08-17 17:54:12 +03:00
|
|
|
completion: accountAction.completion)
|
2021-11-22 13:11:34 +03:00
|
|
|
windowController.contentViewController = accountsList
|
2022-02-12 21:30:05 +03:00
|
|
|
case .approveMessage(let action):
|
2022-08-01 16:39:07 +03:00
|
|
|
let windowController = Window.showNew(closeOthers: false)
|
|
|
|
windowNumber = windowController.window?.windowNumber
|
2022-08-01 17:09:41 +03:00
|
|
|
showApprove(windowController: windowController, browser: .safari, subject: action.subject, meta: action.meta, peerMeta: action.peerMeta, completion: action.completion)
|
2022-02-12 21:30:05 +03:00
|
|
|
case .approveTransaction(let action):
|
2022-08-01 16:39:07 +03:00
|
|
|
let windowController = Window.showNew(closeOthers: false)
|
|
|
|
windowNumber = windowController.window?.windowNumber
|
2022-08-01 17:09:41 +03:00
|
|
|
showApprove(windowController: windowController, browser: .safari, transaction: action.transaction, chain: action.chain, peerMeta: action.peerMeta, completion: action.completion)
|
2022-02-14 03:15:57 +03:00
|
|
|
case .justShowApp:
|
2022-08-01 16:39:07 +03:00
|
|
|
let windowController = Window.showNew(closeOthers: true)
|
|
|
|
windowNumber = windowController.window?.windowNumber
|
2022-02-14 03:15:57 +03:00
|
|
|
let accountsList = instantiate(AccountsListViewController.self)
|
|
|
|
windowController.contentViewController = accountsList
|
2021-11-22 13:11:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:16:23 +03:00
|
|
|
}
|
2021-06-19 14:07:57 +03:00
|
|
|
|
|
|
|
extension Agent: NSMenuDelegate {
|
|
|
|
|
|
|
|
func menuDidClose(_ menu: NSMenu) {
|
|
|
|
statusBarItem.menu = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|