2021-06-13 04:41:04 +03:00
|
|
|
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
|
|
|
|
|
|
|
import Cocoa
|
2021-07-02 23:00:00 +03:00
|
|
|
import WalletConnect
|
2021-06-13 04:41:04 +03:00
|
|
|
|
|
|
|
class ApproveViewController: NSViewController {
|
|
|
|
|
2021-06-13 07:01:01 +03:00
|
|
|
@IBOutlet weak var titleLabel: NSTextField!
|
2021-06-13 10:01:19 +03:00
|
|
|
@IBOutlet var metaTextView: NSTextView!
|
2021-06-19 12:06:13 +03:00
|
|
|
@IBOutlet weak var okButton: NSButton!
|
2021-07-03 22:48:20 +03:00
|
|
|
@IBOutlet weak var peerNameLabel: NSTextField!
|
|
|
|
@IBOutlet weak var peerLogoImageView: NSImageView! {
|
|
|
|
didSet {
|
|
|
|
peerLogoImageView.wantsLayer = true
|
|
|
|
peerLogoImageView.layer?.backgroundColor = NSColor.systemGray.withAlphaComponent(0.5).cgColor
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 07:01:01 +03:00
|
|
|
|
2021-07-03 22:48:20 +03:00
|
|
|
private var approveTitle: String!
|
|
|
|
private var meta: String!
|
|
|
|
private var completion: ((Bool) -> Void)!
|
|
|
|
private var peerMeta: WCPeerMeta?
|
2021-06-13 08:59:24 +03:00
|
|
|
|
2021-07-02 23:00:00 +03:00
|
|
|
static func with(title: String, meta: String, peerMeta: WCPeerMeta?, completion: @escaping (Bool) -> Void) -> ApproveViewController {
|
2021-06-13 09:32:07 +03:00
|
|
|
let new = instantiate(ApproveViewController.self)
|
|
|
|
new.completion = completion
|
|
|
|
new.meta = meta
|
|
|
|
new.approveTitle = title
|
2021-07-03 22:48:20 +03:00
|
|
|
new.peerMeta = peerMeta
|
2021-06-13 09:32:07 +03:00
|
|
|
return new
|
|
|
|
}
|
|
|
|
|
2021-06-27 14:13:34 +03:00
|
|
|
func setMeta(_ meta: String) {
|
|
|
|
self.meta = meta
|
|
|
|
updateDisplayedMeta()
|
|
|
|
}
|
|
|
|
|
2021-06-13 07:01:01 +03:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2021-06-13 09:32:07 +03:00
|
|
|
titleLabel.stringValue = approveTitle
|
2021-06-27 14:13:34 +03:00
|
|
|
updateDisplayedMeta()
|
2021-07-03 22:48:20 +03:00
|
|
|
if let peer = peerMeta {
|
|
|
|
peerNameLabel.stringValue = peer.name
|
|
|
|
if let urlString = peer.icons.first, let url = URL(string: urlString) {
|
|
|
|
peerLogoImageView.kf.setImage(with: url) { [weak peerLogoImageView] result in
|
|
|
|
if case .success = result {
|
|
|
|
peerLogoImageView?.layer?.backgroundColor = NSColor.clear.cgColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-27 14:13:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private func updateDisplayedMeta() {
|
2021-06-13 10:01:19 +03:00
|
|
|
metaTextView.string = meta
|
2021-06-13 07:01:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func actionButtonTapped(_ sender: Any) {
|
2021-06-13 08:59:24 +03:00
|
|
|
completion(true)
|
2021-06-13 07:01:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func cancelButtonTapped(_ sender: NSButton) {
|
2021-06-13 08:59:24 +03:00
|
|
|
completion(false)
|
2021-06-13 07:01:01 +03:00
|
|
|
}
|
|
|
|
|
2021-06-13 04:41:04 +03:00
|
|
|
}
|