Implemented TransferMoneyDialog

This commit is contained in:
dankito 2020-07-17 21:06:41 +02:00
parent b5622a5d90
commit 2552f0fa11
5 changed files with 216 additions and 3 deletions

View File

@ -30,6 +30,8 @@
36BCF88724C0A310005BEC29 /* PreviewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BCF88624C0A310005BEC29 /* PreviewData.swift */; };
36BCF88924C0A7D7005BEC29 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BCF88824C0A7D7005BEC29 /* Message.swift */; };
36BCF88B24C0BD2D005BEC29 /* AccountTransactionsDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BCF88A24C0BD2D005BEC29 /* AccountTransactionsDialog.swift */; };
36BCF88D24C1C1EA005BEC29 /* TransferMoneyDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BCF88C24C1C1EA005BEC29 /* TransferMoneyDialog.swift */; };
36BCF88F24C1DFF7005BEC29 /* SheetPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BCF88E24C1DFF7005BEC29 /* SheetPresenter.swift */; };
36E7BA1424B3D05C00757859 /* ViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E7BA1324B3D05C00757859 /* ViewExtensions.swift */; };
36FC929C24B39A05002B12E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FC929B24B39A05002B12E9 /* AppDelegate.swift */; };
36FC929E24B39A05002B12E9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FC929D24B39A05002B12E9 /* SceneDelegate.swift */; };
@ -103,6 +105,8 @@
36BCF88624C0A310005BEC29 /* PreviewData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewData.swift; sourceTree = "<group>"; };
36BCF88824C0A7D7005BEC29 /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
36BCF88A24C0BD2D005BEC29 /* AccountTransactionsDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTransactionsDialog.swift; sourceTree = "<group>"; };
36BCF88C24C1C1EA005BEC29 /* TransferMoneyDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransferMoneyDialog.swift; sourceTree = "<group>"; };
36BCF88E24C1DFF7005BEC29 /* SheetPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetPresenter.swift; sourceTree = "<group>"; };
36E7BA1324B3D05C00757859 /* ViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtensions.swift; sourceTree = "<group>"; };
36E7BA1824B9E70C00757859 /* xcode-frameworks */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "xcode-frameworks"; path = "../../tools/BankFinder/build/xcode-frameworks"; sourceTree = "<group>"; };
36FC929824B39A05002B12E9 /* BankingiOSApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BankingiOSApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -269,6 +273,7 @@
36BCF86224BA5097005BEC29 /* SwiftUiRouter.swift */,
36BCF86D24BA691B005BEC29 /* DependencyInjector.swift */,
36BCF88824C0A7D7005BEC29 /* Message.swift */,
36BCF88E24C1DFF7005BEC29 /* SheetPresenter.swift */,
);
path = ui;
sourceTree = "<group>";
@ -281,6 +286,7 @@
36BCF88224C098BB005BEC29 /* BankListItem.swift */,
36BCF88424C098C8005BEC29 /* BankAccountListItem.swift */,
36BCF88A24C0BD2D005BEC29 /* AccountTransactionsDialog.swift */,
36BCF88C24C1C1EA005BEC29 /* TransferMoneyDialog.swift */,
);
path = views;
sourceTree = "<group>";
@ -447,11 +453,13 @@
36FC92D724B3A3BA002B12E9 /* NSUrlWebClient.swift in Sources */,
36BCF88324C098BB005BEC29 /* BankListItem.swift in Sources */,
36BCF87F24BFAA7F005BEC29 /* TestEntity.swift in Sources */,
36BCF88D24C1C1EA005BEC29 /* TransferMoneyDialog.swift in Sources */,
36E7BA1424B3D05C00757859 /* ViewExtensions.swift in Sources */,
36BCF88924C0A7D7005BEC29 /* Message.swift in Sources */,
36BCF86C24BA5E72005BEC29 /* DispatchQueueAsyncRunner.swift in Sources */,
36BCF88124BFAB4A005BEC29 /* DependendTestEntity.swift in Sources */,
36BCF86324BA5097005BEC29 /* SwiftUiRouter.swift in Sources */,
36BCF88F24C1DFF7005BEC29 /* SheetPresenter.swift in Sources */,
36FC929C24B39A05002B12E9 /* AppDelegate.swift in Sources */,
36BCF88B24C0BD2D005BEC29 /* AccountTransactionsDialog.swift in Sources */,
36BCF87B24BFA87E005BEC29 /* Extensions.swift in Sources */,

View File

@ -1,12 +1,33 @@
"OK" = "OK";
"Add" = "Add";
"Account" = "Account";
"Accounts" = "Accounts";
"Add account" = "Add account";
/* AddAccountDialog */
"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%@";
"Show transfer money dialog" = "Transfer money";
/* TransferMoneyDialog */
"Transfer Money Dialog Title" = "Überweisung";
"Remittee Name" = "Name";
"Remittee IBAN" = "IBAN";
"Amount" = "Amount";
"Usage" = "Usage";
"Instant Payment" = "Instant Payment";
"Transfer Money" = "Transfer";
"Successfully transferred %@ %@ to %@." = "Successfully transferred %@ %@ to %@.";
"Could not transfer %@ %@ to %@. Error: %@." = "Could not transfer %@ %@ to %@.\n\nError message from your bank:\n\n%@";

View File

