summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-07-07 09:30:34 +0200
committerMarc Stibane <marc@taler.net>2023-07-07 09:30:34 +0200
commit0b2122aba2b6809a0a9327309f5cf0c82dd4f64d (patch)
tree80aa479e0f226a4875362ea61b21b5351ac43d7a
parent25509c967a4753fe80fceacb52cc018f87a3c241 (diff)
downloadtaler-ios-0b2122aba2b6809a0a9327309f5cf0c82dd4f64d.tar.gz
taler-ios-0b2122aba2b6809a0a9327309f5cf0c82dd4f64d.tar.bz2
taler-ios-0b2122aba2b6809a0a9327309f5cf0c82dd4f64d.zip
Enhanced ToS plaintext formatting
-rw-r--r--TalerWallet1/Controllers/PublicConstants.swift3
-rw-r--r--TalerWallet1/Model/Model+Withdraw.swift3
-rw-r--r--TalerWallet1/Views/WithdrawBankIntegrated/WithdrawTOSView.swift20
3 files changed, 21 insertions, 5 deletions
diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift
index bafc2ea..d98dd22 100644
--- 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
index 5a4e39d..36e7b4d 100644
--- 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
index 4298ef2..e7a4a53 100644
--- 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))