taler-ios

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

QRcodesForPayto.swift (3599B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import OrderedCollections
     10 import taler_swift
     11 
     12 struct QRcodeCopyShare: View {
     13     let spec: QrCodeSpec
     14     let textToShare: String
     15     @State private var qrImage: UIImage? = nil
     16 
     17     var body: some View {
     18 //        Text(spec.type)
     19         let logo = spec.type == "spc" ? Image(SWISS_QR) : nil
     20         let size = 276.0    // 46x46mm, swiss flag = 7x7mm plus border  276*9/46 = 54
     21         QRGeneratorView(text: spec.qrContent, size: size, logo: logo, logoSize: size * 9 / 46, image: $qrImage)
     22             .frame(maxWidth: .infinity, alignment: .center)
     23             .listRowSeparator(.hidden)
     24         HStack {
     25             Text(verbatim: "|")       // only reason for this leading-aligned text is to get a nice full length listRowSeparator
     26                 .accessibilityHidden(true)
     27                 .foregroundColor(Color.clear)
     28             //                  Spacer()
     29             CopyShare(textToCopy: textToShare, image: qrImage)
     30                 .disabled(false)
     31         }
     32     }
     33 }
     34 
     35 struct QRcodesForPayto: View {
     36     let stack: CallStack
     37     @Binding var qrCodeSpecs: [QrCodeSpec]
     38     let receiverStr: String
     39     let amountStr: String
     40     let messageStr: String?
     41 
     42     let navTitle = String(localized: "Wire transfer", comment: "ViewTitle of wire-transfer QR codes")
     43 
     44     @AppStorage("minimalistic") var minimalistic: Bool = false
     45 
     46     var body: some View {
     47         let message = messageStr ?? EMPTYSTRING
     48         let textToShare = String(receiverStr + "\n" + amountStr + "\n" + message)
     49         let count = qrCodeSpecs.count
     50         List {
     51             if !minimalistic {
     52                 if count > 1 {
     53                     Text("If your banking software runs on another device, you can scan one of these QR codes:")
     54                         .listRowSeparator(.hidden)
     55                 } else {
     56                     Text("If your banking software runs on another device, you can scan this QR code:")
     57                         .listRowSeparator(.hidden)
     58                 }
     59             }
     60             ForEach(qrCodeSpecs, id: \.self) { spec in
     61                 QRcodeCopyShare(spec: spec, textToShare: textToShare)
     62                     .listRowSeparator(.automatic)
     63             }
     64         }
     65         .navigationTitle(navTitle)
     66         .onAppear() {
     67 //            symLog.log("onAppear")
     68             DebugViewC.shared.setViewID(VIEW_WITHDRAW_QRCODES, stack: stack.push())
     69         }
     70     }
     71 }
     72 // MARK: -
     73 #if DEBUG
     74 //struct QRcodesForPayto_Previews: PreviewProvider {
     75 //    static var previews: some View {
     76 //        let common = TransactionCommon(type: .withdrawal,
     77 //                                    txState: TransactionState(major: .done),
     78 //                            amountEffective: Amount(currency: LONGCURRENCY, cent: 110),
     79 //                                  amountRaw: Amount(currency: LONGCURRENCY, cent: 220),
     80 //                              transactionId: "someTxID",
     81 //                                  timestamp: Timestamp(from: 1_666_666_000_000),
     82 //                                  txActions: [])
     83 //        let payto = "payto://iban/SANDBOXX/DE159593?receiver-name=Exchange+Company"
     84 //        let details = WithdrawalDetails(type: .manual, 
     85 //                                  reservePub: "ReSeRvEpUbLiC_KeY_FoR_WiThDrAwAl",
     86 //                              reserveIsReady: false,
     87 //                                   confirmed: false)
     88 //        List {
     89 //            QRcodesForPayto(stack: CallStack("Preview"), qrCodeSpecs: details)
     90 //        }
     91 //    }
     92 //}
     93 #endif