damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 9080e4efae076cd0459b1a45be589bfd1d5731b9
parent 6ed9c408f901ba1f11548f8211caa342ef925512
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date:   Mon, 13 Feb 2023 23:55:17 -0500

Force default zap amount text field to accept only numbers

Changelog-Fixed: Force default zap amount text field to accept only numbers
Closes: #612

Diffstat:
Mdamus/Views/ConfigView.swift | 25+++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)

diff --git 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) {