From 264250416adc9e604811c02cdf5381dfb93da6a9 Mon Sep 17 00:00:00 2001 From: Rui Date: Tue, 7 Nov 2023 13:52:25 -0800 Subject: [PATCH] Lint --- .../Presenters/SettingsViewPresenter.swift | 105 +++++++++--------- .../RoutingKit/_Router/MappedRouter.swift | 12 +- Utilities/Utilities/_Utils/JsonLoader.swift | 2 +- .../Workers/dydxCarteraConfigWorker.swift | 6 +- .../dydxMarketInfoViewBuilder.swift | 2 +- .../Profile/Help/dydxHelpViewPresenter.swift | 16 +-- .../dydxStateManager/AbacusStateManager.swift | 66 +++++------ dydxV4/dydxV4/AppDelegate.swift | 26 ++--- scripts/pre-commit | 2 +- 9 files changed, 118 insertions(+), 119 deletions(-) diff --git a/PlatformUIJedio/PlatformUIJedio/Presenters/SettingsViewPresenter.swift b/PlatformUIJedio/PlatformUIJedio/Presenters/SettingsViewPresenter.swift index ba78b2a81..8fb3c68a2 100644 --- a/PlatformUIJedio/PlatformUIJedio/Presenters/SettingsViewPresenter.swift +++ b/PlatformUIJedio/PlatformUIJedio/Presenters/SettingsViewPresenter.swift @@ -5,7 +5,6 @@ // Created by Rui Huang on 3/21/23. // - import Utilities import dydxViews import PlatformParticles @@ -17,19 +16,19 @@ import JedioKit open class SettingsViewPresenter: BaseSettingsViewPresenter { private let keyValueStore: KeyValueStoreProtocol? private let appScheme: String? - + public init(definitionFile: String, keyValueStore: KeyValueStoreProtocol?, appScheme: String?) { self.keyValueStore = keyValueStore self.appScheme = appScheme super.init(definitionFile: definitionFile) } - + override open func start() { super.start() - + loadSettings() } - + private func loadSettings() { var sections = [SettingsViewModel.SectionViewModel]() for fieldList in fieldLists ?? [] { @@ -37,7 +36,7 @@ open class SettingsViewPresenter: BaseSettingsViewPresenter { } viewModel?.sections = sections } - + private func createSection(group: FieldListInteractor) -> SettingsViewModel.SectionViewModel { let listViewModel = PlatformListViewModel(firstListItemTopSeparator: true, lastListItemBottomSeparator: true) listViewModel.width = UIScreen.main.bounds.width - 16 @@ -52,12 +51,12 @@ open class SettingsViewPresenter: BaseSettingsViewPresenter { } return SettingsViewModel.SectionViewModel(title: group.title, items: listViewModel) } - + private func createInput(input: FieldInput) -> PlatformViewModel? { guard let fieldInputDefinition = input.fieldInput else { return nil } - + if let fieldName = input.fieldName, let value = keyValueStore?.value(forKey: fieldName) { input.value = value @@ -84,61 +83,61 @@ open class SettingsViewPresenter: BaseSettingsViewPresenter { } else { return FieldInputTextsInputViewModel(input: input, valueChanged: valueChanged) } - -// case .int: -// if hasOptions { -// return "field_input_grid_int" -// } else if fieldInput.min != nil && fieldInput.max != nil { -// return "field_input_slider_int" -// } else { -// return "field_input_textfield_int" -// } -// -// case .float: -// if fieldInput.min != nil && fieldInput.max != nil { -// return "field_input_slider_float" -// } else { -// return "field_input_textfield_float" -// } -// -// case .percent: -// return "field_input_slider_percent" -// -// case .strings: -// return "field_input_grid_strings" + + // case .int: + // if hasOptions { + // return "field_input_grid_int" + // } else if fieldInput.min != nil && fieldInput.max != nil { + // return "field_input_slider_int" + // } else { + // return "field_input_textfield_int" + // } + // + // case .float: + // if fieldInput.min != nil && fieldInput.max != nil { + // return "field_input_slider_float" + // } else { + // return "field_input_textfield_float" + // } + // + // case .percent: + // return "field_input_slider_percent" + // + // case .strings: + // return "field_input_grid_strings" case .bool: return FieldInputSwitchViewModel(input: input, valueChanged: valueChanged) -// case .image: -// #if _iOS -// return "field_button_image" -// #else -// return "field_blank" -// #endif -// -// case .images: -// #if _iOS -// return "field_input_grid_images" -// #else -// return "field_blank" -// #endif -// -// case .signature: -// #if _iOS -// return "field_input_button_signature" -// #else -// return "field_blank" -// #endif - + // case .image: + // #if _iOS + // return "field_button_image" + // #else + // return "field_blank" + // #endif + // + // case .images: + // #if _iOS + // return "field_input_grid_images" + // #else + // return "field_blank" + // #endif + // + // case .signature: + // #if _iOS + // return "field_input_button_signature" + // #else + // return "field_blank" + // #endif + default: - //assertionFailure("Not implemented") + // assertionFailure("Not implemented") break } } return nil } - + private func createOutput(output: FieldOutput) -> PlatformViewModel? { if let xib = output.field?.xib { // TODO: ... diff --git a/RoutingKit/RoutingKit/_Router/MappedRouter.swift b/RoutingKit/RoutingKit/_Router/MappedRouter.swift index 3a79878d8..f508d3762 100644 --- a/RoutingKit/RoutingKit/_Router/MappedRouter.swift +++ b/RoutingKit/RoutingKit/_Router/MappedRouter.swift @@ -22,7 +22,7 @@ public enum RoutingPresentation: Int { case drawer } -fileprivate struct PathTuple { +private struct PathTuple { let path: String let params: [String]? } @@ -123,7 +123,7 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser public var defaults: [String: String]? public var aliases: [String: String]? public var maps: [String: [String: [String: RoutingMap]]]? // ["http":["www.domain.com": ["/": "Home]]] -// public var shared: [String: RoutingMap] + // public var shared: [String: RoutingMap] public init(file: String) { super.init() let shared = JsonLoader.load(bundles: Bundle.particles, fileName: "routing_shared.json") as? [String: Any] @@ -131,12 +131,12 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser parse(dictionary: destinations, shared: shared) } } - + public init(jsonString: String) { super.init() let shared = JsonLoader.load(bundles: Bundle.particles, fileName: "routing_shared.json") as? [String: Any] if let data = jsonString.data(using: .utf8), - let destinations = JsonLoader.load(data: data) as? [String: Any] { + let destinations = JsonLoader.load(data: data) as? [String: Any] { parse(dictionary: destinations, shared: shared) } } @@ -185,7 +185,7 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser let pathTuple = parsePath(path: key) let routing = map(destination: destination, params: pathTuple.params) routing.parse(dictionary: dictionary) - assert(!maps.keys.contains { $0 == pathTuple.path }, + assert(!maps.keys.contains { $0 == pathTuple.path }, "collision on paths \(maps.keys.filter {$0 == pathTuple.path}), remove the duplicate route in routing_swiftui.json") maps[pathTuple.path] = routing } @@ -240,7 +240,7 @@ open class MappedRouter: NSObject, RouterProtocol, ParsingProtocol, CombineObser } open func didSetAppState(oldValue: AppState?) { - changeObservation(from: oldValue, to: appState, keyPath: #keyPath(AppState.background)) {[weak self] observer, obj, change, animated in + changeObservation(from: oldValue, to: appState, keyPath: #keyPath(AppState.background)) {[weak self] _, _, _, _ in self?.sendPending() } } diff --git a/Utilities/Utilities/_Utils/JsonLoader.swift b/Utilities/Utilities/_Utils/JsonLoader.swift index dc2fbbbf8..88911f895 100644 --- a/Utilities/Utilities/_Utils/JsonLoader.swift +++ b/Utilities/Utilities/_Utils/JsonLoader.swift @@ -39,7 +39,7 @@ import Foundation @objc public class func load(bundled fileName: String?) -> Any? { return load(bundle: Bundle.main, fileName: fileName) } - + @objc public class func load(data: Data) -> Any? { return try? JSONSerialization.jsonObject(with: data, options: []) } diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift index 91ceac10a..0d70373ce 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift @@ -16,11 +16,11 @@ final class dydxCarteraConfigWorker: BaseWorker { override init() { let filePath = "configs/wallets.json" -#if DEBUG + #if DEBUG let url: String? = nil -#else + #else let url = AbacusStateManager.shared.deploymentUri + "/" + filePath -#endif + #endif CachedFileLoader.shared.loadData(filePath: filePath, url: url) { walletJson in if let walletJson = walletJson { CarteraConfig.shared.registerWallets(configJsonData: walletJson) diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/dydxMarketInfoViewBuilder.swift b/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/dydxMarketInfoViewBuilder.swift index c58aeab91..826d2cd0a 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/dydxMarketInfoViewBuilder.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/MarketInfo/dydxMarketInfoViewBuilder.swift @@ -27,7 +27,7 @@ public class dydxMarketInfoViewBuilder: NSObject, ObjectBuilderProtocol { private class dydxMarketInfoViewController: HostingViewController { override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool { - if request?.path == "/trade" || request?.path == "/market", let presenter = presenter as? dydxMarketInfoViewPresenter { + if request?.path == "/trade" || request?.path == "/market", let presenter = presenter as? dydxMarketInfoViewPresenter { presenter.marketId = request?.params?["market"] as? String ?? "ETH-USD" DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { if request?.path == "/trade" { diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Help/dydxHelpViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Help/dydxHelpViewPresenter.swift index 6e4a09ca0..2ad52aae1 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Help/dydxHelpViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Help/dydxHelpViewPresenter.swift @@ -47,8 +47,8 @@ private class dydxHelpViewPresenter: HostedViewPresenter, dyd title: DataLocalizer.localize(path: "APP.HELP_MODAL.LIVE_CHAT"), subtitle: DataLocalizer.localize(path: "APP.HELP_MODAL.LIVE_CHAT_DESCRIPTION"), onTapAction: { [weak self] in - self?.handleLink(link: help) - })) + self?.handleLink(link: help) + })) } if let community = AbacusStateManager.shared.environment?.links?.community { @@ -56,8 +56,8 @@ private class dydxHelpViewPresenter: HostedViewPresenter, dyd title: DataLocalizer.localize(path: "APP.HELP_MODAL.JOIN_DISCORD"), subtitle: DataLocalizer.localize(path: "APP.HELP_MODAL.JOIN_DISCORD_DESCRIPTION"), onTapAction: { [weak self] in - self?.handleLink(link: community) - })) + self?.handleLink(link: community) + })) } if let feedback = AbacusStateManager.shared.environment?.links?.feedback { @@ -65,16 +65,16 @@ private class dydxHelpViewPresenter: HostedViewPresenter, dyd title: DataLocalizer.localize(path: "APP.HELP_MODAL.PROVIDE_FEEDBACK"), subtitle: DataLocalizer.localize(path: "APP.HELP_MODAL.PROVIDE_FEEDBACK_DESCRIPTION"), onTapAction: { [weak self] in - self?.handleLink(link: feedback) - })) + self?.handleLink(link: feedback) + })) } if let documentation = AbacusStateManager.shared.environment?.links?.documentation { items.append(dydxHelpViewModel.Item(icon: "help_api", title: DataLocalizer.localize(path: "APP.HEADER.API_DOCUMENTATION"), subtitle: DataLocalizer.localize(path: "APP.HELP_MODAL.API_DOCUMENTATION_DESCRIPTION"), onTapAction: { [weak self] in - self?.handleLink(link: documentation) - })) + self?.handleLink(link: documentation) + })) } viewModel?.items = items diff --git a/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift b/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift index 9bc0a63cd..503d720f1 100644 --- a/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift +++ b/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift @@ -38,37 +38,37 @@ public final class AbacusStateManager: NSObject { public lazy var state: AbacusState = { let perpetualStatePublisher = $_perpetualState - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let alertsPublisher = $_alerts - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let environmentPublisher = $_environment - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let apiStatePublisher = $_apiState - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let errorsStatePublisher = $_errors - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let lastOrderPublisher = $_lastOrder - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let walletStatePublisher = $_walletState - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .receive(on: RunLoop.main) + .eraseToAnyPublisher() let transferStatePublisher = transferStateManager.$state - .compactMap { $0 } - .receive(on: RunLoop.main) - .eraseToAnyPublisher() + .compactMap { $0 } + .receive(on: RunLoop.main) + .eraseToAnyPublisher() return AbacusState(walletStatePublisher: walletStatePublisher, perpetualStatePublisher: perpetualStatePublisher, environmentPublisher: environmentPublisher, @@ -160,7 +160,7 @@ public final class AbacusStateManager: NSObject { _ = foregroundToken _ = backgroundToken -// Abacus.ProtocolNativeImpFactory.companion.setStateNotification(stateNotification: self) + // Abacus.ProtocolNativeImpFactory.companion.setStateNotification(stateNotification: self) } private func start() { @@ -275,23 +275,23 @@ public final class AbacusStateManager: NSObject { /// - callback: returns tuples of addres-restriction pairs public func screen(addresses: [String], callback: @escaping ([(address: String, restriction: Restriction)]) -> Void) { let group = DispatchGroup() - var results: [(String, Restriction)] = [] - let lock = DispatchQueue(label: "com.yourapp.resultsLock.\(UUID().uuidString)") // to synchronize results array + var results: [(String, Restriction)] = [] + let lock = DispatchQueue(label: "com.yourapp.resultsLock.\(UUID().uuidString)") // to synchronize results array - for address in addresses { - group.enter() + for address in addresses { + group.enter() - screen(address: address) { restriction in - lock.async { - results.append((address, restriction)) - group.leave() - } + screen(address: address) { restriction in + lock.async { + results.append((address, restriction)) + group.leave() } } + } - group.notify(queue: .main) { - callback(results) - } + group.notify(queue: .main) { + callback(results) + } } public func faucet(amount: Int32) { @@ -312,9 +312,9 @@ public final class AbacusStateManager: NSObject { private func initializeCurrentEnvironment() { if currentEnvironment == nil, let stored = SettingsStore.shared?.value(forKey: Self.storeKey) as? String, - availableEnvironments.contains(where: { selection in - selection.type == stored - }) { + availableEnvironments.contains(where: { selection in + selection.type == stored + }) { currentEnvironment = stored } else { currentEnvironment = asyncStateManager.environment?.id diff --git a/dydxV4/dydxV4/AppDelegate.swift b/dydxV4/dydxV4/AppDelegate.swift index ee357d7d8..7f2b0dbeb 100644 --- a/dydxV4/dydxV4/AppDelegate.swift +++ b/dydxV4/dydxV4/AppDelegate.swift @@ -23,9 +23,9 @@ import dydxFormatter import dydxPresenters #if _iOS - import FirebaseStaticInjections - import Foundation - import UIKit +import FirebaseStaticInjections +import Foundation +import UIKit #endif public class dydxAppInjection: ParticlesPlatformAppInjection { @@ -39,7 +39,7 @@ public class dydxAppInjection: ParticlesPlatformAppInjection { class AppDelegate: CommonAppDelegate { private var subscriptions = Set() private let workers = dydxGlobalWorkers() - + override public init() { super.init() LocalAuthenticator.shared = dydxBiometricsLocalAuthenticator() @@ -85,7 +85,7 @@ class AppDelegate: CommonAppDelegate { override public func routeToStart(completion: @escaping () -> Void) { DataLocalizer.shared = dydxAbacusDataLocalizer(keyValueStore: SettingsStore.shared) workers.start() - + let localCompletion = { [weak self] in // This gets called after passing the security/login screen if dydxBoolFeatureFlag.full_story.isEnabled { @@ -116,11 +116,11 @@ class AppDelegate: CommonAppDelegate { } .store(in: &self.subscriptions) -// _ = dydxAppUpdateInteractor.shared -// -// if dydxBoolFeatureFlag.push_notification.isEnabled { -// _ = dydxNotificationConfigsInteractor.shared -// } + // _ = dydxAppUpdateInteractor.shared + // + // if dydxBoolFeatureFlag.push_notification.isEnabled { + // _ = dydxNotificationConfigsInteractor.shared + // } } } @@ -137,13 +137,13 @@ class AppDelegate: CommonAppDelegate { override func router() -> RouterProtocol? { let routingFile = "routing_swiftui.json" - + if let scheme = AbacusStateManager.shared.appSetting?.scheme, let file = Bundle.dydxPresenters.path(forResource: routingFile, ofType: ""), let jsonString = try? String(contentsOfFile: file).replacingOccurrences(of: "{APP_SCHEME}", with: scheme) { let router = MappedUIKitAppRouter(jsonString: jsonString) router.appState = AppState.shared - //sets up web app routing path + // sets up web app routing path if let url = URL(string: AbacusStateManager.shared.deploymentUri), let host = url.host { router.aliases?[host] = router.defaults?["host"] @@ -165,7 +165,7 @@ class AppDelegate: CommonAppDelegate { Tracking.shared?.view("/notification/deeplink/failure", data: data) } } - + /// Prioritized CoinbaseWalletSDK handling of the deeplink /// - Parameter url: the deeplink url to handle /// - Returns: true if the CoinbaseWalletSDK handled the url diff --git a/scripts/pre-commit b/scripts/pre-commit index 39536d0a4..7348ef047 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -7,7 +7,7 @@ exec 1>&2 git stash -q --keep-index # Run SwiftLint only on staged files -git diff --cached --name-only --diff-filter=ACM | grep "\.swift$" | while read file; do +git diff --cached --name-only --diff-filter=ACM | grep "\.swift$" | grep --exclude="dydx/Pods" | while read file; do swiftlint --fix --format "$file" 2>/dev/null done