Deduplicate card history entries
This commit is contained in:
@ -668,7 +668,7 @@ extension HomeViewController: ApduCallback {
|
||||
self.updateCardNumberDisplay()
|
||||
|
||||
if (emoney.isTampilRiwayat()){
|
||||
let riwayat = emoney.getRiwayatList()
|
||||
let riwayat = self.deduplicateHistory(emoney.getRiwayatList())
|
||||
if let first = riwayat.first {
|
||||
let dateFmt = DateFormatter()
|
||||
dateFmt.dateFormat = "dd MMM yyyy, HH:mm"
|
||||
@ -707,6 +707,22 @@ private extension HomeViewController {
|
||||
formatter.minimumFractionDigits = 0
|
||||
return formatter
|
||||
}()
|
||||
|
||||
func deduplicateHistory(_ items: [RiwayatCard]) -> [RiwayatCard] {
|
||||
var seen = Set<String>()
|
||||
return items.filter { item in
|
||||
let key = historyKey(for: item)
|
||||
return seen.insert(key).inserted
|
||||
}
|
||||
}
|
||||
|
||||
func historyKey(for item: RiwayatCard) -> String {
|
||||
let timestamp = item.getTransationTime()?.timeIntervalSince1970 ?? 0
|
||||
let locationId = item.getLocationId() ?? ""
|
||||
let locationName = item.getLocationName() ?? ""
|
||||
let title = item.getTitle() ?? ""
|
||||
return "\(timestamp)|\(item.getAmount())|\(item.getProsesTipe())|\(locationId)|\(locationName)|\(title)"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UILabel letter spacing helper
|
||||
|
||||
Reference in New Issue
Block a user