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