WalletEmptyView.swift (11971B)
1 /* 2 * This file is part of GNU Taler, ©2022-26 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * @author Marc Stibane 7 */ 8 import SwiftUI 9 import SymLog 10 import taler_swift 11 12 struct ProdSectionView: View { 13 let stack: CallStack 14 @Binding var showRealCashHint: Bool 15 let isEmpty: Bool 16 let disabled: Bool 17 18 @Environment(\.colorScheme) private var colorScheme 19 @Environment(\.colorSchemeContrast) private var colorSchemeContrast 20 @EnvironmentObject private var controller: Controller 21 @EnvironmentObject private var model: WalletModel 22 #if DEBUG 23 @AppStorage("developerMode") var developerMode: Bool = true 24 #else 25 @AppStorage("developerMode") var developerMode: Bool = false 26 #endif 27 @AppStorage("preferredColorScheme") var preferredColorScheme: Int = 0 28 @AppStorage("minimalistic") var minimalistic: Bool = false 29 30 @State private var selectedCurrency: Int = 0 31 32 func buttonAction() { 33 withAnimation { 34 showRealCashHint.toggle() 35 } 36 } 37 38 var body: some View { 39 let defaultExchanges = controller.defaultExchanges 40 let count = defaultExchanges.count 41 let section = Section { 42 let chevron = Image(systemName: CHEVRON_UP) // 43 if isEmpty { 44 Text("Welcome to Taler Wallet!") 45 .talerFont(.headline) 46 Text("To make your first payment, withdraw digital cash.") 47 .talerFont(.body) 48 } else { 49 let withdraw = Text("Withdraw real digital cash:") 50 .talerFont(.body) 51 Button(action: buttonAction) { 52 HStack(alignment: .firstTextBaseline) { 53 if minimalistic { 54 withdraw 55 } else { 56 Text("Currently you have only demo cash.") 57 .talerFont(.body) 58 } 59 Spacer() 60 chevron.rotationEffect(.degrees((showRealCashHint ? -180 : 0))) 61 .accessibilityHidden(true) 62 } 63 .accessibilityElement(children: .combine) 64 .accessibilityHint(Text(showRealCashHint ? "Hide available real money withdrawals" 65 : "Show available real money withdrawals")) 66 .contentShape(.rect) // can tap in background also 67 } .buttonStyle(.plain) 68 if showRealCashHint && !minimalistic { 69 withdraw 70 .padding(.vertical, -16) 71 } 72 } 73 #if false 74 let qrButton = Image(systemName: QRBUTTON) // "qrcode.viewfinder" 75 let settings = Image(systemName: SETTINGS) // "gear" 76 Text("Use «\(qrButton) Scan QR code» in the Actions menu to start a withdrawal if your bank already supports Taler payments.", comment: "« » 'qrcode.viewfinder'") 77 .talerFont(.body) 78 Text("You can also add a payment service manually in the \(settings) Settings tab.", comment: "« » 'gear'") 79 .talerFont(.body) 80 #endif 81 if (showRealCashHint) { 82 if developerMode { 83 if defaultExchanges.count > 1 { 84 CurrencyPicker(stack: stack.push(), value: $selectedCurrency, 85 exchanges: defaultExchanges) { index in 86 selectedCurrency = index 87 } 88 } 89 } 90 let defaultExchange = defaultExchanges[selectedCurrency < count ? selectedCurrency : 0] 91 let currency = defaultExchange.currency 92 let title = String(localized: "LinkTitle_Withdraw", defaultValue: "Withdraw \(currency)") 93 Button(title) { 94 if let talerUri = URL(string: defaultExchange.talerUri) { 95 controller.talerURI = talerUri 96 } 97 } 98 .buttonStyle(TalerButtonStyle(type: isEmpty ? .prominent : .bordered, 99 narrow: false, 100 disabled: disabled, 101 aligned: .center)) 102 .padding(.top, -6) 103 .padding(.bottom, 6) 104 } // showDropdown 105 } header: { 106 if isEmpty { 107 let firstHeader = EMPTYSTRING 108 Text(firstHeader) 109 .talerFont(.badge) 110 // .foregroundColor(.primary) 111 /// YIKES! when not specifying this color, the Text in the BarGraphHeader vanishes!!! 112 .foregroundColor(WalletColors().secondary2(colorScheme, colorSchemeContrast)) 113 // .listRowInsets(EdgeInsets()) // << here !! 114 } 115 } 116 .listRowSeparator(.hidden) 117 // .listSectionSpacing(.compact) iOS 17 118 119 if preferredColorScheme == 3, #available(iOS 17.0, *) { 120 section.listRowBackground(Color.white.opacity(0.1)) 121 } else { 122 section 123 } 124 } 125 } 126 // MARK: - 127 /// This view shows hints if a wallet is empty 128 /// It is the very first thing the user sees after installing the app 129 struct WalletEmptyHeader: View { 130 let stack: CallStack 131 @Binding var showRealCashHint: Bool 132 133 @EnvironmentObject private var controller: Controller 134 135 func refresh() async { 136 controller.hapticNotification(.success) 137 // symLog.log("refreshing balances") 138 await controller.loadBalances(stack.push("refreshing balances")) 139 } 140 141 var body: some View { 142 let emptyView = WalletEmptyView(stack: stack.push("isEmpty"), 143 showRealCashHint: $showRealCashHint) 144 // .navigationTitle("Taler Wallet") 145 .refreshable { 146 await refresh() 147 } 148 WalletHeader(showSettings: true, content: emptyView) 149 } 150 } 151 // MARK: - 152 struct WalletHeader<Content: View> : View { 153 let showSettings: Bool 154 let content: Content 155 156 @Environment(\.accessibilityVoiceOverEnabled) private var voiceOverEnabled 157 158 var body: some View { 159 let talerLogo = HStack(spacing: 2) { 160 Image(TALER_LOGO_FULL) 161 // .border(Color.gray, width: 1) 162 // Text("TALER Wallet") 163 Text("Wallet") 164 // .font(.logo(27, weight: .medium)) 165 .font(.logo("Atkinson Hyperlegible Next", size: 27, weight: .medium)) 166 .kerning(1.0) 167 .fixedSize(horizontal: true, vertical: true) 168 } 169 .accessibilityElement(children: .combine) 170 .accessibilityAddTraits(.isHeader) 171 .accessibilityLabel(Text("Taler Wallet", comment: "a11y")) 172 173 174 let logoItem = ToolbarItem(placement: .principal) { 175 talerLogo 176 .padding(.top, 10) 177 } 178 if showSettings, #available(iOS 26.0, *) { 179 if voiceOverEnabled { 180 content 181 .toolbar { logoItem } 182 } else { 183 content 184 .toolbar { 185 ToolbarItem(placement: .principal) { 186 HStack { 187 SettingsButton26(sortPriority: 0) 188 .hidden() 189 Spacer() 190 talerLogo 191 .padding(.top, 10) 192 Spacer() 193 SettingsButton26(sortPriority: 0) 194 .offset(x: 16, y: 0) 195 } 196 } 197 } 198 } 199 } else { // iOS 15..18 Settings is the 3rd tab 200 content 201 .toolbar { logoItem } 202 } 203 } 204 } 205 // MARK: - 206 struct WalletEmptyView: View { 207 private let symLog = SymLogV(0) 208 let stack: CallStack 209 @Binding var showRealCashHint: Bool 210 211 @EnvironmentObject private var controller: Controller 212 @EnvironmentObject private var model: WalletModel 213 @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic 214 @AppStorage("preferredColorScheme") var preferredColorScheme: Int = 0 215 @State private var withDrawStarted = false 216 @State private var urlToOpen: URL? = nil 217 218 var body: some View { 219 let list = List { 220 if !controller.defaultExchanges.isEmpty { 221 ProdSectionView(stack: stack.push(), 222 showRealCashHint: $showRealCashHint, 223 isEmpty: true, disabled: withDrawStarted) 224 } 225 #if GNU_TALER 226 Text("If you don't have a Swiss bank account, you can simply try out the demo…") 227 .talerFont(.body) 228 #endif 229 230 #if DEBUG 231 // if developerMode { 232 // Text("Either deposit or send your money to a friend before you delete the app, or it will be lost.") 233 // .talerFont(.body) 234 // } 235 #endif 236 let section = Section { 237 // Text("Demo") 238 // .talerFont(.headline) 239 // Text("Get digital cash to experience how easy you can pay online, and send money to friends & family.") 240 Text("Get demo cash to experience how to pay with digital cash.") 241 // Text("Get digital cash to experience how to pay with the money of the future.") 242 .talerFont(.body) 243 .listRowSeparator(.hidden) 244 let title = String(localized: "LinkTitle_Test_Money", defaultValue: "Get demo cash") 245 Button(title) { 246 withDrawStarted = true // don't run twice 247 Task { // runs on MainActor 248 let amount = Amount(currency: DEMOCURRENCY, cent: DEMOAMOUNT) 249 symLog.log("Withdraw 25 KUDOS") 250 try? await model.loadTestKudos(0, amount: amount) 251 DispatchQueue.main.asyncAfter(deadline: .now() + 5) { 252 withDrawStarted = false 253 } 254 } 255 } 256 .buttonStyle(TalerButtonStyle(type: .prominent, narrow: false, disabled: withDrawStarted, aligned: .center)) 257 .disabled(withDrawStarted) 258 // } header: { 259 // let secondHeader = String(localized: "Demo", comment: "section header") 260 // Text(secondHeader) 261 // .talerFont(.title3) 262 // .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) 263 } 264 if preferredColorScheme == 3, #available(iOS 17.0, *) { 265 section.listRowBackground(Color.white.opacity(0.1)) 266 } else { 267 section 268 } 269 } 270 .listStyle(myListStyle.style).anyView 271 .talerFont(.title2) 272 .background(FullBackground()) 273 ZStack { 274 if preferredColorScheme == 3, #available(iOS 17.0, *) { 275 list.scrollContentBackground(.hidden) 276 } else { 277 list 278 } 279 if withDrawStarted { 280 RotatingTaler(size: 150, progress: true, once: false, 281 background: nil, 282 rotationEnabled: $withDrawStarted) 283 } 284 } 285 .onAppear() { 286 DebugViewC.shared.setViewID(VIEW_EMPTY_WALLET, stack: stack.push("onAppear")) // 10 287 } 288 } 289 } 290 // MARK: - 291 struct WalletEmptyView_Previews: PreviewProvider { 292 static var previews: some View { 293 WalletEmptyView(stack: CallStack("Preview"), 294 showRealCashHint: Binding.constant(true)) 295 } 296 }