-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add slider to target leverage screen (#213)
* create slider text input view * add target leverage slider * temp * fix custom amount switch behavior and fix overwriting bug * undo changes to platforminput * fix lines to 1 for leverage buttons * temp * fix precision * add precision to slider * clean up * address PR comments --------- Co-authored-by: Mike <[email protected]>
- Loading branch information
Showing
13 changed files
with
473 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dydx/dydxFormatter/dydxFormatter/dydxNumberInputFormatter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// dydxNumberInputFormatter.swift | ||
// dydxFormatter | ||
// | ||
// Created by Michael Maguire on 7/19/24. | ||
// | ||
|
||
import Foundation | ||
|
||
/// a number formatter that also supports rounding to nearest 10/100/1000/etc | ||
/// formatter is intended for user inputs, so group separator is omitted, i.e. the "," in "1,000" | ||
public class dydxNumberInputFormatter: NumberFormatter, ObservableObject { | ||
|
||
/// 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 | ||
public var fractionDigits: Int { | ||
get { | ||
maximumFractionDigits | ||
} | ||
set { | ||
if maximumFractionDigits != newValue || minimumFractionDigits != newValue { | ||
maximumFractionDigits = newValue | ||
minimumFractionDigits = newValue | ||
objectWillChange.send() | ||
} | ||
} | ||
} | ||
|
||
/// Use this initializer | ||
/// - Parameter fractionDigits: 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 | ||
public convenience init(fractionDigits: Int = 2) { | ||
self.init() | ||
self.maximumFractionDigits = fractionDigits | ||
self.minimumFractionDigits = fractionDigits | ||
self.numberStyle = .decimal | ||
self.usesGroupingSeparator = false | ||
} | ||
|
||
public override func string(from number: NSNumber) -> String? { | ||
if maximumFractionDigits < 0 { | ||
return String(Int(number.doubleValue.round(to: maximumFractionDigits))) | ||
} else { | ||
return super.string(from: number) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.