taler-ios

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

QRcodesForPayto.swift (3494B)


      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     var transferOptions: [TransferOption]
     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         List {
     50             if !minimalistic {
     51                 Text("If your banking software runs on another device, you can scan one of these QR codes:")
     52                     .listRowSeparator(.hidden)
     53             }
     54             ForEach(transferOptions, id: \.self) { option in
     55                 if let qrCodes = option.qrCodes {
     56                     ForEach(qrCodes, id: \.self) { spec in
     57                         QRcodeCopyShare(spec: spec, textToShare: textToShare)
     58                             .listRowSeparator(.automatic)
     59                     }
     60                 }
     61             }
     62         }
     63         .navigationTitle(navTitle)
     64         .onAppear() {
     65 //            symLog.log("onAppear")
     66             DebugViewC.shared.setViewID(VIEW_WITHDRAW_QRCODES, stack: stack.push())
     67         }
     68     }
     69 }
     70 // MARK: -
     71 #if DEBUG
     72 //struct QRcodesForPayto_Previews: PreviewProvider {
     73 //    static var previews: some View {
     74 //        let common = TransactionCommon(type: .withdrawal,
     75 //                                    txState: TransactionState(major: .done),
     76 //                            amountEffective: Amount(currency: LONGCURRENCY, cent: 110),
     77 //                                  amountRaw: Amount(currency: LONGCURRENCY, cent: 220),
     78 //                              transactionId: "someTxID",
     79 //                                  timestamp: Timestamp(from: 1_666_666_000_000),
     80 //                                  txActions: [])
     81 //        let payto = "payto://iban/SANDBOXX/DE159593?receiver-name=Exchange+Company"
     82 //        let details = WithdrawalDetails(type: .manual, 
     83 //                                  reservePub: "ReSeRvEpUbLiC_KeY_FoR_WiThDrAwAl",
     84 //                              reserveIsReady: false,
     85 //                                   confirmed: false)
     86 //        List {
     87 //            QRcodesForPayto(stack: CallStack("Preview"), qrCodeSpecs: details)
     88 //        }
     89 //    }
     90 //}
     91 #endif