Fix for bug 11963 -- BankEditView: a form that cannot be submitted and a save that fails silently. Four changes, matching the four points in the report: 1. The IBAN field now clears `unchanged` like the label, holder and xTaler fields do. Without it, editing an existing account's IBAN alone could never be saved. 2. The button's enabled state is computed from the three fields `updateAccount()` actually requires -- label, holder and the payto target -- rather than from the payto target plus `unchanged`. Filling in only the IBAN previously left "Add" disabled for ever. `unchanged` is still honoured for an *existing* account, where it means something, and ignored for a new one, where there is nothing yet to be unchanged from. While the button is disabled it carries an accessibility hint naming the field still to fill in. 3. `showAlert` was written by three failure paths and bound to no `.alert` anywhere in the file. It now has one, and each site sets a message saying which thing failed -- "could not save" and "could not forget" being different messages. The `addBankAccount` failure path previously set nothing at all and only wrote to symLog. 4. `a11yStr` is passed to `DoneButton`'s `accessibilityLabelStr`, which is what the two lines computing it were presumably for; the button was announced as just "Add". Four new user-visible strings are introduced (the alert title, the three alert messages and the hint) and they are English-only in this patch; they need translating like any new string. Visible helper text on the screen, as opposed to the accessibility hint, is deliberately not added here: where it should go and how it should look is a design decision rather than a fix. Generated against taler-ios master, 2026-11-08. Apply with `git apply`. --- a/TalerWallet1/Views/Settings/Bank/BankEditView.swift +++ b/TalerWallet1/Views/Settings/Bank/BankEditView.swift @@ -28,8 +28,12 @@ @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) @State private var didDelete: Bool = false @State private var disabled: Bool = false @State private var showAlert: Bool = false + /// What `showAlert` is about. Each failure site sets it, because "could + /// not save" and "could not forget" are not the same message and the + /// flag was previously shared by both with no text at all. + @State private var alertMessage: String = EMPTYSTRING @State private var myAccount: String? = nil @State private var accountHolder: String = EMPTYSTRING @State private var iban: String = EMPTYSTRING @@ -64,18 +68,41 @@ let titleStr = isNew ? String(localized: "Add", comment: "button title: Add bank account") : String(localized: "Update", comment: "button title: Update bank account") let a11yStr = isNew ? String(localized: "Add bank account", comment: "a11y") : String(localized: "Update bank account", comment: "a11y") - let notValid: Bool = paytoType == .iban ? (iban.isEmpty || !ibanValid) - : xTaler.isEmpty - DoneButton(titleStr: titleStr, accessibilityLabelStr: titleStr) { + // `updateAccount()` requires all three of label, holder and the payto + // target and silently returns false otherwise, so the enabled state + // has to be computed from the same three fields. It previously used + // only the payto target plus `unchanged` -- and `unchanged` is never + // cleared by the IBAN field, so filling in only the IBAN left the + // button disabled for ever with nothing on screen saying why. + let missingField: String? = { + if accountLabel.isEmpty { + return String(localized: "Label", comment: "field name") + } + if accountHolder.isEmpty { + return String(localized: "Account holder", comment: "field name") + } + if paytoType == .iban ? (iban.isEmpty || !ibanValid) : xTaler.isEmpty { + return paytoType.rawValue.uppercased() + } + return nil + }() + // For a *new* account "unchanged" is not a meaningful state: there is + // nothing yet for it to be unchanged from. + let notReady = missingField != nil || (unchanged && !isNew) + DoneButton(titleStr: titleStr, accessibilityLabelStr: a11yStr) { Task { if await updateAccount() { dismiss() } } } - .disabled(disabled || notValid || unchanged) + .disabled(disabled || notReady) + .accessibilityHint(missingField.map { + String(localized: "Still to fill in: \($0)", + comment: "a11y hint while Add/Update is disabled") + } ?? EMPTYSTRING) } @MainActor private func viewDidLoad() async { @@ -122,8 +149,9 @@ components.path = "/" + target components.queryItems = [URLQueryItem(name: "receiver-name", value: accountHolder)] guard let paytoUri = components.string else { symLog.log("could not build a payto URI from the entered account") + alertMessage = String(localized: "The account details could not be turned into a valid payto:// address. Please check them and try again.") showAlert = true return false } symLog.log(paytoUri) @@ -135,8 +163,12 @@ myAccount = account return true } else { symLog.log("error addBankAccount") + // Previously this returned false with no user-visible + // effect at all: the screen simply stayed as it was. + alertMessage = String(localized: "The bank account could not be saved. Please check the account details and try again.") + showAlert = true } } } return false @@ -153,8 +185,9 @@ // NotificationCenter.default.post(name: .ExchangeDeleted, object: nil, userInfo: nil) // NotificationCenter.default.post(name: .BalanceChange, object: nil, userInfo: nil) dismissTop(stack.push()) } else { + alertMessage = String(localized: "This bank account could not be forgotten. Please try again.") showAlert = true disabled = false } } @@ -251,8 +284,15 @@ .background(WalletColors().fieldBackground) .textFieldStyle(.roundedBorder) .padding(.bottom) .onChange(of: iban) { newValue in + // Like the label, holder and xTaler fields: this + // is a real edit, so the account is no longer + // unchanged. Without it, editing an existing + // account's IBAN alone could not be saved. + if userTyped { + unchanged = false + } Task { if let result = try? await model.validateIban(newValue) { ibanValid = result } @@ -291,8 +331,16 @@ } }.listRowSeparator(.hidden) } // List .navigationBarItems(trailing: barButton()) + // `showAlert` was declared and written by three failure paths and + // bound to no `.alert` anywhere in the file, so every one of those + // failures was invisible to the user and to a UI test. + .alert(String(localized: "Bank account"), isPresented: $showAlert) { + Button(String(localized: "OK"), role: .cancel) { } + } message: { + Text(alertMessage) + } // .ignoresSafeArea(.keyboard, edges: .bottom) .onChange(of: focus) { [focus] newState in switch newState { case .none: