From b2ebb70fe2b84a29f942f3082f90c72feb7678bd Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 21 Jun 2024 11:43:48 +0100 Subject: [PATCH 1/6] entering custom addresses into baker field will check to see if it exists in the list first, in order to display details --- .../Modules/Stake/StakeViewController.swift | 19 +++++++++++++++---- .../Modules/Stake/StakeViewModel.swift | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Kukai Mobile/Modules/Stake/StakeViewController.swift b/Kukai Mobile/Modules/Stake/StakeViewController.swift index 8d4ee34a..9c8db00f 100644 --- a/Kukai Mobile/Modules/Stake/StakeViewController.swift +++ b/Kukai Mobile/Modules/Stake/StakeViewController.swift @@ -51,6 +51,8 @@ class StakeViewController: UIViewController { } public func enteredCustomBaker(address: String) { + self.showLoadingView() + if address == "" { let currentDelegate = DependencyManager.shared.balanceService.account.delegate let name = currentDelegate?.alias ?? currentDelegate?.address.truncateTezosAddress() ?? "" @@ -66,15 +68,25 @@ class StakeViewController: UIViewController { TransactionService.shared.delegateData.isAdd = false } else { - let baker = TzKTBaker(address: address, name: address.truncateTezosAddress(), logo: nil) - TransactionService.shared.delegateData.chosenBaker = baker - TransactionService.shared.delegateData.isAdd = true + self.showLoadingView() + + if let foundBaker = viewModel.bakerFor(address: address) { + TransactionService.shared.delegateData.chosenBaker = foundBaker + TransactionService.shared.delegateData.isAdd = true + + } else { + let baker = TzKTBaker(address: address, name: address.truncateTezosAddress(), logo: nil) + TransactionService.shared.delegateData.chosenBaker = baker + TransactionService.shared.delegateData.isAdd = true + } } createOperationsAndConfirm(toAddress: address) } public func stakeTapped() { + self.showLoadingView() + if let baker = TransactionService.shared.delegateData.chosenBaker { createOperationsAndConfirm(toAddress: baker.address) } @@ -86,7 +98,6 @@ class StakeViewController: UIViewController { return } - self.showLoadingView() let operations = OperationFactory.delegateOperation(to: toAddress, from: selectedWallet.address) DependencyManager.shared.tezosNodeClient.estimate(operations: operations, walletAddress: selectedWallet.address, base58EncodedPublicKey: selectedWallet.publicKeyBase58encoded()) { [weak self] estimationResult in self?.hideLoadingView() diff --git a/Kukai Mobile/Modules/Stake/StakeViewModel.swift b/Kukai Mobile/Modules/Stake/StakeViewModel.swift index 328cb47b..40a2f6e8 100644 --- a/Kukai Mobile/Modules/Stake/StakeViewModel.swift +++ b/Kukai Mobile/Modules/Stake/StakeViewModel.swift @@ -24,6 +24,7 @@ class StakeViewModel: ViewModel, UITableViewDiffableDataSourceHandler { private var currentSnapshot = NSDiffableDataSourceSnapshot() var dataSource: UITableViewDiffableDataSource? = nil + var bakers: [TzKTBaker] = [] @@ -93,6 +94,7 @@ class StakeViewModel: ViewModel, UITableViewDiffableDataSourceHandler { return } + self?.bakers = res let filteredResults = res.filter { baker in if baker.address == currentDelegate?.address { currentBaker = baker @@ -152,6 +154,10 @@ class StakeViewModel: ViewModel, UITableViewDiffableDataSourceHandler { return dataSource?.itemIdentifier(for: indexPath) as? TzKTBaker } + func bakerFor(address: String) -> TzKTBaker? { + return bakers.first(where: { $0.address == address }) + } + func isEnterCustom(indePath: IndexPath) -> Bool { if let obj = dataSource?.itemIdentifier(for: indePath) as? StakeHeaderData { return obj.actionTitle != nil From 14db003d424443b7da0ec9ce561ce818b9b2871a Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 21 Jun 2024 11:56:31 +0100 Subject: [PATCH 2/6] rest camera preview layer so it doesn't show the last frame briefly when it reopens --- Kukai Mobile/Controls/ScanViewController.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Kukai Mobile/Controls/ScanViewController.swift b/Kukai Mobile/Controls/ScanViewController.swift index 3b4854cb..bbf7d4f9 100644 --- a/Kukai Mobile/Controls/ScanViewController.swift +++ b/Kukai Mobile/Controls/ScanViewController.swift @@ -51,7 +51,7 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega AVCaptureDevice.requestAccess(for: .video) { [weak self] (response) in DispatchQueue.main.async { if response { - self?.setupVideoPreview() + self?.setupCaptureSession() } else { self?.failed() } @@ -73,6 +73,7 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega textfield.text = nil + setupPreviewLayer() if (captureSession?.isRunning == false) { // Xcode warning, should be run on a background thread in order to avoid hanging UI thread DispatchQueue.global(qos: .background).async { [weak self] in @@ -271,7 +272,7 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega setupClearBox() } - func setupVideoPreview() { + func setupCaptureSession() { captureSession = AVCaptureSession() guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else { return } @@ -301,17 +302,14 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega failed() return } - + } + + func setupPreviewLayer() { previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) previewLayer.frame = previewContainerView.bounds previewLayer.videoGravity = .resizeAspectFill previewContainerView.layer.insertSublayer(previewLayer, at: 0) - // Xcode warning, should be run on a background thread in order to avoid hanging UI thread - DispatchQueue.global(qos: .background).async { [weak self] in - self?.captureSession.startRunning() - } - view.setNeedsLayout() } From da779e2225c17b85355f0330ede5afa0659f41be Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 21 Jun 2024 12:07:24 +0100 Subject: [PATCH 3/6] - clean up missing settings error message - make capture session optional --- .../Controls/ScanViewController.swift | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Kukai Mobile/Controls/ScanViewController.swift b/Kukai Mobile/Controls/ScanViewController.swift index bbf7d4f9..9d12661f 100644 --- a/Kukai Mobile/Controls/ScanViewController.swift +++ b/Kukai Mobile/Controls/ScanViewController.swift @@ -18,8 +18,8 @@ protocol ScanViewControllerDelegate: AnyObject { } class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate { - var captureSession: AVCaptureSession! - var previewLayer: AVCaptureVideoPreviewLayer! = AVCaptureVideoPreviewLayer() + var captureSession: AVCaptureSession? + var previewLayer: AVCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer() let scrollView = AutoScrollView() let titleLabel = UILabel() @@ -77,7 +77,7 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega if (captureSession?.isRunning == false) { // Xcode warning, should be run on a background thread in order to avoid hanging UI thread DispatchQueue.global(qos: .background).async { [weak self] in - self?.captureSession.startRunning() + self?.captureSession?.startRunning() } } @@ -92,7 +92,7 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega if (captureSession?.isRunning == true) { DispatchQueue.global(qos: .background).async { [weak self] in - self?.captureSession.stopRunning() + self?.captureSession?.stopRunning() } } } @@ -284,8 +284,8 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega return } - if (captureSession.canAddInput(videoInput)) { - captureSession.addInput(videoInput) + if captureSession?.canAddInput(videoInput) == true { + captureSession?.addInput(videoInput) } else { failed() return @@ -293,8 +293,8 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega let metadataOutput = AVCaptureMetadataOutput() - if (captureSession.canAddOutput(metadataOutput)) { - captureSession.addOutput(metadataOutput) + if captureSession?.canAddOutput(metadataOutput) == true { + captureSession?.addOutput(metadataOutput) metadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main) metadataOutput.metadataObjectTypes = [.qr] @@ -305,7 +305,11 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega } func setupPreviewLayer() { - previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) + guard let session = captureSession else { + return + } + + previewLayer = AVCaptureVideoPreviewLayer(session: session) previewLayer.frame = previewContainerView.bounds previewLayer.videoGravity = .resizeAspectFill previewContainerView.layer.insertSublayer(previewLayer, at: 0) @@ -319,9 +323,9 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega if permissionsDenied { os_log(.error, log: .default, "User revoked camera permissions") - alertController = UIAlertController(title: "error", message: "NSCameraUsageDescription", preferredStyle: .alert) + alertController = UIAlertController(title: "error".localized(), message: "This app does not have permission to access the camera. If you wish to scan a QRCode, please go to settings and enable camera access", preferredStyle: .alert) - let systemSettingsAction = UIAlertAction(title: "wlt_navigation_settings", style: .default) { (action) in + let systemSettingsAction = UIAlertAction(title: "Settings", style: .default) { (action) in guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else { return } @@ -331,13 +335,13 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega } } - alertController?.addAction(UIAlertAction(title: "cancel", style: .default)) + alertController?.addAction(UIAlertAction(title: "Cancel", style: .default)) alertController?.addAction(systemSettingsAction) } else { os_log(.error, log: .default, "Unable to scan on this device") - alertController = UIAlertController(title: "error", message: "error_cant_scan", preferredStyle: .alert) - alertController?.addAction(UIAlertAction(title: "ok", style: .default)) + alertController = UIAlertController(title: "error".localized(), message: "Unbale to setup camera at this time. Please check camera access is enabled in settings", preferredStyle: .alert) + alertController?.addAction(UIAlertAction(title: "Ok", style: .default)) } if let ac = alertController { From 9ead39330d75aa1d5e7224a1c4e489c733331941 Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 21 Jun 2024 12:29:13 +0100 Subject: [PATCH 4/6] collectible attributes sorted alphabetically --- .../Modules/Collectibles/CollectiblesDetailsViewModel.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Kukai Mobile/Modules/Collectibles/CollectiblesDetailsViewModel.swift b/Kukai Mobile/Modules/Collectibles/CollectiblesDetailsViewModel.swift index 001be0ad..b704deb7 100644 --- a/Kukai Mobile/Modules/Collectibles/CollectiblesDetailsViewModel.swift +++ b/Kukai Mobile/Modules/Collectibles/CollectiblesDetailsViewModel.swift @@ -317,6 +317,9 @@ class CollectiblesDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourc } if self.attributes.count > 0 { + self.attributes = self.attributes.sorted { lhs, rhs in + return lhs.name < rhs.name + } self.currentSnapshot.insertItems([self.attributesContent], afterItem: self.descriptionData) self.currentSnapshot.appendItems(self.attributes, toSection: 1) needsUpdating = true From 88807bca6fa781c1ca5b7b37fc86b709964d6f6d Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 21 Jun 2024 14:14:51 +0100 Subject: [PATCH 5/6] bug fix for accessibility bold text, truncating button text --- .../EnterAddressComponent.xib | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Kukai Mobile/Controls/EnterAddressComponent/EnterAddressComponent.xib b/Kukai Mobile/Controls/EnterAddressComponent/EnterAddressComponent.xib index 8aaea3e9..248b0a72 100644 --- a/Kukai Mobile/Controls/EnterAddressComponent/EnterAddressComponent.xib +++ b/Kukai Mobile/Controls/EnterAddressComponent/EnterAddressComponent.xib @@ -1,8 +1,9 @@ - + - + + @@ -44,13 +45,13 @@ - + @@ -62,8 +63,8 @@ - - + @@ -230,10 +231,10 @@ - + - + @@ -265,7 +266,7 @@ - + From 4e925ad733d1ceef0f2e7ad66fd35ea8a72030eb Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Fri, 21 Jun 2024 14:18:46 +0100 Subject: [PATCH 6/6] update library for new wallet cache logic --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a81c4c7e..2d7d5abd 100644 --- a/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Kukai Mobile.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -70,7 +70,7 @@ "location" : "https://github.com/kukai-wallet/kukai-core-swift", "state" : { "branch" : "develop", - "revision" : "7342af3601139f45da065c67ca71aa060ecccb8f" + "revision" : "922e83b63c68ac275182ae2df5dbf7ce0c4a3ae9" } }, {