update active wallet dependency, add passing activities pipeline instead of realm instance #5341

pull/5342/head
Krypto Pank 2 years ago
parent e898866bcb
commit 81eac740f8
  1. 7
      AlphaWallet/ActiveWalletCoordinator.swift
  2. 2
      AlphaWallet/AppCoordinator.swift
  3. 14
      AlphaWalletTests/Coordinators/ActiveWalletViewTests.swift
  4. 9
      AlphaWalletTests/ViewControllers/PaymentCoordinatorTests.swift
  5. 14
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Activities/ActivitiesPipeLine.swift
  6. 16
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/WalletDependencyContainer.swift

@ -28,7 +28,7 @@ class ActiveWalletCoordinator: NSObject, Coordinator, DappRequestHandlerDelegate
private let transactionsDataStore: TransactionDataStore
private var claimOrderCoordinatorCompletionBlock: ((Bool) -> Void)?
private let blockscanChatService: BlockscanChatService
private lazy var activitiesPipeLine = ActivitiesPipeLine(config: config, wallet: wallet, store: store, assetDefinitionStore: assetDefinitionStore, transactionDataStore: transactionsDataStore, tokensService: tokensService, sessionsProvider: sessionsProvider)
private let activitiesPipeLine: ActivitiesPipeLine
private let sessionsProvider: SessionsProvider
private let importToken: ImportToken
private lazy var tokensFilter: TokensFilter = {
@ -130,7 +130,6 @@ class ActiveWalletCoordinator: NSObject, Coordinator, DappRequestHandlerDelegate
private let notificationService: NotificationService
private let blockiesGenerator: BlockiesGenerator
private let domainResolutionService: DomainResolutionServiceType
private let store: RealmStore
private let tokenSwapper: TokenSwapper
private let tokensService: DetectedContractsProvideble & TokenProvidable & TokenAddable
private let lock: Lock
@ -138,7 +137,7 @@ class ActiveWalletCoordinator: NSObject, Coordinator, DappRequestHandlerDelegate
init(
navigationController: UINavigationController = NavigationController(),
walletAddressesStore: WalletAddressesStore,
store: RealmStore,
activitiesPipeLine: ActivitiesPipeLine,
wallet: Wallet,
keystore: Keystore,
assetDefinitionStore: AssetDefinitionStore,
@ -169,7 +168,7 @@ class ActiveWalletCoordinator: NSObject, Coordinator, DappRequestHandlerDelegate
self.transactionsDataStore = transactionsDataStore
self.importToken = importToken
self.tokenCollection = tokenCollection
self.store = store
self.activitiesPipeLine = activitiesPipeLine
self.tokenSwapper = tokenSwapper
self.sessionsProvider = sessionsProvider
self.walletConnectCoordinator = walletConnectCoordinator

@ -269,7 +269,7 @@ class AppCoordinator: NSObject, Coordinator {
let coordinator = ActiveWalletCoordinator(
navigationController: navigationController,
walletAddressesStore: walletAddressesStore,
store: dep.store,
activitiesPipeLine: dep.activitiesPipeLine,
wallet: wallet,
keystore: keystore,
assetDefinitionStore: assetDefinitionStore,

@ -19,7 +19,7 @@ class ActiveWalletViewTests: XCTestCase {
let coordinator = ActiveWalletCoordinator(
navigationController: navigationController,
walletAddressesStore: EtherKeystore.migratedWalletAddressesStore(userDefaults: .test),
store: .fake(for: wallet),
activitiesPipeLine: dep.activitiesPipeLine,
wallet: wallet,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),
@ -87,7 +87,7 @@ class ActiveWalletViewTests: XCTestCase {
let c1 = ActiveWalletCoordinator(
navigationController: FakeNavigationController(),
walletAddressesStore: EtherKeystore.migratedWalletAddressesStore(userDefaults: .test),
store: .fake(for: account1),
activitiesPipeLine: dep1.activitiesPipeLine,
wallet: account1,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),
@ -121,7 +121,7 @@ class ActiveWalletViewTests: XCTestCase {
let c2 = ActiveWalletCoordinator(
navigationController: FakeNavigationController(),
walletAddressesStore: EtherKeystore.migratedWalletAddressesStore(userDefaults: .test),
store: .fake(for: account2),
activitiesPipeLine: dep2.activitiesPipeLine,
wallet: account2,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),
@ -164,7 +164,7 @@ class ActiveWalletViewTests: XCTestCase {
let coordinator = ActiveWalletCoordinator(
navigationController: FakeNavigationController(),
walletAddressesStore: fakeWalletAddressesStore(wallets: [.make()]),
store: .fake(for: wallet),
activitiesPipeLine: dep.activitiesPipeLine,
wallet: wallet,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),
@ -208,7 +208,7 @@ class ActiveWalletViewTests: XCTestCase {
let coordinator = ActiveWalletCoordinator(
navigationController: navigationController,
walletAddressesStore: EtherKeystore.migratedWalletAddressesStore(userDefaults: .test),
store: .fake(for: wallet),
activitiesPipeLine: dep.activitiesPipeLine,
wallet: wallet,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),
@ -252,7 +252,7 @@ class ActiveWalletViewTests: XCTestCase {
let coordinator = ActiveWalletCoordinator(
navigationController: navigationController,
walletAddressesStore: EtherKeystore.migratedWalletAddressesStore(userDefaults: .test),
store: .fake(for: wallet),
activitiesPipeLine: dep.activitiesPipeLine,
wallet: wallet,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),
@ -315,7 +315,7 @@ class ActiveWalletViewTests: XCTestCase {
let coordinator: ActiveWalletCoordinator = ActiveWalletCoordinator(
navigationController: navigationController,
walletAddressesStore: EtherKeystore.migratedWalletAddressesStore(userDefaults: .test),
store: .fake(for: wallet),
activitiesPipeLine: dep.activitiesPipeLine,
wallet: wallet,
keystore: keystore,
assetDefinitionStore: AssetDefinitionStore(),

@ -22,7 +22,8 @@ extension WalletDataProcessingPipeline {
static func make(wallet: Wallet = .make(), server: RPCServer = .main) -> WalletDependency {
let fas = FakeAnalyticsService()
let sessionsProvider: SessionsProvider = .make(wallet: wallet, servers: [server])
let store: RealmStore = .fake(for: wallet)
let eventsActivityDataStore: EventsActivityDataStoreProtocol = EventsActivityDataStore(store: .fake(for: wallet))
let tokensDataStore = FakeTokensDataStore(account: wallet, servers: [server])
let importToken = ImportToken(sessionProvider: sessionsProvider, wallet: wallet, tokensDataStore: tokensDataStore, assetDefinitionStore: .init(), analytics: fas)
let eventsDataStore = FakeEventsDataStore()
@ -36,7 +37,9 @@ extension WalletDataProcessingPipeline {
let fetcher = WalletBalanceFetcher(wallet: wallet, tokensService: pipeline)
let dep = FakeWalletDep(store: store, tokensDataStore: tokensDataStore, transactionsDataStore: transactionsDataStore, importToken: importToken, tokensService: tokensService, pipeline: pipeline, fetcher: fetcher, sessionsProvider: sessionsProvider)
let activitiesPipeLine = ActivitiesPipeLine(config: .make(), wallet: wallet, assetDefinitionStore: .init(), transactionDataStore: transactionsDataStore, tokensService: tokensService, sessionsProvider: sessionsProvider, eventsActivityDataStore: eventsActivityDataStore, eventsDataStore: eventsDataStore)
let dep = FakeWalletDep(activitiesPipeLine: activitiesPipeLine, tokensDataStore: tokensDataStore, transactionsDataStore: transactionsDataStore, importToken: importToken, tokensService: tokensService, pipeline: pipeline, fetcher: fetcher, sessionsProvider: sessionsProvider)
dep.sessionsProvider.start(wallet: wallet)
dep.fetcher.start()
dep.pipeline.start()
@ -45,7 +48,7 @@ extension WalletDataProcessingPipeline {
}
struct FakeWalletDep: WalletDependency {
let store: RealmStore
let activitiesPipeLine: ActivitiesPipeLine
let tokensDataStore: TokensDataStore
let transactionsDataStore: TransactionDataStore
let importToken: ImportToken

@ -11,17 +11,12 @@ import Combine
public final class ActivitiesPipeLine: ActivitiesServiceType {
private let config: Config
private let wallet: Wallet
private let store: RealmStore
private let assetDefinitionStore: AssetDefinitionStore
private let sessionsProvider: SessionsProvider
private let transactionDataStore: TransactionDataStore
lazy private var eventsDataStore: NonActivityEventsDataStore = {
return NonActivityMultiChainEventsDataStore(store: store)
}()
lazy private var eventsActivityDataStore: EventsActivityDataStoreProtocol = {
return EventsActivityDataStore(store: store)
}()
private let eventsDataStore: NonActivityEventsDataStore
private let eventsActivityDataStore: EventsActivityDataStoreProtocol
private lazy var eventSourceForActivities: EventSourceForActivities? = {
guard Features.default.isAvailable(.isActivityEnabled) else { return nil }
return EventSourceForActivities(wallet: wallet, config: config, tokensService: tokensService, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsActivityDataStore)
@ -44,11 +39,12 @@ public final class ActivitiesPipeLine: ActivitiesServiceType {
activitiesSubService.didUpdateActivityPublisher
}
public init(config: Config, wallet: Wallet, store: RealmStore, assetDefinitionStore: AssetDefinitionStore, transactionDataStore: TransactionDataStore, tokensService: TokenProvidable, sessionsProvider: SessionsProvider) {
public init(config: Config, wallet: Wallet, assetDefinitionStore: AssetDefinitionStore, transactionDataStore: TransactionDataStore, tokensService: TokenProvidable, sessionsProvider: SessionsProvider, eventsActivityDataStore: EventsActivityDataStoreProtocol, eventsDataStore: NonActivityEventsDataStore) {
self.eventsActivityDataStore = eventsActivityDataStore
self.eventsDataStore = eventsDataStore
self.tokensService = tokensService
self.config = config
self.wallet = wallet
self.store = store
self.assetDefinitionStore = assetDefinitionStore
self.transactionDataStore = transactionDataStore
self.sessionsProvider = sessionsProvider

@ -13,7 +13,7 @@ public protocol WalletDependencyContainer {
}
public protocol WalletDependency {
var store: RealmStore { get }
var activitiesPipeLine: ActivitiesPipeLine { get }
var transactionsDataStore: TransactionDataStore { get }
var importToken: ImportToken { get }
var tokensService: DetectedContractsProvideble & TokenProvidable & TokenAddable & TokensServiceTests { get }
@ -32,7 +32,7 @@ public class WalletComponentsFactory: WalletDependencyContainer {
private var walletDependencies: [Wallet: WalletDependency] = [:]
public struct Dependencies: WalletDependency {
public let store: RealmStore
public let activitiesPipeLine: ActivitiesPipeLine
public let transactionsDataStore: TransactionDataStore
public let importToken: ImportToken
public let tokensService: DetectedContractsProvideble & TokenProvidable & TokenAddable & TokensServiceTests
@ -53,11 +53,10 @@ public class WalletComponentsFactory: WalletDependencyContainer {
public func makeDependencies(for wallet: Wallet) -> WalletDependency {
if let dep = walletDependencies[wallet] { return dep }
let store: RealmStore = .storage(for: wallet)
let tokensDataStore: TokensDataStore = MultipleChainsTokensDataStore(store: store, servers: config.enabledServers)
let eventsDataStore: NonActivityEventsDataStore = NonActivityMultiChainEventsDataStore(store: store)
let transactionsDataStore = TransactionDataStore(store: store)
let tokensDataStore: TokensDataStore = MultipleChainsTokensDataStore(store: .storage(for: wallet), servers: config.enabledServers)
let eventsDataStore: NonActivityEventsDataStore = NonActivityMultiChainEventsDataStore(store: .storage(for: wallet))
let transactionsDataStore: TransactionDataStore = TransactionDataStore(store: .storage(for: wallet))
let eventsActivityDataStore: EventsActivityDataStoreProtocol = EventsActivityDataStore(store: .storage(for: wallet))
let sessionsProvider: SessionsProvider = .init(config: config, analytics: analytics)
let importToken = ImportToken(sessionProvider: sessionsProvider, wallet: wallet, tokensDataStore: tokensDataStore, assetDefinitionStore: assetDefinitionStore, analytics: analytics)
@ -66,8 +65,9 @@ public class WalletComponentsFactory: WalletDependencyContainer {
let pipeline: TokensProcessingPipeline = WalletDataProcessingPipeline(wallet: wallet, tokensService: tokensService, coinTickersFetcher: coinTickersFetcher, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore)
let fetcher = WalletBalanceFetcher(wallet: wallet, tokensService: pipeline)
let activitiesPipeLine = ActivitiesPipeLine(config: config, wallet: wallet, assetDefinitionStore: assetDefinitionStore, transactionDataStore: transactionsDataStore, tokensService: tokensService, sessionsProvider: sessionsProvider, eventsActivityDataStore: eventsActivityDataStore, eventsDataStore: eventsDataStore)
let dependency: WalletDependency = Dependencies(store: store, transactionsDataStore: transactionsDataStore, importToken: importToken, tokensService: tokensService, pipeline: pipeline, fetcher: fetcher, sessionsProvider: sessionsProvider, eventsDataStore: eventsDataStore)
let dependency: WalletDependency = Dependencies(activitiesPipeLine: activitiesPipeLine, transactionsDataStore: transactionsDataStore, importToken: importToken, tokensService: tokensService, pipeline: pipeline, fetcher: fetcher, sessionsProvider: sessionsProvider, eventsDataStore: eventsDataStore)
walletDependencies[wallet] = dependency

Loading…
Cancel
Save