Cache wallet balance and activity so screens show it instantly
This commit is contained in:
@@ -63,9 +63,24 @@ enum WalletStore {
|
||||
|
||||
static func removeWallet(_ chain: Chain) {
|
||||
defaults.removeObject(forKey: walletKey(chain))
|
||||
defaults.removeObject(forKey: cacheKey(chain))
|
||||
Keychain.remove(secretKey(chain))
|
||||
}
|
||||
|
||||
// MARK: - Cached state (balance, transactions, accounts)
|
||||
|
||||
private static func cacheKey(_ chain: Chain) -> String { "koins.cache.\(chain.rawValue)" }
|
||||
|
||||
static func cachedState(_ chain: Chain) -> ChainCache? {
|
||||
guard let data = defaults.data(forKey: cacheKey(chain)) else { return nil }
|
||||
return try? JSONDecoder().decode(ChainCache.self, from: data)
|
||||
}
|
||||
|
||||
static func saveCachedState(_ state: ChainCache, chain: Chain) {
|
||||
guard let data = try? JSONEncoder().encode(state) else { return }
|
||||
defaults.set(data, forKey: cacheKey(chain))
|
||||
}
|
||||
|
||||
static func secret(_ chain: Chain) -> String? {
|
||||
Keychain.get(secretKey(chain))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user