From bb6d1b2522f8f2b3ae8896e84a9edb2952200f17 Mon Sep 17 00:00:00 2001 From: Suhail Saqan Date: Thu, 22 Dec 2022 04:20:37 -0600 Subject: [PATCH] add wallet modal --- damus.xcodeproj/project.pbxproj | 4 +++ damus/Components/InvoiceView.swift | 10 +++--- damus/Util/Constants.swift | 13 ++++++++ damus/Views/SelectWalletView.swift | 51 ++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 damus/Views/SelectWalletView.swift diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index 2a30c20..1bb8b7a 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -129,6 +129,7 @@ 4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */; }; 4CEE2AF9280B2EAC00AB5EEF /* PowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */; }; 4CEE2B02280B39E800AB5EEF /* EventActionBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */; }; + BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -306,6 +307,7 @@ 4CEE2AF6280B2DEA00AB5EEF /* ProfileName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileName.swift; sourceTree = ""; }; 4CEE2AF8280B2EAC00AB5EEF /* PowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PowView.swift; sourceTree = ""; }; 4CEE2B01280B39E800AB5EEF /* EventActionBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventActionBar.swift; sourceTree = ""; }; + BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectWalletView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -473,6 +475,7 @@ 4C216F31286E388800040376 /* DMChatView.swift */, 4C216F33286F5ACD00040376 /* DMView.swift */, 4C06670028FC7C5900038D2A /* RelayView.swift */, + BAB68BEC29543FA3007BA466 /* SelectWalletView.swift */, ); path = Views; sourceTree = ""; @@ -797,6 +800,7 @@ 4C3AC79F2833115300E1F516 /* FollowButtonView.swift in Sources */, 4C3BEFD22819DB9B00B3DE84 /* ProfileModel.swift in Sources */, 4C0A3F93280F66F5000448DE /* ReplyMap.swift in Sources */, + BAB68BED29543FA3007BA466 /* SelectWalletView.swift in Sources */, 3169CAE6294E69C000EE4006 /* EmptyTimelineView.swift in Sources */, 4C3EA64928FF597700C48A62 /* bech32.c in Sources */, 4C90BD162839DB54008EE7EF /* NostrMetadata.swift in Sources */, diff --git a/damus/Components/InvoiceView.swift b/damus/Components/InvoiceView.swift index 8ac1ab4..0cab40f 100644 --- a/damus/Components/InvoiceView.swift +++ b/damus/Components/InvoiceView.swift @@ -9,13 +9,13 @@ import SwiftUI struct InvoiceView: View { let invoice: Invoice + @State var show_select_wallet: Bool = false + @State var inv: String = "" var PayButton: some View { Button("Pay") { - guard let url = URL(string: "lightning:" + invoice.string) else { - return - } - UIApplication.shared.open(url) + inv = invoice.string + show_select_wallet = true } .buttonStyle(.bordered) } @@ -39,6 +39,8 @@ struct InvoiceView: View { .zIndex(5.0) } .padding() + } .sheet(isPresented: $show_select_wallet, onDismiss: {show_select_wallet = false}) { + SelectWalletView(show_select_wallet: $show_select_wallet, invoice: $inv) } } } diff --git a/damus/Util/Constants.swift b/damus/Util/Constants.swift index cca0fb4..3f4dba3 100644 --- a/damus/Util/Constants.swift +++ b/damus/Util/Constants.swift @@ -22,4 +22,17 @@ public class Constants { NostrEvent(content: "Hello World! This is so cool!", pubkey: "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"), NostrEvent(content: "Nostr - Damus... Haha get it?", pubkey: "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681"), ] + + static let WALLETS = """ + [ + {"id": 0, "name": "Strike", "link": "strike:lightning", "appStoreLink": "https://apps.apple.com/us/app/strike-bitcoin-payments/id1488724463"}, + {"id": 1, "name": "Cash App", "link": "squarecash://", "appStoreLink": "https://apps.apple.com/us/app/cash-app/id711923939"}, + {"id": 2, "name": "Muun", "link": "muun:", "appStoreLink": "https://apps.apple.com/us/app/muun-wallet/id1482037683"}, + {"id": 3, "name": "Blue Wallet", "link": "bluewallet:lightning", "appStoreLink": "https://apps.apple.com/us/app/bluewallet-bitcoin-wallet/id1376878040"}, + {"id": 4, "name": "Wallet Of Satoshi", "link": "walletofsatoshi:lightning", "appStoreLink": "https://apps.apple.com/us/app/wallet-of-satoshi/id1438599608"}, + {"id": 5, "name": "Breez", "link": "breez:lightning", "appStoreLink": "https://testflight.apple.com/join/wPju2Du7"}, + {"id": 6, "name": "Zebedee", "link": "zebedee:lightning", "appStoreLink": "https://apps.apple.com/us/app/zebedee-wallet/id1484394401"}, + {"id": 7, "name": "Zeus LN", "link": "zeusln:lightning", "appStoreLink": "https://apps.apple.com/us/app/zeus-ln/id1456038895"}, + ] + """.data(using: .utf8)! } diff --git a/damus/Views/SelectWalletView.swift b/damus/Views/SelectWalletView.swift new file mode 100644 index 0000000..a2e4c31 --- /dev/null +++ b/damus/Views/SelectWalletView.swift @@ -0,0 +1,51 @@ +// +// SelectWalletView.swift +// damus +// +// Created by Suhail Saqan on 12/22/22. +// + +import SwiftUI + +struct WalletItem : Decodable, Identifiable { + var id: Int + var name : String + var link : String + var appStoreLink : String +} + +struct SelectWalletView: View { + @Binding var show_select_wallet: Bool + @Binding var invoice: String + @Environment(\.openURL) private var openURL + + let walletItems = try! JSONDecoder().decode([WalletItem].self, from: Constants.WALLETS) + + var body: some View { + VStack(alignment: .leading) { + ForEach(walletItems) { wallet in + HStack(spacing: 20) { + Button("\(wallet.name)"){ + if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) { + openURL(url) + } else { + if let url = URL(string: wallet.appStoreLink), UIApplication.shared.canOpenURL(url) { + openURL(url) + } + } + }.buttonStyle(.borderedProminent) + .contentShape(Rectangle()) + } + } + } + } +} + +struct SelectWalletView_Previews: PreviewProvider { + @State static var show: Bool = true + @State static var invoice: String = "" + + static var previews: some View { + SelectWalletView(show_select_wallet: $show, invoice: $invoice) + } +}