@ -1,10 +1,11 @@
import SwiftUI
struct ContentView: View {
@State private var selection = 0
var body: some View {
TabView(selection: $selection){
TabView(selection: $selection) {
AccountsTab()
.tabItem {
VStack {
@ -13,8 +14,14 @@ struct ContentView: View {
}
}
.tag(0)
Text("Second View")
.font(.title)
NavigationView {
VStack {
NavigationLink(destination: TransferMoneyDialog()) {
Text("Show transfer money dialog")
}
}
}
.tabItem {
VStack {
Image("second")

View File

@ -1,12 +1,33 @@
"OK" = "OK";
"Add" = "Hinzufügen";
"Account" = "Konto";
"Accounts" = "Konten";
"Add account" = "Konto hinzufügen";
/* AddAccountDialog */
"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%@";
"Show transfer money dialog" = "Überweisung";
/* TransferMoneyDialog */
"Transfer Money Dialog Title" = "Überweisung";
"Remittee Name" = "Name";
"Remittee IBAN" = "IBAN";
"Amount" = "Betrag";
"Usage" = "Verwendungszweck";
"Instant Payment" = "Echtzeitüberweisung";
"Transfer Money" = "Überweisen";
"Successfully transferred %@ %@ to %@." = "%@ %@ wurden erfolgreich an %@ überwiesen.";
"Could not transfer %@ %@ to %@. Error: %@." = "Konnte nicht %@ %@ an %@ überweisen.\n\nFehlermeldung Ihrer Bank:\n\n%@";

View File

@ -0,0 +1,156 @@
import SwiftUI
import BankingUiSwift
import Combine
struct TransferMoneyDialog: View {
@Environment(\.presentationMode) var presentation
private var showAccounts = false
private var accountsSupportingTransferringMoney: [BUCBankAccount] = []
@State private var selectedAccountIndex = 0
private var account: BUCBankAccount? = nil
@State private var remitteeName: String = ""
@State private var isValidRemitteeNameEntered = false
@State private var remitteeIban: String = ""
@State private var isValidRemitteeIbanEntered = false
@State private var remitteeBic: String = "" // TODO
@State private var isValidRemitteeBicEntered = true // TODO
@State private var amount = ""
@State private var isValidAmountEntered = false
@State private var usage: String = ""
@State private var isValidUsageEntered = true
@State private var instantPayment = false
private var supportsInstantPayment: Bool {
return self.account?.supportsInstantPaymentMoneyTransfer ?? false
}
@State private var transferMoneyResponseMessage: Message? = nil
@Inject private var presenter: BankingPresenterSwift
init() {
self.accountsSupportingTransferringMoney = self.presenter.bankAccounts.filter({ $0.supportsTransferringMoney })
self.account = self.accountsSupportingTransferringMoney.first
self.showAccounts = self.accountsSupportingTransferringMoney.count > 1
}
var body: some View {
Form {
if (showAccounts) {
Section {
Picker("Account", selection: $selectedAccountIndex) {
ForEach(0 ..< self.accountsSupportingTransferringMoney.count) { accountIndex in
Text(self.accountsSupportingTransferringMoney[accountIndex].displayName)
}
}
}
}
Section {
TextField("Remittee Name", text: $remitteeName)
.onReceive(Just(remitteeName)) { newValue in
self.isValidRemitteeNameEntered = self.remitteeName.isEmpty == false
}
TextField("Remittee IBAN", text: $remitteeIban)
.onReceive(Just(remitteeIban)) { newValue in
self.isValidRemitteeIbanEntered = self.remitteeIban.isEmpty == false
}
TextField("Amount", text: $amount)
.keyboardType(.decimalPad)
.onReceive(Just(amount)) { newValue in
let filtered = newValue.filter { "0123456789,".contains($0) }
if filtered != newValue {
self.amount = filtered
}
self.isValidAmountEntered = self.amount.isEmpty == false
}
TextField("Usage", text: $usage)
.onReceive(Just($usage)) { newValue in
self.isValidUsageEntered = true
}
}
if supportsInstantPayment {
Section {
Toggle("Instant Payment", isOn: $instantPayment)
}
}
Section {
HStack {
Spacer()
Button(action: { self.transferMoney() },
label: { Text("Transfer Money") })
.disabled(!self.isRequiredDataEntered())
Spacer()
}
}
}
.alert(item: $transferMoneyResponseMessage) { message in
if let secondaryButton = message.secondaryButton {
return Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: secondaryButton)
}
else {
return Alert(title: message.title, message: message.message, dismissButton: message.primaryButton)
}
}
.navigationBarTitle("Transfer Money Dialog Title", displayMode: .inline)
}
func isRequiredDataEntered() -> Bool {
return account != nil
&& isValidRemitteeNameEntered
&& isValidRemitteeIbanEntered
//&& isValidRemitteeBicEntered
&& isValidAmountEntered
&& isValidUsageEntered
}
func transferMoney() {
let data = BUCTransferMoneyData(creditorName: remitteeName, creditorIban: remitteeIban, creditorBic: remitteeBic, amount: CommonBigDecimal(decimal: amount.replacingOccurrences(of: ",", with: ".")), usage: usage, instantPayment: instantPayment)
presenter.transferMoneyAsync(bankAccount: account!, data: data) { response in
self.handleTransferMoneyResponse(data, response)
}
}
func handleTransferMoneyResponse(_ data: BUCTransferMoneyData, _ response: BUCBankingClientResponse) {
if (response.isSuccessful) {
self.transferMoneyResponseMessage = Message(message: Text("Successfully transferred \(data.amount) \("") to \(data.creditorName)"))
presentation.wrappedValue.dismiss()
}
else {
self.transferMoneyResponseMessage = Message(message: Text("Could not transfer \(data.amount) \("") to \(data.creditorName). Error: \(response.errorToShowToUser ?? response.error?.message ?? "")."))
}
}
}
struct TransferMoneyDialog_Previews: PreviewProvider {
static var previews: some View {
TransferMoneyDialog()
}
}