commit 16f910c035c946f06888775b642bddd65706f2cc
parent a7951193abd3778252650eb13bd18653d1e162e5
Author: William Casarin <jb55@jb55.com>
Date: Sat, 8 Oct 2022 07:52:44 -0700
load from clipboard
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 48 insertions(+), 16 deletions(-)
diff --git a/lightninglink.xcodeproj/project.pbxproj b/lightninglink.xcodeproj/project.pbxproj
@@ -568,7 +568,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 2;
+ CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"lightninglink/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -590,7 +590,7 @@
"$(PROJECT_DIR)/lnsocket/target/ios",
);
MACOSX_DEPLOYMENT_TARGET = 12.2;
- MARKETING_VERSION = 0.4;
+ MARKETING_VERSION = 0.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.lightninglink;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -609,7 +609,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 2;
+ CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"lightninglink/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -631,7 +631,7 @@
"$(PROJECT_DIR)/lnsocket/target/ios",
);
MACOSX_DEPLOYMENT_TARGET = 12.2;
- MARKETING_VERSION = 0.4;
+ MARKETING_VERSION = 0.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.lightninglink;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
diff --git a/lightninglink/Views/AuthView.swift b/lightninglink/Views/AuthView.swift
@@ -75,7 +75,7 @@ struct AuthView: View {
return
}
- guard var msg = hex_decode(auth.k1) else {
+ guard let msg = hex_decode(auth.k1) else {
self.error = "Could not decode k1 challenge string as hex: '\(auth.k1)'"
return
}
@@ -83,6 +83,7 @@ struct AuthView: View {
let opts = UInt32(SECP256K1_CONTEXT_SIGN)
guard let ctx = secp256k1_context_create(opts) else {
+ self.error = "Could not create secp256k1 context"
return
}
diff --git a/lightninglink/Views/SetupView.swift b/lightninglink/Views/SetupView.swift
@@ -29,7 +29,7 @@ public enum SetupResult {
public enum SetupViewState {
case initial
case validating(LNLink)
- case validated
+ case validated(LNLink)
}
func initial_state() -> SetupViewState {
@@ -46,7 +46,7 @@ struct SetupView: View {
@State var state: SetupViewState = initial_state()
@State var error: String? = nil
@State var dashboard: Dashboard = .empty
- @State var lnlink: LNLink? = nil
+ @State var has_clipboard_lnlink: Bool = false
@State var scan_invoice: String? = nil
func perform_validation(_ lnlink: LNLink) {
@@ -64,9 +64,8 @@ struct SetupView: View {
self.error = str
case .success(let info, let funds):
save_lnlink(lnlink: lnlink)
- self.lnlink = lnlink
self.dashboard = Dashboard(info: info, funds: funds)
- self.state = .validated
+ self.state = .validated(lnlink)
self.error = nil
}
}
@@ -83,7 +82,20 @@ struct SetupView: View {
.foregroundColor(.gray)
Spacer()
+
+ Button("Use LNLink from Clipboard") {
+ guard let lnlink = check_clipboard_lnlink() else {
+ self.error = "No clipboard lnlink found"
+ return
+ }
+ self.state = .validating(lnlink)
+ }
+ .foregroundColor(Color.blue)
+ .padding()
+ .background(Color(.secondarySystemBackground))
+ .cornerRadius(16)
+
Button("Scan LNLink QR Code") {
self.active_sheet = .qr
}
@@ -149,8 +161,8 @@ struct SetupView: View {
setup_view()
case .validating(let lnlink):
validating_view(lnlink: lnlink)
- case .validated:
- ContentView(dashboard: self.dashboard, lnlink: self.lnlink!, scan_invoice: self.scan_invoice)
+ case .validated(let lnlink):
+ ContentView(dashboard: self.dashboard, lnlink: lnlink, scan_invoice: self.scan_invoice)
}
}
}
@@ -162,6 +174,24 @@ struct SetupView_Previews: PreviewProvider {
}
}
+func check_clipboard_lnlink() -> LNLink? {
+ guard UIPasteboard.general.hasStrings else {
+ return nil
+ }
+
+ guard let clip = UIPasteboard.general.string else {
+ return nil
+ }
+
+ let m_lnlink = parse_auth_qr(clip)
+
+ switch m_lnlink {
+ case .left:
+ return nil
+ case .right(let lnlink):
+ return lnlink
+ }
+}
func get_qs_param(qs: URLComponents, param: String) -> String? {
return qs.queryItems?.first(where: { $0.name == param })?.value
@@ -236,3 +266,8 @@ func validate_connection(lnlink: LNLink, completion: @escaping (SetupResult) ->
}
}
}
+
+
+func handle_scan(_ str: String) {
+
+}
diff --git a/lightninglink/lightninglinkApp.swift b/lightninglink/lightninglinkApp.swift
@@ -39,10 +39,6 @@ func fetch_dashboard(lnlink: LNLink) -> Either<String, Dashboard> {
@main
struct lightninglinkApp: App {
- @State var dashboard: Dashboard?
- @State var lnlink: LNLink? = load_lnlink()
- @State var error: String?
-
var body: some Scene {
WindowGroup {
SetupView()
diff --git a/lightninglinkTests/lightninglinkTests.swift b/lightninglinkTests/lightninglinkTests.swift
@@ -38,7 +38,7 @@ class lightninglinkTests: XCTestCase {
let amt = mamt!
switch amt {
- case .amount(let _):
+ case .amount:
XCTAssert(false)
case .any:
XCTAssert(true)