Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Jul 24, 2024
1 parent dc5d5dd commit 04aa600
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
public class dydxNumberInputFormatter: NumberFormatter {

/// if greater than 0, numbers will be rounded to nearest 10, 100, 1000, etc. If less than 0 numbers will be rounded to nearest 0.1, 0.01, .001
var fractionDigits: Int {
public var fractionDigits: Int {
get {
maximumFractionDigits
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ public class dydxSliderInputViewModel: PlatformViewModel {
@Published public var minValue: Double = 0
@Published public var maxValue: Double = 0
/// number of decimals after the decimal place to display
@Published public var precision: Int = 0
@Published public var precision: Int = 0 {
didSet {
numberFormatter.fractionDigits = precision
}
}
@Published public private(set) var valueAsString: String = ""
@Published public var value: Double? {
didSet {
valueAsString = value.map { numberFormatter.string(from: $0 as NSNumber) ?? "" } ?? ""
}
}

var numberFormatter: dydxNumberInputFormatter {
private lazy var numberFormatter: dydxNumberInputFormatter = {
dydxNumberInputFormatter(fractionDigits: precision)
}
}()

init(title: String?, accessoryTitle: String? = nil, precision: Int) {
self.title = title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ private struct NumberTextField: View {
let minValue: Double
let maxValue: Double
let precision: Int

private var numberFormatter: dydxNumberInputFormatter {
dydxNumberInputFormatter(fractionDigits: precision)
let numberFormatter: dydxNumberInputFormatter

init(actualValue: Binding<Double?>, minValue: Double, maxValue: Double, precision: Int) {
self._actualValue = actualValue
self.minValue = minValue
self.maxValue = maxValue
self.precision = precision
self.numberFormatter = dydxNumberInputFormatter(fractionDigits: precision)
}

private var keyboardType: UIKeyboardType {
Expand Down

0 comments on commit 04aa600

Please sign in to comment.