* I add timer to update prices.

* Call timer init

* Remove empty space.
pull/2/head
Oleg Gordiichuk 7 years ago committed by Michael Scoff
parent 2769013b6d
commit e63d823c0a
  1. 13
      Trust/Tokens/Types/TokensDataStore.swift

@ -27,6 +27,9 @@ class TokensDataStore {
weak var delegate: TokensDataStoreDelegate?
let realm: Realm
var tickers: [String: CoinTicker]? = .none
var timer = Timer()
//We should refresh prices every 5 minutes.
let intervalToRefresh = 300.0
init(
session: WalletSession,
@ -34,6 +37,7 @@ class TokensDataStore {
) {
self.session = session
self.realm = try! Realm(configuration: configuration)
self.scheduledTimerForPricesUpdate()
}
var objects: [TokenObject] {
@ -227,4 +231,13 @@ class TokensDataStore {
}
return tokens
}
private func scheduledTimerForPricesUpdate() {
timer = Timer.scheduledTimer(withTimeInterval: intervalToRefresh, repeats: true) { [weak self] _ in
self?.updatePrices()
}
}
deinit {
//We should make sure that timer is invalidate.
timer.invalidate()
}
}

Loading…
Cancel
Save