taler-ios

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

HistoryDetailView.swift (4107B)


      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 @available(iOS 16.4, *)
     12 struct HistoryDetailView: View {
     13     let stack: CallStack
     14     let currency: OIMcurrency
     15     let balance: Double
     16     let talerTX: TalerTransaction
     17     let effective: Amount
     18 
     19     @StateObject private var cash: OIMcash
     20     @State var amountVal: UInt64 = 0
     21     @Namespace var namespace
     22 
     23     init(stack: CallStack,
     24       currency: OIMcurrency,
     25        balance: Double,
     26        talerTX: TalerTransaction
     27     ) {
     28         self.stack = stack
     29         self.currency = currency
     30         self.balance = balance
     31         self.talerTX = talerTX
     32         let oimCash = OIMcash(currency)
     33         self._cash = StateObject(wrappedValue: { oimCash }())
     34         let common = talerTX.common
     35         let eff = common.amountEffective
     36         self.effective = eff
     37         let cents = eff.centValue
     38         self._amountVal = State(wrappedValue: { cents }())
     39 //        print("ChartOverlayV init:", cents)
     40     }
     41 
     42     var imageID: String? {
     43         switch talerTX {
     44             case .peer2peer(let p2pTransaction):
     45                 return p2pTransaction.details.info.iconId
     46             default:
     47                 break
     48         }
     49         return nil
     50     }
     51 
     52     var body: some View {
     53         // TODO: hero animation from index
     54         VStack {
     55             Spacer()
     56             let balance2 =  balance * Double(currency.factor)
     57             let incoming = talerTX.common.isIncoming
     58             VStack {
     59                 VStack(alignment: .trailing) {
     60                     HStack {
     61                         if let imageID {
     62                             Image(imageID)
     63                                 .resizable()
     64                                 .background(Color.white)
     65                                 .scaledToFit()
     66                             //                          .matchedGeometryEffect(id: imageID, in: wrapper.namespace)
     67                                 .padding(.horizontal)
     68                         }
     69                         VStack(alignment: .trailing) {
     70                             Text("Balance: \(balance2.pTwo)")
     71                                 .foregroundStyle(WalletColors().gray2)
     72                             Spacer()
     73                             OIMamountV(amount: effective, currencyName: currency.currencyStr,
     74                                        factor: currency.factor, mayChangeSpeed: false)
     75                         }
     76                     }
     77                 }
     78                 OIMlineView(stack: stack.push(),
     79                              cash: cash,
     80                         amountVal: $amountVal,
     81                           canEdit: false)
     82 //                .opacity(isOpen ? 1 : INVISIBLE)
     83 //                .scaleEffect(scaleMoney ? 0.6 : 1)
     84             }.environmentObject(NamespaceWrapper(namespace))         // keep OIMviews apart
     85             .padding()
     86             .onAppear {
     87                 cash.update2(amountVal)             // set cash to talerTX.common.effective
     88             }
     89             .onChange(of: effective) { newVal in
     90                 print("ChartOverlayV onChange of:", newVal)
     91                 let cents = newVal.centValue
     92                 cash.update2(cents)                 // set cash to talerTX.common.effective
     93             }
     94             .background(
     95                 RoundedRectangle(cornerRadius: 30)
     96                 .style(
     97                     withStroke: Color.primary,
     98                     lineWidth: 2,
     99                     fill: LinearGradient(
    100 //                        gradient: Gradient(colors: [WalletColors().talerColor, .white]),
    101                         gradient: Gradient(colors: [WalletColors().transactionColor(incoming), .white]),
    102                       startPoint: .top,
    103                         endPoint: .bottom
    104                     ).opacity(0.85)
    105                 )
    106                 .background(
    107                     RoundedRectangle(cornerRadius: 30)
    108                         .fill(Color.white
    109                                    .opacity(0.8))
    110                 )
    111             )
    112             Spacer()
    113         }
    114     }
    115 }