taler-ios

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

PhaseView.swift (2935B)


      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 
     10 struct PhaseView: View {
     11     let stack: CallStack
     12     let date: Date
     13 //    let phase: Int
     14     let sendDisabled: Bool   // can't send/deposit if wallet has no coins at all
     15     let recvDisabled: Bool   // can't receive/withdraw if wallet has no payments services
     16     let depoDisabled: Bool
     17     let wthdDisabled: Bool
     18 
     19 #if TALER_NIGHTLY
     20     @State private var phaseCounter = -5
     21 #else
     22     @State private var phaseCounter = -300
     23 #endif
     24 
     25     func phase(_ first: Bool) -> Int {
     26         if phaseCounter >= 0 {
     27             let myPhase = phaseCounter % 32
     28             if first {
     29                 return myPhase > 15 ? 0 : myPhase
     30             }
     31             return myPhase < 17 ? 0 : myPhase - 16
     32         }
     33         return 0
     34     }
     35 
     36     var body: some View {
     37         let sendTitle = String(localized: "SendButton_Short", defaultValue: "Send",
     38                                comment: "Abbreviation of button `Send (currency)´")
     39         let requTitle = String(localized: "RequestButton_Short", defaultValue: "Request",
     40                                comment: "Abbreviation of button `Request (currency)´")
     41 
     42         ///   [􁉇 Send   ] [􁉅 Request]
     43         TwoRowButtons(stack: stack.push(),
     44                       phase: phase(true),
     45                   sendTitle: sendTitle,
     46                    sendType: .peerPushDebit,
     47                    sendA11y: sendTitle,
     48                   recvTitle: requTitle,
     49                    recvType: .peerPullCredit,
     50                    recvA11y: requTitle,
     51                sendDisabled: sendDisabled,
     52                  sendAction: .SendAction,
     53                recvDisabled: recvDisabled,
     54                  recvAction: .RequestAction)
     55         .accessibility(sortPriority: 1)     // read this after maps
     56         .onChange(of: date) { _ in
     57             phaseCounter += 1
     58         }
     59 
     60         let depositTitle = String(localized: "DepositButton_Short", defaultValue: "Deposit",
     61                                     comment: "Abbreviation of button `Deposit (currency)´")
     62         let withdrawTitle = String(localized: "WithdrawButton_Short", defaultValue: "Withdraw",
     63                                      comment: "Abbreviation of button `Withdraw (currency)´")
     64         ///   [􁾩Deposit] [􁾭 Withdraw]
     65         TwoRowButtons(stack: stack.push(),
     66                       phase: phase(false),
     67                   sendTitle: depositTitle,
     68                    sendType: .deposit,
     69                    sendA11y: depositTitle,
     70                   recvTitle: withdrawTitle,
     71                    recvType: .withdrawal,
     72                    recvA11y: withdrawTitle,
     73                sendDisabled: depoDisabled,
     74                  sendAction: .DepositAction,
     75                recvDisabled: wthdDisabled,
     76                  recvAction: .WithdrawAction)
     77         .accessibility(sortPriority: 0)     // read this last
     78     }
     79 }