Skip to content

Commit

Permalink
Classify a few types comforming to Initializer as a new protocol `S…
Browse files Browse the repository at this point in the history
…ervice` instead, to be more intention revealing, reflecting that they are long-running
  • Loading branch information
hboon committed May 3, 2023
1 parent 14b0d44 commit d2375a6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
5 changes: 2 additions & 3 deletions AlphaWallet/Common/Services/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ protocol ApplicationNavigatable: RestartQueueNavigatable, DonationUserActivityHa

// swiftlint:disable type_body_length
class Application: WalletDependenciesProvidable {
//TODO rename and replace type? Not Initializer but similar as of writing
private var services: [Initializer] = []
private var services: [Service] = []
private let dependencies: AtomicDictionary<Wallet, WalletDependencies> = .init()
private var cancelable = Set<AnyCancellable>()
private let launchOptionsService: LaunchOptionsService
Expand Down Expand Up @@ -430,14 +429,14 @@ class Application: WalletDependenciesProvidable {
CleanupPasscode(keystore: keystore, lock: lock),
KeyboardInitializer(),
DatabasePathLog(),
TickerIdsMatchLog()
]

initializers.forEach { $0.perform() }
}

private func runServices() {
services = [
TickerIdsMatchLog(),
ReportUsersWalletAddresses(keystore: keystore),
ReportUsersActiveChains(serversProvider: serversProvider),
MigrateToSupportEip1559Transactions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import AlphaWalletLogger
import AlphaWalletOpenSea
import AlphaWalletENS

Expand All @@ -17,24 +18,11 @@ public class ConfigureApp: Initializer {
}
}

import AlphaWalletLogger
public class DatabasePathLog: Initializer {
public init() {}
public func perform() {
let config = RealmConfiguration.configuration(name: "")
debugLog("Database filepath: \(config.fileURL!)")
debugLog("Database directory: \(config.fileURL!.deletingLastPathComponent())")
}
}

public class TickerIdsMatchLog: Initializer {
public init() {}
public func perform() {
if Features.default.isAvailable(.isLoggingEnabledForTickerMatches) {
Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
infoLog("Ticker ID positive matching counts: \(TickerIdFilter.matchCounts)")
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import Combine
import AlphaWalletLogger

public final class MigrateToSupportEip1559Transactions: Initializer {
public final class MigrateToSupportEip1559Transactions: Service {
private let serversProvider: ServersProvidable
private let keychain: Keystore
private var cancelable = Set<AnyCancellable>()
Expand All @@ -35,7 +35,7 @@ public final class MigrateToSupportEip1559Transactions: Initializer {
let storage = TransactionDataStore(store: RealmStore.storage(for: wallet))
storage.deleteAll()
}

Config.setAsMigratedToEip1559TransactionsSupport()
}.store(in: &cancelable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Foundation
import Combine

public final class ReportUsersActiveChains: Initializer {
public final class ReportUsersActiveChains: Service {
private let serversProvider: ServersProvidable
private var cancelable = Set<AnyCancellable>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Combine

public final class ReportUsersWalletAddresses: Initializer {
public final class ReportUsersWalletAddresses: Service {
private let keystore: Keystore
private var cancelable = Set<AnyCancellable>()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright © 2023 Stormbird PTE. LTD.

import Foundation

public protocol Service {
func perform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright © 2023 Stormbird PTE. LTD.

import AlphaWalletLogger
import Foundation

public class TickerIdsMatchLog: Service {
public init() {}
public func perform() {
if Features.default.isAvailable(.isLoggingEnabledForTickerMatches) {
Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
infoLog("Ticker ID positive matching counts: \(TickerIdFilter.matchCounts)")
}
}
}
}
2 changes: 2 additions & 0 deletions resources/SwiftFormatFiles.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ $(SRCROOT)/AlphaWalletTests/Tokens/TokensDataStoreTest.swift
$(SRCROOT)/AlphaWalletTests/Tokens/Helpers/TokenAdaptorTest.swift
$(SRCROOT)/modules/AlphaWalletENS/AlphaWalletENS/ENS.swift
$(SRCROOT)/modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/RPCServers.swift
$(SRCROOT)/modules/AlphaWalletFoundation/AlphaWalletFoundation/Services/Service.swift
$(SRCROOT)/modules/AlphaWalletFoundation/AlphaWalletFoundation/Services/TickerIdsMatchLog.swift

0 comments on commit d2375a6

Please sign in to comment.