taler-ios

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

PaymentDone.swift (2692B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import SymLog
     10 
     11 struct PaymentDone: View {
     12     private let symLog = SymLogV(0)
     13     let stack: CallStack
     14     let url: URL
     15 //    let scope: ScopeInfo?
     16     let transactionId: String
     17 
     18     @EnvironmentObject private var controller: Controller
     19     @EnvironmentObject private var model: WalletModel
     20 
     21     @State private var paymentDone: Bool = false
     22     @State private var talerTX: TalerTransaction = TalerTransaction(dummyCurrency: DEMOCURRENCY)
     23 
     24     @MainActor
     25     private func viewDidLoad() async {
     26         if let confirmPayResult = try? await model.confirmPay(transactionId) {
     27 //          symLog.log(confirmPayResult as Any)
     28             if confirmPayResult.type == "done" {
     29                 controller.removeURL(url)
     30                 paymentDone = true
     31             }
     32         }
     33     }
     34 
     35     var body: some View {
     36 #if PRINT_CHANGES
     37         let _ = Self._printChanges()
     38         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     39 #endif
     40         Group {
     41             if paymentDone {
     42                 let navTitle = String(localized: "Paid", comment: "Title, short")
     43                 TransactionSummaryV(stack: stack.push(),
     44 //                                    scope: scope,
     45                             transactionId: transactionId,
     46                                   talerTX: $talerTX,
     47                                  navTitle: navTitle,
     48                                   hasDone: true,
     49                               abortAction: nil,
     50                              deleteAction: nil,
     51                                failAction: nil,
     52                             suspendAction: nil,
     53                              resumeAction: nil)
     54                 .navigationBarBackButtonHidden(true)
     55                 .interactiveDismissDisabled()           // can only use "Done" button to dismiss
     56                 .navigationTitle(navTitle)
     57                 .safeAreaInset(edge: .bottom) {
     58                     Button("Done") { dismissTop(stack.push()) }
     59                         .buttonStyle(TalerButtonStyle(type: .bordered))
     60                         .padding(.horizontal)
     61                 }
     62             } else {
     63                 let message = String(localized: "Paying...", comment: "loading")
     64                 LoadingView(stack: stack.push(), scopeInfo: nil, message: message)
     65                     .task { await viewDidLoad() }
     66             }
     67         }.onAppear() {
     68             symLog.log("onAppear")
     69             DebugViewC.shared.setSheetID(SHEET_PAY_CONFIRM)
     70         }
     71     }
     72 }
     73 
     74 // MARK: -
     75 //#Preview {
     76 //    PaymentDone(stack: CallStack("Preview"))
     77 //}