taler-ios

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

commit e4ce6345dbed62a2dc15f9727427e996527603dd
parent a914a934b9268d65b8db53ee4d2d1723b47b5f3d
Author: Marc Stibane <marc@taler.net>
Date:   Fri, 17 Nov 2023 16:52:49 +0100

KYC

Diffstat:
MTalerWallet1/Model/Transaction.swift | 3+++
MTalerWallet1/Views/Main/MainView.swift | 24++++++++++++++----------
MTalerWallet1/Views/Transactions/TransactionDetailView.swift | 16++++++++++++++++
3 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/TalerWallet1/Model/Transaction.swift b/TalerWallet1/Model/Transaction.swift @@ -97,6 +97,7 @@ struct TransactionTransition: Codable { // Notification var oldTxState: TransactionState var newTxState: TransactionState var transactionId: String + var experimentalUserData: String? // KYC } enum TxAction: String, Codable { @@ -436,6 +437,8 @@ enum Transaction: Decodable, Hashable, Identifiable, Sendable { var isP2pIncoming: Bool { isSendInvoice || isRcvCoins} var isPending : Bool { common.txState.major == .pending } + var isPendingReady : Bool { common.txState.minor == .ready } + var isPendingKYC : Bool { common.txState.minor == .kyc } var isDone : Bool { common.txState.major == .done } var isAborting : Bool { common.txState.major == .aborting } var isAborted : Bool { common.txState.major == .aborted } diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift @@ -94,11 +94,16 @@ extension MainView { #if TABBAR // Taler Wallet @State private var selectedTab: Tab = .balances @State private var showKycAlert: Bool = false + @State private var kycURI: URL? private var openKycButton: some View { Button("KYC") { showKycAlert = false -// UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) + if let kycURI { + UIApplication.shared.open(kycURI) + } else { + // YIKES! + } } } private var dismissAlertButton: some View { @@ -242,19 +247,18 @@ extension MainView { hamburgerAction: hamburgerAction) } #endif - } .onNotification(.TransactionStateTransition) { notification in + } .onNotification(.KYCrequired) { notification in // show an alert with the KYC link (button) which opens in Safari if let transition = notification.userInfo?[TRANSACTIONTRANSITION] as? TransactionTransition { - if transition.newTxState.major == .pending { - if let newMinor = transition.newTxState.minor { - if newMinor == .kyc { // user did confirm on bank website - logger.log(".onNotification(): KYC required") - showKycAlert = true - } + if let kycString = transition.experimentalUserData { + if let urlForKYC = URL(string: kycString) { + logger.log(".onNotification(.KYCrequired): \(kycString)") + kycURI = urlForKYC + showKycAlert = true } + } else { + // TODO: no KYC URI } - } else { // should never happen - logger.error("Yikes❗️ TransactionStateTransition without transition") } } .alert("You need to pass a KYC procedure", diff --git a/TalerWallet1/Views/Transactions/TransactionDetailView.swift b/TalerWallet1/Views/Transactions/TransactionDetailView.swift @@ -225,6 +225,22 @@ struct TransactionDetailView: View { } } } + } else if transaction.isPendingKYC { + if let kycUrl = common.kycUrl { + if let destination = URL(string: kycUrl) { + VStack(alignment: .leading) { // Show Hint that User must pass KYC on website + if !iconOnly { + Text("You need to pass a KYC procedure") + .fixedSize(horizontal: false, vertical: true) // wrap in scrollview + .multilineTextAlignment(.leading) // otherwise + .listRowSeparator(.hidden) + } + Link("Open KYC website", destination: destination) + .buttonStyle(TalerButtonStyle(type: .prominent, narrow: false, aligned: .center)) + .padding(.horizontal) + } + } + } } } // switch } // ManualDetails or Confirm with bank