wallet: refactor, make it work with ln tip button
Changelog-Added: Added option to choose default wallet
This commit is contained in:
@@ -17,7 +17,6 @@ struct ConfigView: View {
|
||||
@State var privkey: String
|
||||
@State var privkey_copied: Bool = false
|
||||
@State var pubkey_copied: Bool = false
|
||||
@State var allWallets: [Wallet] = Wallet.allCases
|
||||
@State var relays: [RelayDescriptor]
|
||||
@EnvironmentObject var user_settings: UserSettingsStore
|
||||
|
||||
@@ -95,10 +94,10 @@ struct ConfigView: View {
|
||||
}
|
||||
|
||||
Section("Wallet Selector") {
|
||||
Toggle("Show wallet selector", isOn: $user_settings.showWalletSelector).toggleStyle(.switch)
|
||||
Toggle("Show wallet selector", isOn: $user_settings.show_wallet_selector).toggleStyle(.switch)
|
||||
Picker("Select default wallet",
|
||||
selection: $user_settings.defaultWallet) {
|
||||
ForEach(allWallets, id: \.self) { wallet in
|
||||
selection: $user_settings.default_wallet) {
|
||||
ForEach(Wallet.allCases, id: \.self) { wallet in
|
||||
Text(wallet.model.displayName)
|
||||
.tag(wallet.model.tag)
|
||||
}
|
||||
|
||||
@@ -118,25 +118,23 @@ struct ProfileView: View {
|
||||
@State private var selected_tab: ProfileTab = .posts
|
||||
@StateObject var profile: ProfileModel
|
||||
@StateObject var followers: FollowersModel
|
||||
@StateObject var user_settings = UserSettingsStore()
|
||||
@State private var showingEditProfile = false
|
||||
@State var showingSelectWallet: Bool = false
|
||||
@State var inv: String = ""
|
||||
@State var showing_select_wallet: Bool = false
|
||||
@State var is_zoomed: Bool = false
|
||||
@StateObject var user_settings = UserSettingsStore()
|
||||
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
//@EnvironmentObject var profile: ProfileModel
|
||||
|
||||
func LNButton(lud06: String?, lud16: String?, profile: Profile) -> some View {
|
||||
func LNButton(lnurl: String, profile: Profile) -> some View {
|
||||
Button(action: {
|
||||
if let l = lud06 {
|
||||
inv = l
|
||||
if user_settings.show_wallet_selector {
|
||||
showing_select_wallet = true
|
||||
} else {
|
||||
inv = lud16 ?? ""
|
||||
open_with_wallet(wallet: user_settings.default_wallet.model, invoice: lnurl)
|
||||
}
|
||||
showingSelectWallet = true
|
||||
}) {
|
||||
Image(systemName: "bolt.circle")
|
||||
.symbolRenderingMode(.palette)
|
||||
@@ -149,8 +147,8 @@ struct ProfileView: View {
|
||||
Label("Copy LNURL", systemImage: "doc.on.doc")
|
||||
}
|
||||
}
|
||||
}.sheet(isPresented: $showingSelectWallet, onDismiss: {showingSelectWallet = false}) {
|
||||
SelectWalletView(showingSelectWallet: $showingSelectWallet, invoice: $inv)
|
||||
}.sheet(isPresented: $showing_select_wallet, onDismiss: {showing_select_wallet = false}) {
|
||||
SelectWalletView(showingSelectWallet: $showing_select_wallet, invoice: lnurl)
|
||||
.environmentObject(user_settings)
|
||||
}
|
||||
}
|
||||
@@ -183,8 +181,8 @@ struct ProfileView: View {
|
||||
Spacer()
|
||||
|
||||
if let profile = data {
|
||||
if (profile.lud06 != nil || profile.lud16 != nil) {
|
||||
LNButton(lud06: profile.lud06, lud16: profile.lud16, profile: profile)
|
||||
if let lnurl = profile.lnurl {
|
||||
LNButton(lnurl: lnurl, profile: profile)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
struct SelectWalletView: View {
|
||||
@Binding var showingSelectWallet: Bool
|
||||
@Binding var invoice: String
|
||||
let invoice: String
|
||||
@Environment(\.openURL) private var openURL
|
||||
@State var invoice_copied: Bool = false
|
||||
@EnvironmentObject var user_settings: UserSettingsStore
|
||||
@@ -38,7 +38,7 @@ struct SelectWalletView: View {
|
||||
Section("Select a lightning wallet"){
|
||||
List{
|
||||
Button() {
|
||||
let walletModel = user_settings.defaultWallet.model
|
||||
let walletModel = user_settings.default_wallet.model
|
||||
if let url = URL(string: "\(walletModel.link)\(invoice)"), UIApplication.shared.canOpenURL(url) {
|
||||
openURL(url)
|
||||
} else {
|
||||
@@ -85,6 +85,6 @@ struct SelectWalletView_Previews: PreviewProvider {
|
||||
@State static var invoice: String = ""
|
||||
|
||||
static var previews: some View {
|
||||
SelectWalletView(showingSelectWallet: $show, invoice: $invoice)
|
||||
SelectWalletView(showingSelectWallet: $show, invoice: "")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user