Implement bank transfer app flows
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Foundation
|
||||
|
||||
struct CachedBmlForeignLimits: Codable {
|
||||
let userName: String
|
||||
let limits: [BmlForeignLimit]
|
||||
}
|
||||
|
||||
struct DashboardCachePayload: Codable {
|
||||
let foreignLimits: [CachedBmlForeignLimits]
|
||||
let mibFinancing: [MibFinanceDeal]
|
||||
}
|
||||
|
||||
struct DashboardCache {
|
||||
static let shared = DashboardCache()
|
||||
private let udKey = "thijooree_dashboard_v1"
|
||||
private init() {}
|
||||
|
||||
func save(foreignLimits: [(userName: String, limits: [BmlForeignLimit])], mibFinancing: [MibFinanceDeal]) {
|
||||
let payload = DashboardCachePayload(
|
||||
foreignLimits: foreignLimits.map { CachedBmlForeignLimits(userName: $0.userName, limits: $0.limits) },
|
||||
mibFinancing: mibFinancing
|
||||
)
|
||||
guard let json = try? JSONEncoder().encode(payload),
|
||||
let encrypted = try? CacheEncryption.shared.encryptData(json) else { return }
|
||||
UserDefaults.standard.set(encrypted, forKey: udKey)
|
||||
}
|
||||
|
||||
func load() -> DashboardCachePayload? {
|
||||
guard let encrypted = UserDefaults.standard.string(forKey: udKey),
|
||||
let json = try? CacheEncryption.shared.decryptData(encrypted),
|
||||
let payload = try? JSONDecoder().decode(DashboardCachePayload.self, from: json) else { return nil }
|
||||
return payload
|
||||
}
|
||||
|
||||
func clear() {
|
||||
UserDefaults.standard.removeObject(forKey: udKey)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user