From 4b8a48e4c7c11aabf5965f9c9cb4a136ea38c09b Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 16 Jul 2020 18:45:10 +0200 Subject: [PATCH] Implemented displaying an error message if account couldn't be added and navigation back if adding account was successful --- .../Base.lproj/Localizable.strings | 3 +++ .../de.lproj/Localizable.strings | 3 +++ .../BankingiOSApp/ui/Message.swift | 8 +++++++ .../ui/views/AddAccountDialog.swift | 22 +++++++++++++++---- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 ui/BankingiOSApp/BankingiOSApp/ui/Message.swift diff --git a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings index 6ea8ffa6..6b24c28c 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings @@ -7,3 +7,6 @@ "Bank code" = "Bank code"; "Customer ID" = "Online banking login name"; "Password" = "Online banking password"; + +"Could not add account" = "Could not add account"; +"Error message from your bank %@" = "Error message from your bank:\n\n%@"; diff --git a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings index ab7a217f..e7d70051 100644 --- a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings @@ -7,3 +7,6 @@ "Bank code" = "Bankleitzahl"; "Customer ID" = "Onlinebanking Login Name"; "Password" = "Online banking password"; + +"Could not add account" = "Konto konnte nicht hinzugefĆ¼gt werden."; +"Error message from your bank %@" = "Fehlermeldung Ihrer Bank:\n\n%@"; diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift b/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift new file mode 100644 index 00000000..46f2d332 --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/ui/Message.swift @@ -0,0 +1,8 @@ +import Foundation + + +struct Message: Identifiable { + let id = UUID() + + let text: String +} diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift index 7792bf93..9dffbe76 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift @@ -4,12 +4,16 @@ import BankingUiSwift struct AddAccountDialog: View { + @Environment(\.presentationMode) var presentation + @State private var enteredBank = "" @State private var customerId = "" @State private var password = "" @State private var bank: BankFinderBankInfo? = BankFinderBankInfo() + @State private var errorMessage: Message? = nil + @Inject private var presenter: BankingPresenterSwift @@ -43,6 +47,9 @@ struct AddAccountDialog: View { } } } + .alert(item: $errorMessage) { message in + Alert(title: Text("Could not add account"), message: Text("Error message from your bank \(message.text)"), dismissButton: Alert.Button.cancel()) + } .navigationBarTitle(Text("Add account"), displayMode: NavigationBarItem.TitleDisplayMode.inline) } @@ -58,14 +65,21 @@ struct AddAccountDialog: View { } func addAccount() { - if let bank = bank { - - presenter.addAccountAsync(bankInfo: bank, customerId: customerId, pin: password) { (response: BUCAddAccountResponse) in - NSLog("Is successful? \(response.isSuccessful), name = \(response.customer.customerName), \(response.customer.accounts.count) accounts, \(response.bookedTransactionsOfLast90Days.flatMap( { $1 }).count) transactions") + presenter.addAccountAsync(bankInfo: bank, customerId: customerId, pin: password) { (response) in + self.handleAddAccountResponse(response) } } } + + func handleAddAccountResponse(_ response: BUCAddAccountResponse) { + if (response.isSuccessful) { + presentation.wrappedValue.dismiss() + } + else { + self.errorMessage = Message(text: (response.errorToShowToUser ?? "")) + } + } }