Merge pull request #3129 from AlphaWallet/refactor-add-assetdefinitionstore-arg

Non-functional change for now. Adding an arg to be used for another bigger PR (ERC1155)
pull/3131/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit acccc8621f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      AlphaWallet/AppCoordinator.swift
  2. 5
      AlphaWallet/Core/Coordinators/WalletBalance/PrivateBalanceFetcher.swift
  3. 8
      AlphaWallet/Core/Coordinators/WalletBalance/WalletBalanceCoordinator.swift
  4. 10
      AlphaWallet/Core/Coordinators/WalletBalance/WalletBalanceFetcher.swift

@ -1,7 +1,7 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
import UIKit
class AppCoordinator: NSObject, Coordinator {
private let config = Config()
@ -44,7 +44,7 @@ class AppCoordinator: NSObject, Coordinator {
return coordinators.first { $0 is InCoordinator } as? InCoordinator
}
private lazy var coinTickersFetcher: CoinTickersFetcherType = CoinTickersFetcher(provider: AlphaWalletProviderFactory.makeProvider(), config: config)
private lazy var walletBalanceCoordinator: WalletBalanceCoordinatorType = WalletBalanceCoordinator(keystore: keystore, config: config, coinTickersFetcher: coinTickersFetcher)
private lazy var walletBalanceCoordinator: WalletBalanceCoordinatorType = WalletBalanceCoordinator(keystore: keystore, config: config, assetDefinitionStore: assetDefinitionStore, coinTickersFetcher: coinTickersFetcher)
private var pendingInCoordinator: InCoordinator?
@ -463,7 +463,7 @@ extension AppCoordinator: AccountsCoordinatorDelegate {
func didAddAccount(account: Wallet, in coordinator: AccountsCoordinator) {
coordinator.navigationController.dismiss(animated: true)
}
}
func didDeleteAccount(account: Wallet, in coordinator: AccountsCoordinator) {
TransactionsStorage.deleteAllTransactions(realm: Wallet.functional.realm(forAccount: account))

@ -46,15 +46,16 @@ class PrivateBalanceFetcher: PrivateBalanceFetcherType {
private var isRefeshingBalance: Bool = false
weak var delegate: PrivateTokensDataStoreDelegate?
private var enabledObjectsObservation: NotificationToken?
private let tokensDatastore: PrivateTokensDatastoreType
private let assetDefinitionStore: AssetDefinitionStore
init(account: Wallet, tokensDatastore: PrivateTokensDatastoreType, server: RPCServer, queue: DispatchQueue) {
init(account: Wallet, tokensDatastore: PrivateTokensDatastoreType, server: RPCServer, assetDefinitionStore: AssetDefinitionStore, queue: DispatchQueue) {
self.account = account
self.server = server
self.backgroundQueue = queue
self.openSea = OpenSea.createInstance(forServer: server)
self.tokensDatastore = tokensDatastore
self.assetDefinitionStore = assetDefinitionStore
//NOTE: fire refresh balance only for initial scope, and while adding new tokens
enabledObjectsObservation = tokensDatastore.enabledObjects.observe(on: backgroundQueue) { [weak self] change in
guard let strongSelf = self else { return }

@ -24,6 +24,7 @@ class WalletBalanceCoordinator: NSObject, WalletBalanceCoordinatorType {
private let keystore: Keystore
private let config: Config
private let assetDefinitionStore: AssetDefinitionStore
private var coinTickersFetcher: CoinTickersFetcherType
private var subscribableEnabledServersSubscriptionKey: Subscribable<[RPCServer]>.SubscribableKey!
private var walletsSubscriptionKey: Subscribable<Set<Wallet>>.SubscribableKey!
@ -33,9 +34,10 @@ class WalletBalanceCoordinator: NSObject, WalletBalanceCoordinatorType {
private (set) lazy var subscribableWalletsSummary: Subscribable<WalletSummary> = .init(walletSummary)
private let queue: DispatchQueue = DispatchQueue(label: "com.WalletBalanceCoordinator.updateQueue")
init(keystore: Keystore, config: Config, coinTickersFetcher: CoinTickersFetcherType) {
init(keystore: Keystore, config: Config, assetDefinitionStore: AssetDefinitionStore, coinTickersFetcher: CoinTickersFetcherType) {
self.keystore = keystore
self.config = config
self.assetDefinitionStore = assetDefinitionStore
self.coinTickersFetcher = coinTickersFetcher
super.init()
@ -81,7 +83,7 @@ class WalletBalanceCoordinator: NSObject, WalletBalanceCoordinatorType {
func refreshBalance() {
balanceFetchers[keystore.currentWallet].flatMap { $0.refreshBalance() }
}
func refreshEthBalance() {
balanceFetchers[keystore.currentWallet].flatMap { $0.refreshEthBalance() }
}
@ -113,7 +115,7 @@ class WalletBalanceCoordinator: NSObject, WalletBalanceCoordinatorType {
}
private func createWalletBalanceFetcher(wallet: Wallet) -> WalletBalanceFetcherType {
let fetcher = WalletBalanceFetcher(wallet: wallet, servers: servers, queue: queue, coinTickersFetcher: coinTickersFetcher)
let fetcher = WalletBalanceFetcher(wallet: wallet, servers: servers, assetDefinitionStore: assetDefinitionStore, queue: queue, coinTickersFetcher: coinTickersFetcher)
fetcher.delegate = self
return fetcher

@ -35,6 +35,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
private static let updateBalanceInterval: TimeInterval = 60
private var timer: Timer?
private let wallet: Wallet
private let assetDefinitionStore: AssetDefinitionStore
private (set) lazy var subscribableWalletBalance: Subscribable<WalletBalance> = .init(balance)
let tokensChangeSubscribable: Subscribable<Void> = .init(nil)
private var tokensDataStores: ServerDictionary<(PrivateTokensDatastoreType, PrivateBalanceFetcherType, TransactionsStorage)> = .init()
@ -51,8 +52,9 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
private lazy var realm = Wallet.functional.realm(forAccount: wallet)
required init(wallet: Wallet, servers: [RPCServer], queue: DispatchQueue, coinTickersFetcher: CoinTickersFetcherType) {
required init(wallet: Wallet, servers: [RPCServer], assetDefinitionStore: AssetDefinitionStore, queue: DispatchQueue, coinTickersFetcher: CoinTickersFetcherType) {
self.wallet = wallet
self.assetDefinitionStore = assetDefinitionStore
self.queue = queue
self.coinTickersFetcher = coinTickersFetcher
@ -61,7 +63,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
for each in servers {
let transactionsStorage = TransactionsStorage(realm: realm, server: each, delegate: nil)
let tokensDatastore: PrivateTokensDatastoreType = PrivateTokensDatastore(realm: realm, server: each, queue: queue)
let balanceFetcher = PrivateBalanceFetcher(account: wallet, tokensDatastore: tokensDatastore, server: each, queue: queue)
let balanceFetcher = PrivateBalanceFetcher(account: wallet, tokensDatastore: tokensDatastore, server: each, assetDefinitionStore: assetDefinitionStore, queue: queue)
balanceFetcher.erc721TokenIdsFetcher = transactionsStorage
balanceFetcher.delegate = self
@ -85,7 +87,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
} else {
let transactionsStorage = TransactionsStorage(realm: realm, server: each, delegate: nil)
let tokensDatastore: PrivateTokensDatastoreType = PrivateTokensDatastore(realm: realm, server: each, queue: queue)
let balanceFetcher = PrivateBalanceFetcher(account: wallet, tokensDatastore: tokensDatastore, server: each, queue: queue)
let balanceFetcher = PrivateBalanceFetcher(account: wallet, tokensDatastore: tokensDatastore, server: each, assetDefinitionStore: assetDefinitionStore, queue: queue)
balanceFetcher.erc721TokenIdsFetcher = transactionsStorage
balanceFetcher.delegate = self
@ -182,7 +184,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
}
return .init(wallet: wallet, values: balances)
}
}
var isRunning: Bool {
if let timer = timer {

Loading…
Cancel
Save