diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift index 2c3971d4..fd61390d 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift @@ -1,6 +1,35 @@ import SwiftUI +extension String { + + var isNotEmpty: Bool { + return !isEmpty + } + + var isBlank: Bool { + return isEmpty || trimmingCharacters(in: .whitespaces).isEmpty + } + + var isNotBlank: Bool { + return !isBlank + } + +} + +extension Optional where Wrapped == String { + + var isNullOrEmpty: Bool { + return self?.isEmpty ?? true + } + + var isNullOrBlank: Bool { + return self?.isBlank ?? true + } + +} + + extension NSDecimalNumber { func isPositive() -> Bool { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift index 0f0f211a..6956b8ca 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift @@ -80,7 +80,7 @@ struct AccountTransactionsDialog: View { private func filterTransactions(_ query: String) { self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query) - self.balanceOfFilteredTransactions = query.isEmpty ? balanceOfAllTransactions : filteredTransactions.sumAmounts() + self.balanceOfFilteredTransactions = query.isBlank ? balanceOfAllTransactions : filteredTransactions.sumAmounts() } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift index c992b5c7..fe8b4a80 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift @@ -63,8 +63,8 @@ struct AddAccountDialog: View { func isRequiredDataEntered() -> Bool { return bank != nil - && customerId.isEmpty == false - && password.isEmpty == false + && customerId.isNotBlank + && password.isNotBlank } func addAccount() { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift index a5ac94ed..4839ba14 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift @@ -136,7 +136,7 @@ struct EnterTanDialog: View { Spacer() Button(action: { self.enteringTanDone() }, label: { Text("OK") }) - .disabled(self.enteredTan.isEmpty) + .disabled(self.enteredTan.isBlank) Spacer() } } @@ -202,7 +202,7 @@ struct EnterTanDialog: View { private func enteringTanDone() { let companion = EnterTanResult.Companion() - let result = enteredTan.isEmpty ? companion.userDidNotEnterTan() : companion.userEnteredTan(enteredTan: enteredTan) + let result = enteredTan.isBlank ? companion.userDidNotEnterTan() : companion.userEnteredTan(enteredTan: enteredTan) sendEnterTanResult(result) } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift index 3f4c61c8..87fb3b67 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift @@ -72,9 +72,19 @@ struct TransferMoneyDialog: View { Section { TextField("Remittee Name", text: $remitteeName) .onReceive(Just(remitteeName)) { newValue in - self.isValidRemitteeNameEntered = self.remitteeName.isEmpty == false + self.isValidRemitteeNameEntered = self.remitteeName.isNotBlank } + if self.showRemitteeAutocompleteList { + Section { + List(self.remitteeSearchResults) { remittee in + RemitteeListItem(remittee: remittee) + .onTapGesture { self.remitteeSelected(remittee) } + } + .padding(.vertical, 12) + } + } + TextField("Remittee IBAN", text: $remitteeIban) .onReceive(Just(remitteeIban)) { newValue in self.isValidRemitteeIbanEntered = newValue.count > 14 // TODO: implement real check if IBAN is valid @@ -91,7 +101,7 @@ struct TransferMoneyDialog: View { self.amount = filtered } - self.isValidAmountEntered = self.amount.isEmpty == false + self.isValidAmountEntered = self.amount.isNotBlank } TextField("Usage", text: $usage)