summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-11-19 18:17:38 +0100
committerMarc Stibane <marc@taler.net>2023-11-19 18:20:52 +0100
commitaca4f65273e295805b5e456b016a864c4eab0513 (patch)
tree2279a9412599b199415d3431bf78dcbd5ac0f51a
parentc0cf8461feaf8cb84d0686f1d72617ebb40e73f9 (diff)
downloadtaler-ios-aca4f65273e295805b5e456b016a864c4eab0513.tar.gz
taler-ios-aca4f65273e295805b5e456b016a864c4eab0513.tar.bz2
taler-ios-aca4f65273e295805b5e456b016a864c4eab0513.zip
unify P2P subject
-rw-r--r--TalerWallet1/Helper/CurrencySpecification.swift4
-rw-r--r--TalerWallet1/Views/Exchange/QuiteSomeCoins.swift19
-rw-r--r--TalerWallet1/Views/Peer2peer/RequestPayment.swift28
-rw-r--r--TalerWallet1/Views/Peer2peer/SendAmount.swift45
-rw-r--r--TalerWallet1/Views/Peer2peer/SendDoneV.swift18
-rw-r--r--TalerWallet1/Views/Peer2peer/SendPurpose.swift47
6 files changed, 96 insertions, 65 deletions
diff --git a/TalerWallet1/Helper/CurrencySpecification.swift b/TalerWallet1/Helper/CurrencySpecification.swift
index 982eba7..523a67a 100644
--- a/TalerWallet1/Helper/CurrencySpecification.swift
+++ b/TalerWallet1/Helper/CurrencySpecification.swift
@@ -19,9 +19,9 @@ extension Locale {
}
extension Amount {
- func string(_ currencyInfo: CurrencyInfo?) -> String {
+ func string(_ currencyInfo: CurrencyInfo?, useSymbol: Bool = true) -> String {
if let currencyInfo {
- return currencyInfo.string(for: valueAsFloatTuple)
+ return currencyInfo.string(for: valueAsFloatTuple, useSymbol: useSymbol)
} else {
return valueStr
}
diff --git a/TalerWallet1/Views/Exchange/QuiteSomeCoins.swift b/TalerWallet1/Views/Exchange/QuiteSomeCoins.swift
index a0376f2..8e046a2 100644
--- a/TalerWallet1/Views/Exchange/QuiteSomeCoins.swift
+++ b/TalerWallet1/Views/Exchange/QuiteSomeCoins.swift
@@ -15,6 +15,16 @@ struct SomeCoins {
var tooMany: Bool { numCoins > 999 }
let fee: Amount?
+ func feeLabel(_ currencyInfo: CurrencyInfo?) -> String {
+ return if let fee {
+ invalid ? "Amount too small!"
+ : tooMany ? "Amount too big for a single withdrawal!"
+ : fee.isZero ? "No withdrawal fee"
+ : "- \(fee.string(currencyInfo)) fee"
+ } else {
+ EMPTYSTRING
+ }
+ }
}
extension SomeCoins {
@@ -68,12 +78,9 @@ struct QuiteSomeCoins: View {
}
if shouldShowFee {
if let fee = someCoins.fee {
- Text(someCoins.invalid ? "Amount too small!"
- : someCoins.tooMany ? "Amount too big for a single withdrawal!"
- : fee.isZero ? "No withdrawal fee"
- : "- \(fee.string(currencyInfo)) fee")
- .foregroundColor((someCoins.invalid || someCoins.tooMany || !fee.isZero) ? .red : .primary)
- .accessibilityFont(.body)
+ Text(someCoins.feeLabel(currencyInfo))
+ .foregroundColor((someCoins.invalid || someCoins.tooMany || !fee.isZero) ? .red : .primary)
+ .accessibilityFont(.body)
}
}
}
diff --git a/TalerWallet1/Views/Peer2peer/RequestPayment.swift b/TalerWallet1/Views/Peer2peer/RequestPayment.swift
index 1440e90..e2b3ef8 100644
--- a/TalerWallet1/Views/Peer2peer/RequestPayment.swift
+++ b/TalerWallet1/Views/Peer2peer/RequestPayment.swift
@@ -28,8 +28,18 @@ struct RequestPayment: View {
#endif
let currency = amountToTransfer.currencyStr
let currencyInfo = controller.info(for: currency, controller.currencyTicker)
- let navTitle = String(localized: "Request \(currency)", comment: "Dialog Title")
+ let currencySymbol = currencyInfo.specs.altUnitNames?[0] ?? currency
+ let navTitle = String(localized: "NavTitle_Request_Currency",
+ defaultValue: "Request \(currencySymbol)",
+ comment: "NavTitle: Request 'currencySymbol'")
+ let amountStr = amountToTransfer.string(currencyInfo)
+ let amountWithCurrency = amountToTransfer.string(currencyInfo, useSymbol: false)
+ let buttonTitle = String(localized: "Request \(amountWithCurrency)", comment: "amount with currency")
+ let navTitle2 = String(localized: "NavTitle_Request_AmountStr",
+ defaultValue: "Request \(amountStr)",
+ comment: "NavTitle: Request 'amountStr'")
+ let _ = symLog.log("currency: \(currency)")
ScrollView { VStack(alignment: .trailing) {
CurrencyInputView(amount: $amountToTransfer,
available: nil,
@@ -46,15 +56,19 @@ struct RequestPayment: View {
let disabled = amountToTransfer.isZero || someCoins.invalid || someCoins.tooMany
NavigationLink(destination: LazyView {
- RequestPurpose(stack: stack.push(),
- amountToTransfer: amountToTransfer,
- fee: someCoins.fee,
- summary: $summary,
- expireDays: $expireDays)
+ SendPurpose(stack: stack.push(),
+ amountToSend: nil,
+ amountToReceive: amountToTransfer,
+ navTitle: navTitle2,
+ buttonTitle: buttonTitle,
+ feeLabel: someCoins.feeLabel(currencyInfo),
+ currencyInfo: currencyInfo,
+ summary: $summary,
+ expireDays: $expireDays)
}) { Text("Next") }
.buttonStyle(TalerButtonStyle(type: .prominent))
.disabled(disabled)
- Spacer()
+// Spacer()
} } // ScrollVStack
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
diff --git a/TalerWallet1/Views/Peer2peer/SendAmount.swift b/TalerWallet1/Views/Peer2peer/SendAmount.swift
index d833f64..48bebee 100644
--- a/TalerWallet1/Views/Peer2peer/SendAmount.swift
+++ b/TalerWallet1/Views/Peer2peer/SendAmount.swift
@@ -22,7 +22,7 @@ struct SendAmount: View {
@State var peerPushCheck: CheckPeerPushDebitResponse? = nil
@State private var expireDays: UInt = SEVENDAYS
@State private var insufficient: Bool = false
- @State private var fee: String = ""
+ @State private var feeStr: String = EMPTYSTRING
private func fee(ppCheck: CheckPeerPushDebitResponse?) -> Amount? {
do {
@@ -35,20 +35,29 @@ struct SendAmount: View {
return nil
}
- var feeLabel: String { String(localized: " + \(fee) payment fee") }
+ var feeLabel: String { feeStr.count > 0 ? String(localized: "+ \(feeStr) send fee") : EMPTYSTRING }
var body: some View {
#if DEBUG
let _ = Self._printChanges()
let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear
#endif
- let currency = amountAvailable.currencyStr
- let _ = symLog.log("currency: \(currency)")
+ let currency = amountToTransfer.currencyStr
let currencyInfo = controller.info(for: currency, controller.currencyTicker)
- let navTitle = String(localized: "Send \(currency)", comment: "Dialog Title")
+ let currencySymbol = currencyInfo.specs.altUnitNames?[0] ?? currency
+ let navTitle = String(localized: "NavTitle_Send_Currency",
+ defaultValue: "Send \(currencySymbol)",
+ comment: "NavTitle: Send 'currencySymbol'")
+ let amountStr = amountToTransfer.string(currencyInfo)
+ let amountWithCurrency = amountToTransfer.string(currencyInfo, useSymbol: false)
+ let buttonTitle = String(localized: "Send \(amountWithCurrency) now", comment: "amount with currency")
+ let navTitle2 = String(localized: "NavTitle_Send_AmountStr",
+ defaultValue: "Send \(amountStr)",
+ comment: "NavTitle: Send 'amountStr'")
+
let available = amountAvailable.string(currencyInfo)
- let _ = symLog.log("available: \(available)")
- let current = amountToTransfer.string(currencyInfo)
+ let _ = symLog.log("currency: \(currency), available: \(available)")
+ let amountVoiceOver = amountToTransfer.string(currencyInfo)
let insufficientLabel = String(localized: "You don't have enough \(currency).")
let insufficientLabel2 = String(localized: "but you only have \(available) to send.")
@@ -70,16 +79,18 @@ struct SendAmount: View {
NavigationLink(destination: LazyView {
SendPurpose(stack: stack.push(),
- amountAvailable: amountAvailable,
- amountToTransfer: amountToTransfer,
- fee: fee,
+ amountToSend: amountToTransfer,
+ amountToReceive: nil,
+ navTitle: navTitle2,
+ buttonTitle: buttonTitle,
+ feeLabel: feeLabel,
currencyInfo: currencyInfo,
summary: $summary,
expireDays: $expireDays)
}) { Text("Next") }
.buttonStyle(TalerButtonStyle(type: .prominent))
.disabled(disabled)
- Spacer()
+// Spacer()
} } // ScrollVStack
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
@@ -95,16 +106,16 @@ struct SendAmount: View {
.task(id: amountToTransfer.value) {
do {
insufficient = try amountToTransfer > amountAvailable
- print("current: \(current)")
+ print("amountStr: \(amountVoiceOver)")
} catch {
print("Yikes❗️ insufficient failed❗️")
insufficient = true
}
if insufficient {
- announce(this: "\(current), \(insufficientLabel2)")
+ announce(this: "\(amountVoiceOver), \(insufficientLabel2)")
} else if amountToTransfer.isZero {
- fee = EMPTYSTRING
+ feeStr = EMPTYSTRING
} else {
do {
let ppCheck = try await model.checkPeerPushDebitM(amountToTransfer)
@@ -112,9 +123,9 @@ struct SendAmount: View {
// TODO: set from exchange
// agePicker.setAges(ages: peerPushCheck?.ageRestrictionOptions)
if let feeAmount = fee(ppCheck: peerPushCheck) {
- fee = feeAmount.string(currencyInfo)
- } else { fee = EMPTYSTRING }
- announce(this: "\(current), \(feeLabel)")
+ feeStr = feeAmount.string(currencyInfo)
+ } else { feeStr = EMPTYSTRING }
+ announce(this: "\(amountVoiceOver), \(feeLabel)")
} catch { // TODO: error
symLog.log(error.localizedDescription)
peerPushCheck = nil
diff --git a/TalerWallet1/Views/Peer2peer/SendDoneV.swift b/TalerWallet1/Views/Peer2peer/SendDoneV.swift
index b52b4bc..776e9be 100644
--- a/TalerWallet1/Views/Peer2peer/SendDoneV.swift
+++ b/TalerWallet1/Views/Peer2peer/SendDoneV.swift
@@ -10,7 +10,12 @@ import SymLog
struct SendDoneV: View {
private let symLog = SymLogV()
let stack: CallStack
- let navTitle = String(localized: "P2P Ready")
+ let amountToSend: Amount?
+ let amountToReceive: Amount?
+ let summary: String
+ let expireDays: UInt
+ @Binding var transactionStarted: Bool
+
@EnvironmentObject private var model: WalletModel
#if DEBUG
@AppStorage("developerMode") var developerMode: Bool = true
@@ -19,12 +24,7 @@ struct SendDoneV: View {
#endif
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
- let amountToSend: Amount?
- let amountToReceive: Amount?
- let summary: String
- let expireDays: UInt
- @Binding var transactionStarted: Bool
-
+ let navTitle = String(localized: "P2P Ready")
@State private var transactionId: String? = nil
func reloadOneAction(_ transactionId: String) async throws -> Transaction {
@@ -72,7 +72,7 @@ struct SendDoneV: View {
let terms = PeerContractTerms(amount: amountToSend,
summary: summary,
purse_expiration: timestamp)
- // TODO: user might choose baseURL
+ // TODO: let user choose baseURL
let response = try await model.initiatePeerPushDebitM(nil, terms: terms)
// will switch from WithdrawProgressView to TransactionDetailView
transactionId = response.transactionId
@@ -80,7 +80,7 @@ struct SendDoneV: View {
let terms = PeerContractTerms(amount: amountToReceive,
summary: summary,
purse_expiration: timestamp)
- // TODO: user might choose baseURL
+ // TODO: let user choose baseURL
let response = try await model.initiatePeerPullCreditM(nil, terms: terms)
// will switch from WithdrawProgressView to TransactionDetailView
transactionId = response.transactionId
diff --git a/TalerWallet1/Views/Peer2peer/SendPurpose.swift b/TalerWallet1/Views/Peer2peer/SendPurpose.swift
index ba17c92..9d6ff77 100644
--- a/TalerWallet1/Views/Peer2peer/SendPurpose.swift
+++ b/TalerWallet1/Views/Peer2peer/SendPurpose.swift
@@ -10,14 +10,17 @@ struct SendPurpose: View {
private let symLog = SymLogV(0)
let stack: CallStack
- let amountAvailable: Amount
- let amountToTransfer: Amount
- let fee: String
+ let amountToSend: Amount?
+ let amountToReceive: Amount?
+// let amountToTransfer: Amount
+ let navTitle: String
+ let buttonTitle: String
+ let feeLabel: String
let currencyInfo: CurrencyInfo
@Binding var summary: String
@Binding var expireDays: UInt
+
@AppStorage("iconOnly") var iconOnly: Bool = false
- let navTitle = String(localized: "NavTitle_Send_Subject", defaultValue: "Subject", comment: "NavTitle for entering the subject for Send-Money")
@State private var transactionStarted: Bool = false
@FocusState private var isFocused: Bool
@@ -27,30 +30,31 @@ struct SendPurpose: View {
let _ = Self._printChanges()
let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear
#endif
- let currency = amountAvailable.currencyStr
- let current = amountToTransfer.string(currencyInfo)
- ScrollView { VStack (spacing: 6) {
- Text(current)
- Text("+ \(fee) payment fee")
- .accessibilityFont(.body)
- .foregroundColor(.red)
- VStack(alignment: .leading, spacing: 6) {
+ ScrollView { VStack (alignment: .leading, spacing: 6) {
+ if feeLabel.count > 0 {
+ HStack {
+ Spacer()
+ Text(feeLabel)
+ .foregroundColor(.red)
+ .accessibilityFont(.body)
+ }
+ }
if !iconOnly {
Text("Enter subject:") // Purpose
- .accessibilityFont(.title2)
+ .accessibilityFont(.title3)
.accessibilityAddTraits(.isHeader)
.accessibilityRemoveTraits(.isStaticText)
.padding(.top)
}
Group { if #available(iOS 16.0, *) {
- TextField("Subject", text: $summary, axis: .vertical)
+ TextField(iconOnly ? "Subject" : EMPTYSTRING, text: $summary, axis: .vertical)
.focused($isFocused)
.lineLimit(2...)
} else {
TextField("Subject", text: $summary)
.focused($isFocused)
// .lineLimit(2...5) // lineLimit' is only available in iOS 16.0 or newer
- } }
+ } } // Group for iOS16+ & iOS15
.accessibilityFont(.title2)
.foregroundColor(WalletColors().fieldForeground) // text color
.background(WalletColors().fieldBackground)
@@ -77,23 +81,18 @@ struct SendPurpose: View {
let disabled = (expireDays == 0) || (summary.count < 1) // TODO: check amountAvailable
NavigationLink(destination: LazyView {
SendDoneV(stack: stack.push(),
- amountToSend: amountToTransfer,
- amountToReceive: nil,
+ amountToSend: amountToSend,
+ amountToReceive: amountToReceive,
summary: summary,
expireDays: expireDays,
transactionStarted: $transactionStarted)
}) {
- Text("Send \(current) now", comment: "amountToTransfer") // TODO: currency formatter
+ Text(buttonTitle)
}
.buttonStyle(TalerButtonStyle(type: .prominent))
.disabled(disabled)
.accessibilityHint(disabled ? "enabled when subject and expiration are set" : EMPTYSTRING)
-
- Spacer()
- }
- .frame(maxWidth: .infinity, alignment: .leading)
- .padding(.horizontal)
- } } // ScrollVStack
+ }.padding(.horizontal) } // ScrollVStack
.navigationTitle(navTitle)
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
.onAppear {