taler-ios

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

commit 0b2122aba2b6809a0a9327309f5cf0c82dd4f64d
parent 25509c967a4753fe80fceacb52cc018f87a3c241
Author: Marc Stibane <marc@taler.net>
Date:   Fri,  7 Jul 2023 09:30:34 +0200

Enhanced ToS plaintext formatting

Diffstat:
MTalerWallet1/Controllers/PublicConstants.swift | 3+++
MTalerWallet1/Model/Model+Withdraw.swift | 3++-
MTalerWallet1/Views/WithdrawBankIntegrated/WithdrawTOSView.swift | 20++++++++++++++++----
3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift @@ -27,6 +27,9 @@ public let LONGCURRENCY = "GOLDLATINUM" // 11 characters // MARK: - Keys used in JSON +public let PLAINTEXT = "text/plain" +public let MARKDOWN = "text/markdown" + public let EXCHANGEBASEURL = "exchangeBaseUrl" public let TALERURI = "talerUri" diff --git a/TalerWallet1/Model/Model+Withdraw.swift b/TalerWallet1/Model/Model+Withdraw.swift @@ -67,9 +67,10 @@ fileprivate struct GetWithdrawalDetailsForAmount: WalletBackendFormattedRequest } // MARK: - struct ExchangeTermsOfService: Decodable { - var content: String var currentEtag: String var acceptedEtag: String? + var contentType: String + var content: String } /// A request to query an exchange's terms of service. fileprivate struct GetExchangeTermsOfService: WalletBackendFormattedRequest { diff --git a/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawTOSView.swift b/TalerWallet1/Views/WithdrawBankIntegrated/WithdrawTOSView.swift @@ -62,7 +62,7 @@ struct WithdrawTOSView: View { }.task { do { if let exchangeBaseUrl { - let acceptedFormat: [String] = ["text/markdown", "text/plain"] + let acceptedFormat: [String] = [MARKDOWN, PLAINTEXT] let someTOS = try await model.loadExchangeTermsOfServiceM(exchangeBaseUrl, acceptedFormat: acceptedFormat) exchangeTOS = someTOS @@ -83,10 +83,22 @@ extension WithdrawTOSView { var body: some View { if let tos = exchangeTOS { - let components = tos.content.components(separatedBy:"\n\n") + let components = tos.content.components(separatedBy: "\n\n") - List (components, id: \.self) { term in - Text(term) + List (components, id: \.self) { term0 in + if tos.contentType == PLAINTEXT { + let term1 = term0.replacingOccurrences(of: "\n ", with: " ") // newline + 5 blanks + let term2 = term1.replacingOccurrences(of: "\n" , with: " ") // remove all other linebreaks + let term3 = term2.replacingOccurrences(of: " ====", with: "\n====") // add them back for underscoring + let term4 = term3.replacingOccurrences(of: " ----", with: "\n----") // special for "Highlights:" + Section { + Text(term4) + } + } else { + Section { + Text(term0) + } + } }.safeAreaInset(edge: .bottom) { Button(String(localized: "Accept ToS"), action: acceptAction) .buttonStyle(TalerButtonStyle(type: .prominent))