diff --git a/Shared/Views/EditTransactionView.swift b/Shared/Views/EditTransactionView.swift new file mode 100644 index 00000000..e0c0a5be --- /dev/null +++ b/Shared/Views/EditTransactionView.swift @@ -0,0 +1,28 @@ +// Copyright © 2023 Tokenary. All rights reserved. + +import SwiftUI + +struct EditTransactionView: View { + + @Environment(\.presentationMode) var presentationMode + @State private var initialTransaction: Transaction + @State private var didEdit = true // TODO: tmp for dev + + private let completion: ((Transaction?) -> Void) + + var body: some View { + VStack { + Text("advanced settings") + HStack { + Button(Strings.cancel) { completion(nil) }.keyboardShortcut(.cancelAction) + Button(Strings.ok) { completion(nil) }.keyboardShortcut(.defaultAction) + .disabled(!didEdit) // TODO: directly check if there are custom values entered? + }.frame(height: 36).offset(CGSize(width: 0, height: -6)) + } + } + + init(initialTransaction: Transaction, completion: @escaping ((Transaction?) -> Void)) { + self._initialTransaction = State(initialValue: initialTransaction) + self.completion = completion + } +} diff --git a/Tokenary macOS/Extensions/NSViewController.swift b/Tokenary macOS/Extensions/NSViewController.swift index 651cf5b5..b90da4d1 100644 --- a/Tokenary macOS/Extensions/NSViewController.swift +++ b/Tokenary macOS/Extensions/NSViewController.swift @@ -4,12 +4,14 @@ import SwiftUI extension NSViewController { - func makeHostingWindow(content: Content, title: String) -> NSWindow where Content: View { + func makeHostingWindow(content: Content, title: String? = nil) -> NSWindow where Content: View { let hostingWindow = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 300, height: 400), styleMask: [.closable, .fullSizeContentView, .titled], backing: .buffered, defer: false) - hostingWindow.title = title + if let title = title { + hostingWindow.title = title + } hostingWindow.center() hostingWindow.titleVisibility = .visible hostingWindow.titlebarAppearsTransparent = false diff --git a/Tokenary macOS/Screens/ApproveTransactionViewController.swift b/Tokenary macOS/Screens/ApproveTransactionViewController.swift index 87eb323d..c8b6c45b 100644 --- a/Tokenary macOS/Screens/ApproveTransactionViewController.swift +++ b/Tokenary macOS/Screens/ApproveTransactionViewController.swift @@ -155,7 +155,12 @@ class ApproveTransactionViewController: NSViewController { } @IBAction func editTransactionButtonTapped(_ sender: Any) { - // TODO: implement + let editTransactionView = EditTransactionView(initialTransaction: transaction) { [weak self] editedTransaction in + self?.endAllSheets() + // TODO: apply new values + } + let editWindow = makeHostingWindow(content: editTransactionView) + view.window?.beginSheet(editWindow) } @IBAction func sliderValueChanged(_ sender: NSSlider) { @@ -178,6 +183,7 @@ extension ApproveTransactionViewController: NSWindowDelegate { func windowWillClose(_ notification: Notification) { callCompletion(result: nil) + endAllSheets() } } diff --git a/Tokenary.xcodeproj/project.pbxproj b/Tokenary.xcodeproj/project.pbxproj index 71e37733..6e3c2ad5 100644 --- a/Tokenary.xcodeproj/project.pbxproj +++ b/Tokenary.xcodeproj/project.pbxproj @@ -185,6 +185,8 @@ 2CD0669226B5537B00728C20 /* WalletsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD0668926B213E500728C20 /* WalletsManager.swift */; }; 2CD0B3F526A0DAA900488D92 /* NSPasteboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD0B3F426A0DAA900488D92 /* NSPasteboard.swift */; }; 2CD0B3F726AC619900488D92 /* AddAccountOptionCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD0B3F626AC619900488D92 /* AddAccountOptionCellView.swift */; }; + 2CD7FC8D2B1115AE00659439 /* EditTransactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7FC8C2B1115AE00659439 /* EditTransactionView.swift */; }; + 2CD7FC8E2B1115AE00659439 /* EditTransactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CD7FC8C2B1115AE00659439 /* EditTransactionView.swift */; }; 2CDAB3722675B3F0009F8B97 /* PasswordViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */; }; 2CE059372763D60A0042D844 /* KeyboardObserver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE059362763D60A0042D844 /* KeyboardObserver.swift */; }; 2CE059392763F3FF0042D844 /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CE059382763F3FF0042D844 /* CGFloat.swift */; }; @@ -444,6 +446,7 @@ 2CD0668B26B2142000728C20 /* TokenaryWallet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenaryWallet.swift; sourceTree = ""; }; 2CD0B3F426A0DAA900488D92 /* NSPasteboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSPasteboard.swift; sourceTree = ""; }; 2CD0B3F626AC619900488D92 /* AddAccountOptionCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAccountOptionCellView.swift; sourceTree = ""; }; + 2CD7FC8C2B1115AE00659439 /* EditTransactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditTransactionView.swift; sourceTree = ""; }; 2CDAB3712675B3F0009F8B97 /* PasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordViewController.swift; sourceTree = ""; }; 2CE059362763D60A0042D844 /* KeyboardObserver.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardObserver.swift; sourceTree = ""; }; 2CE059382763F3FF0042D844 /* CGFloat.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CGFloat.swift; sourceTree = ""; }; @@ -953,6 +956,7 @@ isa = PBXGroup; children = ( 2C9931DB2AEEC0E200577C8A /* NetworksListView.swift */, + 2CD7FC8C2B1115AE00659439 /* EditTransactionView.swift */, ); path = Views; sourceTree = ""; @@ -1559,6 +1563,7 @@ 2C728B5F2AFBE7EA00E4DD47 /* NetworksListView.swift in Sources */, 2C8A09EE2675965F00993638 /* WaitingViewController.swift in Sources */, 2C797E7E267BB88800F2CE2D /* WelcomeViewController.swift in Sources */, + 2CD7FC8D2B1115AE00659439 /* EditTransactionView.swift in Sources */, 2C4B72CB2B0E7EA800113087 /* NSViewController.swift in Sources */, 2CD0669226B5537B00728C20 /* WalletsManager.swift in Sources */, 2C4768A9282598C5005E8D4D /* CoinDerivationCellView.swift in Sources */, @@ -1608,6 +1613,7 @@ 2C6F6D5A28273FE500D6E8FB /* EditAccountsViewController.swift in Sources */, 2CF255BA275A749300AE54B9 /* ApproveViewController.swift in Sources */, 2C3024FD28C1193100C304ED /* TokenaryAccount.swift in Sources */, + 2CD7FC8E2B1115AE00659439 /* EditTransactionView.swift in Sources */, 2C96D3962762380400687301 /* ButtonWithExtendedArea.swift in Sources */, 2C264BC227B2F2C100234393 /* EthereumSafariRequest.swift in Sources */, 2CE059372763D60A0042D844 /* KeyboardObserver.swift in Sources */,