From 1c8b9fdac4b6aaa1495ea101cc54007abde23d47 Mon Sep 17 00:00:00 2001 From: Marc Stibane Date: Sat, 4 Nov 2023 08:27:12 +0100 Subject: KYC - wip --- TalerWallet1/Model/Transaction.swift | 1 + TalerWallet1/Views/Main/MainView.swift | 35 +++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/TalerWallet1/Model/Transaction.swift b/TalerWallet1/Model/Transaction.swift index 823e1d7..5c9f16e 100644 --- a/TalerWallet1/Model/Transaction.swift +++ b/TalerWallet1/Model/Transaction.swift @@ -150,6 +150,7 @@ struct TransactionCommon: Decodable, Sendable { var transactionId: String var timestamp: Timestamp var txActions: [TxAction] + var kycUrl: String? func localizedType(_ type: TransactionType) -> String { switch type { diff --git a/TalerWallet1/Views/Main/MainView.swift b/TalerWallet1/Views/Main/MainView.swift index 56b166e..0edd3ef 100644 --- a/TalerWallet1/Views/Main/MainView.swift +++ b/TalerWallet1/Views/Main/MainView.swift @@ -89,6 +89,19 @@ extension MainView { let settingsTitle = String(localized: "TitleSettings", defaultValue: "Settings") #if TABBAR // Taler Wallet @State private var selectedTab: Tab = .balances + @State private var showKycAlert: Bool = false + + private var openKycButton: some View { + Button("KYC") { + showKycAlert = false +// UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) + } + } + private var dismissAlertButton: some View { + Button("Cancel", role: .cancel) { + showKycAlert = false + } + } private func tabSelection() -> Binding { Binding { //this is the get block @@ -220,7 +233,27 @@ extension MainView { hamburgerAction: hamburgerAction) } #endif - } + } .onNotification(.TransactionStateTransition) { 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 + } + } + } + } else { // should never happen + logger.error("Yikes! TransactionStateTransition without transition") +// symLog.log(notification.userInfo as Any) + } + } + .alert("You need to pass a KYC procedure", + isPresented: $showKycAlert, + actions: { openKycButton + dismissAlertButton }, + message: { Text("Tap the button to go to the KYC website.") }) .onNotification(.BalanceChange) { notification in // reload balances on receiving BalanceChange notification ... logger.info(".onNotification(.BalanceChange) ==> reload") -- cgit v1.2.3