add wallet modal

This commit is contained in:
Suhail Saqan
2022-12-22 04:20:37 -06:00
parent 205b1ba731
commit bb6d1b2522
4 changed files with 74 additions and 4 deletions

View File

@@ -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)
}
}
}

View File

@@ -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)!
}

View File

@@ -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)
}
}