gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 190/204: timeToPay w.i.p.


From: gnunet
Subject: [taler-taler-ios] 190/204: timeToPay w.i.p.
Date: Thu, 05 Dec 2024 23:52:38 +0100

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit 60ce6feee08490700f9f7d6180382f87c1adcb3a
Author: Marc Stibane <marc@taler.net>
AuthorDate: Wed Dec 4 07:24:30 2024 +0100

    timeToPay w.i.p.
---
 .../Views/Sheets/Payment/PaymentView.swift         | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift 
b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift
index b384f65..c78ee08 100644
--- a/TalerWallet1/Views/Sheets/Payment/PaymentView.swift
+++ b/TalerWallet1/Views/Sheets/Payment/PaymentView.swift
@@ -87,13 +87,14 @@ struct PaymentView: View, Sendable {
 
     @State private var currencyInfo: CurrencyInfo = CurrencyInfo.zero(UNKNOWN)
     @State var preparePayResult: PreparePayResult? = nil
+    @State private var elapsed: Int = 0
 
     @MainActor
     func checkCurrencyInfo(for result: PreparePayResult) async {
         let scopes = result.scopes
         if scopes.count > 0 {
             for scope in scopes {
-                await controller.checkInfo(for: scope, model: model)
+                controller.checkInfo(for: scope, model: model)
             }
             return
         }
@@ -130,6 +131,17 @@ struct PaymentView: View, Sendable {
         }
     }
 
+    func timeToPay(_ terms: MerchantContractTerms) -> Int {
+        if terms.payDeadline > terms.timestamp {
+            if let duration = try? terms.payDeadline - terms.timestamp {
+                switch duration {
+                    case .milliseconds(let uInt64):
+                        return Int(uInt64 / 1000)
+                    case .forever: break
+        }   }   }
+        return 0
+    }
+
     var body: some View {
       Group {
         if let preparePayResult {
@@ -144,6 +156,8 @@ struct PaymentView: View, Sendable {
             let paid = status == .alreadyConfirmed
             let navTitle = paid ? String(localized: "Already paid", 
comment:"pay merchant navTitle")
                                 : String(localized: "Confirm Payment", 
comment:"pay merchant navTitle")
+            let timeToPay = timeToPay(terms)
+
             List {
                 if paid {
                     Text("You already paid for this article.")
@@ -219,6 +233,28 @@ struct PaymentView: View, Sendable {
                 if !paid {
                     if let effective {
                         VStack {
+                            if timeToPay > 0 {
+                                let startDate = Date()
+                                HStack {
+                                    Text("Time to pay:")
+                                    TimelineView(.animation) { context in
+                                        let elapsed = 
Int(context.date.timeIntervalSince(startDate))
+                                        let seconds = timeToPay - elapsed
+
+                                        if #available(iOS 17.0, *) {
+                                            Text("\(seconds)")
+                                                
.contentTransition(.numericText(countsDown: true))
+                                                .animation(.default, value: 
elapsed)
+                                        } else if #available(iOS 16.0, *) {
+                                            Text("\(seconds)")
+                                                .animation(.default, value: 
elapsed)
+                                        } else {
+                                            Text("\(seconds)")
+                                        }
+                                    }.monospacedDigit()
+                                    Text("seconds")
+                                }
+                            }
                             let destination = PaymentDone(stack: stack.push(),
 //                                                          scope: firstScope, 
   // TODO: let user choose which currency
                                                   transactionId: 
preparePayResult.transactionId)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]