Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Apr 22, 2024
1 parent 76f5e9b commit 1d0a1d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
40 changes: 17 additions & 23 deletions PlatformUI/PlatformUI/Components/Input/PlatformInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions dydx/dydxFormatter/dydxFormatter/dydxFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1d0a1d9

Please sign in to comment.