taler-ios

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

QRcodesForPayto.swift (3347B)


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