From 47a7e191456d772a05b84e391f3c0761073dde4f Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Sun, 16 Aug 2020 23:56:05 -0400 Subject: [PATCH] ADD: View Wallet xPub --- WatchConnectivity.ios.js | 1 + ios/BlueWallet.xcodeproj/project.pbxproj | 18 +++++---- .../BlueWalletWatch Extension.entitlements | 7 +++- .../Objects/Wallet.swift | 7 +++- .../Objects/WatchDataSource.swift | 7 +--- .../ViewQRCodefaceController.swift | 37 +++++++++++++++++++ .../WalletDetailsInterfaceController.swift | 17 +++++++++ .../Base.lproj/Interface.storyboard | 23 ++++++++++-- 8 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift diff --git a/WatchConnectivity.ios.js b/WatchConnectivity.ios.js index 8c4b6494d..70d96c118 100644 --- a/WatchConnectivity.ios.js +++ b/WatchConnectivity.ios.js @@ -163,6 +163,7 @@ export default class WatchConnectivity { preferredBalanceUnit: wallet.getPreferredBalanceUnit(), receiveAddress: receiveAddress, transactions: watchTransactions, + xpub: wallet.getXpub(), }); } Watch.updateApplicationContext({ wallets, randomID: Math.floor(Math.random() * 11) }); diff --git a/ios/BlueWallet.xcodeproj/project.pbxproj b/ios/BlueWallet.xcodeproj/project.pbxproj index 026bb5457..f2645271b 100644 --- a/ios/BlueWallet.xcodeproj/project.pbxproj +++ b/ios/BlueWallet.xcodeproj/project.pbxproj @@ -26,7 +26,8 @@ 32B5A32A2334450100F8D608 /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32B5A3292334450100F8D608 /* Bridge.swift */; }; 32F0A29A2311DBB20095C559 /* ComplicationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32F0A2992311DBB20095C559 /* ComplicationController.swift */; }; 6DF25A9F249DB97E001D06F5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6DF25A9E249DB97E001D06F5 /* LaunchScreen.storyboard */; }; - 6DFC807024EA0B6C007B8700 /* BuildFile in Frameworks */ = {isa = PBXBuildFile; productRef = 6DFC806F24EA0B6C007B8700 /* SwiftPackageProductDependency */; }; + 6DFC807024EA0B6C007B8700 /* EFQRCode in Frameworks */ = {isa = PBXBuildFile; productRef = 6DFC806F24EA0B6C007B8700 /* EFQRCode */; }; + 6DFC807224EA2FA9007B8700 /* ViewQRCodefaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DFC807124EA2FA9007B8700 /* ViewQRCodefaceController.swift */; }; 764B49B1420D4AEB8109BF62 /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B468CC34D5B41F3950078EF /* libsqlite3.0.tbd */; }; 782F075B5DD048449E2DECE9 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = B9D9B3A7B2CB4255876B67AF /* libz.tbd */; }; 906451CAD44154C2950030EC /* libPods-BlueWallet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 731973BA0AC6EA78962CE5B6 /* libPods-BlueWallet.a */; }; @@ -218,6 +219,7 @@ 6D294A9D24D5127F0039E22B /* xh */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = xh; path = xh.lproj/Interface.strings; sourceTree = ""; }; 6D294A9E24D512800039E22B /* xh */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = xh; path = xh.lproj/MainInterface.strings; sourceTree = ""; }; 6DF25A9E249DB97E001D06F5 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; + 6DFC807124EA2FA9007B8700 /* ViewQRCodefaceController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewQRCodefaceController.swift; sourceTree = ""; }; 6EB3338E347F4AFAA8C85C04 /* libRNDeviceInfo-tvOS.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = "libRNDeviceInfo-tvOS.a"; sourceTree = ""; }; 70C9C17A3F52430B99582AF4 /* libRNCamera.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libRNCamera.a; sourceTree = ""; }; 731973BA0AC6EA78962CE5B6 /* libPods-BlueWallet.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-BlueWallet.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -337,7 +339,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 6DFC807024EA0B6C007B8700 /* BuildFile in Frameworks */, + 6DFC807024EA0B6C007B8700 /* EFQRCode in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -506,6 +508,7 @@ B40D4E552258425400428FCC /* InterfaceController.swift */, B40D4E562258425400428FCC /* NumericKeypadInterfaceController.swift */, B40D4E5B2258425500428FCC /* ReceiveInterfaceController.swift */, + 6DFC807124EA2FA9007B8700 /* ViewQRCodefaceController.swift */, B40D4E582258425400428FCC /* SpecifyInterfaceController.swift */, B40D4E5C2258425500428FCC /* WalletDetailsInterfaceController.swift */, B40D4E49225841ED00428FCC /* Info.plist */, @@ -691,7 +694,7 @@ ); name = "BlueWalletWatch Extension"; packageProductDependencies = ( - 6DFC806F24EA0B6C007B8700 /* SwiftPackageProductDependency */, + 6DFC806F24EA0B6C007B8700 /* EFQRCode */, ); productName = "BlueWalletWatch Extension"; productReference = B40D4E3C225841ED00428FCC /* BlueWalletWatch Extension.appex */; @@ -790,7 +793,7 @@ ); mainGroup = 83CBB9F61A601CBA00E9B192; packageReferences = ( - 6DFC806E24EA0B6C007B8700 /* RemoteSwiftPackageReference */, + 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */, ); productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; projectDirPath = ""; @@ -1005,6 +1008,7 @@ 32F0A29A2311DBB20095C559 /* ComplicationController.swift in Sources */, B40D4E602258425500428FCC /* SpecifyInterfaceController.swift in Sources */, B43D0379225847C500FBAA95 /* WatchDataSource.swift in Sources */, + 6DFC807224EA2FA9007B8700 /* ViewQRCodefaceController.swift in Sources */, B40D4E46225841ED00428FCC /* NotificationController.swift in Sources */, B40D4E5D2258425500428FCC /* InterfaceController.swift in Sources */, B43D037B225847C500FBAA95 /* TransactionTableRow.swift in Sources */, @@ -1921,7 +1925,7 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 6DFC806E24EA0B6C007B8700 /* RemoteSwiftPackageReference */ = { + 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/EFPrefix/EFQRCode.git"; requirement = { @@ -1932,9 +1936,9 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 6DFC806F24EA0B6C007B8700 /* SwiftPackageProductDependency */ = { + 6DFC806F24EA0B6C007B8700 /* EFQRCode */ = { isa = XCSwiftPackageProductDependency; - package = 6DFC806E24EA0B6C007B8700 /* RemoteSwiftPackageReference */; + package = 6DFC806E24EA0B6C007B8700 /* XCRemoteSwiftPackageReference "EFQRCode" */; productName = EFQRCode; }; /* End XCSwiftPackageProductDependency section */ diff --git a/ios/BlueWalletWatch Extension/BlueWalletWatch Extension.entitlements b/ios/BlueWalletWatch Extension/BlueWalletWatch Extension.entitlements index 0c67376eb..86bfd6c51 100644 --- a/ios/BlueWalletWatch Extension/BlueWalletWatch Extension.entitlements +++ b/ios/BlueWalletWatch Extension/BlueWalletWatch Extension.entitlements @@ -1,5 +1,10 @@ - + + com.apple.security.application-groups + + group.io.bluewallet.bluewallet + + diff --git a/ios/BlueWalletWatch Extension/Objects/Wallet.swift b/ios/BlueWalletWatch Extension/Objects/Wallet.swift index cbbea850b..37439461b 100644 --- a/ios/BlueWalletWatch Extension/Objects/Wallet.swift +++ b/ios/BlueWalletWatch Extension/Objects/Wallet.swift @@ -18,8 +18,9 @@ class Wallet: NSObject, NSCoding { let preferredBalanceUnit: String let receiveAddress: String let transactions: [Transaction] + let xpub: String? - init(label: String, balance: String, type: String, preferredBalanceUnit: String, receiveAddress: String, transactions: [Transaction], identifier: Int) { + init(label: String, balance: String, type: String, preferredBalanceUnit: String, receiveAddress: String, transactions: [Transaction], identifier: Int, xpub: String?) { self.label = label self.balance = balance self.type = type @@ -27,6 +28,7 @@ class Wallet: NSObject, NSCoding { self.receiveAddress = receiveAddress self.transactions = transactions self.identifier = identifier + self.xpub = xpub } func encode(with aCoder: NSCoder) { @@ -37,6 +39,7 @@ class Wallet: NSObject, NSCoding { aCoder.encode(preferredBalanceUnit, forKey: "preferredBalanceUnit") aCoder.encode(transactions, forKey: "transactions") aCoder.encode(identifier, forKey: "identifier") + aCoder.encode(xpub, forKey: "xpub") } required init?(coder aDecoder: NSCoder) { @@ -46,6 +49,8 @@ class Wallet: NSObject, NSCoding { preferredBalanceUnit = aDecoder.decodeObject(forKey: "preferredBalanceUnit") as! String receiveAddress = aDecoder.decodeObject(forKey: "receiveAddress") as! String transactions = aDecoder.decodeObject(forKey: "transactions") as? [Transaction] ?? [Transaction]() + xpub = aDecoder.decodeObject(forKey: "xpub") as? String + } } diff --git a/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift b/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift index 7d0177f42..e98eabd2a 100644 --- a/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift +++ b/ios/BlueWalletWatch Extension/Objects/WatchDataSource.swift @@ -45,7 +45,8 @@ class WatchDataSource: NSObject, WCSessionDelegate { transactionsProcessed.append(transaction) } let receiveAddress = entry["receiveAddress"] as? String ?? "" - let wallet = Wallet(label: label, balance: balance, type: type, preferredBalanceUnit: preferredBalanceUnit, receiveAddress: receiveAddress, transactions: transactionsProcessed, identifier: index) + let xpub = entry["xpub"] as? String ?? "" + let wallet = Wallet(label: label, balance: balance, type: type, preferredBalanceUnit: preferredBalanceUnit, receiveAddress: receiveAddress, transactions: transactionsProcessed, identifier: index, xpub: xpub) wallets.append(wallet) } @@ -78,10 +79,6 @@ class WatchDataSource: NSObject, WCSessionDelegate { } } - func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) { - WatchDataSource.shared.processWalletsData(walletsInfo: applicationContext) - } - func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) { WatchDataSource.shared.processWalletsData(walletsInfo: applicationContext) } diff --git a/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift b/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift new file mode 100644 index 000000000..7bae665f1 --- /dev/null +++ b/ios/BlueWalletWatch Extension/ViewQRCodefaceController.swift @@ -0,0 +1,37 @@ +// +// ReceiveInterfaceController.swift +// BlueWalletWatch Extension +// +// Created by Marcos Rodriguez on 3/12/19. +// Copyright © 2019 Facebook. All rights reserved. +// + +import WatchKit +import Foundation +import EFQRCode + +class ViewQRCodefaceController: WKInterfaceController { + + static let identifier = "ViewQRCodefaceController" + @IBOutlet weak var imageInterface: WKInterfaceImage! + var qrcodeData: String? + + override func awake(withContext context: Any?) { + super.awake(withContext: context) + guard let passedContext = context as? String else { + pop() + return + } + + DispatchQueue.main.async { + guard let cgImage = EFQRCode.generate( + content: passedContext) else { + return + } + let image = UIImage(cgImage: cgImage) + self.imageInterface.setImage(nil) + self.imageInterface.setImage(image) + } + } + +} diff --git a/ios/BlueWalletWatch Extension/WalletDetailsInterfaceController.swift b/ios/BlueWalletWatch Extension/WalletDetailsInterfaceController.swift index fe534208f..5e9b5f644 100644 --- a/ios/BlueWalletWatch Extension/WalletDetailsInterfaceController.swift +++ b/ios/BlueWalletWatch Extension/WalletDetailsInterfaceController.swift @@ -36,6 +36,23 @@ class WalletDetailsInterfaceController: WKInterfaceController { walletBasicsGroup.setBackgroundImageNamed(WalletGradient(rawValue: wallet.type)?.imageString) createInvoiceButton.setHidden(wallet.type != "lightningCustodianWallet") processWalletsTable() + addMenuItems() + } + + func addMenuItems() { + guard let wallet = wallet else { + return + } + if wallet.type != "lightningCustodianWallet" && !(wallet.xpub ?? "").isEmpty { + addMenuItem(with: .share, title: "View XPub", action: #selector(viewXPubMenuItemTapped)) + } + } + + @objc func viewXPubMenuItemTapped() { + guard let xpub = wallet?.xpub else { + return + } + presentController(withName: ViewQRCodefaceController.identifier, context: xpub) } override func willActivate() { diff --git a/ios/BlueWalletWatch/Base.lproj/Interface.storyboard b/ios/BlueWalletWatch/Base.lproj/Interface.storyboard index f613fcb0d..2a8a62f43 100644 --- a/ios/BlueWalletWatch/Base.lproj/Interface.storyboard +++ b/ios/BlueWalletWatch/Base.lproj/Interface.storyboard @@ -54,10 +54,10 @@ - + - + @@ -167,10 +167,10 @@ - + - + + + + + + + + + + + + + + + +