diff --git a/ios/BlueWalletWatch Extension/Objects/Wallet.swift b/ios/BlueWalletWatch Extension/Objects/Wallet.swift index 37439461b..afa4575d7 100644 --- a/ios/BlueWalletWatch Extension/Objects/Wallet.swift +++ b/ios/BlueWalletWatch Extension/Objects/Wallet.swift @@ -8,6 +8,10 @@ import Foundation +enum InterfaceMode { + case Address, QRCode +} + class Wallet: NSObject, NSCoding { static let identifier: String = "Wallet" diff --git a/ios/BlueWalletWatch Extension/ReceiveInterfaceController.swift b/ios/BlueWalletWatch Extension/ReceiveInterfaceController.swift index 2293a1af9..07729bac4 100644 --- a/ios/BlueWalletWatch Extension/ReceiveInterfaceController.swift +++ b/ios/BlueWalletWatch Extension/ReceiveInterfaceController.swift @@ -14,11 +14,14 @@ import EFQRCode class ReceiveInterfaceController: WKInterfaceController { static let identifier = "ReceiveInterfaceController" - @IBOutlet weak var imageInterface: WKInterfaceImage! private var wallet: Wallet? private var isRenderingQRCode: Bool? private var receiveMethod: String = "receive" + private var interfaceMode: InterfaceMode = .Address + @IBOutlet weak var addressLabel: WKInterfaceLabel! @IBOutlet weak var loadingIndicator: WKInterfaceGroup! + @IBOutlet weak var imageInterface: WKInterfaceImage! + override func awake(withContext context: Any?) { super.awake(withContext: context) @@ -47,6 +50,9 @@ class ReceiveInterfaceController: WKInterfaceController { self?.imageInterface.setHidden(false) self?.imageInterface.setImage(nil) self?.imageInterface.setImage(image) + self?.addressLabel.setText(invoice) + self?.interfaceMode = .QRCode + self?.toggleViewButtonPressed() WCSession.default.sendMessage(["message": "fetchTransactions"], replyHandler: nil, errorHandler: nil) } else { self?.presentAlert(withTitle: "Error", message: "Unable to create invoice. Please, make sure your iPhone is paired and nearby.", preferredStyle: .alert, actions: [WKAlertAction(title: "OK", style: .default, handler: { [weak self] in @@ -81,6 +87,9 @@ class ReceiveInterfaceController: WKInterfaceController { self?.imageInterface.setImage(nil) self?.imageInterface.setImage(image) self?.imageInterface.setHidden(false) + self?.addressLabel.setText(receiveAddress) + self?.interfaceMode = .QRCode + self?.toggleViewButtonPressed() self?.loadingIndicator.setHidden(true) self?.isRenderingQRCode = false } @@ -94,6 +103,17 @@ class ReceiveInterfaceController: WKInterfaceController { let image = UIImage(cgImage: cgImage) imageInterface.setImage(image) + + if #available(watchOSApplicationExtension 6.0, *) { + if let image = UIImage(systemName: "textformat.subscript") { + addMenuItem(with: image, title: "Address", action:#selector(toggleViewButtonPressed)) + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + addressLabel.setText(wallet.receiveAddress) } override func didAppear() { @@ -117,4 +137,36 @@ class ReceiveInterfaceController: WKInterfaceController { presentController(withName: SpecifyInterfaceController.identifier, context: wallet?.identifier) } + + @IBAction @objc func toggleViewButtonPressed() { + clearAllMenuItems() + switch interfaceMode { + case .Address: + addressLabel.setHidden(false) + imageInterface.setHidden(true) + if #available(watchOSApplicationExtension 6.0, *) { + if let image = UIImage(systemName: "qrcode") { + addMenuItem(with: image, title: "QR Code", action:#selector(toggleViewButtonPressed)) + } else { + addMenuItem(with: .shuffle, title: "QR Code", action: #selector(toggleViewButtonPressed)) + } + } else { + addMenuItem(with: .shuffle, title: "QR Code", action: #selector(toggleViewButtonPressed)) + + } + case .QRCode: + addressLabel.setHidden(true) + imageInterface.setHidden(false) + if #available(watchOSApplicationExtension 6.0, *) { + if let image = UIImage(systemName: "textformat.subscript") { + addMenuItem(with: image, title: "Address", action:#selector(toggleViewButtonPressed)) + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } + interfaceMode = interfaceMode == .QRCode ? .Address : .QRCode + } } diff --git a/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift b/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift index 7bae665f1..4b2b37031 100644 --- a/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift +++ b/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift @@ -14,7 +14,9 @@ class ViewQRCodefaceController: WKInterfaceController { static let identifier = "ViewQRCodefaceController" @IBOutlet weak var imageInterface: WKInterfaceImage! + @IBOutlet weak var addressLabel: WKInterfaceLabel! var qrcodeData: String? + private var interfaceMode = InterfaceMode.Address override func awake(withContext context: Any?) { super.awake(withContext: context) @@ -22,7 +24,7 @@ class ViewQRCodefaceController: WKInterfaceController { pop() return } - + addressLabel.setText(passedContext) DispatchQueue.main.async { guard let cgImage = EFQRCode.generate( content: passedContext) else { @@ -32,6 +34,45 @@ class ViewQRCodefaceController: WKInterfaceController { self.imageInterface.setImage(nil) self.imageInterface.setImage(image) } + if #available(watchOSApplicationExtension 6.0, *) { + if let image = UIImage(systemName: "textformat.subscript") { + addMenuItem(with: image, title: "Address", action:#selector(toggleViewButtonPressed)) + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } + @IBAction @objc func toggleViewButtonPressed() { + clearAllMenuItems() + switch interfaceMode { + case .Address: + addressLabel.setHidden(false) + imageInterface.setHidden(true) + if #available(watchOSApplicationExtension 6.0, *) { + if let image = UIImage(systemName: "qrcode") { + addMenuItem(with: image, title: "QR Code", action:#selector(toggleViewButtonPressed)) + } else { + addMenuItem(with: .shuffle, title: "QR Code", action: #selector(toggleViewButtonPressed)) + } + } else { + addMenuItem(with: .shuffle, title: "QR Code", action: #selector(toggleViewButtonPressed)) + + } + case .QRCode: + addressLabel.setHidden(true) + imageInterface.setHidden(false) + if #available(watchOSApplicationExtension 6.0, *) { + if let image = UIImage(systemName: "textformat.subscript") { + addMenuItem(with: image, title: "Address", action:#selector(toggleViewButtonPressed)) + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } else { + addMenuItem(with: .shuffle, title: "Address", action: #selector(toggleViewButtonPressed)) + } + } + interfaceMode = interfaceMode == .QRCode ? .Address : .QRCode } - } diff --git a/ios/BlueWalletWatch/Base.lproj/Interface.storyboard b/ios/BlueWalletWatch/Base.lproj/Interface.storyboard index 2a8a62f43..ebc45149c 100644 --- a/ios/BlueWalletWatch/Base.lproj/Interface.storyboard +++ b/ios/BlueWalletWatch/Base.lproj/Interface.storyboard @@ -173,6 +173,7 @@ +