Skip to content

Commit

Permalink
TRCL-2841 : Trading Network current value not shown on Settings (#19)
Browse files Browse the repository at this point in the history
* attempt to parse a trading network value

* look up env in available environments instead

* clean up
  • Loading branch information
mike-dydx committed Aug 21, 2024
1 parent ae85168 commit 66a76a0
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ParticlesKit
import PlatformUI
import PlatformUIJedio
import JedioKit
import dydxStateManager

class SettingsLandingViewPresenter: SettingsViewPresenter {

Expand All @@ -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")
}
}
Expand All @@ -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
}
Expand Down

0 comments on commit 66a76a0

Please sign in to comment.