taler-ios

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

KYCauth.swift (4766B)


      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 SymLog
     10 
     11 struct KYCauth: View {
     12     let stack: CallStack
     13     let common: TransactionCommon
     14 
     15     @AppStorage("minimalistic") var minimalistic: Bool = false
     16     @State private var accountID = 0
     17     @State private var listID = UUID()
     18 
     19     func redraw(_ newAccount: Int) -> Void {
     20         if newAccount != accountID {
     21             accountID = newAccount
     22             withAnimation { listID = UUID() }
     23         }
     24     }
     25 
     26     func validDetails(_ paytoUris: [String]) -> [ExchangeAccountDetails] {
     27         var details: [ExchangeAccountDetails] = []
     28         for paytoUri in paytoUris {
     29             let payTo = PayTo(paytoUri)
     30             let amount = common.kycAuthTransferInfo?.amount
     31             let detail = ExchangeAccountDetails(status: "ok",
     32                                               paytoUri: paytoUri,
     33                                         transferAmount: amount,
     34                                                  scope: common.scopes[0])
     35             details.append(detail)
     36         }
     37         return details
     38     }
     39 
     40     var body: some View {
     41         if let info = common.kycAuthTransferInfo {
     42             let debitPayTo = PayTo(info.debitPaytoUri)
     43             let amount = info.amount
     44             let amountStr = amount.formatted(specs: nil,
     45                                         isNegative: false,
     46                                              scope: common.scopes[0])
     47             let amountValue = amount.valueStr
     48             let creditPaytoUris = info.creditPaytoUris
     49             let validDetails = validDetails(creditPaytoUris)
     50             if !validDetails.isEmpty {
     51                 let countPaytos = creditPaytoUris.count
     52                 let account = validDetails[accountID]
     53 
     54                 Text("You need to prove having control over the bank account for the deposit.")
     55                     .bold()
     56                     .fixedSize(horizontal: false, vertical: true)       // wrap in scrollview
     57                     .multilineTextAlignment(.leading)                   // otherwise
     58                     .listRowSeparator(.hidden)
     59 
     60                 if countPaytos > 1 {
     61                     if countPaytos > 3 { // too many for SegmentControl
     62                         AccountPicker(title: String(localized: "Bank"),
     63                                       value: $accountID,
     64                              accountDetails: validDetails,
     65                                      action: redraw)
     66                         .listRowSeparator(.hidden)
     67                         .pickerStyle(.menu)
     68                     } else {
     69                         SegmentControl(value: $accountID,
     70                               accountDetails: validDetails,
     71                                       action: redraw)
     72                         .listRowSeparator(.hidden)
     73                     }
     74                 } else if let creditPaytoUri = creditPaytoUris.first {
     75                     if let bankName = account.bankLabel {
     76                         Text(bankName + ":   " + amountStr.0)
     77                             .accessibilityLabel(bankName + ":   " + amountStr.1)
     78 //                    } else {
     79 //                        Text(amountStr)
     80                     }
     81                 }
     82                 let payto = PayTo(account.paytoUri)
     83                 if let receiverStr = payto.receiver {
     84                     let wireDetails = ManualDetailsWireV(stack: stack.push(),
     85                                                     reservePub: info.accountPub,
     86                                                    receiverStr: receiverStr,
     87                                                    receiverZip: payto.postalCode,
     88                                                   receiverTown: payto.town,
     89                                                           iban: payto.iban,
     90                                                         cyclos: payto.cyclos ?? EMPTYSTRING,
     91                                                         xTaler: payto.xTaler ?? EMPTYSTRING,
     92                                                    amountValue: amountValue,
     93                                                      amountStr: amountStr,
     94                                                      obtainStr: nil,        // only for withdrawal
     95                                                      debitIBAN: debitPayTo.iban,
     96                                                        account: account)
     97                     NavigationLink(destination: wireDetails) {
     98                         Text(minimalistic ? "Instructions"
     99                                           : "Wire transfer instructions")
    100                         .talerFont(.title3)
    101                     }
    102                 }
    103             }
    104         }
    105     } // body
    106 }