Rename EventsDataStoreProtocol with NonActivityMultiChainEventsDataStore #4054

pull/4055/head
Krypto Pank 3 years ago
parent 39d1071b67
commit 2ec2bda6a6
  1. 8
      AlphaWallet.xcodeproj/project.pbxproj
  2. 4
      AlphaWallet/Activities/ActivitiesService.swift
  3. 3
      AlphaWallet/InCoordinator.swift
  4. 6
      AlphaWallet/TokenScriptClient/Coordinators/EventSourceCoordinator.swift
  5. 17
      AlphaWallet/TokenScriptClient/Models/NonActivityEventsDataStore.swift
  6. 4
      AlphaWallet/Tokens/Collectibles/Coordinators/TokensCardCollectionCoordinator.swift
  7. 2
      AlphaWallet/Tokens/Collectibles/ViewModels/TokensCardCollectionInfoPageViewModel.swift
  8. 4
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift
  9. 4
      AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift
  10. 4
      AlphaWallet/Tokens/Helpers/TokenAdaptor.swift
  11. 4
      AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift
  12. 4
      AlphaWallet/Tokens/ViewControllers/TokensViewController.swift
  13. 4
      AlphaWallet/Tokens/ViewModels/TokensCardViewModel.swift
  14. 4
      AlphaWallet/Transactions/Coordinators/TokensCardCoordinator.swift
  15. 4
      AlphaWallet/Transfer/Coordinators/PaymentCoordinator.swift
  16. 4
      AlphaWallet/Transfer/Coordinators/TokenScriptCoordinator.swift
  17. 2
      AlphaWalletTests/TokenScriptClient/FakeEventsDataStore.swift

@ -337,7 +337,7 @@
5E7C732AA43385E80681B24F /* EmailList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7B097096FC37B68A399B /* EmailList.swift */; };
5E7C732BD09AABEEE6096BF4 /* ServersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C74C0C1803DD17FE9EBA7 /* ServersViewController.swift */; };
5E7C733638D7596F93DEE2A9 /* OnboardingCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C75CE3F1D6B7993E7A840 /* OnboardingCollectionViewController.swift */; };
5E7C733C6C4DD52495427B66 /* EventsDataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7EDC84FC2C767ED0C167 /* EventsDataStore.swift */; };
5E7C733C6C4DD52495427B66 /* NonActivityEventsDataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7EDC84FC2C767ED0C167 /* NonActivityEventsDataStore.swift */; };
5E7C733D2CA2A0FC585D93D1 /* AssetInternalValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C79199D828A206A7F23B1 /* AssetInternalValue.swift */; };
5E7C7350C5F9ADE212A0F1CA /* CallForAssetAttributeCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C74F4900AB6D34CDD3674 /* CallForAssetAttributeCoordinator.swift */; };
5E7C7376B566E5A59CC8F463 /* ImportMagicTokenViewControllerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C72D0E7CA03ADE5CFAE7A /* ImportMagicTokenViewControllerViewModel.swift */; };
@ -1706,7 +1706,7 @@
5E7C7EC53B2B5DFAAC7965EC /* TokenViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenViewController.swift; sourceTree = "<group>"; };
5E7C7ED293E477AD7C13056C /* Bookmark.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bookmark.swift; sourceTree = "<group>"; };
5E7C7ED522A9E75F10594EFB /* DirectoryContentsWatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectoryContentsWatcher.swift; sourceTree = "<group>"; };
5E7C7EDC84FC2C767ED0C167 /* EventsDataStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventsDataStore.swift; sourceTree = "<group>"; };
5E7C7EDC84FC2C767ED0C167 /* NonActivityEventsDataStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NonActivityEventsDataStore.swift; sourceTree = "<group>"; };
5E7C7EE374A74F2B00013C18 /* EthTokenViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EthTokenViewCell.swift; sourceTree = "<group>"; };
5E7C7EE467A7F5F2E5B1F660 /* TokensViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokensViewModel.swift; sourceTree = "<group>"; };
5E7C7EE6BFC8BB79CD1C5565 /* AlphaWalletAddressExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlphaWalletAddressExtension.swift; sourceTree = "<group>"; };
@ -3922,7 +3922,7 @@
5E7C72FABB78B9E1655A06A2 /* FunctionOrigin.swift */,
5E7C7E014F0C6BD090E955A2 /* TokenInterfaceType.swift */,
5E7C740BBC5AAF5C545CCC6A /* EventOrigin.swift */,
5E7C7EDC84FC2C767ED0C167 /* EventsDataStore.swift */,
5E7C7EDC84FC2C767ED0C167 /* NonActivityEventsDataStore.swift */,
5E7C78302634885C93D9B6FA /* TokenIdOrEvent.swift */,
5E7C77E52AD90BA044CFD67A /* TokenScriptFilterParser.swift */,
5E7C71E8E2D256BC461E9597 /* TokenScriptSelection.swift */,
@ -6497,7 +6497,7 @@
5E7C7F3CB1F280E6795A479C /* EventOrigin.swift in Sources */,
5E7C7A2DBFF7FB3B8B5DEB1B /* EventInstance.swift in Sources */,
5E7C7D918B514B4C2F8DF296 /* EventSourceCoordinator.swift in Sources */,
5E7C733C6C4DD52495427B66 /* EventsDataStore.swift in Sources */,
5E7C733C6C4DD52495427B66 /* NonActivityEventsDataStore.swift in Sources */,
5E7C797F3278A290BE47BFA2 /* TokenIdOrEvent.swift in Sources */,
870CC47D27C6566400A19380 /* AutoDetectTokensOperation.swift in Sources */,
5E7C7193C577A84710D71F5C /* TokenScriptFilterParser.swift in Sources */,

