Skip to content

Commit

Permalink
Merge branch 'feature/stability_improvements' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Jun 21, 2024
2 parents 236d832 + 4e925ad commit f7b847a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"location" : "https://github.com/kukai-wallet/kukai-core-swift",
"state" : {
"branch" : "develop",
"revision" : "7342af3601139f45da065c67ca71aa060ecccb8f"
"revision" : "922e83b63c68ac275182ae2df5dbf7ce0c4a3ae9"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="dark"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -44,13 +45,13 @@
<rect key="frame" x="0.0" y="0.0" width="602" height="30"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Send to:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3BH-hp-rC3">
<rect key="frame" x="0.0" y="0.0" width="53" height="30"/>
<rect key="frame" x="0.0" y="0.0" width="53.5" height="30"/>
<fontDescription key="fontDescription" name="Figtree-SemiBold" family="Figtree" pointSize="14"/>
<color key="textColor" name="Txt10"/>
<color key="highlightedColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" distribution="equalCentering" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="zCc-Un-MPC">
<rect key="frame" x="57" y="0.0" width="16" height="30"/>
<rect key="frame" x="57.5" y="0.0" width="16" height="30"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Social_TZ_1color" translatesAutoresizingMaskIntoConstraints="NO" id="vZE-UR-e9Q">
<rect key="frame" x="0.0" y="7" width="16" height="16"/>
Expand All @@ -62,8 +63,8 @@
</imageView>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" horizontalHuggingPriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cJo-dB-oV7" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="77" y="0.0" width="139" height="30"/>
<button opaque="NO" contentMode="scaleToFill" semanticContentAttribute="forceRightToLeft" horizontalHuggingPriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="clip" translatesAutoresizingMaskIntoConstraints="NO" id="cJo-dB-oV7" customClass="CustomisableButton" customModule="Kukai_Mobile" customModuleProvider="target">
<rect key="frame" x="77.5" y="0.0" width="132" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="cL4-Pd-8X8"/>
</constraints>
Expand Down Expand Up @@ -91,7 +92,7 @@
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Tbg-bU-5Xa">
<rect key="frame" x="220" y="0.0" width="382" height="30"/>
<rect key="frame" x="213.5" y="0.0" width="388.5" height="30"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</subviews>
Expand Down Expand Up @@ -230,10 +231,10 @@
<size key="intrinsicContentSize" width="36" height="36"/>
</designable>
<designable name="NiH-S7-rDy">
<size key="intrinsicContentSize" width="109.5" height="20.5"/>
<size key="intrinsicContentSize" width="104" height="21"/>
</designable>
<designable name="cJo-dB-oV7">
<size key="intrinsicContentSize" width="139" height="17"/>
<size key="intrinsicContentSize" width="132" height="17"/>
</designable>
</designables>
<resources>
Expand Down Expand Up @@ -265,7 +266,7 @@
<color red="1" green="0.45899999141693115" blue="0.62000000476837158" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="labelColor">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="secondaryLabelColor">
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
44 changes: 23 additions & 21 deletions Kukai Mobile/Controls/ScanViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}
Expand All @@ -73,10 +73,11 @@ 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
self?.captureSession.startRunning()
self?.captureSession?.startRunning()
}
}

Expand All @@ -91,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()
}
}
}
Expand Down Expand Up @@ -271,7 +272,7 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega
setupClearBox()
}

func setupVideoPreview() {
func setupCaptureSession() {
captureSession = AVCaptureSession()

guard let videoCaptureDevice = AVCaptureDevice.default(for: .video) else { return }
Expand All @@ -283,35 +284,36 @@ class ScanViewController: UIViewController, AVCaptureMetadataOutputObjectsDelega
return
}

if (captureSession.canAddInput(videoInput)) {
captureSession.addInput(videoInput)
if captureSession?.canAddInput(videoInput) == true {
captureSession?.addInput(videoInput)
} else {
failed()
return
}

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]
} else {
failed()
return
}
}

func setupPreviewLayer() {
guard let session = captureSession else {
return
}

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer = AVCaptureVideoPreviewLayer(session: session)
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()
}

Expand All @@ -321,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
}
Expand All @@ -333,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions Kukai Mobile/Modules/Stake/StakeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() ?? ""
Expand All @@ -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)
}
Expand All @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions Kukai Mobile/Modules/Stake/StakeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class StakeViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
private var currentSnapshot = NSDiffableDataSourceSnapshot<Int, AnyHashable>()

var dataSource: UITableViewDiffableDataSource<Int, AnyHashable>? = nil
var bakers: [TzKTBaker] = []



Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f7b847a

Please sign in to comment.