taler-ios

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

commit 4a5313073b28e35139d11e759e0a04c66b4e162c
parent ce69e320b6672dda07289adfb7d02d89879db597
Author: Marc Stibane <marc@taler.net>
Date:   Thu,  6 Aug 2026 20:50:09 +0200

imageBase64

Diffstat:
MTalerWallet1/Helper/Image+fallback.swift | 20++++++++++++++++----
MTalerWallet1/Views/Transactions/PaymentTransactionView.swift | 20+++++++++++---------
MTalerWallet1/Views/Transactions/ThreeAmountsSection.swift | 9+--------
3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/TalerWallet1/Helper/Image+fallback.swift b/TalerWallet1/Helper/Image+fallback.swift @@ -23,12 +23,24 @@ import SwiftUI extension Image { init(_ name: String, _ sysName: String, fallback: String = SYSTEM_DUMMY1) { - if UIImage(named: name) != nil { - self.init(name) - } else if UIImage(systemName: sysName) != nil { - self.init(systemName: sysName) + if let uiImage = UIImage(named: name) { + self.init(uiImage: uiImage) + } else if let sysImage = UIImage(systemName: sysName) { + self.init(uiImage: sysImage) } else { self.init(systemName: fallback) } } + + init?(imageBase64: String) { + if let url = NSURL(string: imageBase64) { + if let data = NSData(contentsOf: url as URL) { + if let uiImage = UIImage(data: data as Data) { + self.init(uiImage: uiImage) + return + } + } + } + return nil + } } diff --git a/TalerWallet1/Views/Transactions/PaymentTransactionView.swift b/TalerWallet1/Views/Transactions/PaymentTransactionView.swift @@ -26,6 +26,12 @@ struct MerchantHeader: View { return terms.summary } + func logo(_ logoBase64: String) -> Image? { + if let image = Image(imageBase64: logoBase64) { + return image + } + return nil + } var body: some View { if let terms { Section { @@ -36,15 +42,11 @@ struct MerchantHeader: View { Spacer() VStack(alignment: .center) { if let imageBase64 = terms.merchant.logo { - if let url = NSURL(string: imageBase64) { - if let data = NSData(contentsOf: url as URL) { - if let uiImage = UIImage(data: data as Data) { - Image(uiImage: uiImage) - .resizable() - .aspectRatio(contentMode: .fit) - .frame(maxHeight: 60) - } - } + if let image = logo(imageBase64) { + image + .resizable() + .aspectRatio(contentMode: .fit) + .frame(maxHeight: 60) } } else { #if TALER_NIGHTLY diff --git a/TalerWallet1/Views/Transactions/ThreeAmountsSection.swift b/TalerWallet1/Views/Transactions/ThreeAmountsSection.swift @@ -83,14 +83,7 @@ struct ProductImage: Codable, Hashable { } var image: Image? { - if let url = NSURL(string: imageBase64) { - if let data = NSData(contentsOf: url as URL) { - if let uiImage = UIImage(data: data as Data) { - return Image(uiImage: uiImage) - } - } - } - return nil + Image(imageBase64) } }