Customized Zaps

Changelog-Added: Customized zaps
This commit is contained in:
William Casarin
2023-02-25 12:10:37 -08:00
parent 64b1a57918
commit 71f7ea47df
13 changed files with 458 additions and 86 deletions
+18 -15
View File
@@ -129,26 +129,14 @@ struct ConfigView: View {
}
}
Section(NSLocalizedString("Default Zap Amount in sats", comment: "Section title for zap configuration")) {
TextField(String("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 let parsed = handle_string_amount(new_value: newValue) {
self.default_zap_amount = String(parsed)
}
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)
}
}
@@ -346,3 +334,18 @@ struct ConfigView_Previews: PreviewProvider {
}
}
}
func handle_string_amount(new_value: String) -> Int? {
let filtered = new_value.filter { Set("0123456789").contains($0) }
if filtered == "" {
return nil
}
guard let amt = Int(filtered) else {
return nil
}
return amt
}