diff --git a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings index 2387fbee..9bd582a7 100644 --- a/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/Base.lproj/Localizable.strings @@ -49,3 +49,6 @@ "TAN medium" = "TAN medium"; "TAN hint from your bank:" = "Hint from your bank:"; "Enter TAN:" = "TAN"; +"TAN medium change" = "TAN medium change"; +"TAN medium successfully changed to %@." = "TAN medium successfully changed to '%@'."; +"Could not change TAN medium to %@. Error: %@." = "Could not change TAN medium to '%@'.\n\nError 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 ed9f3659..2651d069 100644 --- a/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings +++ b/ui/BankingiOSApp/BankingiOSApp/de.lproj/Localizable.strings @@ -49,3 +49,6 @@ "TAN medium" = "TAN Medium"; "TAN hint from your bank:" = "Hinweis Ihrer Bank:"; "Enter TAN:" = "TAN"; +"TAN medium change" = "TAN Medium Wechsel"; +"TAN medium successfully changed to %@." = "TAN Medium erfolgreich zu '%@' geändert."; +"Could not change TAN medium to %@. Error: %@." = "TAN medium konnte nicht zu '%@' geändert werden.\n\nFehlermeldung Ihrer Bank:\n\n%@."; diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift index a280e1d2..8d12bb52 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift @@ -28,9 +28,22 @@ struct EnterTanDialog: View { }) } - @State private var selectedTanMediumIndex = 0 private var customersTanMedia: [TanMedium] = [] + @State private var selectedTanMediumIndex = 0 + + private var selectedTanMediumIndexBinding: Binding { + Binding( + get: { self.selectedTanMediumIndex }, + set: { + if (self.selectedTanMediumIndex != $0) { // only if TAN media has really changed + self.selectedTanMediumIndex = $0 + self.selectedTanMediumChanged(self.customersTanMedia[$0]) + } + }) + } + + private var showSelectTanMediumView = false private var showFlickerCodeTanView = false @@ -38,6 +51,9 @@ struct EnterTanDialog: View { private var showImageTanView = false @State private var enteredTan = "" + + + @State private var errorMessage: Message? = nil @Inject private var presenter: BankingPresenterSwift @@ -74,7 +90,7 @@ struct EnterTanDialog: View { } if showSelectTanMediumView { - Picker("TAN medium", selection: $selectedTanMediumIndex) { + Picker("TAN medium", selection: selectedTanMediumIndexBinding) { ForEach(0 ..< self.customersTanMedia.count) { index in Text(self.customersTanMedia[index].displayName) } @@ -118,6 +134,9 @@ struct EnterTanDialog: View { } } } + .alert(item: $errorMessage) { message in + Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) + } .showNavigationBarTitle("Enter TAN Dialog Title") .customNavigationBarBackButton { self.sendEnterTanResult(EnterTanResult.Companion().userDidNotEnterTan()) @@ -134,6 +153,30 @@ struct EnterTanDialog: View { } } + private func selectedTanMediumChanged(_ changeTanMediumTo: TanMedium) { + if (changeTanMediumTo.status == .used) { // TAN medium already in use, no need to activate it + return + } + + // do async as at this point Picker dialog gets dismissed -> this EnterTanDialog would never get dismissed (and dismiss has to be called before callback.changeTanMedium()) + DispatchQueue.main.async { + self.dismissDialog() + + self.state.callback(EnterTanResult.Companion().userAsksToChangeTanMedium(changeTanMediumTo: changeTanMediumTo) { changeTanMediumResponse in + self.handleChangeTanMediumResponse(changeTanMediumTo, changeTanMediumResponse) + }) + } + } + + private func handleChangeTanMediumResponse(_ newTanMedium: TanMedium, _ changeTanMediumResponse: BankingClientResponse) { + if (changeTanMediumResponse.isSuccessful) { + self.errorMessage = Message(title: Text("TAN medium change"), message: Text("TAN medium successfully changed to \(newTanMedium.displayName).")) + } + else { + self.errorMessage = Message(title: Text("TAN medium change"), message: Text("Could not change TAN medium to \(newTanMedium.displayName). Error: \(changeTanMediumResponse.errorToShowToUser ?? changeTanMediumResponse.error?.message ?? "").")) + } + } + private func enteringTanDone() { let companion = EnterTanResult.Companion()