From 4ee94a0c86b6e5357bcc47204a428033ec2657a0 Mon Sep 17 00:00:00 2001 From: John Huang Date: Fri, 10 Nov 2023 14:37:49 -0800 Subject: [PATCH] Use the Info.plist scheme for router. And updated Abacus (#14) * Use the Info.plist scheme for router. And updated Abacus * Replaces other occurrences of AbacusStateManager.shared.appSetting?.scheme * Update Cocoapods --- .../_Extensions/Bundle+UIBundle.swift | 22 +++++++++----- dydx/Podfile.lock | 2 +- dydx/Pods/Manifest.lock | 2 +- .../Workers/dydxCarteraConfigWorker.swift | 2 +- .../Profile/Debug/dydxDebugViewBuilder.swift | 2 +- .../dydxFeatureFlagsViewBuilder.swift | 2 +- .../dydxSettingsLandingViewBuilder.swift | 2 +- dydxV4/dydxV4/AppDelegate.swift | 30 +++++++++---------- 8 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Utilities/Utilities/_Extensions/Bundle+UIBundle.swift b/Utilities/Utilities/_Extensions/Bundle+UIBundle.swift index af0c8eab..bf3711b2 100644 --- a/Utilities/Utilities/_Extensions/Bundle+UIBundle.swift +++ b/Utilities/Utilities/_Extensions/Bundle+UIBundle.swift @@ -25,7 +25,7 @@ public extension Bundle { var bundles = [Bundle]() bundles.append(Bundle.main) if let json = JsonLoader.load(bundle: Bundle.main, fileName: "ui.json") as? [String] { - let names = json.map({ (name) -> String in + let names = json.map({ name -> String in name.lowercased() }) let set = Set(names) @@ -52,9 +52,9 @@ public extension Bundle { } return bundles }() - - @objc static func load(xib name: String, owner: Any?, options: [UINib.OptionsKey : Any]? = nil) -> [Any]? { - var result: [Any]? = nil + + @objc static func load(xib name: String, owner: Any?, options: [UINib.OptionsKey: Any]? = nil) -> [Any]? { + var result: [Any]? for bundle in particles { result = bundle.safeLoad(xib: name, owner: owner, options: options) } @@ -68,6 +68,14 @@ public extension Bundle { } return nil } + + var scheme: String? { + return parser.asStrings( + parser.asDictionary( + parser.asArray(Bundle.main.infoDictionary?["CFBundleURLTypes"])?.first + )?["CFBundleURLSchemes"] + )?.first + } } public extension Bundle { @@ -76,7 +84,7 @@ public extension Bundle { object(forInfoDictionaryKey: "CFBundleName") as? String } - @objc func safeLoad(xib: String, owner: Any? = nil, options: [UINib.OptionsKey : Any]? = nil) -> [Any]? { + @objc func safeLoad(xib: String, owner: Any? = nil, options: [UINib.OptionsKey: Any]? = nil) -> [Any]? { let file = path(forResource: xib, ofType: "nib") if File.exists(file) { return loadNibNamed(xib, owner: owner, options: options) @@ -93,7 +101,7 @@ public extension Bundle { var build: String? { return infoDictionary?["CFBundleVersion"] as? String } - + var versionAndBuild: String? { if let version = version { if let build = build { @@ -111,7 +119,7 @@ public extension Bundle { } return nil } - + func versionCompare(otherVersion: String) -> ComparisonResult { guard let version = version else { return .orderedAscending diff --git a/dydx/Podfile.lock b/dydx/Podfile.lock index 305fd53a..2bff87be 100644 --- a/dydx/Podfile.lock +++ b/dydx/Podfile.lock @@ -435,4 +435,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a4f25d50f2991cc8e84eca8d34be23b37908132b -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.2 diff --git a/dydx/Pods/Manifest.lock b/dydx/Pods/Manifest.lock index 305fd53a..2bff87be 100644 --- a/dydx/Pods/Manifest.lock +++ b/dydx/Pods/Manifest.lock @@ -435,4 +435,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: a4f25d50f2991cc8e84eca8d34be23b37908132b -COCOAPODS: 1.13.0 +COCOAPODS: 1.14.2 diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift index 0d70373c..b6710bdb 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxCarteraConfigWorker.swift @@ -54,7 +54,7 @@ extension WalletConnectV2Config { guard let projectId = environment.walletConnection?.walletConnect?.v2?.projectId, let clientName = environment.walletConnection?.walletConnect?.client.name, let clientDescription = environment.walletConnection?.walletConnect?.client.description, - let scheme = AbacusStateManager.shared.appSetting?.scheme + let scheme = Bundle.main.scheme else { return nil } diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Debug/dydxDebugViewBuilder.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Debug/dydxDebugViewBuilder.swift index 46928387..d3496d5e 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Debug/dydxDebugViewBuilder.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Debug/dydxDebugViewBuilder.swift @@ -29,7 +29,7 @@ private class dydxDebugViewPresenter: SettingsViewPresenter { init() { super.init(definitionFile: "debug.json", keyValueStore: FeatureFlagsStore.shared, - appScheme: AbacusStateManager.shared.appSetting?.scheme) + appScheme: Bundle.main.scheme) let header = SettingHeaderViewModel() header.text = "Debug Settings" diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/FeatureFlags/dydxFeatureFlagsViewBuilder.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/FeatureFlags/dydxFeatureFlagsViewBuilder.swift index b4122f85..7c36b7cb 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/FeatureFlags/dydxFeatureFlagsViewBuilder.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/FeatureFlags/dydxFeatureFlagsViewBuilder.swift @@ -29,7 +29,7 @@ private class dydxFeatureFlagsViewPresenter: SettingsViewPresenter { init() { super.init(definitionFile: "features.json", keyValueStore: FeatureFlagsStore.shared, - appScheme: AbacusStateManager.shared.appSetting?.scheme) + appScheme: Bundle.main.scheme) let header = SettingHeaderViewModel() header.text = "Feature Flags" diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/dydxSettingsLandingViewBuilder.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/dydxSettingsLandingViewBuilder.swift index 6638a7c5..cfaf41c6 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/dydxSettingsLandingViewBuilder.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/dydxSettingsLandingViewBuilder.swift @@ -37,7 +37,7 @@ private class dydxSettingsLandingViewPresenter: SettingsLandingViewPresenter { } super.init(definitionFile: definitionFile, keyValueStore: SettingsStore.shared, - appScheme: AbacusStateManager.shared.appSetting?.scheme) + appScheme: Bundle.main.scheme) let header = SettingHeaderViewModel() header.text = DataLocalizer.localize(path: "APP.EMAIL_NOTIFICATIONS.SETTINGS") diff --git a/dydxV4/dydxV4/AppDelegate.swift b/dydxV4/dydxV4/AppDelegate.swift index 7f2b0dbe..94a3b5ed 100644 --- a/dydxV4/dydxV4/AppDelegate.swift +++ b/dydxV4/dydxV4/AppDelegate.swift @@ -6,26 +6,26 @@ // Copyright © 2018 dYdX. All rights reserved. // +import Cartera +import CoinbaseWalletSDK +import Combine +import dydxFormatter +import dydxPresenters +import dydxStateManager +import dydxViews import ParticlesKit import PlatformParticles import PlatformRouting +import PlatformUI import RoutingKit import UIAppToolkits import UIToolkits import Utilities -import CoinbaseWalletSDK -import PlatformUI -import dydxViews -import dydxStateManager -import Cartera -import Combine -import dydxFormatter -import dydxPresenters #if _iOS -import FirebaseStaticInjections -import Foundation -import UIKit + import FirebaseStaticInjections + import Foundation + import UIKit #endif public class dydxAppInjection: ParticlesPlatformAppInjection { @@ -138,9 +138,9 @@ 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 scheme = Bundle.main.scheme ?? "dydxv4" + if 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 @@ -155,7 +155,7 @@ class AppDelegate: CommonAppDelegate { } override func deepLinkHandled(deeplink: URL, successful: Bool) { - let data = ["url": deeplink.absoluteString] + let data = ["url": deeplink.absoluteString] if successful { if let type = deeplink.params?["notification_type"] { Tracking.shared?.view("/notification/deeplink/" + type, data: data)