1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
* See LICENSE.md
*/
import SwiftUI
import taler_swift
import SymLog
struct PaymentPurpose: View {
private let symLog = SymLogV(0)
let stack: CallStack
let scopeInfo: ScopeInfo
let centsToTransfer: UInt64
let fee: String
@Binding var summary: String
@Binding var expireDays: UInt
@AppStorage("iconOnly") var iconOnly: Bool = false
let navTitle = String(localized: "NavTitle_Request_Subject", defaultValue: "Request", comment: "NavTitle for entering the subject for Request-Payment")
@FocusState private var isFocused: Bool
private var label: String {
// let mag = pow(10, formatter.maximumFractionDigits)
// return formatter.string(for: Decimal(centsToTransfer) / mag) ?? ""
return String(centsToTransfer / 100) // TODO: based on currency
}
var body: some View {
let amount = Amount.amountFromCents(scopeInfo.currency, centsToTransfer)
VStack (spacing: 6) {
Text(amount.readableDescription)
Text("+ \(fee) payment fee")
.foregroundColor(.red)
VStack(alignment: .leading, spacing: 6) {
if !iconOnly {
Text("Subject:")
.accessibilityFont(.title3)
.padding(.top)
}
TextField("Subject", text: $summary)
.accessibilityFont(.title)
.foregroundColor(WalletColors().fieldForeground) // text color
.background(WalletColors().fieldBackground)
.textFieldStyle(.roundedBorder)
.focused($isFocused)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
isFocused = true // make first responder - raise keybord
}
}
HStack{
Spacer()
Text(verbatim: "\(summary.count)/100")
} // maximum 100 characters
SelectDays(selected: $expireDays, maxExpiration: THIRTYDAYS)
.disabled(false)
.padding(.bottom)
let emptyStr = ""
let disabled = (expireDays == 0) || (summary.count < 1)
NavigationLink(destination: LazyView {
SendDone(stack: stack.push(),
amountToSend: nil,
amountToReceive: amount,
summary: summary,
expireDays: expireDays)
}) {
Text("Request \(label) \(scopeInfo.currency)")
// .accessibilityFont(buttonFont)
}
.buttonStyle(TalerButtonStyle(type: .prominent))
.disabled(disabled)
.accessibilityHint(disabled ? "enabled when subject and expiration are set" : emptyStr)
Spacer()
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal)
}
.navigationTitle(navTitle)
.background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
.onAppear {
DebugViewC.shared.setViewID(VIEW_REQUEST_PURPOSE, stack: stack.push())
// print("❗️ PaymentPurpose onAppear")
}
.onDisappear {
// print("❗️ PaymentPurpose onDisappear")
}
}
}
// MARK: -
#if DEBUG
//struct PaymentPurpose_Previews: PreviewProvider {
// static var previews: some View {
// let scopeInfo = ScopeInfo(type: ScopeInfo.ScopeInfoType.exchange, exchangeBaseUrl: DEMOEXCHANGE, currency: LONGCURRENCY)
// @State var summary: String = "pUrPoSe"
// @State var expireDays: UInt = 0
// PaymentPurpose(scopeInfo: scopeInfo,
// centsToTransfer: 5,
// fee: "fee",
// summary: $summary,
// expireDays: $expireDays)
// }
//}
#endif
|