ADD: View Address / QRCode toggle

This commit is contained in:
marcosrdz 2020-08-18 22:25:59 -04:00 committed by Overtorment
parent b95c5f5a72
commit 0e3c5b60f4
4 changed files with 107 additions and 4 deletions

View File

@ -8,6 +8,10 @@
import Foundation
enum InterfaceMode {
case Address, QRCode
}
class Wallet: NSObject, NSCoding {
static let identifier: String = "Wallet"

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -173,6 +173,7 @@
<controller identifier="ReceiveInterfaceController" title="Receive" fullBounds="YES" id="egq-Yw-qK5" customClass="ReceiveInterfaceController" customModule="BlueWalletWatch_Extension">
<items>
<imageView height="0.90000000000000002" alignment="left" id="Dnb-sM-wdN"/>
<label alignment="center" verticalAlignment="center" hidden="YES" text="Label" numberOfLines="0" id="c3W-8T-srG"/>
<group width="1" alignment="center" verticalAlignment="center" hidden="YES" layout="vertical" id="0If-FP-smM">
<items>
<imageView width="60" height="60" alignment="center" image="loadingIndicator" contentMode="scaleAspectFit" id="nQb-s6-ySB"/>
@ -191,6 +192,7 @@
</menu>
<edgeInsets key="margins" left="4" right="4" top="4" bottom="4"/>
<connections>
<outlet property="addressLabel" destination="c3W-8T-srG" id="fOe-1I-II2"/>
<outlet property="imageInterface" destination="Dnb-sM-wdN" id="z1e-zC-anB"/>
<outlet property="loadingIndicator" destination="0If-FP-smM" id="Wtf-mm-8Ke"/>
</connections>
@ -203,10 +205,13 @@
<objects>
<controller identifier="ViewQRCodefaceController" fullBounds="YES" id="ON9-Qg-65y" customClass="ViewQRCodefaceController" customModule="BlueWalletWatch_Extension">
<items>
<imageView height="0.90000000000000002" alignment="left" id="cp4-B3-gV6"/>
<imageView height="0.90000000000000002" alignment="left" image="textfor" id="cp4-B3-gV6"/>
<label alignment="center" verticalAlignment="center" hidden="YES" text="Label" numberOfLines="0" minimumScaleFactor="0.90000000000000002" id="JMO-XZ-1si"/>
<table alignment="left" id="2TT-ef-7YA"/>
</items>
<edgeInsets key="margins" left="4" right="4" top="4" bottom="4"/>
<connections>
<outlet property="addressLabel" destination="JMO-XZ-1si" id="yEj-Ha-tXA"/>
<outlet property="imageInterface" destination="cp4-B3-gV6" id="aOC-cT-eKL"/>
</connections>
</controller>
@ -362,6 +367,7 @@
<resources>
<image name="loadingIndicator" width="108" height="108"/>
<image name="pendingConfirmation" width="12" height="12"/>
<image name="textfor" width="128" height="128"/>
<image name="walletHD" width="249" height="100.5"/>
</resources>
</document>