Files
damus/damus/Views/QRScanNSECView.swift
Jericho Hasselbush 439f9974c5 login: add nsec qr-scanning
- Allow scanning of QR codes, and if detects a nsec, will provide it to
  the login prompt.

- If nsec is found, provides option to keep nsec in keychain; default is
  to not store

- User stays logged in until they logout, or app is force-quit if nsec
  is not stored.

damusApp.swift:
  Obtains keypair from the notification generated to allow login.

LoginView.swift:
  New views allowing for adding and logic handling the QR reader in
  QRScanNSECView.swift to enable QR scan for nsec.

QRScanNSECView.swift:
  New view to scan for QR code. The sparkling magnifying glass is enabled
  if the view calling the QR view changes the privKeyFound bound variable.

Tipjar: npub1el277q4kesp8vhs7rq6qkwnhpxfp345u7tnuxykwr67d9wg0wvyslam5n0
Closes: https://github.com/damus-io/damus/issues/1291
Changelog-Added: Add QR scan nsec logins.
Signed-off-by: Jericho Hasselbush <jericho@sal-et-lucem.com>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
2023-10-16 03:12:53 +02:00

67 lines
2.2 KiB
Swift

//
// QRScanNSECView.swift
// damus
//
// Created by Jericho Hasselbush on 9/29/23.
//
import SwiftUI
import VisionKit
struct QRScanNSECView: View {
@Binding var showQR: Bool
@Binding var privKeyFound: Bool
var codeScannerCompletion: (Result<ScanResult, ScanError>) -> Void
var body: some View {
ZStack {
ZStack {
DamusGradient()
}
VStack {
Text("Scan Your Private Key QR",
comment: "Text to prompt scanning a QR code of a user's privkey to login to their profile.")
.padding(.top, 50)
.font(.system(size: 24, weight: .heavy))
Spacer()
CodeScannerView(codeTypes: [.qr],
scanMode: .continuous,
scanInterval: 2.0,
showViewfinder: false,
simulatedData: "",
shouldVibrateOnSuccess: false,
isTorchOn: false,
isGalleryPresented: .constant(false),
videoCaptureDevice: .default(for: .video),
completion: codeScannerCompletion)
.scaledToFit()
.frame(width: 300, height: 300)
.cornerRadius(10)
.overlay(RoundedRectangle(cornerRadius: 10).stroke(DamusColors.white, lineWidth: 5.0))
.shadow(radius: 10)
Button(action: { showQR = false }) {
VStack {
Image(systemName: privKeyFound ? "sparkle.magnifyingglass" : "magnifyingglass")
.font(privKeyFound ? .title : .title3)
}}
.padding(.top)
.buttonStyle(GradientButtonStyle())
Spacer()
Spacer()
}
}
}
}
#Preview {
@State var showQR = true
@State var privKeyFound = false
@State var shouldSaveKey = true
return QRScanNSECView(showQR: $showQR,
privKeyFound: $privKeyFound,
codeScannerCompletion: { _ in })
}