ZapSettingsView.swift (3460B)
1 // 2 // WalletSettingsView.swift 3 // damus 4 // 5 // Created by William Casarin on 2023-04-05. 6 // 7 8 import SwiftUI 9 import Combine 10 11 struct ZapSettingsView: View { 12 @ObservedObject var settings: UserSettingsStore 13 14 @State var default_zap_amount: String 15 @Environment(\.dismiss) var dismiss 16 17 init(settings: UserSettingsStore) { 18 _default_zap_amount = State(initialValue: settings.default_zap_amount.formatted()) 19 self._settings = ObservedObject(initialValue: settings) 20 } 21 22 var body: some View { 23 Form { 24 Section( 25 header: Text(NSLocalizedString("OnlyZaps", comment: "Section header for enabling OnlyZaps mode (hide reactions)")), 26 footer: Text(NSLocalizedString("Hide all 🤙's", comment: "Section footer describing OnlyZaps mode")) 27 28 ) { 29 Toggle(NSLocalizedString("OnlyZaps mode", comment: "Setting toggle to hide reactions."), isOn: $settings.onlyzaps_mode) 30 .toggleStyle(.switch) 31 .onChange(of: settings.onlyzaps_mode) { newVal in 32 notify(.onlyzaps_mode(newVal)) 33 } 34 } 35 36 Section(NSLocalizedString("Wallet", comment: "Title for section in zap settings that controls the Lightning wallet selection.")) { 37 38 Toggle(NSLocalizedString("Show wallet selector", comment: "Toggle to show or hide selection of wallet."), isOn: $settings.show_wallet_selector).toggleStyle(.switch) 39 Picker(NSLocalizedString("Select default wallet", comment: "Prompt selection of user's default wallet"), 40 selection: $settings.default_wallet) { 41 ForEach(Wallet.allCases, id: \.self) { wallet in 42 Text(wallet.model.displayName) 43 .tag(wallet.model.tag) 44 } 45 } 46 } 47 48 Section(NSLocalizedString("Zaps", comment: "Title for section in zap settings that controls general zap preferences.")) { 49 Toggle(NSLocalizedString("Zap Vibration", comment: "Setting to enable vibration on zap"), isOn: $settings.zap_vibration) 50 .toggleStyle(.switch) 51 } 52 53 Section(NSLocalizedString("Default Zap Amount in sats", comment: "Title for section in zap settings that controls the default zap amount in sats.")) { 54 TextField(fallback_zap_amount.formatted(), text: $default_zap_amount) 55 .keyboardType(.numberPad) 56 .onReceive(Just(default_zap_amount)) { newValue in 57 if let parsed = handle_string_amount(new_value: newValue) { 58 self.default_zap_amount = parsed.formatted() 59 settings.default_zap_amount = parsed 60 } else { 61 self.default_zap_amount = "" 62 settings.default_zap_amount = 0 63 } 64 } 65 } 66 } 67 .navigationTitle(NSLocalizedString("Zaps", comment: "Navigation title for zap settings.")) 68 .onReceive(handle_notify(.switched_timeline)) { _ in 69 dismiss() 70 } 71 } 72 } 73 74 struct WalletSettingsView_Previews: PreviewProvider { 75 static var previews: some View { 76 ZapSettingsView(settings: UserSettingsStore()) 77 } 78 }