@ -28,7 +28,7 @@ class ActivitiesService: NSObject, ActivitiesServiceType {
private let assetDefinitionStore: AssetDefinitionStore
private let eventsActivityDataStore: EventsActivityDataStoreProtocol
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
//Dictionary for lookup. Using `.firstIndex` too many times is too slow (60s for 10k events)
private var activitiesIndexLookup: [Int: (index: Int, activity: Activity)] = .init()
private var activities: [Activity] = .init()
@ -71,7 +71,7 @@ class ActivitiesService: NSObject, ActivitiesServiceType {
sessions: ServerDictionary<WalletSession>,
assetDefinitionStore: AssetDefinitionStore,
eventsActivityDataStore: EventsActivityDataStoreProtocol,
eventsDataStore: EventsDataStoreProtocol,
eventsDataStore: NonActivityEventsDataStore,
transactionCollection: TransactionCollection,
activitiesFilterStrategy: ActivitiesFilterStrategy = .none,
transactionsFilterStrategy: TransactionsFilterStrategy = .all,

@ -31,8 +31,7 @@ class InCoordinator: NSObject, Coordinator {
}
}
private let queue: DispatchQueue = DispatchQueue(label: "com.Background.updateQueue", qos: .userInitiated)
//TODO rename this generic name to reflect that it's for event instances, not for event activity
lazy private var eventsDataStore: EventsDataStoreProtocol = EventsDataStore(realm: realm)
lazy private var eventsDataStore: NonActivityEventsDataStore = NonActivityMultiChainEventsDataStore(realm: realm)
lazy private var eventsActivityDataStore: EventsActivityDataStoreProtocol = EventsActivityDataStore(realm: realm)
private var eventSourceCoordinatorForActivities: EventSourceCoordinatorForActivities?
private let coinTickersFetcher: CoinTickersFetcherType

@ -26,13 +26,13 @@ class EventSourceCoordinator: EventSourceCoordinatorType {
private var wallet: Wallet
private let tokensDataStore: TokensDataStore
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private var isFetching = false
private var rateLimitedUpdater: RateLimiter?
private let queue = DispatchQueue(label: "com.eventSourceCoordinator.updateQueue")
private let enabledServers: [RPCServer]
init(wallet: Wallet, tokensDataStore: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: EventsDataStoreProtocol, config: Config) {
init(wallet: Wallet, tokensDataStore: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: NonActivityEventsDataStore, config: Config) {
self.wallet = wallet
self.tokensDataStore = tokensDataStore
self.assetDefinitionStore = assetDefinitionStore
@ -105,7 +105,7 @@ extension EventSourceCoordinator {
extension EventSourceCoordinator.functional {
static func fetchEvents(forTokenId tokenId: TokenId, token: TokenObject, eventOrigin: EventOrigin, wallet: Wallet, eventsDataStore: EventsDataStoreProtocol, queue: DispatchQueue) -> Promise<Void> {
static func fetchEvents(forTokenId tokenId: TokenId, token: TokenObject, eventOrigin: EventOrigin, wallet: Wallet, eventsDataStore: NonActivityEventsDataStore, queue: DispatchQueue) -> Promise<Void> {
//Important to not access `token` in the queue or another thread. Do it outside
//TODO better to pass in a non-Realm representation of the TokenObject instead
let contractAddress = token.contractAddress

@ -1,11 +1,11 @@
// Copyright © 2020 Stormbird PTE. LTD.
import Foundation
import RealmSwift
import PromiseKit
import RealmSwift
import Combine
import PromiseKit
protocol EventsDataStoreProtocol {
protocol NonActivityEventsDataStore {
func getLastMatchingEventSortedByBlockNumber(forContract contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, eventName: String) -> Promise<EventInstanceValue?>
func add(events: [EventInstanceValue])
func deleteEvents(forTokenContract contract: AlphaWallet.Address)
@ -13,8 +13,7 @@ protocol EventsDataStoreProtocol {
func recentEvents(forTokenContract tokenContract: AlphaWallet.Address) -> AnyPublisher<RealmCollectionChange<Results<EventInstance>>, Never>
}
//TODO rename to indicate it's for instances, not activity
class EventsDataStore: EventsDataStoreProtocol {
class NonActivityMultiChainEventsDataStore: NonActivityEventsDataStore {
private let realm: Realm
init(realm: Realm) {
@ -22,7 +21,7 @@ class EventsDataStore: EventsDataStoreProtocol {
}
func getMatchingEvent(forContract contract: AlphaWallet.Address, tokenContract: AlphaWallet.Address, server: RPCServer, eventName: String, filterName: String, filterValue: String) -> EventInstance? {
let predicate = EventsDataStore
let predicate = NonActivityMultiChainEventsDataStore
.functional
.matchingEventPredicate(forContract: contract, tokenContract: tokenContract, server: server, eventName: eventName, filterName: filterName, filterValue: filterValue)
@ -54,7 +53,7 @@ class EventsDataStore: EventsDataStoreProtocol {
return Promise { seal in
DispatchQueue.main.async { [weak self] in
guard let strongSelf = self else { return seal.reject(PMKError.cancelled) }
let predicate = EventsDataStore
let predicate = NonActivityMultiChainEventsDataStore
.functional
.matchingEventPredicate(forContract: contract, tokenContract: tokenContract, server: server, eventName: eventName)
@ -79,11 +78,11 @@ class EventsDataStore: EventsDataStoreProtocol {
}
}
extension EventsDataStore {
extension NonActivityMultiChainEventsDataStore {
enum functional {}
}
extension EventsDataStore.functional {
extension NonActivityMultiChainEventsDataStore.functional {
static func isFilterMatchPredicate(filterName: String, filterValue: String) -> NSPredicate {
return NSPredicate(format: "filter = '\(filterName)=\(filterValue)'")

@ -29,7 +29,7 @@ class TokensCardCollectionCoordinator: NSObject, Coordinator {
private let session: WalletSession
private let tokensStorage: TokensDataStore
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private let transactionsStorage: TransactionsStorage
private (set) var analyticsCoordinator: AnalyticsCoordinator
@ -47,7 +47,7 @@ class TokensCardCollectionCoordinator: NSObject, Coordinator {
tokensStorage: TokensDataStore,
token: TokenObject,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
eventsDataStore: NonActivityEventsDataStore,
analyticsCoordinator: AnalyticsCoordinator,
activitiesService: ActivitiesServiceType,
transactionsStorage: TransactionsStorage,

@ -70,7 +70,7 @@ struct TokensCardCollectionInfoPageViewModel {
.flatMap { URL(string: $0) }
}
init(server: RPCServer, token: TokenObject, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: EventsDataStoreProtocol, forWallet wallet: Wallet) {
init(server: RPCServer, token: TokenObject, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: NonActivityEventsDataStore, forWallet wallet: Wallet) {
self.server = server
self.tokenObject = token
tokenHolders = TokenAdaptor(token: token, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore).getTokenHolders(forWallet: wallet)

@ -29,7 +29,7 @@ class SingleChainTokenCoordinator: Coordinator {
private let keystore: Keystore
private let tokensDataStore: TokensDataStore
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private let analyticsCoordinator: AnalyticsCoordinator
private let tokenActionsProvider: TokenActionsProvider
private let transactionsStorage: TransactionsStorage
@ -53,7 +53,7 @@ class SingleChainTokenCoordinator: Coordinator {
keystore: Keystore,
tokensStorage: TokensDataStore,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
eventsDataStore: NonActivityEventsDataStore,
analyticsCoordinator: AnalyticsCoordinator,
tokenActionsProvider: TokenActionsProvider,
transactionsStorage: TransactionsStorage,

@ -32,7 +32,7 @@ class TokensCoordinator: Coordinator {
return MultipleChainsTokenCollection(tokensFilter: tokensFilter, tokensDataStore: tokensDataStore, config: config)
}()
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private let promptBackupCoordinator: PromptBackupCoordinator
private lazy var tokensFilter: TokensFilter = {
return .init(assetDefinitionStore: assetDefinitionStore, tokenActionsService: tokenActionsService, coinTickersFetcher: coinTickersFetcher)
@ -109,7 +109,7 @@ class TokensCoordinator: Coordinator {
config: Config,
tokensDataStore: TokensDataStore,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
eventsDataStore: NonActivityEventsDataStore,
promptBackupCoordinator: PromptBackupCoordinator,
analyticsCoordinator: AnalyticsCoordinator,
tokenActionsService: TokenActionsServiceType,

@ -12,10 +12,10 @@ import BigInt
class TokenAdaptor {
private let token: TokenObject
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private lazy var xmlHandler = XMLHandler(token: token, assetDefinitionStore: assetDefinitionStore)
init(token: TokenObject, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: EventsDataStoreProtocol) {
init(token: TokenObject, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: NonActivityEventsDataStore) {
self.token = token
self.assetDefinitionStore = assetDefinitionStore
self.eventsDataStore = eventsDataStore

@ -24,7 +24,7 @@ class TokensCardViewController: UIViewController {
private let tokenObject: TokenObject
private let session: WalletSession
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private let analyticsCoordinator: AnalyticsCoordinator
private lazy var buttonsBar: ButtonsBar = {
let buttonsBar = ButtonsBar(configuration: .empty)
@ -74,7 +74,7 @@ class TokensCardViewController: UIViewController {
private let activitiesService: ActivitiesServiceType
private let keystore: Keystore
init(keystore: Keystore, session: WalletSession, assetDefinition: AssetDefinitionStore, analyticsCoordinator: AnalyticsCoordinator, token: TokenObject, viewModel: TokensCardViewModel, activitiesService: ActivitiesServiceType, eventsDataStore: EventsDataStoreProtocol) {
init(keystore: Keystore, session: WalletSession, assetDefinition: AssetDefinitionStore, analyticsCoordinator: AnalyticsCoordinator, token: TokenObject, viewModel: TokensCardViewModel, activitiesService: ActivitiesServiceType, eventsDataStore: NonActivityEventsDataStore) {
self.tokenObject = token
self.viewModel = viewModel
self.session = session

@ -52,7 +52,7 @@ class TokensViewController: UIViewController {
private let tokenCollection: TokenCollection
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private let analyticsCoordinator: AnalyticsCoordinator
private (set) var viewModel: TokensViewModel {
@ -205,7 +205,7 @@ class TokensViewController: UIViewController {
account: Wallet,
tokenCollection: TokenCollection,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
eventsDataStore: NonActivityEventsDataStore,
tokensFilter: TokensFilter,
config: Config,
walletConnectCoordinator: WalletConnectCoordinator,

@ -37,10 +37,10 @@ struct TokensCardViewModel {
return token.titleInPluralForm(withAssetDefinitionStore: assetDefinitionStore)
}
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private let account: Wallet
init(token: TokenObject, forWallet account: Wallet, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: EventsDataStoreProtocol) {
init(token: TokenObject, forWallet account: Wallet, assetDefinitionStore: AssetDefinitionStore, eventsDataStore: NonActivityEventsDataStore) {
self.token = token
self.account = account
self.eventsDataStore = eventsDataStore

@ -30,7 +30,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private let session: WalletSession
private let tokensDataStore: TokensDataStore
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
private weak var transferTokensViewController: TransferTokensCardViaWalletAddressViewController?
private let analyticsCoordinator: AnalyticsCoordinator
private let activitiesService: ActivitiesServiceType
@ -46,7 +46,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
tokensStorage: TokensDataStore,
token: TokenObject,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
eventsDataStore: NonActivityEventsDataStore,
analyticsCoordinator: AnalyticsCoordinator,
activitiesService: ActivitiesServiceType
) {

@ -19,7 +19,7 @@ class PaymentCoordinator: Coordinator {
private let ethPrice: Subscribable<Double>
private let assetDefinitionStore: AssetDefinitionStore
private let analyticsCoordinator: AnalyticsCoordinator
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
weak var delegate: PaymentCoordinatorDelegate?
var coordinators: [Coordinator] = []
let navigationController: UINavigationController
@ -36,7 +36,7 @@ class PaymentCoordinator: Coordinator {
ethPrice: Subscribable<Double>,
assetDefinitionStore: AssetDefinitionStore,
analyticsCoordinator: AnalyticsCoordinator,
eventsDataStore: EventsDataStoreProtocol
eventsDataStore: NonActivityEventsDataStore
) {
self.navigationController = navigationController
self.session = session

@ -31,7 +31,7 @@ class TokenScriptCoordinator: Coordinator {
private var transactionConfirmationResult: ConfirmResult? = .none
private let action: TokenInstanceAction
private let tokensStorage: TokensDataStore
private let eventsDataStore: EventsDataStoreProtocol
private let eventsDataStore: NonActivityEventsDataStore
weak var delegate: TokenScriptCoordinatorDelegate?
let navigationController: UINavigationController
var coordinators: [Coordinator] = []
@ -48,7 +48,7 @@ class TokenScriptCoordinator: Coordinator {
assetDefinitionStore: AssetDefinitionStore,
analyticsCoordinator: AnalyticsCoordinator,
action: TokenInstanceAction,
eventsDataStore: EventsDataStoreProtocol
eventsDataStore: NonActivityEventsDataStore
) {
self.eventsDataStore = eventsDataStore
self.action = action

@ -7,7 +7,7 @@ import RealmSwift
@testable import AlphaWallet
class FakeEventsDataStore: EventsDataStoreProtocol {
class FakeEventsDataStore: NonActivityEventsDataStore {
func recentEvents(forTokenContract tokenContract: AlphaWallet.Address) -> AnyPublisher<RealmCollectionChange<Results<EventInstance>>, Never> {
fatalError()
}

Loading…
Cancel
Save