commit 01726cada2e886147be614e59d837807da357d08
parent 8a126ae2156ef416a42075ff2bf712c221fa4e2a
Author: Marc Stibane <marc@taler.net>
Date: Mon, 24 Jul 2023 16:02:48 +0200
SendDone
Diffstat:
5 files changed, 103 insertions(+), 99 deletions(-)
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj
@@ -94,7 +94,7 @@
4EB0956E2989CBFE0043A8A1 /* Model+Pending.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB0954C2989CBFE0043A8A1 /* Model+Pending.swift */; };
4EB0956F2989CBFE0043A8A1 /* PendingOpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB0954D2989CBFE0043A8A1 /* PendingOpView.swift */; };
4EB095702989CBFE0043A8A1 /* PendingOpsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB0954E2989CBFE0043A8A1 /* PendingOpsListView.swift */; };
- 4EB3136129FEE79B007D68BC /* SendNow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB3136029FEE79B007D68BC /* SendNow.swift */; };
+ 4EB3136129FEE79B007D68BC /* SendDone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB3136029FEE79B007D68BC /* SendDone.swift */; };
4EB431672A1E55C700C5690E /* ManualWithdrawDone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EB431662A1E55C700C5690E /* ManualWithdrawDone.swift */; };
4EBA82AB2A3EB2CA00E5F39A /* TransactionButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EBA82AA2A3EB2CA00E5F39A /* TransactionButton.swift */; };
4EBA82AD2A3F580500E5F39A /* QuiteSomeCoins.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EBA82AC2A3F580500E5F39A /* QuiteSomeCoins.swift */; };
@@ -232,7 +232,7 @@
4EB0954C2989CBFE0043A8A1 /* Model+Pending.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Model+Pending.swift"; sourceTree = "<group>"; };
4EB0954D2989CBFE0043A8A1 /* PendingOpView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PendingOpView.swift; sourceTree = "<group>"; };
4EB0954E2989CBFE0043A8A1 /* PendingOpsListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PendingOpsListView.swift; sourceTree = "<group>"; };
- 4EB3136029FEE79B007D68BC /* SendNow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendNow.swift; sourceTree = "<group>"; };
+ 4EB3136029FEE79B007D68BC /* SendDone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendDone.swift; sourceTree = "<group>"; };
4EB431662A1E55C700C5690E /* ManualWithdrawDone.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManualWithdrawDone.swift; sourceTree = "<group>"; };
4EBA82AA2A3EB2CA00E5F39A /* TransactionButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionButton.swift; sourceTree = "<group>"; };
4EBA82AC2A3F580500E5F39A /* QuiteSomeCoins.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuiteSomeCoins.swift; sourceTree = "<group>"; };
@@ -538,7 +538,7 @@
children = (
4E40E0BD29F25ABB00B85369 /* SendAmount.swift */,
4E7940DD29FC307C00A9AEA1 /* SendPurpose.swift */,
- 4EB3136029FEE79B007D68BC /* SendNow.swift */,
+ 4EB3136029FEE79B007D68BC /* SendDone.swift */,
4E9320442A1645B600A87B0E /* RequestPayment.swift */,
4E9320462A164BC700A87B0E /* PaymentPurpose.swift */,
);
@@ -788,7 +788,7 @@
4EAD117629F672FA008EDD0B /* KeyboardResponder.swift in Sources */,
4EB095572989CBFE0043A8A1 /* TransactionRowView.swift in Sources */,
4EA1ABBE29A3833A008821EA /* PublicConstants.swift in Sources */,
- 4EB3136129FEE79B007D68BC /* SendNow.swift in Sources */,
+ 4EB3136129FEE79B007D68BC /* SendDone.swift in Sources */,
4EB0956B2989CBFE0043A8A1 /* TextFieldAlert.swift in Sources */,
4EBA82AD2A3F580500E5F39A /* QuiteSomeCoins.swift in Sources */,
4EB431672A1E55C700C5690E /* ManualWithdrawDone.swift in Sources */,
diff --git a/TalerWallet1/Views/Peer2peer/PaymentPurpose.swift b/TalerWallet1/Views/Peer2peer/PaymentPurpose.swift
@@ -65,7 +65,7 @@ struct PaymentPurpose: View {
let disabled = (expireDays == 0) || (summary.count < 1)
NavigationLink(destination: LazyView {
- SendNow(amountToSend: nil,
+ SendDone(amountToSend: nil,
amountToReceive: amount,
summary: summary, expireDays: expireDays)
}) {
diff --git a/TalerWallet1/Views/Peer2peer/SendDone.swift b/TalerWallet1/Views/Peer2peer/SendDone.swift
@@ -0,0 +1,97 @@
+/*
+ * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
+ * See LICENSE.md
+ */
+import SwiftUI
+import taler_swift
+import SymLog
+
+struct SendDone: View {
+ private let symLog = SymLogV()
+ let navTitle = String(localized: "P2P Ready")
+#if DEBUG
+ @AppStorage("developerMode") var developerMode: Bool = true
+#else
+ @AppStorage("developerMode") var developerMode: Bool = false
+#endif
+ @AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
+
+ let amountToSend: Amount?
+ let amountToReceive: Amount?
+ let summary: String
+ let expireDays: UInt
+
+ @EnvironmentObject private var model: WalletModel
+
+ @State var talerURI: String = ""
+
+ var body: some View {
+ List {
+ let incoming = (amountToSend == nil)
+ QRCodeDetailView(talerURI: talerURI,
+ incoming: incoming,
+ amount: incoming ? amountToReceive : amountToSend)
+ Text("QR code and link can also be scanned or copied / shared from Transactions later.")
+ .multilineTextAlignment(.leading)
+ .font(.subheadline)
+ .padding(.top)
+ }
+ .listStyle(myListStyle.style).anyView
+ .safeAreaInset(edge: .bottom) {
+ Button("Done") {
+ withAnimation() { ViewState.shared.popToRootView() }
+ }
+ .buttonStyle(TalerButtonStyle(type: .prominent))
+ .padding(.horizontal)
+ }
+ .overlay {
+ if talerURI.isEmpty {
+ LoadingView(backButtonHidden: true)
+ }
+ }
+ .interactiveDismissDisabled() // can only use "Done" button to dismiss
+ .navigationBarBackButtonHidden(true)
+ .navigationTitle(navTitle)
+// .navigationBarHidden(true) // no back button, no title
+ .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
+ .task {
+ symLog.log(".task")
+ do {
+ // generate talerURI
+ let timestamp = developerMode ? Timestamp.inSomeMinutes(expireDays > 20 ? (24*60)
+ : expireDays > 5 ? 60 : 3)
+ : Timestamp.inSomeDays(expireDays)
+ if let amountToSend {
+ let terms = PeerContractTerms(amount: amountToSend,
+ summary: summary,
+ purse_expiration: timestamp)
+ // TODO: user might choose baseURL
+ let response = try await model.initiatePeerPushDebitM(nil, terms: terms)
+ talerURI = response.talerUri
+ } else if let amountToReceive {
+ let terms = PeerContractTerms(amount: amountToReceive,
+ summary: summary,
+ purse_expiration: timestamp)
+ // TODO: user might choose baseURL
+ let response = try await model.initiatePeerPullCreditM(nil, terms: terms)
+ talerURI = response.talerUri
+ } else { talerURI = "" }
+ } catch { // TODO: error
+ symLog.log(error.localizedDescription)
+ talerURI = ""
+ }
+ } // task
+ }
+}
+// MARK: -
+struct SendNow_Previews: PreviewProvider {
+ static var previews: some View {
+ Group {
+ SendDone(amountToSend: try! Amount(fromString: LONGCURRENCY + ":4.8"),
+ amountToReceive: nil,
+ summary: "some purpose",
+ expireDays: 0,
+ talerURI: "taler://pay-push/exchange.demo.taler.net/95ZG4D1AGFGZQ7CNQ1V49D3FT18HXKA6HQT4X3XME9YSJQVFQ520")
+ }
+ }
+}
diff --git a/TalerWallet1/Views/Peer2peer/SendNow.swift b/TalerWallet1/Views/Peer2peer/SendNow.swift
@@ -1,93 +0,0 @@
-/*
- * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
- * See LICENSE.md
- */
-import SwiftUI
-import taler_swift
-import SymLog
-
-struct SendNow: View {
- private let symLog = SymLogV()
-#if DEBUG
- @AppStorage("developerMode") var developerMode: Bool = true
-#else
- @AppStorage("developerMode") var developerMode: Bool = false
-#endif
-
- let amountToSend: Amount?
- let amountToReceive: Amount?
- let summary: String
- let expireDays: UInt
-
- @EnvironmentObject private var model: WalletModel
-
- @State var talerURI: String = ""
-
- var body: some View {
- VStack {
- if talerURI.isEmpty {
- LoadingView(backButtonHidden: true)
- } else {
- QRCodeDetailView(talerURI: talerURI,
- incoming: amountToSend == nil)
- .padding()
- Text("The QR code can also be copied and shared from Transactions later.")
- .fixedSize(horizontal: false, vertical: true)
- .font(.subheadline)
- .padding(.vertical, 20)
-
- Spacer()
- Button("Done") {
- withAnimation(){ ViewState.shared.popToRootView() }
- }
- .buttonStyle(TalerButtonStyle(type: .prominent))
- .padding()
-
- }
- }
-// .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
-// .padding(.horizontal)
- .interactiveDismissDisabled() // can only use "Done" button to dismiss
- .navigationBarHidden(true) // no back button, no title
- .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
- .task {
- symLog.log(".task")
- do {
- // generate talerURI
- var timestamp = developerMode ? Timestamp.inSomeMinutes(expireDays > 20 ? (24*60)
- : expireDays > 5 ? 60 : 3)
- : Timestamp.inSomeDays(expireDays)
- if let amountToSend {
- let terms = PeerContractTerms(amount: amountToSend,
- summary: summary,
- purse_expiration: timestamp)
- // TODO: user might choose baseURL
- let response = try await model.initiatePeerPushDebitM(nil, terms: terms)
- talerURI = response.talerUri
- } else if let amountToReceive {
- let terms = PeerContractTerms(amount: amountToReceive,
- summary: summary,
- purse_expiration: timestamp)
- // TODO: user might choose baseURL
- let response = try await model.initiatePeerPullCreditM(nil, terms: terms)
- talerURI = response.talerUri
- } else { talerURI = "" }
- } catch { // TODO: error
- symLog.log(error.localizedDescription)
- talerURI = ""
- }
- } // task
- }
-}
-// MARK: -
-struct SendNow_Previews: PreviewProvider {
- static var previews: some View {
- Group {
- SendNow(amountToSend: try! Amount(fromString: LONGCURRENCY + ":4.8"),
- amountToReceive: nil,
- summary: "some purpose",
- expireDays: 0,
- talerURI: "taler://pay-push/exchange.demo.taler.net/95ZG4D1AGFGZQ7CNQ1V49D3FT18HXKA6HQT4X3XME9YSJQVFQ520")
- }
- }
-}
diff --git a/TalerWallet1/Views/Peer2peer/SendPurpose.swift b/TalerWallet1/Views/Peer2peer/SendPurpose.swift
@@ -65,7 +65,7 @@ struct SendPurpose: View {
let disabled = (expireDays == 0) || (summary.count < 1) // TODO: check amountAvailable
NavigationLink(destination: LazyView {
- SendNow(amountToSend: amount,
+ SendDone(amountToSend: amount,
amountToReceive: nil,
summary: summary, expireDays: expireDays)
}) {