summaryrefslogtreecommitdiff
path: root/TalerWallet1/Views/HelperViews/QRCodeDetailView.swift
blob: 3f7b1391c6646eab6196f7ea758abc4abdda8763 (plain)
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
/*
 * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
 * See LICENSE.md
 */
import SwiftUI
import taler_swift
import AVFoundation


struct QRCodeDetailView: View {
    let talerURI: String
    let incoming: Bool
    let amount: Amount?

    var body: some View {
        if talerURI.count > 10 {
            Section {
                Text("Either")
                    .multilineTextAlignment(.leading)
                    .accessibilityFont(.title3)
//                    .padding(.vertical)
                    .listRowSeparator(.hidden)

                CopyShare(textToCopy: talerURI)
                    .disabled(false)
//                    .padding(.bottom)
                    .listRowSeparator(.hidden)

                let otherParty = incoming ? String(localized: "payer")
                                          : String(localized: "payee")
                Text("the link to the \(otherParty), or", comment: "(copy/share) the link to the other party (payer/payee), or")
                    .multilineTextAlignment(.leading)
                    .accessibilityFont(.title3)
                    .listRowSeparator(.hidden)

                HStack {
                    Spacer()
                    QRGeneratorView(text: talerURI)
                        .accessibilityLabel("QR Code")
                    Spacer()
                }
                .listRowSeparator(.hidden)

                // TODO: use currency formatter instead of .readableDescription
                let hintStr = (amount == nil) ?
                    (incoming ? String(localized: "let the payer scan this QR code to pay.")
                              : String(localized: "let the payee scan this QR code to receive."))
                :   (incoming ? String(localized: "let the payer scan this QR code to pay \(amount!.readableDescription).",
                                       comment: "e.g. '5,3 €'")
                              : String(localized: "let the payee scan this QR code to receive \(amount!.readableDescription).",
                                       comment: "e.g. '$ 7.41'"))
                Text(hintStr)
                    .fixedSize(horizontal: false, vertical: true)       // wrap in scrollview
                    .accessibilityFont(.title3)
            }
        }
    }
}
// MARK: -
#if DEBUG
fileprivate struct ContentView: View {
    @State var talerURI: String = "taler://pay-push/exchange.demo.taler.net/95ZG4D1AGFGZQ7CNQ1V49D3FT18HXKA6HQT4X3XME9YSJQVFQ520"

    var body: some View {
        List {
            QRCodeDetailView(talerURI: talerURI, incoming: false, amount: nil)
        }
    }
}
struct QRCodeDetailView_Previews: PreviewProvider {

    static var previews: some View {
        ContentView()
    }
}
#endif