diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift index 4cd3ef44..3471843a 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/CoreDataBankingPersistence.swift @@ -89,6 +89,30 @@ class CoreDataBankingPersistence: IBankingPersistence, IRemitteeSearcher { return UserDefaults.standard.data(forKey: filePath) } + func findRemittees(query: String) -> [Remittee] { + var transactions: [PersistedAccountTransaction] = [] + + do { + let request: NSFetchRequest = PersistedAccountTransaction.fetchRequest() + request.returnsObjectsAsFaults = false + + request.predicate = NSPredicate(format: "otherPartyName CONTAINS[c] %@", query) + + request.propertiesToFetch = [ "otherPartyName", "otherPartyBankCode", "otherPartyAccountId" ] + request.sortDescriptors = [ NSSortDescriptor(key: "otherPartyName", ascending: true) ] + + try transactions = context.fetch(request) + } catch { + NSLog("Could not request Customers: \(error)") + } + + let remittees = transactions.map( { Remittee(name: $0.otherPartyName ?? "", iban: $0.otherPartyAccountId, bic: $0.otherPartyBankCode, bankName: nil) } ) + + let uniqueRemittees = Set(remittees) + + return Array(uniqueRemittees) + } + func deleteAll() { do { diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift index ac92eaa9..3a97d99b 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/Extensions.swift @@ -46,6 +46,13 @@ extension BankInfo : Identifiable { } +extension Remittee : Identifiable { + + public var id: String { name.localizedLowercase + "_" + (iban ?? "") } + +} + + extension TanProcedure : Identifiable { public var id: String { self.bankInternalProcedureCode } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/RemitteeListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/RemitteeListItem.swift new file mode 100644 index 00000000..78415564 --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/RemitteeListItem.swift @@ -0,0 +1,46 @@ +import SwiftUI +import BankingUiSwift + + +struct RemitteeListItem: View { + + let remittee: Remittee + + + var body: some View { + VStack { + + HStack { + Text(remittee.name) + .font(.headline) + + Spacer() + } + + HStack { + Text(remittee.bankName ?? "") + + Spacer() + } + .padding(.vertical, 6) + + HStack { + Text(remittee.iban ?? "") + + Text(remittee.bic ?? "") + + Spacer() + } + .padding(.bottom, 6.0) + + } + } +} + +struct RemitteeListItem_Previews: PreviewProvider { + + static var previews: some View { + RemitteeListItem(remittee: Remittee(name: "Marieke Musterfrau", iban: "DE12876543211234567890", bic: "ABZODEBBXX", bankName: "Abzockbank Berlin")) + } + +} diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift index 46b4f1e8..070380c9 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift @@ -17,6 +17,9 @@ struct TransferMoneyDialog: View { @State private var remitteeName: String = "" @State private var isValidRemitteeNameEntered = false + @State private var showRemitteeAutocompleteList = false + @State private var remitteeSearchResults = [Remittee]() + @State private var remitteeIban: String = "" @State private var isValidRemitteeIbanEntered = false @@ -49,6 +52,8 @@ struct TransferMoneyDialog: View { @Inject private var presenter: BankingPresenterSwift + @Inject private var persistence: CoreDataBankingPersistence + init() { self.accountsSupportingTransferringMoney = self.presenter.bankAccounts.filter({ $0.supportsTransferringMoney })