From 8dcb53e084e3b69ec785a7f6d6525f1e08e790e6 Mon Sep 17 00:00:00 2001 From: mike-dydx <149746839+mike-dydx@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:24:36 -0500 Subject: [PATCH] TRCL-2841 : Trading Network current value not shown on Settings (#19) * attempt to parse a trading network value * look up env in available environments instead * clean up --- .../SettingsLandingViewPresenter.swift | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/SettingsLandingViewPresenter.swift b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/SettingsLandingViewPresenter.swift index a1d07f495..7bdb7e496 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/SettingsLandingViewPresenter.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/Profile/Settings/SettingsLandingViewPresenter.swift @@ -13,6 +13,7 @@ import ParticlesKit import PlatformUI import PlatformUIJedio import JedioKit +import dydxStateManager class SettingsLandingViewPresenter: SettingsViewPresenter { @@ -31,13 +32,13 @@ class SettingsLandingViewPresenter: SettingsViewPresenter { } } - var localizerKeyLookup: [String: String] { + var localizerKeyLookup: [String: String]? { switch self { // extracting the localizer key lookup from the definition file reduces sources of truth for the key value mapping case .language: return SettingsLandingViewPresenter.extractLocalizerKeyLookup(fromDefinitionFile: "settings_language.json") case .theme: return SettingsLandingViewPresenter.extractLocalizerKeyLookup(fromDefinitionFile: "settings_theme.json") // this one is hardcoded for now, there is no field input definition file for environment selection yet - case .env: return envLocalizerKeyLookup + case .env: return nil case .colorPreference: return SettingsLandingViewPresenter.extractLocalizerKeyLookup(fromDefinitionFile: "settings_direction_color_preference.json") } } @@ -58,21 +59,19 @@ class SettingsLandingViewPresenter: SettingsViewPresenter { return dictionary } - private static let envLocalizerKeyLookup: [String: String] = [ - "dydxprotocol-testnet": "APP.HEADER.TESTNET", - "1": "APP.HEADER.MAINNET" - ] - override func createOutputItem(output: FieldOutput) -> FieldOutputTextViewModel { let textViewModel = super.createOutputItem(output: output) guard let link = output.link, let deepLink = DeepLink(rawValue: link), - let localizerKey = SettingsStore.shared?.value(forKey: deepLink.settingsStoreKey) as? String, - let displayTextKey = deepLink.localizerKeyLookup[localizerKey] + let localizerKey = SettingsStore.shared?.value(forKey: deepLink.settingsStoreKey) as? String else { return textViewModel } - textViewModel.text = DataLocalizer.shared?.localize(path: displayTextKey, params: nil) + if let displayTextKey = deepLink.localizerKeyLookup?[localizerKey] { + textViewModel.text = DataLocalizer.shared?.localize(path: displayTextKey, params: nil) + } else if let env = AbacusStateManager.shared.availableEnvironments.first(where: { $0.type == localizerKey }) { + textViewModel.text = env.localizedString + } return textViewModel }