P2pAcceptDone.swift (2366B)
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 DebugViewC.shared.setSheetID(incoming ? SHEET_RCV_P2P_ACCEPT 59 : SHEET_PAY_P2P_CONFIRM) 60 } 61 } 62 } 63 // MARK: - 64 struct P2pAcceptDone_Previews: PreviewProvider { 65 static var previews: some View { 66 P2pAcceptDone(stack: CallStack("Preview"), 67 url: URL("taler://nothing"), 68 transactionId: "some ID", 69 incoming: true) 70 } 71 }