-
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.
move convenience inits to dydxViews, clean up
- Loading branch information
Showing
5 changed files
with
50 additions
and
46 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// SignedAmountView.swift | ||
// dydxViews | ||
// | ||
// Created by Michael Maguire on 2/13/24. | ||
// | ||
|
||
import PlatformUI | ||
import dydxFormatter | ||
|
||
public extension SignedAmountViewModel { | ||
convenience init(text: String? = nil, sign: PlatformUISign = .plus, coloringOption: ColoringOption) { | ||
self.init(text: text, | ||
sign: sign, | ||
coloringOption: coloringOption, | ||
positiveTextStyleKey: ThemeSettings.positiveTextStyleKey, | ||
negativeTextStyleKey: ThemeSettings.negativeTextStyleKey) | ||
} | ||
|
||
convenience init(amount: Double?, displayType: DisplayType, coloringOption: ColoringOption, shouldDisplaySignForPositiveNumbers: Bool = false) { | ||
let formattedZero: String? | ||
let formattedText: String? | ||
let sign: PlatformUISign | ||
switch displayType { | ||
case .dollar: | ||
formattedText = dydxFormatter.shared.dollarVolume(number: amount?.magnitude, shouldDisplaySignForPositiveNumbers: shouldDisplaySignForPositiveNumbers) | ||
formattedZero = dydxFormatter.shared.dollarVolume(number: 0.0, shouldDisplaySignForPositiveNumbers: shouldDisplaySignForPositiveNumbers) | ||
case .percent: | ||
let digits = 2 | ||
formattedText = dydxFormatter.shared.percent(number: amount?.magnitude, digits: digits, shouldDisplayPlusSignForPositiveNumbers: shouldDisplaySignForPositiveNumbers) | ||
formattedZero = dydxFormatter.shared.percent(number: 0.0, digits: digits, shouldDisplayPlusSignForPositiveNumbers: shouldDisplaySignForPositiveNumbers) | ||
} | ||
// special logic for when a value like -0.001 would render as "-$0.00" instead of "$0.00" | ||
if formattedText == formattedZero { | ||
sign = .none | ||
} else if (amount ?? 0) > 0 { | ||
sign = .plus | ||
} else { | ||
sign = .minus | ||
} | ||
self.init(text: formattedText, | ||
sign: sign, | ||
coloringOption: coloringOption) | ||
} | ||
} |
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