Implemented displaying an error message if account couldn't be added and navigation back if adding account was successful

This commit is contained in:
dankito 2020-07-16 18:45:10 +02:00
parent 5dc0c7a74f
commit 4b8a48e4c7
4 changed files with 32 additions and 4 deletions

View File

@ -7,3 +7,6 @@
"Bank code" = "Bank code"; "Bank code" = "Bank code";
"Customer ID" = "Online banking login name"; "Customer ID" = "Online banking login name";
"Password" = "Online banking password"; "Password" = "Online banking password";
"Could not add account" = "Could not add account";
"Error message from your bank %@" = "Error message from your bank:\n\n%@";

View File

@ -7,3 +7,6 @@
"Bank code" = "Bankleitzahl"; "Bank code" = "Bankleitzahl";
"Customer ID" = "Onlinebanking Login Name"; "Customer ID" = "Onlinebanking Login Name";
"Password" = "Online banking password"; "Password" = "Online banking password";
"Could not add account" = "Konto konnte nicht hinzugefügt werden.";
"Error message from your bank %@" = "Fehlermeldung Ihrer Bank:\n\n%@";

View File

@ -0,0 +1,8 @@
import Foundation
struct Message: Identifiable {
let id = UUID()
let text: String
}

View File

@ -4,12 +4,16 @@ import BankingUiSwift
struct AddAccountDialog: View { struct AddAccountDialog: View {
@Environment(\.presentationMode) var presentation
@State private var enteredBank = "" @State private var enteredBank = ""
@State private var customerId = "" @State private var customerId = ""
@State private var password = "" @State private var password = ""
@State private var bank: BankFinderBankInfo? = BankFinderBankInfo() @State private var bank: BankFinderBankInfo? = BankFinderBankInfo()
@State private var errorMessage: Message? = nil
@Inject private var presenter: BankingPresenterSwift @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) .navigationBarTitle(Text("Add account"), displayMode: NavigationBarItem.TitleDisplayMode.inline)
} }
@ -58,14 +65,21 @@ struct AddAccountDialog: View {
} }
func addAccount() { func addAccount() {
if let bank = bank { if let bank = bank {
presenter.addAccountAsync(bankInfo: bank, customerId: customerId, pin: password) { (response) in
presenter.addAccountAsync(bankInfo: bank, customerId: customerId, pin: password) { (response: BUCAddAccountResponse) in self.handleAddAccountResponse(response)
NSLog("Is successful? \(response.isSuccessful), name = \(response.customer.customerName), \(response.customer.accounts.count) accounts, \(response.bookedTransactionsOfLast90Days.flatMap( { $1 }).count) transactions")
} }
} }
} }
func handleAddAccountResponse(_ response: BUCAddAccountResponse) {
if (response.isSuccessful) {
presentation.wrappedValue.dismiss()
}
else {
self.errorMessage = Message(text: (response.errorToShowToUser ?? ""))
}
}
} }