DebugViewC.swift (9792B)
1 /* MIT License 2 * Copyright (c) 2023 Marc Stibane 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in all 12 * copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 * SOFTWARE. 21 */ 22 import SwiftUI 23 import SymLog 24 import os.log 25 26 // Numbering Scheme for Views 27 // MARK: - Main View 28 public let VIEW_EMPTY_WALLET = 10 // 10 WalletEmptyView 29 public let VIEW_BALANCES = VIEW_EMPTY_WALLET + 1 // 11 BalancesListView 30 public let VIEW_CAROUSEL = VIEW_BALANCES + 1 // 12 CarouselView 31 32 // MARK: - Transactions 33 public let VIEW_EMPTY_HISTORY = VIEW_EMPTY_WALLET + 10 // 20 TransactionsEmptyView 34 public let VIEW_TRANSACTIONLIST = VIEW_EMPTY_HISTORY + 1 // 21 TransactionsListView 35 public let VIEW_TRANSACTIONSUMMARY = VIEW_TRANSACTIONLIST + 1 // 22 TransactionSummary 36 public let VIEW_TRANSACTIONDETAIL = VIEW_TRANSACTIONSUMMARY + 1 // 23 TransactionDetail 37 38 // MARK: - (Manual) Withdrawal (from Actions) 39 // receive coins from bank ==> shows payee, IBAN + Purpose/Subject for manual wire transfer 40 public let VIEW_WITHDRAWAL = VIEW_EMPTY_HISTORY + 10 // 30 WithdrawAmount 41 public let VIEW_WITHDRAW_TOS = VIEW_WITHDRAWAL + 1 // 31 WithdrawTOSView 42 public let VIEW_WITHDRAW_ACCEPT = VIEW_WITHDRAW_TOS + 1 // 32 ManualWithdrawDone 43 public let VIEW_WITHDRAW_INSTRUCTIONS = VIEW_WITHDRAW_ACCEPT + 1 // 33 ManualDetailsWireV 44 public let VIEW_WITHDRAW_QRCODES = VIEW_WITHDRAW_INSTRUCTIONS + 1 // 34 QRcodesForPayto 45 46 // MARK: (Manual) Deposit (from Actions) 47 // send money back to user's bank account ==> instruct exchange to make the wire transfer 48 public let VIEW_DEPOSIT = VIEW_WITHDRAWAL + 10 // 40 Deposit Coins 49 //public let VIEW_DEPOSIT_TOS // - user already accepted the ToS at withdrawal, invoice or receive 50 public let VIEW_DEPOSIT_ACCEPT = VIEW_DEPOSIT + 2 // 42 51 52 // MARK: start a Send (from Actions) 53 // push debit to another wallet ==> shows QR code to be scanned / link to be sent by mail or messenger 54 public let VIEW_P2P_SEND = VIEW_DEPOSIT + 10 // 50 Send Coins 55 //public let VIEW_SEND_TOS // - user already accepted the ToS at withdrawal, invoice or receive 56 public let VIEW_P2P_SUBJECT = VIEW_P2P_SEND + 2 // 52 Send / Request Subject 57 public let VIEW_P2P_READY = VIEW_P2P_SUBJECT + 1 // 53 Send / Request Ready 58 59 // MARK: start a Request (from Actions) 60 // pull credit from another wallet ==> shows QR code to be scanned / link to be sent by mail or messenger 61 public let VIEW_P2P_REQUEST = VIEW_P2P_SEND + 10 // 60 Request Amount 62 public let VIEW_P2P_TOS = VIEW_P2P_REQUEST + 1 // 61 Request ToS 63 64 // MARK: - Settings 65 public let VIEW_SETTINGS = VIEW_P2P_REQUEST + 10 // 70 SettingsView 66 public let VIEW_ABOUT = VIEW_SETTINGS + 1 // 71 AboutView 67 public let VIEW_PAYMENT_SERVICES = VIEW_ABOUT + 1 // 72 ExchangeListView 68 public let VIEW_BANK_ACCOUNTS = VIEW_PAYMENT_SERVICES + 1 // 73 BankListView 69 public let VIEW_BACKUP = VIEW_BANK_ACCOUNTS + 1 // 74 BackupView 70 public let VIEW_SETTINGS2 = VIEW_BACKUP + 1 // 75 MoreSettingsView 71 public let VIEW_SETTINGS3 = VIEW_SETTINGS2 + 1 // 76 DebugSettingsView 72 73 // MARK: - Business Invoice (from Actions) 74 // TBD 75 //public let VIEW_INVOICE_P2P = VIEW_SETTINGS + 10 // 80 Invoice Amount 76 //public let VIEW_INVOICE_TOS = VIEW_INVOICE_P2P + 1 // 81 Invoice ToS 77 //public let VIEW_INVOICE_PURPOSE = VIEW_INVOICE_TOS + 1 // 82 Invoice Purpose 78 79 80 // MARK: scan Bank-Integrated Withdrawal 81 public let SHEET_WITHDRAWAL = VIEW_WITHDRAWAL + 100 // 130 WithdrawUriScan 82 public let SHEET_WITHDRAW_TOS = SHEET_WITHDRAWAL + 1 // 131 WithdrawTOSView 83 public let SHEET_WITHDRAW_ACCEPT = SHEET_WITHDRAW_TOS + 1 // 132 WithdrawAcceptView 84 public let SHEET_WITHDRAW_AUTHORIZE = SHEET_WITHDRAW_ACCEPT + 1 // 133 waiting for bank confirmation 85 86 public let SHEET_WITHDRAW_EXCHANGE = SHEET_WITHDRAWAL + 5 // 135 WithdrawExchangeScan 87 88 // MARK: scan Merchant Payment 89 public let SHEET_PAYMENT = SHEET_WITHDRAWAL + 10 // 140 Pay Merchant 90 public let SHEET_PAY_TEMPLATE = SHEET_PAYMENT + 1 // 141 Pay Merchant Template 91 public let SHEET_PAY_TEMPL_AMOUNT = SHEET_PAY_TEMPLATE + 1 // 142 Pay Template Amount 92 public let SHEET_PAY_TEMPL_SUBJECT = SHEET_PAY_TEMPL_AMOUNT + 1 // 143 Pay Template Subject 93 public let SHEET_PAY_CONFIRM = SHEET_PAY_TEMPL_SUBJECT + 1 // 144 Pay Confirm 94 95 // MARK: scan Pay Request P2P 96 public let SHEET_PAY_P2P = SHEET_PAYMENT + 10 // 150 Pay P2P Request 97 public let SHEET_PAY_P2P_CONFIRM = SHEET_PAY_P2P + 2 // 152 Pay P2P Confirm 98 99 // MARK: scan Receive P2P 100 public let SHEET_RCV_P2P = SHEET_PAY_P2P + 10 // 160 Receive Money 101 public let SHEET_RCV_P2P_TOS = SHEET_RCV_P2P + 1 // 161 Receive TOSView 102 public let SHEET_RCV_P2P_ACCEPT = SHEET_RCV_P2P_TOS + 1 // 162 Receive AcceptView 103 104 // MARK: scan Refund - get money back from merchant 105 public let SHEET_REFUND = SHEET_RCV_P2P + 10 // 170 Receive Refunds 106 107 108 // MARK: - 109 struct DebugViewV: View { 110 private let symLog = SymLogV(0) 111 @EnvironmentObject private var debugViewC: DebugViewC 112 113 var body: some View { 114 #if PRINT_CHANGES 115 // let _ = Self._printChanges() 116 // let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear 117 #endif 118 let viewIDString = debugViewC.viewID > 0 ? String(debugViewC.viewID) 119 : EMPTYSTRING 120 let viewIDv = Text(viewIDString) 121 .foregroundColor(.red) 122 .font(.system(size: 11)) // no talerFont 123 .monospacedDigit() 124 .id("viewID") 125 HStack { 126 Spacer() 127 viewIDv 128 .padding(.trailing, UIScreen.hasNotch ? 50 : 60) // need more space for touchID phones 129 } 130 .accessibilityHidden(true) 131 .ignoresSafeArea(edges: .top) 132 } 133 } 134 // MARK: - 135 class DebugViewC: ObservableObject { 136 private let symLog = SymLogC(0) // 0 to switch off viewID change logging 137 public static let shared = DebugViewC() 138 #if DEBUG 139 @AppStorage("developerMode") var developerMode: Bool = true 140 #else 141 @AppStorage("developerMode") var developerMode: Bool = false 142 #endif 143 let logger = Logger(subsystem: "net.taler.gnu", category: "DebugView") 144 145 @Published var viewID: Int = 0 146 @Published var sheetID: Int = 0 147 148 // func announce(_ this: String) { 149 // if UIAccessibility.isVoiceOverRunning { 150 // UIAccessibility.post(notification: .announcement, argument: this) 151 // } 152 // } 153 154 @MainActor func setViewID(_ newID: Int, stack: CallStack) -> Void { 155 #if DEBUG 156 let msg = stack.peek()?.file ?? "?" 157 #else 158 let msg = stack.peek()?.message ?? "?" 159 #endif 160 if viewID == 0 { 161 logger.log("switching to \(newID, privacy: .public) \(msg, privacy: .public)") 162 if developerMode { viewID = newID } 163 } else if viewID != newID { 164 logger.log("switching from \(self.viewID, privacy: .public) to \(newID, privacy: .public) \(msg, privacy: .public)") 165 viewID = developerMode ? newID : 0 166 } else { 167 logger.log("\(newID, privacy: .public) stays \(msg, privacy: .public)") 168 // don't set viewID to the same value, it would just trigger an unneccessary redraw 169 if !developerMode { viewID = 0 } 170 } 171 } 172 173 @MainActor func setSheetID(_ newID: Int, stack: CallStack) -> Void { 174 #if DEBUG 175 let msg = stack.peek()?.file ?? "?" 176 #else 177 let msg = stack.peek()?.message ?? "?" 178 #endif 179 if sheetID == 0 { 180 logger.log("switching to \(newID, privacy: .public) \(msg, privacy: .public)") 181 if developerMode { sheetID = newID } 182 } else if sheetID != newID { 183 logger.log("sheet switching from \(self.sheetID, privacy: .public) to \(newID, privacy: .public) \(msg, privacy: .public)") 184 sheetID = developerMode ? newID : 0 // publish new sheetID 185 } else { 186 logger.log("sheet \(newID, privacy: .public) stays \(msg, privacy: .public)") 187 // don't set sheetID to the same value, it would just trigger an unneccessary redraw 188 if !developerMode { sheetID = 0 } 189 } 190 } 191 }