DebugViewC.swift (10216B)
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 coins back to customer ==> instruct exchange to make the wire transfer to the customer's bank account 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: 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: 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: - Bank-Integrated Withdrawal 81 // openURL (Link or scan QR) ==> obtains coins from bank 82 public let SHEET_WITHDRAWAL = VIEW_WITHDRAWAL + 100 // 130 WithdrawURIView 83 public let SHEET_WITHDRAW_TOS = SHEET_WITHDRAWAL + 1 // 131 WithdrawTOSView 84 public let SHEET_WITHDRAW_ACCEPT = SHEET_WITHDRAW_TOS + 1 // 132 WithdrawAcceptView 85 public let SHEET_WITHDRAW_AUTHORIZE = SHEET_WITHDRAW_ACCEPT + 1 // 133 waiting for bank confirmation 86 87 public let SHEET_WITHDRAW_EXCHANGE = SHEET_WITHDRAWAL + 5 // 135 WithdrawExchangeV 88 89 90 // MARK: Merchant Payment 91 // openURL (Link, NFC or scan QR) ==> pays merchant 92 public let SHEET_PAYMENT = SHEET_WITHDRAWAL + 10 // 140 Pay Merchant 93 public let SHEET_PAY_TEMPLATE = SHEET_PAYMENT + 1 // 141 Pay Merchant Template 94 public let SHEET_PAY_TEMPL_AMOUNT = SHEET_PAY_TEMPLATE + 1 // 142 Pay Template Amount 95 public let SHEET_PAY_TEMPL_SUBJECT = SHEET_PAY_TEMPL_AMOUNT + 1 // 143 Pay Template Subject 96 public let SHEET_PAY_CONFIRM = SHEET_PAY_TEMPL_SUBJECT + 1 // 144 Pay Confirm 97 98 // MARK: Pay Request 99 // peer pull debit - openURL (Link or scan QR) 100 public let SHEET_PAY_P2P = SHEET_PAYMENT + 10 // 150 Pay P2P Request 101 public let SHEET_PAY_P2P_CONFIRM = SHEET_PAY_P2P + 2 // 152 Pay P2P Confirm 102 103 // MARK: Receive 104 // peer push credit - openURL (Link or scan QR) 105 public let SHEET_RCV_P2P = SHEET_PAY_P2P + 10 // 160 Receive Money 106 public let SHEET_RCV_P2P_TOS = SHEET_RCV_P2P + 1 // 161 Receive TOSView 107 public let SHEET_RCV_P2P_ACCEPT = SHEET_RCV_P2P_TOS + 1 // 162 Receive AcceptView 108 109 // MARK: Refund - Get Coins back from merchant 110 // openURL (Link, NFC or scan QR) ==> receive coins from merchant 111 public let SHEET_REFUND = SHEET_RCV_P2P + 10 // 170 Receive Refunds 112 113 114 // MARK: - 115 struct DebugViewV: View { 116 private let symLog = SymLogV(0) 117 @EnvironmentObject private var debugViewC: DebugViewC 118 119 var body: some View { 120 #if PRINT_CHANGES 121 // let _ = Self._printChanges() 122 // let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear 123 #endif 124 let viewIDString = debugViewC.viewID > 0 ? String(debugViewC.viewID) 125 : EMPTYSTRING 126 let viewIDv = Text(viewIDString) 127 .foregroundColor(.red) 128 .font(.system(size: 11)) // no talerFont 129 .monospacedDigit() 130 .id("viewID") 131 HStack { 132 Spacer() 133 viewIDv 134 .padding(.trailing, UIScreen.hasNotch ? 50 : 60) // need more space for touchID phones 135 } 136 .accessibilityHidden(true) 137 .ignoresSafeArea(edges: .top) 138 } 139 } 140 // MARK: - 141 class DebugViewC: ObservableObject { 142 private let symLog = SymLogC(0) // 0 to switch off viewID change logging 143 public static let shared = DebugViewC() 144 #if DEBUG 145 @AppStorage("developerMode") var developerMode: Bool = true 146 #else 147 @AppStorage("developerMode") var developerMode: Bool = false 148 #endif 149 let logger = Logger(subsystem: "net.taler.gnu", category: "DebugView") 150 151 @Published var viewID: Int = 0 152 @Published var sheetID: Int = 0 153 154 // func announce(_ this: String) { 155 // if UIAccessibility.isVoiceOverRunning { 156 // UIAccessibility.post(notification: .announcement, argument: this) 157 // } 158 // } 159 160 @MainActor func setViewID(_ newID: Int, stack: CallStack) -> Void { 161 if developerMode { 162 if viewID == 0 { 163 logger.log("switching ON, \(newID, privacy: .public)") 164 viewID = newID // publish ON 165 // announce("Current view is: \(newID).") 166 } else if viewID != newID { 167 logger.log("switching from \(self.viewID, privacy: .public) to \(newID, privacy: .public)") 168 // announce("View switched from \(self.viewID) to \(newID).") 169 viewID = newID // publish new viewID 170 } else { 171 logger.log("\(newID, privacy: .public) stays") 172 // don't set viewID to the same value, it would just trigger an unneccessary redraw 173 } 174 } else { 175 logger.log("view \(newID, privacy: .public)") 176 if viewID > 0 { 177 viewID = 0 // publish OFF 178 } 179 } 180 } 181 182 @MainActor func setSheetID(_ newID: Int) -> Void { 183 if developerMode { 184 if sheetID != newID { 185 logger.log("sheet switching from \(self.sheetID, privacy: .public) to \(newID, privacy: .public)") 186 sheetID = newID // publish new sheetID 187 } else { 188 logger.log("sheet \(newID, privacy: .public) stays") 189 // don't set sheetID to the same value, it would just trigger an unneccessary redraw 190 } 191 } else { 192 logger.log("sheet \(newID, privacy: .public)") 193 if sheetID > 0 { 194 // might happen after switching DevMode off, if sheetID still has the old value of the last sheet 195 sheetID = 0 // publish OFF 196 } 197 } 198 } 199 }