diff --git a/damus/Views/ConfigView.swift b/damus/Views/ConfigView.swift index 225d48d7..0c849c04 100644 --- a/damus/Views/ConfigView.swift +++ b/damus/Views/ConfigView.swift @@ -8,6 +8,7 @@ import AVFoundation import Kingfisher import SwiftUI import LocalAuthentication +import Combine struct ConfigView: View { let state: DamusState @@ -131,6 +132,24 @@ struct ConfigView: View { Section(NSLocalizedString("Default Zap Amount in sats", comment: "Section title for zap configuration")) { TextField("1000", text: $default_zap_amount) + .keyboardType(.numberPad) + .onReceive(Just(default_zap_amount)) { newValue in + let filtered = newValue.filter { Set("0123456789").contains($0) } + + if filtered != newValue { + default_zap_amount = filtered + } + + if filtered == "" { + set_default_zap_amount(pubkey: state.pubkey, amount: 1000) + return + } + + guard let amt = Int(filtered) else { + return + } + set_default_zap_amount(pubkey: state.pubkey, amount: amt) + } } Section(NSLocalizedString("Translations", comment: "Section title for selecting the translation service.")) { @@ -208,12 +227,6 @@ struct ConfigView: View { } } } - .onChange(of: default_zap_amount) { val in - guard let amt = Int(val) else { - return - } - set_default_zap_amount(pubkey: state.pubkey, amount: amt) - } .navigationTitle(NSLocalizedString("Settings", comment: "Navigation title for Settings view.")) .navigationBarTitleDisplayMode(.large) .alert(NSLocalizedString("Permanently Delete Account", comment: "Alert for deleting the users account."), isPresented: $confirm_delete_account) {