allow opening wallet selector for profile LN button

This commit is contained in:
Suhail Saqan
2022-12-24 20:44:10 -06:00
parent 70756938d7
commit dd50ffd555
3 changed files with 20 additions and 11 deletions

View File

@@ -9,13 +9,13 @@ import SwiftUI
struct InvoiceView: View { struct InvoiceView: View {
let invoice: Invoice let invoice: Invoice
@State var show_select_wallet: Bool = false @State var showingSelectWallet: Bool = false
@State var inv: String = "" @State var inv: String = ""
var PayButton: some View { var PayButton: some View {
Button("Pay") { Button("Pay") {
inv = invoice.string inv = invoice.string
show_select_wallet = true showingSelectWallet = true
} }
.buttonStyle(.bordered) .buttonStyle(.bordered)
} }
@@ -39,8 +39,8 @@ struct InvoiceView: View {
.zIndex(5.0) .zIndex(5.0)
} }
.padding() .padding()
} .sheet(isPresented: $show_select_wallet, onDismiss: {show_select_wallet = false}) { }.sheet(isPresented: $showingSelectWallet, onDismiss: {showingSelectWallet = false}) {
SelectWalletView(show_select_wallet: $show_select_wallet, invoice: $inv) SelectWalletView(showingSelectWallet: $showingSelectWallet, invoice: $inv)
} }
} }
} }

View File

@@ -118,20 +118,29 @@ struct ProfileView: View {
@StateObject var profile: ProfileModel @StateObject var profile: ProfileModel
@StateObject var followers: FollowersModel @StateObject var followers: FollowersModel
@State private var showingEditProfile = false @State private var showingEditProfile = false
@State var showingSelectWallet: Bool = false
@State var inv: String = ""
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
@Environment(\.colorScheme) var colorScheme @Environment(\.colorScheme) var colorScheme
//@EnvironmentObject var profile: ProfileModel //@EnvironmentObject var profile: ProfileModel
func LNButton(_ url: URL) -> some View { func LNButton(lud06: String?, lud16: String?) -> some View {
Button(action: { Button(action: {
UIApplication.shared.open(url) if let l = lud06 {
inv = l
} else {
inv = lud16 ?? ""
}
showingSelectWallet = true
}) { }) {
Image(systemName: "bolt.circle") Image(systemName: "bolt.circle")
.symbolRenderingMode(.palette) .symbolRenderingMode(.palette)
.font(.system(size: 34).weight(.thin)) .font(.system(size: 34).weight(.thin))
.foregroundStyle(colorScheme == .light ? .black : .white, colorScheme == .light ? .black.opacity(0.1) : .white.opacity(0.2)) .foregroundStyle(colorScheme == .light ? .black : .white, colorScheme == .light ? .black.opacity(0.1) : .white.opacity(0.2))
}.sheet(isPresented: $showingSelectWallet, onDismiss: {showingSelectWallet = false}) {
SelectWalletView(showingSelectWallet: $showingSelectWallet, invoice: $inv)
} }
} }
@@ -156,8 +165,8 @@ struct ProfileView: View {
Spacer() Spacer()
if let lnuri = data?.lightning_uri { if (data != nil) && (data?.lud06 != nil || data?.lud16 != nil) {
LNButton(lnuri) LNButton(lud06: data?.lud06, lud16: data?.lud16)
} }
DMButton DMButton

View File

@@ -16,7 +16,7 @@ struct WalletItem : Decodable, Identifiable, Hashable {
} }
struct SelectWalletView: View { struct SelectWalletView: View {
@Binding var show_select_wallet: Bool @Binding var showingSelectWallet: Bool
@Binding var invoice: String @Binding var invoice: String
@Environment(\.openURL) private var openURL @Environment(\.openURL) private var openURL
@State var invoice_copied: Bool = false @State var invoice_copied: Bool = false
@@ -78,7 +78,7 @@ struct SelectWalletView: View {
} }
} }
}.navigationBarTitle(Text("Pay the lightning invoice"), displayMode: .inline).navigationBarItems(trailing: Button(action: { }.navigationBarTitle(Text("Pay the lightning invoice"), displayMode: .inline).navigationBarItems(trailing: Button(action: {
self.show_select_wallet = false self.showingSelectWallet = false
}) { }) {
Text("Done").bold() Text("Done").bold()
}) })
@@ -91,6 +91,6 @@ struct SelectWalletView_Previews: PreviewProvider {
@State static var invoice: String = "" @State static var invoice: String = ""
static var previews: some View { static var previews: some View {
SelectWalletView(show_select_wallet: $show, invoice: $invoice) SelectWalletView(showingSelectWallet: $show, invoice: $invoice)
} }
} }