mirror of
https://github.com/lil-org/tokenary.git
synced 2025-01-05 20:16:25 +03:00
Resolve TODO - add AuthenticationReason enum
This commit is contained in:
parent
f84f7ba458
commit
62a93308ff
@ -21,6 +21,7 @@
|
||||
0DB7291E2674E2DB0011F7A1 /* EIP712Signable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB7290F2674E2DB0011F7A1 /* EIP712Signable.swift */; };
|
||||
0DB7291F2674E2DB0011F7A1 /* EIP712Representable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB729102674E2DB0011F7A1 /* EIP712Representable.swift */; };
|
||||
0DB729202674E2DB0011F7A1 /* EIP712Domain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DB729112674E2DB0011F7A1 /* EIP712Domain.swift */; };
|
||||
0DC850E726B73A5900809E82 /* AuthenticationReason.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DC850E626B73A5900809E82 /* AuthenticationReason.swift */; };
|
||||
28BDF30EBC80362870C988B6 /* Pods_Encrypted_Ink.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E2A642C960E4952955E6E82 /* Pods_Encrypted_Ink.framework */; };
|
||||
2C03D1D2269B407900EF10EA /* NetworkMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C03D1D1269B407900EF10EA /* NetworkMonitor.swift */; };
|
||||
2C03D1D5269B428C00EF10EA /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C03D1D4269B428C00EF10EA /* Notification.swift */; };
|
||||
@ -73,6 +74,7 @@
|
||||
0DB7290F2674E2DB0011F7A1 /* EIP712Signable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP712Signable.swift; sourceTree = "<group>"; };
|
||||
0DB729102674E2DB0011F7A1 /* EIP712Representable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP712Representable.swift; sourceTree = "<group>"; };
|
||||
0DB729112674E2DB0011F7A1 /* EIP712Domain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP712Domain.swift; sourceTree = "<group>"; };
|
||||
0DC850E626B73A5900809E82 /* AuthenticationReason.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationReason.swift; sourceTree = "<group>"; };
|
||||
2C03D1D1269B407900EF10EA /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = "<group>"; };
|
||||
2C03D1D4269B428C00EF10EA /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
|
||||
2C19953C2674C4B900A8E370 /* Encrypted Ink.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Encrypted Ink.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@ -158,6 +160,14 @@
|
||||
path = Protocols;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
0DC850E926B73A8200809E82 /* Models */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0DC850E626B73A5900809E82 /* AuthenticationReason.swift */,
|
||||
);
|
||||
path = Models;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2C1995332674C4B900A8E370 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -185,6 +195,7 @@
|
||||
2C528A15267FA8EB00CA3ADD /* Defaults.swift */,
|
||||
2C8A09D32675184700993638 /* Window.swift */,
|
||||
2C901C492689F01700D0926A /* Strings.swift */,
|
||||
0DC850E926B73A8200809E82 /* Models */,
|
||||
2CD0668826B213BB00728C20 /* Wallets */,
|
||||
2C6706A7267A6C04006AAEF2 /* Extensions */,
|
||||
2C8A09C92675142700993638 /* Screens */,
|
||||
@ -438,6 +449,7 @@
|
||||
0DB7291D2674E2DB0011F7A1 /* EIP712Hashable.swift in Sources */,
|
||||
0DB729162674E2DB0011F7A1 /* EIP712SimpleValue.swift in Sources */,
|
||||
0DB729122674E2DB0011F7A1 /* EIP712ParameterEncoder.swift in Sources */,
|
||||
0DC850E726B73A5900809E82 /* AuthenticationReason.swift in Sources */,
|
||||
2C8A09D726751A0C00993638 /* WalletConnect.swift in Sources */,
|
||||
2C03D1D2269B407900EF10EA /* NetworkMonitor.swift in Sources */,
|
||||
2C8A09E326757FC000993638 /* AccountCellView.swift in Sources */,
|
||||
|
@ -53,7 +53,7 @@ class Agent: NSObject {
|
||||
}
|
||||
|
||||
guard didEnterPasswordOnStart else {
|
||||
askAuthentication(on: nil, onStart: true, reason: "Start") { [weak self] success in
|
||||
askAuthentication(on: nil, onStart: true, reason: .start) { [weak self] success in
|
||||
if success {
|
||||
self?.didEnterPasswordOnStart = true
|
||||
self?.showInitialScreen(wcSession: wcSession)
|
||||
@ -82,7 +82,7 @@ class Agent: NSObject {
|
||||
let windowController = Window.showNew()
|
||||
let approveViewController = ApproveTransactionViewController.with(transaction: transaction, peerMeta: peerMeta) { [weak self] transaction in
|
||||
if transaction != nil {
|
||||
self?.askAuthentication(on: windowController.window, onStart: false, reason: Strings.sendTransaction) { success in
|
||||
self?.askAuthentication(on: windowController.window, onStart: false, reason: .sendTransaction) { success in
|
||||
completion(success ? transaction : nil)
|
||||
Window.closeAllAndActivateBrowser()
|
||||
}
|
||||
@ -98,7 +98,7 @@ class Agent: NSObject {
|
||||
let windowController = Window.showNew()
|
||||
let approveViewController = ApproveViewController.with(title: title, meta: meta, peerMeta: peerMeta) { [weak self] result in
|
||||
if result {
|
||||
self?.askAuthentication(on: windowController.window, onStart: false, reason: title) { success in
|
||||
self?.askAuthentication(on: windowController.window, onStart: false, reason: .signAction(title: title)) { success in
|
||||
completion(success)
|
||||
Window.closeAllAndActivateBrowser()
|
||||
}
|
||||
@ -249,7 +249,7 @@ class Agent: NSObject {
|
||||
return WalletConnect.shared.sessionWithLink(link)
|
||||
}
|
||||
|
||||
func askAuthentication(on: NSWindow?, getBackTo: NSViewController? = nil, onStart: Bool, reason: String, completion: @escaping (Bool) -> Void) {
|
||||
func askAuthentication(on: NSWindow?, getBackTo: NSViewController? = nil, onStart: Bool, reason: AuthenticationReason, completion: @escaping (Bool) -> Void) {
|
||||
let context = LAContext()
|
||||
var error: NSError?
|
||||
let policy = LAPolicy.deviceOwnerAuthenticationWithBiometrics
|
||||
@ -271,7 +271,7 @@ class Agent: NSObject {
|
||||
if canDoLocalAuthentication {
|
||||
context.localizedCancelTitle = "Cancel"
|
||||
didStartInitialLAEvaluation = true
|
||||
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason ) { [weak self] success, _ in
|
||||
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: reason.title) { [weak self] success, _ in
|
||||
DispatchQueue.main.async {
|
||||
self?.didCompleteInitialLAEvaluation = true
|
||||
if !success, onStart, self?.didEnterPasswordOnStart == false {
|
||||
|
24
Encrypted Ink/Models/AuthenticationReason.swift
Normal file
24
Encrypted Ink/Models/AuthenticationReason.swift
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
||||
|
||||
enum AuthenticationReason {
|
||||
case start
|
||||
case sendTransaction
|
||||
case removeAccount
|
||||
case showPrivateKey
|
||||
case signAction(title: String)
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .start:
|
||||
return "Start"
|
||||
case .sendTransaction:
|
||||
return "Send Transaction"
|
||||
case .removeAccount:
|
||||
return "Remove account"
|
||||
case .showPrivateKey:
|
||||
return "Show private key"
|
||||
case .signAction(let title):
|
||||
return title
|
||||
}
|
||||
}
|
||||
}
|
@ -145,7 +145,7 @@ class AccountsListViewController: NSViewController {
|
||||
alert.addButton(withTitle: "Remove anyway")
|
||||
alert.addButton(withTitle: "Cancel")
|
||||
if alert.runModal() == .alertFirstButtonReturn {
|
||||
agent.askAuthentication(on: view.window, getBackTo: self, onStart: false, reason: "Remove account") { [weak self] allowed in
|
||||
agent.askAuthentication(on: view.window, getBackTo: self, onStart: false, reason: .removeAccount) { [weak self] allowed in
|
||||
Window.activateWindow(self?.view.window)
|
||||
if allowed {
|
||||
self?.removeAccountAtIndex(row)
|
||||
@ -164,7 +164,7 @@ class AccountsListViewController: NSViewController {
|
||||
alert.addButton(withTitle: "I understand the risks")
|
||||
alert.addButton(withTitle: "Cancel")
|
||||
if alert.runModal() == .alertFirstButtonReturn {
|
||||
agent.askAuthentication(on: view.window, getBackTo: self, onStart: false, reason: "Show private key") { [weak self] allowed in
|
||||
agent.askAuthentication(on: view.window, getBackTo: self, onStart: false, reason: .showPrivateKey) { [weak self] allowed in
|
||||
Window.activateWindow(self?.view.window)
|
||||
if allowed {
|
||||
self?.showPrivateKey(index: row)
|
||||
|
@ -4,7 +4,7 @@ import Cocoa
|
||||
|
||||
class PasswordViewController: NSViewController {
|
||||
|
||||
static func with(mode: Mode, reason: String? = nil, completion: ((Bool) -> Void)?) -> PasswordViewController {
|
||||
static func with(mode: Mode, reason: AuthenticationReason? = nil, completion: ((Bool) -> Void)?) -> PasswordViewController {
|
||||
let new = instantiate(PasswordViewController.self)
|
||||
new.mode = mode
|
||||
new.reason = reason
|
||||
@ -18,7 +18,7 @@ class PasswordViewController: NSViewController {
|
||||
|
||||
private let keychain = Keychain.shared
|
||||
private var mode = Mode.create
|
||||
private var reason: String?
|
||||
private var reason: AuthenticationReason?
|
||||
private var passwordToRepeat: String?
|
||||
private var completion: ((Bool) -> Void)?
|
||||
|
||||
@ -35,11 +35,12 @@ class PasswordViewController: NSViewController {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
switchToMode(mode)
|
||||
// TODO: use enum for reason to avoid strings comparison
|
||||
if let reason = reason, reason != "Start" {
|
||||
reasonLabel.stringValue = "to " + reason.lowercased()
|
||||
} else {
|
||||
|
||||
switch reason {
|
||||
case .none, .start:
|
||||
reasonLabel.stringValue = ""
|
||||
case .sendTransaction, .removeAccount, .showPrivateKey, .signAction:
|
||||
reasonLabel.stringValue = "to " + (reason?.title.lowercased() ?? "")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user