add show toggle and default wallet selector

This commit is contained in:
Suhail Saqan
2022-12-29 06:04:58 -06:00
parent 754b47d693
commit d10ee72fec
8 changed files with 184 additions and 44 deletions

View File

@@ -17,7 +17,10 @@ struct ConfigView: View {
@State var privkey: String
@State var privkey_copied: Bool = false
@State var pubkey_copied: Bool = false
@EnvironmentObject var user_settings: UserSettingsStore
let walletItems: [WalletItem] = get_wallet_list()
let generator = UIImpactFeedbackGenerator(style: .light)
init(state: DamusState) {
@@ -78,6 +81,17 @@ struct ConfigView: View {
}
}
Section("Wallet Selector") {
Toggle("Show wallet selector", isOn: $user_settings.showwalletselector).toggleStyle(.switch)
if walletItems != [] {
Picker(selection: $user_settings.defaultwallet, label: Text("Select default wallet"), content: {
ForEach(walletItems, id: \.self) { wallet in
Text(wallet.name).tag(get_wallet_tag(wallet.tag))
}
})
}
}
Section("Reset") {
Button("Logout") {
confirm_logout = true

View File

@@ -118,6 +118,7 @@ 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 = ""
@@ -149,7 +150,7 @@ struct ProfileView: View {
}
}
}.sheet(isPresented: $showingSelectWallet, onDismiss: {showingSelectWallet = false}) {
SelectWalletView(showingSelectWallet: $showingSelectWallet, invoice: $inv)
SelectWalletView(showingSelectWallet: $showingSelectWallet, invoice: $inv).environmentObject(user_settings)
}
}

View File

@@ -7,23 +7,15 @@
import SwiftUI
struct WalletItem : Decodable, Identifiable, Hashable {
var id: Int
var name : String
var link : String
var appStoreLink : String
var image: String
}
struct SelectWalletView: View {
@Binding var showingSelectWallet: Bool
@Binding var invoice: String
@Environment(\.openURL) private var openURL
@State var invoice_copied: Bool = false
@EnvironmentObject var user_settings: UserSettingsStore
let generator = UIImpactFeedbackGenerator(style: .light)
let walletItems = try! JSONDecoder().decode([WalletItem].self, from: Constants.WALLETS)
let walletItems: [WalletItem] = get_wallet_list()
var body: some View {
NavigationView {
@@ -46,8 +38,13 @@ struct SelectWalletView: View {
Section("Select a lightning wallet"){
List{
Button() {
if let url = URL(string: "lightning:\(invoice)"), UIApplication.shared.canOpenURL(url) {
let wallet = get_default_wallet(user_settings.defaultwallet.rawValue)
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)
}
}
} label: {
HStack {
@@ -55,21 +52,22 @@ struct SelectWalletView: View {
}
}.buttonStyle(.plain)
ForEach(walletItems, id: \.self) { wallet in
Button() {
if let url = URL(string: "\(wallet.link)\(invoice)"), UIApplication.shared.canOpenURL(url) {
print("opening wallet url \(url)")
openURL(url)
} else {
if let url = URL(string: wallet.appStoreLink), UIApplication.shared.canOpenURL(url) {
if (wallet.id >= 0){
Button() {
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)
}
}
}
} label: {
HStack {
Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5)
Text(wallet.name).font(.body)
}
}.buttonStyle(.plain)
} label: {
HStack {
Image(wallet.image).resizable().frame(width: 32.0, height: 32.0,alignment: .center).cornerRadius(5)
Text(wallet.name).font(.body)
}
}.buttonStyle(.plain)
}
}
}.padding(.vertical, 2.5)
}