Implemented searching for banks with imported BankFinder

This commit is contained in:
dankito 2020-07-11 20:59:52 +02:00
parent 79906f3dbb
commit be8d9c96d2
1 changed files with 24 additions and 4 deletions

View File

@ -1,17 +1,32 @@
import SwiftUI import SwiftUI
import fints4k
import BankFinder
struct AddAccountDialog: View { struct AddAccountDialog: View {
@State private var bankCode = "" @State private var enteredBank = ""
@State private var customerId = "" @State private var customerId = ""
@State private var password = "" @State private var password = ""
@State private var bank: BankInfo? = nil
private let bankFinder = InMemoryBankFinder()
var body: some View { var body: some View {
NavigationView { let textValueBinding = Binding<String>(get: {
self.enteredBank
}, set: {
self.enteredBank = $0
self.findBank()
})
return NavigationView {
Form { Form {
Section { Section {
TextField("Bank code", text: $bankCode) TextField("Bank code", text: textValueBinding)
} }
Section { Section {
@ -34,8 +49,13 @@ struct AddAccountDialog: View {
} }
} }
func findBank() {
self.bank = bankFinder.findBankByNameBankCodeOrCity(query: enteredBank).first
}
func isRequiredDataEntered() -> Bool { func isRequiredDataEntered() -> Bool {
return bankCode.isEmpty == false return bank != nil
&& customerId.isEmpty == false && customerId.isEmpty == false
&& password.isEmpty == false && password.isEmpty == false
} }