taler-ios

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

P2pAcceptDone.swift (2601B)


      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 taler_swift
     10 import SymLog
     11 
     12 // Called when accepting a scanned P2P transaction: Receive, or pay Request(Invoice)
     13 struct P2pAcceptDone: View {
     14     private let symLog = SymLogV(0)
     15     let stack: CallStack
     16 
     17     let url: URL?
     18     let transactionId: String
     19     let incoming: Bool
     20 
     21     @EnvironmentObject private var controller: Controller
     22     @EnvironmentObject private var model: WalletModel
     23 
     24     @MainActor
     25     private func viewDidLoad() async {
     26         if incoming {
     27             if let _ = try? await model.acceptPeerPushCredit(transactionId) {
     28                 if let url {
     29                     controller.removeURL(url)
     30                 }
     31                 dismissTop(stack.push())
     32             }
     33         } else {
     34             if let _ = try? await model.confirmPeerPullDebit(transactionId) {
     35                 if let url {
     36                     controller.removeURL(url)
     37                 }
     38                 dismissTop(stack.push())
     39             }
     40         }
     41     }
     42 
     43     var body: some View {
     44 #if PRINT_CHANGES
     45         let _ = Self._printChanges()
     46         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     47 #endif
     48         let navTitle = incoming ? String(localized: "Received", comment: "Nav Title, short")
     49                                 : String(localized: "Paid", comment: "Nav Title, short")
     50         let message = String(localized: "Accepting...", comment: "loading")
     51         LoadingView(stack: stack.push(), scopeInfo: nil, message: message)
     52             .navigationBarBackButtonHidden(true)
     53 //            .interactiveDismissDisabled()           // can only use "Done" button to dismiss
     54             .navigationTitle(navTitle)
     55             .task { await viewDidLoad() }
     56             .onAppear() {
     57                 symLog.log("onAppear")
     58                 let isSheet: Bool = true
     59                 let viewID = incoming ? SHEET_RCV_P2P_ACCEPT
     60                                       : SHEET_PAY_P2P_CONFIRM
     61                 if isSheet {
     62                     DebugViewC.shared.setSheetID(viewID, stack: stack.push())
     63                 } else {
     64                     DebugViewC.shared.setViewID(viewID, stack: stack.push())
     65                 }
     66             }
     67     }
     68 }
     69 // MARK: -
     70 struct P2pAcceptDone_Previews: PreviewProvider {
     71     static var previews: some View {
     72         P2pAcceptDone(stack: CallStack("Preview"),
     73                         url: URL("taler://nothing"),
     74               transactionId: "some ID",
     75                    incoming: true)
     76     }
     77 }