WalletEmptyView.swift (11810B)
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().secondary(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 132 @EnvironmentObject private var model: WalletModel 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"), model) 139 } 140 141 var body: some View { 142 let emptyView = WalletEmptyView(stack: stack.push("isEmpty")) 143 // .navigationTitle("Taler Wallet") 144 .refreshable { 145 await refresh() 146 } 147 WalletHeader(showSettings: true, content: emptyView) 148 } 149 } 150 // MARK: - 151 struct WalletHeader<Content: View> : View { 152 let showSettings: Bool 153 let content: Content 154 155 @Environment(\.accessibilityVoiceOverEnabled) private var voiceOverEnabled 156 157 var body: some View { 158 let talerLogo = HStack(spacing: 2) { 159 Image(TALER_LOGO_FULL) 160 // .border(Color.gray, width: 1) 161 // Text("TALER Wallet") 162 Text("Wallet") 163 // .font(.logo(27, weight: .medium)) 164 .font(.logo("Atkinson Hyperlegible Next", size: 27, weight: .medium)) 165 .kerning(1.0) 166 .fixedSize(horizontal: true, vertical: true) 167 } 168 .accessibilityElement(children: .combine) 169 .accessibilityAddTraits(.isHeader) 170 .accessibilityLabel(Text("Taler Wallet", comment: "a11y")) 171 172 173 let logoItem = ToolbarItem(placement: .principal) { 174 talerLogo 175 .padding(.top, 10) 176 } 177 if showSettings, #available(iOS 26.0, *) { 178 if voiceOverEnabled { 179 content 180 .toolbar { logoItem } 181 } else { 182 content 183 .toolbar { 184 ToolbarItem(placement: .principal) { 185 HStack { 186 SettingsButton26(sortPriority: 0) 187 .hidden() 188 Spacer() 189 talerLogo 190 .padding(.top, 10) 191 Spacer() 192 SettingsButton26(sortPriority: 0) 193 .offset(x: 16, y: 0) 194 } 195 } 196 } 197 } 198 } else { // iOS 15..18 Settings is the 3rd tab 199 content 200 .toolbar { logoItem } 201 } 202 } 203 } 204 // MARK: - 205 struct WalletEmptyView: View { 206 private let symLog = SymLogV(0) 207 let stack: CallStack 208 209 @EnvironmentObject private var controller: Controller 210 @EnvironmentObject private var model: WalletModel 211 @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic 212 @AppStorage("preferredColorScheme") var preferredColorScheme: Int = 0 213 @State private var withDrawStarted = false 214 @State private var urlToOpen: URL? = nil 215 @State private var showRealCashHint = true 216 217 var body: some View { 218 let list = List { 219 if !controller.defaultExchanges.isEmpty { 220 ProdSectionView(stack: stack.push(), 221 showRealCashHint: $showRealCashHint, 222 isEmpty: true, disabled: withDrawStarted) 223 } 224 #if GNU_TALER 225 Text("If you don't have a Swiss bank account, you can simply try out the demo…") 226 .talerFont(.body) 227 #endif 228 229 #if DEBUG 230 // if developerMode { 231 // Text("Either deposit or send your money to a friend before you delete the app, or it will be lost.") 232 // .talerFont(.body) 233 // } 234 #endif 235 let section = Section { 236 // Text("Demo") 237 // .talerFont(.headline) 238 // Text("Get digital cash to experience how easy you can pay online, and send money to friends & family.") 239 Text("Get demo cash to experience how to pay with digital cash.") 240 // Text("Get digital cash to experience how to pay with the money of the future.") 241 .talerFont(.body) 242 .listRowSeparator(.hidden) 243 let title = String(localized: "LinkTitle_Test_Money", defaultValue: "Get demo cash") 244 Button(title) { 245 withDrawStarted = true // don't run twice 246 Task { // runs on MainActor 247 let amount = Amount(currency: DEMOCURRENCY, cent: 2500) 248 symLog.log("Withdraw 25 KUDOS") 249 try? await model.loadTestKudos(0, amount: amount) 250 DispatchQueue.main.asyncAfter(deadline: .now() + 5) { 251 withDrawStarted = false 252 } 253 } 254 } 255 .buttonStyle(TalerButtonStyle(type: .prominent, narrow: false, disabled: withDrawStarted, aligned: .center)) 256 .disabled(withDrawStarted) 257 // } header: { 258 // let secondHeader = String(localized: "Demo", comment: "section header") 259 // Text(secondHeader) 260 // .talerFont(.title3) 261 // .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) 262 } 263 if preferredColorScheme == 3, #available(iOS 17.0, *) { 264 section.listRowBackground(Color.white.opacity(0.1)) 265 } else { 266 section 267 } 268 } 269 .listStyle(myListStyle.style).anyView 270 .talerFont(.title2) 271 .background(FullBackground()) 272 ZStack { 273 if preferredColorScheme == 3, #available(iOS 17.0, *) { 274 list.scrollContentBackground(.hidden) 275 } else { 276 list 277 } 278 if withDrawStarted { 279 RotatingTaler(size: 150, progress: true, once: false, rotationEnabled: $withDrawStarted) 280 } 281 } 282 .onAppear() { 283 DebugViewC.shared.setViewID(VIEW_EMPTY_WALLET, stack: stack.push("onAppear")) // 10 284 } 285 } 286 } 287 // MARK: - 288 struct WalletEmptyView_Previews: PreviewProvider { 289 static var previews: some View { 290 WalletEmptyView(stack: CallStack("Preview")) 291 } 292 }