taler-ios

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

OIMp2pReceiveView.swift (2731B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import taler_swift
     10 
     11 // MARK: -
     12 @available(iOS 16.4, *)
     13 struct OIMp2pReceiveView: View {
     14     let stack: CallStack
     15     let cash: OIMcash
     16     let available: Amount?
     17     @Binding var peerPushCreditResponse: PreparePeerPushCreditResponse?
     18     @Binding var fwdButtonTapped: Bool
     19 
     20     @EnvironmentObject private var wrapper: NamespaceWrapper
     21 
     22     @State private var amount: Amount?
     23     @State private var amountVal: UInt64 = 0
     24     @State private var appeared = false
     25 
     26     var body: some View {
     27 //        let _ = Self._printChanges()
     28         let currency = cash.currency
     29         OIMnavBack(stack: stack.push(),
     30                    chest: currency.chest,
     31                     type: .requestP2P,          // TODO: define receive
     32                  isFinal: false,
     33                isSending: false,
     34                   action: { fwdButtonTapped = true },
     35              actDisabled: amount?.isZero ?? true
     36         ) {
     37             Group {
     38                 if let peerPushCreditResponse {
     39                     let terms = peerPushCreditResponse.contractTerms
     40                     let goal = terms.icon_id
     41                     let effective = terms.amount
     42                     VStack {
     43                         OIMtitleView(cash: cash,
     44                                    amount: effective,
     45                                   history: false,
     46                              secondAmount: nil)
     47                         Spacer()
     48                         if let goal {
     49                             Image(goal)
     50                                 .resizable()
     51                                 .background(Color.white)
     52                                 .scaledToFit()
     53                                 .matchedGeometryEffect(id: goal, in: wrapper.namespace)
     54                         }
     55 
     56                         OIMlineView(stack: stack.push(),
     57                                      cash: cash,
     58                                 amountVal: $amountVal,
     59                                   canEdit: false)
     60                         Spacer()
     61                     }
     62                     .opacity(appeared ? 1 : INVISIBLE)
     63                     .scaleEffect(appeared ? 1 : 0.3)
     64                     .task {
     65                         amount = effective
     66                         amountVal = effective.centValue                         // TODO: centValue factor
     67                         cash.update2(amountVal)
     68                         withAnimation(.basic1) {
     69                             appeared = true
     70                         }
     71                     }
     72                 } else {
     73                     Text(verbatim: "loading")
     74                 }
     75             }
     76         }
     77     }
     78 }