commit ab68cbf3dfd80e09da00cbcdee82fae82f805479
parent d06f7abe1b576a508379f1429d0c192682bd315f
Author: Marc Stibane <marc@taler.net>
Date: Thu, 4 Jan 2024 17:57:04 +0100
Markdown for ToS
Diffstat:
2 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj
@@ -12,6 +12,7 @@
4E2254982A822B8100E41D29 /* payment_sent.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 4E2254962A822B8100E41D29 /* payment_sent.m4a */; };
4E2E5F7F2AEE30DA0027FA8A /* AmountRowV.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2E5F7E2AEE30DA0027FA8A /* AmountRowV.swift */; };
4E2E5F802AEE30DA0027FA8A /* AmountRowV.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2E5F7E2AEE30DA0027FA8A /* AmountRowV.swift */; };
+ 4E2D8DD32B3F513800234039 /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = 4E2D8DD22B3F513800234039 /* MarkdownUI */; };
4E3327BA2AD1635100BF5AD6 /* AsyncSemaphore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3327B92AD1635100BF5AD6 /* AsyncSemaphore.swift */; };
4E3327BB2AD1635100BF5AD6 /* AsyncSemaphore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3327B92AD1635100BF5AD6 /* AsyncSemaphore.swift */; };
4E363CBC2A237E0900D7E98C /* URL+id+iban.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E363CBB2A237E0900D7E98C /* URL+id+iban.swift */; };
@@ -441,6 +442,7 @@
ABE97B1D286D82BF00580772 /* AnyCodable in Frameworks */,
4EB094FD29897D280043A8A1 /* SymLog in Frameworks */,
4EB094F829897CA20043A8A1 /* FTalerWalletcore.framework in Frameworks */,
+ 4E2D8DD32B3F513800234039 /* MarkdownUI in Frameworks */,
ABC13AA32859962800D23185 /* taler-swift in Frameworks */,
4EEC157629F8ECBF00D46A03 /* CodeScanner in Frameworks */,
);
@@ -875,6 +877,7 @@
ABE97B1C286D82BF00580772 /* AnyCodable */,
4EB094FC29897D280043A8A1 /* SymLog */,
4EEC157529F8ECBF00D46A03 /* CodeScanner */,
+ 4E2D8DD22B3F513800234039 /* MarkdownUI */,
);
productName = Taler;
productReference = D14AFD1D24D232B300C51073 /* Taler_Wallet.app */;
@@ -955,6 +958,7 @@
ABE97B1B286D82BF00580772 /* XCRemoteSwiftPackageReference "AnyCodable" */,
4EB094FB29897D280043A8A1 /* XCRemoteSwiftPackageReference "SymLog" */,
4EEC157429F8ECBF00D46A03 /* XCRemoteSwiftPackageReference "CodeScanner" */,
+ 4E2D8DD12B3F513800234039 /* XCRemoteSwiftPackageReference "swift-markdown-ui-standalone" */,
);
productRefGroup = D14AFD1E24D232B300C51073 /* Products */;
projectDirPath = "";
@@ -1703,6 +1707,14 @@
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
+ 4E2D8DD12B3F513800234039 /* XCRemoteSwiftPackageReference "swift-markdown-ui-standalone" */ = {
+ isa = XCRemoteSwiftPackageReference;
+ repositoryURL = "https://github.com/Fesh-com/swift-markdown-ui-standalone";
+ requirement = {
+ branch = main;
+ kind = branch;
+ };
+ };
4E3EAE172A990778009F1BE8 /* XCRemoteSwiftPackageReference "AnyCodable" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Flight-School/AnyCodable";
@@ -1754,6 +1766,11 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
+ 4E2D8DD22B3F513800234039 /* MarkdownUI */ = {
+ isa = XCSwiftPackageProductDependency;
+ package = 4E2D8DD12B3F513800234039 /* XCRemoteSwiftPackageReference "swift-markdown-ui-standalone" */;
+ productName = MarkdownUI;
+ };
4E3EAE152A990778009F1BE8 /* taler-swift */ = {
isa = XCSwiftPackageProductDependency;
productName = "taler-swift";
diff --git a/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift b/TalerWallet1/Views/Sheets/WithdrawBankIntegrated/WithdrawTOSView.swift
@@ -4,6 +4,7 @@
*/
import SwiftUI
import SymLog
+import MarkdownUI
struct WithdrawTOSView: View {
private let symLog = SymLogV(0)
@@ -41,10 +42,11 @@ struct WithdrawTOSView: View {
}
var body: some View {
- let language = Locale.preferredLanguageCode
+ let languageCode = Locale.preferredLanguageCode
+// let languageName = Locale.current.localizedString(forLanguageCode: languageCode)
if let exchangeTOS {
Content(symLog: symLog, tos: exchangeTOS, myListStyle: $myListStyle,
- language: language, languageAction: loadToS) {
+ language: languageCode, languageAction: loadToS) {
Task { // runs on MainActor
do {
if let exchangeBaseUrl {
@@ -73,13 +75,38 @@ struct WithdrawTOSView: View {
} else {
LoadingView(url: nil, message: exchangeBaseUrl?.trimURL() ?? "No exchangeBaseUrl!")
.task {
- await loadToS(language)
+ await loadToS(languageCode)
}
}
}
}
// MARK: -
extension WithdrawTOSView {
+ struct plaintextToSV: View {
+ let plaintext: String
+
+ var body: some View {
+ let components = plaintext.components(separatedBy: "\n\n")
+
+ ForEach (components, id: \.self) { term0 in
+ let term1 = term0.replacingOccurrences(of: "\n ", with: " ") // newline + 5 blanks
+ let term2 = term1.replacingOccurrences(of: "\n ", with: " ") // newline + 4 blanks
+ let term3 = term2.replacingOccurrences(of: "\n ", with: " ") // newline + 3 blanks
+ let term4 = term3.replacingOccurrences(of: "\n ", with: " ") // newline + 2 blanks
+ let term5 = term4.replacingOccurrences(of: "\n ", with: " ") // newline + 1 blank
+ let term6 = term5.replacingOccurrences(of: "\n", with: " ") // remove all other linebreaks
+ let term7 = term6.replacingOccurrences(of: " ====", with: "\n====") // add them back for underscoring
+ let term8 = term7.replacingOccurrences(of: " ----", with: "\n----") // special for "Highlights:"
+ let term9 = term8.replacingOccurrences(of: " ****", with: "\n****") // special for "Terms of Service:"
+ Section {
+ Text(term9)
+ .accessibilityFont(.footnote)
+ .foregroundColor(Color(UIColor.label))
+ }
+ } // for
+ }
+ }
+
struct Content: View {
let symLog: SymLogV
var tos: ExchangeTermsOfService
@@ -95,8 +122,9 @@ extension WithdrawTOSView {
List {
if tos.tosAvailableLanguages.count > 1 {
Picker(title, selection: $selectedLanguage) {
- ForEach(tos.tosAvailableLanguages, id: \.self) {
- Text($0)
+ ForEach(tos.tosAvailableLanguages, id: \.self) { code in
+ let languageName = Locale.current.localizedString(forLanguageCode: code)
+ Text(languageName ?? code)
}
}
.accessibilityFont(.title3)
@@ -110,34 +138,30 @@ extension WithdrawTOSView {
}
}
}
+ if tos.contentType == MARKDOWN {
+ Section {
+ let content = MarkdownContent(tos.content)
+ Markdown(content)
+ }
+ } else {
let components = tos.content.components(separatedBy: "\n\n")
-
ForEach (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:"
- let term5 = term4.replacingOccurrences(of: " ****", with: "\n****") // special for "Terms of Service:"
-// Text("term0")
- if #available(iOS 16.0, *) {
+ let term2 = term1.replacingOccurrences(of: "\n ", with: " ") // newline + 4 blanks
+ let term3 = term2.replacingOccurrences(of: "\n ", with: " ") // newline + 3 blanks
+ let term4 = term3.replacingOccurrences(of: "\n ", with: " ") // newline + 2 blanks
+ let term5 = term4.replacingOccurrences(of: "\n ", with: " ") // newline + 1 blank
+ let term6 = term5.replacingOccurrences(of: "\n", with: " ") // remove all other linebreaks
+ let term7 = term6.replacingOccurrences(of: " ====", with: "\n====") // add them back for underscoring
+ let term8 = term7.replacingOccurrences(of: " ----", with: "\n----") // special for "Highlights:"
+ let term9 = term8.replacingOccurrences(of: " ****", with: "\n****") // special for "Terms of Service:"
Section {
- Text(term5)
- .accessibilityFont(.footnote)
- .foregroundColor(Color(UIColor.label))
- }
- } else {
- Text(term5)
+ Text(term9)
.accessibilityFont(.footnote)
.foregroundColor(Color(UIColor.label))
}
- } else { // MarkDown
- Section {
- Text(term0)
- .accessibilityFont(.body)
- }
- }
- }
+ } // for
+ } // plain text
}.safeAreaInset(edge: .bottom) {
let currentEtag = tos.currentEtag
let showButton = tos.acceptedEtag == nil ? true