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. 2
      AlphaWallet/AppCoordinator.swift
  2. 5
      AlphaWallet/Core/Coordinators/WalletBalance/PrivateBalanceFetcher.swift
  3. 6
      AlphaWallet/Core/Coordinators/WalletBalance/WalletBalanceCoordinator.swift
  4. 8
      AlphaWallet/Core/Coordinators/WalletBalance/WalletBalanceFetcher.swift

@ -44,7 +44,7 @@ class AppCoordinator: NSObject, Coordinator {
return coordinators.first { $0 is InCoordinator } as? InCoordinator return coordinators.first { $0 is InCoordinator } as? InCoordinator
} }
private lazy var coinTickersFetcher: CoinTickersFetcherType = CoinTickersFetcher(provider: AlphaWalletProviderFactory.makeProvider(), config: config) 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? private var pendingInCoordinator: InCoordinator?

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

@ -24,6 +24,7 @@ class WalletBalanceCoordinator: NSObject, WalletBalanceCoordinatorType {
private let keystore: Keystore private let keystore: Keystore
private let config: Config private let config: Config
private let assetDefinitionStore: AssetDefinitionStore
private var coinTickersFetcher: CoinTickersFetcherType private var coinTickersFetcher: CoinTickersFetcherType
private var subscribableEnabledServersSubscriptionKey: Subscribable<[RPCServer]>.SubscribableKey! private var subscribableEnabledServersSubscriptionKey: Subscribable<[RPCServer]>.SubscribableKey!
private var walletsSubscriptionKey: Subscribable<Set<Wallet>>.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 (set) lazy var subscribableWalletsSummary: Subscribable<WalletSummary> = .init(walletSummary)
private let queue: DispatchQueue = DispatchQueue(label: "com.WalletBalanceCoordinator.updateQueue") 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.keystore = keystore
self.config = config self.config = config
self.assetDefinitionStore = assetDefinitionStore
self.coinTickersFetcher = coinTickersFetcher self.coinTickersFetcher = coinTickersFetcher
super.init() super.init()
@ -113,7 +115,7 @@ class WalletBalanceCoordinator: NSObject, WalletBalanceCoordinatorType {
} }
private func createWalletBalanceFetcher(wallet: Wallet) -> WalletBalanceFetcherType { 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 fetcher.delegate = self
return fetcher return fetcher

@ -35,6 +35,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
private static let updateBalanceInterval: TimeInterval = 60 private static let updateBalanceInterval: TimeInterval = 60
private var timer: Timer? private var timer: Timer?
private let wallet: Wallet private let wallet: Wallet
private let assetDefinitionStore: AssetDefinitionStore
private (set) lazy var subscribableWalletBalance: Subscribable<WalletBalance> = .init(balance) private (set) lazy var subscribableWalletBalance: Subscribable<WalletBalance> = .init(balance)
let tokensChangeSubscribable: Subscribable<Void> = .init(nil) let tokensChangeSubscribable: Subscribable<Void> = .init(nil)
private var tokensDataStores: ServerDictionary<(PrivateTokensDatastoreType, PrivateBalanceFetcherType, TransactionsStorage)> = .init() 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) 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.wallet = wallet
self.assetDefinitionStore = assetDefinitionStore
self.queue = queue self.queue = queue
self.coinTickersFetcher = coinTickersFetcher self.coinTickersFetcher = coinTickersFetcher
@ -61,7 +63,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
for each in servers { for each in servers {
let transactionsStorage = TransactionsStorage(realm: realm, server: each, delegate: nil) let transactionsStorage = TransactionsStorage(realm: realm, server: each, delegate: nil)
let tokensDatastore: PrivateTokensDatastoreType = PrivateTokensDatastore(realm: realm, server: each, queue: queue) 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.erc721TokenIdsFetcher = transactionsStorage
balanceFetcher.delegate = self balanceFetcher.delegate = self
@ -85,7 +87,7 @@ class WalletBalanceFetcher: NSObject, WalletBalanceFetcherType {
} else { } else {
let transactionsStorage = TransactionsStorage(realm: realm, server: each, delegate: nil) let transactionsStorage = TransactionsStorage(realm: realm, server: each, delegate: nil)
let tokensDatastore: PrivateTokensDatastoreType = PrivateTokensDatastore(realm: realm, server: each, queue: queue) 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.erc721TokenIdsFetcher = transactionsStorage
balanceFetcher.delegate = self balanceFetcher.delegate = self

Loading…
Cancel
Save