taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 96a637c16a52a7606d14e510fdaff76f50176875
parent 3770e0b49e113905d8d13017a81343457b46f115
Author: Marc Stibane <marc@taler.net>
Date:   Mon,  3 Aug 2026 18:31:42 +0200

simplify

Diffstat:
MTalerWallet1/Views/HelperViews/CopyShare.swift | 25++++++++++++++-----------
MTalerWallet1/Views/HelperViews/LoadingView.swift | 3+--
MTalerWallet1/Views/Main/ErrorView.swift | 4+---
MTalerWallet1/Views/Transactions/ManualDetailsV.swift | 2+-
MTalerWallet1/Views/Transactions/ManualDetailsWireV.swift | 42+++++++++++++++++++++---------------------
MTalerWallet1/Views/Transactions/TransactionSummaryList.swift | 3+--
MTalerWallet1/Views/Transactions/TransactionTypeDetail.swift | 3+--
7 files changed, 40 insertions(+), 42 deletions(-)

diff --git a/TalerWallet1/Views/HelperViews/CopyShare.swift b/TalerWallet1/Views/HelperViews/CopyShare.swift @@ -64,7 +64,7 @@ struct FeedbackButton: View { struct CopyButton: View { private let symLog = SymLogV(0) let textToCopy: String - @Binding var isCopied: Bool + @Binding var isCopied: Bool? let image: UIImage? let vertical: Bool let title: String? @@ -74,17 +74,19 @@ struct CopyButton: View { @State private var scale: CGFloat = 1.0 - init(textToCopy: String, isCopied: Binding<Bool>, vertical: Bool, image: UIImage? = nil) { + init(_ textToCopy: String, isCopied: Binding<Bool?>? = nil, + vertical: Bool, image: UIImage? = nil) { self.textToCopy = textToCopy - self._isCopied = isCopied + self._isCopied = isCopied ?? Binding.constant(nil) self.image = image self.vertical = vertical self.title = nil } - init(textToCopy: String, isCopied: Binding<Bool>, title: String, image: UIImage? = nil) { + init(_ textToCopy: String, isCopied: Binding<Bool?>? = nil, + title: String, image: UIImage? = nil) { self.textToCopy = textToCopy - self._isCopied = isCopied + self._isCopied = isCopied ?? Binding.constant(nil) self.image = image self.vertical = false self.title = title @@ -101,7 +103,9 @@ struct CopyButton: View { items.append(images) } UIPasteboard.general.setItems(items) - isCopied = true + if isCopied != nil { + isCopied = true + } } private func triggerPulse() { @@ -163,12 +167,12 @@ struct ShareButton: View { @State private var scale: CGFloat = 1.0 - init(textToShare: String, image: UIImage? = nil) { + init(_ textToShare: String, image: UIImage? = nil) { self.textToShare = textToShare self.image = image self.title = String(localized: "Share") } - init(textToShare: String, title: String, image: UIImage? = nil) { + init(_ textToShare: String, title: String, image: UIImage? = nil) { self.textToShare = textToShare self.image = image self.title = title @@ -227,7 +231,6 @@ struct ShareButton: View { // MARK: - struct CopyShare: View { @Environment(\.isEnabled) private var isEnabled: Bool - @State var isCopied: Bool = false let textToCopy: String let image: UIImage? @@ -238,9 +241,9 @@ struct CopyShare: View { } var body: some View { - let copyB = CopyButton(textToCopy: textToCopy, isCopied: $isCopied, vertical: false, image: image) + let copyB = CopyButton(textToCopy, vertical: false, image: image) .buttonStyle(TalerButtonStyle(type: .bordered)) - let share = ShareButton(textToShare: textToCopy, image: image) + let share = ShareButton(textToCopy, image: image) .buttonStyle(TalerButtonStyle(type: .bordered)) let vLayout = VStack { diff --git a/TalerWallet1/Views/HelperViews/LoadingView.swift b/TalerWallet1/Views/HelperViews/LoadingView.swift @@ -29,7 +29,6 @@ struct LoadingView: View { @State private var showAlert: Bool = false @State private var disabled: Bool = false @State private var isFinished: Bool? = false - @State private var isCopied: Bool = false private var dismissButton: some View { Button("Cancel", role: .cancel) { @@ -102,7 +101,7 @@ struct LoadingView: View { .talerFont(.body) if developerMode { if let jsonString = toJSON(lastError) { - CopyButton(textToCopy: jsonString, isCopied: $isCopied, title: "Copy JSON") + CopyButton(jsonString, title: "Copy JSON") .padding(.vertical) } } diff --git a/TalerWallet1/Views/Main/ErrorView.swift b/TalerWallet1/Views/Main/ErrorView.swift @@ -72,8 +72,6 @@ struct ErrorView: View { var requestUrl: String? = nil var copyable: Bool - @State var isCopied: Bool = false - var onDismiss: () -> Void init(_ stack: CallStack, title: String, message: String? = nil, @@ -167,7 +165,7 @@ struct ErrorView: View { Text(message).font(.system(.body, design: .monospaced)) } - CopyButton(textToCopy: message, isCopied: $isCopied, vertical: false) + CopyButton(message, vertical: false) .accessibilityLabel(Text("Copy the error JSON", comment: "a11y")) .padding() } else { diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift @@ -144,7 +144,7 @@ struct ManualDetailsV: View { let minTitle = String(localized: "Share PayTo", comment: "mini") let textToShare = String("\(payto)\n\nIBAN: \(iban)\nReceiver: \(receiverStr)\nAmount: \(amountStr.1)\nSubject: \(details.reservePub)") let _ = print(textToShare) - ShareButton(textToShare: textToShare, title: minimalistic ? minTitle : title) + ShareButton(textToShare, title: minimalistic ? minTitle : title) .frame(maxWidth: .infinity, alignment: .center) .accessibilityLabel(Text(title)) .disabled(false) diff --git a/TalerWallet1/Views/Transactions/ManualDetailsWireV.swift b/TalerWallet1/Views/Transactions/ManualDetailsWireV.swift @@ -99,7 +99,7 @@ struct RestrictionsV: View { // MARK: - struct PayeeZip: View { let receiverZip: String - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { VStack(alignment: .leading) { @@ -107,12 +107,12 @@ struct PayeeZip: View { .talerFont(.subheadline) Text(receiverZip) .monospacedDigit() - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .padding(.leading) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .combine) .accessibilityLabel(Text("Zip code", comment: "a11y")) - CopyButton(textToCopy: receiverZip, isCopied: $isCopied, vertical: true) + CopyButton(receiverZip, isCopied: $isCopied, vertical: true) .accessibilityLabel(Text("Copy the zip code", comment: "a11y")) .disabled(false) } .padding(.top, -8) @@ -121,7 +121,7 @@ struct PayeeZip: View { // MARK: - struct PayeeReceiver: View { let receiverStr: String - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { VStack(alignment: .leading) { @@ -129,12 +129,12 @@ struct PayeeReceiver: View { .talerFont(.subheadline) Text(receiverStr) .monospacedDigit() - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .padding(.leading) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .combine) .accessibilityLabel(Text("Recipient", comment: "a11y")) - CopyButton(textToCopy: receiverStr, isCopied: $isCopied, vertical: true) + CopyButton(receiverStr, isCopied: $isCopied, vertical: true) .accessibilityLabel(Text("Copy the recipient", comment: "a11y")) .disabled(false) } .padding(.top, -8) @@ -143,7 +143,7 @@ struct PayeeReceiver: View { // MARK: - struct PayeeTown: View { let receiverTown: String - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { VStack(alignment: .leading) { @@ -151,12 +151,12 @@ struct PayeeTown: View { .talerFont(.subheadline) Text(receiverTown) .monospacedDigit() - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .padding(.leading) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .combine) .accessibilityLabel(Text("City", comment: "a11y")) - CopyButton(textToCopy: receiverTown, isCopied: $isCopied, vertical: true) + CopyButton(receiverTown, isCopied: $isCopied, vertical: true) .accessibilityLabel(Text("Copy the city", comment: "a11y")) .disabled(false) } .padding(.top, -8) @@ -165,15 +165,15 @@ struct PayeeTown: View { // MARK: - struct Cryptocode: View { let cryptoString: String - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { Text(cryptoString) - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .monospacedDigit() .accessibilityLabel(Text("Cryptocode", comment: "a11y")) .frame(maxWidth: .infinity, alignment: .leading) - CopyButton(textToCopy: cryptoString, isCopied: $isCopied, vertical: true) + CopyButton(cryptoString, isCopied: $isCopied, vertical: true) .accessibilityLabel(Text("Copy the cryptocode", comment: "a11y")) .disabled(false) } .padding(.leading) @@ -182,7 +182,7 @@ struct Cryptocode: View { // MARK: - struct IbanCode: View { let iban: String - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { VStack(alignment: .leading) { @@ -190,12 +190,12 @@ struct IbanCode: View { .talerFont(.subheadline) Text(iban) .monospacedDigit() - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .padding(.leading) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .combine) .accessibilityLabel(Text("IBAN of the recipient", comment: "a11y")) // TODO: BBAN - CopyButton(textToCopy: iban, isCopied: $isCopied, vertical: true) + CopyButton(iban, isCopied: $isCopied, vertical: true) .accessibilityLabel(Text("Copy the IBAN", comment: "a11y")) // TODO: BBAN .disabled(false) } // .padding(.top, -8) @@ -205,7 +205,7 @@ struct IbanCode: View { struct AmountCode: View { let amountStr: (String, String) let amountValue: String // string representation of the value, formatted as "`integer`.`fraction`" - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { VStack(alignment: .leading) { @@ -214,12 +214,12 @@ struct AmountCode: View { Text(amountStr.0) .accessibilityLabel(amountStr.1) .monospacedDigit() - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .padding(.leading) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .combine) .accessibilityLabel(Text("Amount to transfer", comment: "a11y")) - CopyButton(textToCopy: amountValue, isCopied: $isCopied, vertical: true) + CopyButton(amountValue, isCopied: $isCopied, vertical: true) // only digits + separator, no currency name or symbol .accessibilityLabel(Text("Copy the amount", comment: "a11y")) .disabled(false) @@ -229,7 +229,7 @@ struct AmountCode: View { // MARK: - struct XTalerCode: View { let xTaler: String - @State var isCopied: Bool = false + @State var isCopied: Bool? = false var body: some View { HStack { VStack(alignment: .leading) { @@ -237,12 +237,12 @@ struct XTalerCode: View { .talerFont(.subheadline) Text(xTaler) .monospacedDigit() - .foregroundStyle(isCopied ? Color.secondary : .primary) + .foregroundStyle(isCopied == true ? Color.secondary : .primary) .padding(.leading) } .frame(maxWidth: .infinity, alignment: .leading) .accessibilityElement(children: .combine) .accessibilityLabel(Text("account of the recipient", comment: "a11y")) - CopyButton(textToCopy: xTaler, isCopied: $isCopied, vertical: true) + CopyButton(xTaler, isCopied: $isCopied, vertical: true) .accessibilityLabel(Text("Copy the account", comment: "a11y")) .disabled(false) } .padding(.top, -8) diff --git a/TalerWallet1/Views/Transactions/TransactionSummaryList.swift b/TalerWallet1/Views/Transactions/TransactionSummaryList.swift @@ -51,7 +51,6 @@ struct TransactionSummaryList: View { #endif @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN) - @State private var isCopied: Bool = false @State private var ignoreThis: Bool = false @State private var didDelete: Bool = false @State var jsonTransaction: String = EMPTYSTRING @@ -185,7 +184,7 @@ struct TransactionSummaryList: View { } // TODO: a11y for tx icon if developerMode { if !jsonTransaction.isEmpty { - CopyButton(textToCopy: jsonTransaction, isCopied: $isCopied, title: "Copy JSON") + CopyButton(jsonTransaction, title: "Copy JSON") } } } diff --git a/TalerWallet1/Views/Transactions/TransactionTypeDetail.swift b/TalerWallet1/Views/Transactions/TransactionTypeDetail.swift @@ -27,7 +27,6 @@ struct TransactionTypeDetail: View { @AppStorage("minimalistic") var minimalistic: Bool = false @State private var rotationEnabled = true @State private var ignoreAccept: Bool = false // accept could be set by OIM to trigger accept - @State private var isCopied: Bool = false func refreshFee(input: Amount, output: Amount) -> Amount? { do { @@ -191,7 +190,7 @@ struct TransactionTypeDetail: View { } let stackStr = error.stack ?? EMPTYSTRING let errorStr = error.hint + "\n" + stackStr - CopyButton(textToCopy: errorStr, isCopied: $isCopied, vertical: true) + CopyButton(errorStr, vertical: true) .accessibilityLabel(Text("Copy the error", comment: "a11y")) .disabled(false) }