taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

TalDirSettingsView.swift (5636B)


      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 taler_swift
     10 import SymLog
     11 
     12 #if GNU_TALER || TALER_NIGHTLY
     13 struct TalDirSettingsView: View {
     14     private let symLog = SymLogV(0)
     15     let stack: CallStack
     16     let navTitle: String
     17 
     18     @EnvironmentObject private var controller: Controller
     19     @EnvironmentObject private var model: WalletModel
     20 //    @Environment(\.colorSchemeContrast) private var colorSchemeContrast
     21 #if DEBUG
     22     @AppStorage("developerMode") var developerMode: Bool = true
     23 #else
     24     @AppStorage("developerMode") var developerMode: Bool = false
     25 #endif
     26     @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
     27     @AppStorage("acceptAutomatically") var acceptAutomatically: Bool = false
     28     @AppStorage("deleteAutomatically") var deleteAutomatically: Bool = false
     29 //    @AppStorage("minimalistic") var minimalistic: Bool = false
     30 
     31     var body: some View {
     32 #if PRINT_CHANGES
     33         let _ = Self._printChanges()
     34         let _ = symLog.vlog()       // just to get the # to compare it with .onAppear & onDisappear
     35 #endif
     36         let list = List {
     37             Section {
     38                 let contacts = "contacts"
     39                 let contactsDest = ContactsView(stack: stack.push(contacts), talerURI: nil, subject: nil)
     40                 NavigationLink {
     41                     contactsDest
     42                 } label: {
     43                     SettingsItem(name: contactsDest.navTitle, id1: contacts,
     44                             imageName: ICONNAME_PERSON3,    // 􀝊
     45                           description: String(localized: "Manage contact information")) {}
     46                 }
     47             } // contacts
     48             if let configuration = controller.mailboxConfiguration {
     49                 Section {
     50                     let mailboxTitle = String(localized: "TitleMailbox", defaultValue: "Mailbox")
     51                     let mailboxDest = MailboxView(stack: stack.push(mailboxTitle),
     52                                                navTitle: mailboxTitle)
     53                     NavigationLink {
     54                         mailboxDest
     55                     } label: {
     56                         SettingsItem(name: mailboxTitle, id1: "mailbox",
     57                                 imageName: ICONNAME_MAILBOX,    // 􀍷
     58                               description: String(localized: "P2P Messaging")) {}
     59                     }.listRowSeparator(.hidden)
     60 #if TALDIR2
     61                     SettingsToggle(name: String(localized: "Automatically accept"),
     62                                   value: $acceptAutomatically,
     63                                     id1: "acceptAutomatically",
     64                             description: String(localized: "...incoming payments, skip confirmation")
     65                     ).listRowSeparator(.hidden)
     66                     SettingsToggle(name: String(localized: "Automatically delete"),
     67                                   value: $deleteAutomatically,
     68                                     id1: "deleteAutomatically",
     69                             description: String(localized: "...messages after the transaction finishes")
     70                     )
     71 #endif
     72                     let aliasTitle = String(localized: "TitleAlias", defaultValue: "Alias Registration")
     73                     let aliasDest = AliasView(stack: stack.push(aliasTitle),
     74                                            navTitle: aliasTitle)
     75                     NavigationLink {
     76                         aliasDest
     77                     } label: {
     78                         SettingsItem(name: aliasTitle, id1: "alias",
     79                                 imageName: ICONNAME_ALIAS,    // 􀲏
     80                               description: String(localized: "Taldir Registration")) {}
     81                     }
     82 
     83                 }
     84             } else {
     85                 Text("If you only want to send money (or payment requests) to others you don't need a mailbox.")
     86                     .listRowSeparator(.hidden)
     87                 let contactsIcon = Image(systemName: ICONNAME_PERSON3)  // 􀝊
     88                 Text("Just add contacts, e.g. by scanning a QR code. Send as usual, then in the final step choose '\(contactsIcon)\(NONBREAKING)Contacts'.", comment: "contactsIcon, NONBREAKING - don't add a space")
     89                     .padding(.top, -4)
     90                     .padding(.bottom, 6)
     91                     .listRowSeparator(.visible)
     92                 Text("You need a mailbox to be able to receive money (or requests) that other people send to your mail address or phone number.")
     93                     .padding(.top, 6)
     94                     .listRowSeparator(.hidden)
     95                 Text("Once you have a mailbox, create one or more Aliases (of your mail address, phone number, matrix ID, ...) and publish them on your website, GitHub page, on Mastodon or any other place.")
     96                     .listRowSeparator(.hidden)
     97                 Button("Create Mailbox") {
     98                     Task {
     99                         await controller.createMailbox()
    100                     }
    101                 }.buttonStyle(TalerButtonStyle(type: .bordered))
    102                     .padding()
    103                     .listRowSeparator(.hidden)
    104                 Text("Your mailbox will be hosted at gnunet.org. Currently there is no fee.")
    105             }
    106         }
    107             .listStyle(myListStyle.style).anyView
    108             .navigationTitle(navTitle)
    109             .onAppear() {
    110                 DebugViewC.shared.setViewID(VIEW_SETTINGS4, stack: stack.push())
    111             }
    112         if #available(iOS 26.0, *) {
    113             list
    114         } else {
    115             list
    116                 .padding(.bottom)
    117         }
    118     } // body
    119 }
    120 #endif