Update of the refresh method.

pull/2/head
Oleg Gordiichuk 7 years ago committed by Michael Scoff
parent 2f76aefcdd
commit e69fb5e4ab
  1. 23
      Trust/Tokens/Types/TokensDataStore.swift
  2. 4
      Trust/Transactions/Coordinators/BalanceCoordinator.swift

@ -109,7 +109,6 @@ class TokensDataStore {
switch result {
case .success(let response):
self.update(tokens: response)
self.refreshEthBalance()
self.refreshBalance()
case .failure: break
}
@ -139,22 +138,20 @@ class TokensDataStore {
}
count += 1
if count == updateTokens.count {
self.updateDelegate()
//We should use prommis kit.
self.getBalanceCoordinator.getEthBalance(for: self.account.address) { [weak self] result in
guard let `self` = self else { return }
switch result {
case .success(let balance):
self.update(token: self.objects.first (where: { $0.contract == self.ethToken.contract })!, action: .value(balance.value))
self.updateDelegate()
case .failure: break
}
}
}
}
}
}
func refreshEthBalance() {
getBalanceCoordinator.getEthBalance(for: account.address) { [weak self] result in
guard let `self` = self else { return }
switch result {
case .success(let balance):
self.update(token: self.objects.first (where: { $0.contract == self.ethToken.contract })!, action: .value(balance.value))
self.updateDelegate()
case .failure: break
}
}
}
func updateDelegate() {
tokensModel.value = enabledObject
let tokensViewModel = TokensViewModel( tokens: enabledObject, tickers: tickers )

@ -25,7 +25,7 @@ class BalanceCoordinator {
init(account: Wallet, storage: TokensDataStore) {
self.account = account
self.storage = storage
self.storage.refreshEthBalance()
self.storage.refreshBalance()
storage.tokensModel.subscribe {[weak self] tokensModel in
guard let tokens = tokensModel, let eth = tokens.first(where: { $0.contract == "0x" }) else {
return
@ -37,7 +37,7 @@ class BalanceCoordinator {
}
}
func refresh() {
self.storage.refreshEthBalance()
self.storage.refreshBalance()
}
func update() {
delegate?.didUpdate(viewModel: viewModel)

Loading…
Cancel
Save