From 0c667e20af382499f27ef20b0645d3f19bfd24d6 Mon Sep 17 00:00:00 2001 From: mike-dydx Date: Thu, 11 Apr 2024 21:32:28 -0400 Subject: [PATCH] clean up --- .../Components/Input/PlatformInput.swift | 40 ++++++++----------- .../dydxFormatter/dydxFormatter.swift | 5 --- .../Workers/dydxAlertsWorker.swift | 8 ++-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/PlatformUI/PlatformUI/Components/Input/PlatformInput.swift b/PlatformUI/PlatformUI/Components/Input/PlatformInput.swift index 0c1903241..72624e27d 100644 --- a/PlatformUI/PlatformUI/Components/Input/PlatformInput.swift +++ b/PlatformUI/PlatformUI/Components/Input/PlatformInput.swift @@ -229,32 +229,26 @@ open class PlatformTextInputViewModel: PlatformValueInputViewModel { } @Published private var input: String = "" - - /// use this to bind input to another source which cannot be focused (such as a slider) - public lazy var inputBindingIgnoringFocus = Binding( - get: { self.input }, - set: { self.updateInput($0, shouldConsiderFocus: false) } - ) - + public lazy var inputBinding = Binding( - get: { self.input }, - set: { self.updateInput($0, shouldConsiderFocus: true) } - ) - - private func updateInput(_ newInput: String, shouldConsiderFocus: Bool) { - if self.focused || !shouldConsiderFocus { - let sanitized = self.inputType.sanitize(newInput) - if let sanitized { - self.input = sanitized - } else if newInput.isEmpty { - self.input = "" - } else { - // this is necessary to make binding work properly - self.input = self.input + get: { + return self.input + }, + set: { newInput in + if self.focused { + let sanitized = self.inputType.sanitize(newInput) + if let sanitized { + self.input = sanitized + } else if newInput.isEmpty { + self.input = "" + } else { + // this is necessary to make binding work properly + self.input = self.input + } + self.valueChanged(value: self.input) } - self.valueChanged(value: self.input) } - } + ) @Published public var placeHolder: String? private var focused: Bool = false { diff --git a/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift b/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift index f9db18b72..48ca631bc 100644 --- a/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift +++ b/dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift @@ -394,11 +394,6 @@ public final class dydxFormatter: NSObject, SingletonProtocol { raw(number: number, digits: digits, locale: Locale(identifier: "en-US")) } - public func raw(number: String?, digits: Int, locale: Locale = Locale.current) -> String? { - guard let number = number else { return nil } - return raw(number: Parser.standard.asNumber(number), digits: digits, locale: locale) - } - public func raw(number: Double?, digits: Int, locale: Locale = Locale.current) -> String? { guard let number = number else { return nil } return raw(number: NSNumber(value: number), digits: digits, locale: locale) diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxAlertsWorker.swift b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxAlertsWorker.swift index f4bb91b8c..7faa90e94 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxAlertsWorker.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxAlertsWorker.swift @@ -58,10 +58,10 @@ final class dydxAlertsWorker: BaseWorker { Router.shared?.navigate(to: RoutingRequest(path: link!), animated: true, completion: nil) }] : nil if SettingsStore.shared?.shouldDisplayInAppNotifications != false { - ErrorInfo.shared?.info(title: alert.title, - message: alert.text, - type: alert.type.infoType, - error: nil, time: nil, actions: actions) + ErrorInfo.shared?.info(title: alert.title, + message: alert.text, + type: alert.type.infoType, + error: nil, time: nil, actions: actions) } // add to alert ids set to avoid double handling handledAlertHashes.insert(alert.hashValue)