Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor last showSign values #5914

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum FeePriceScale {
}

func description(value: Float, showSymbol: Bool = true) -> String {
ValueFormatter.instance.formatFull(value: Decimal(Double(value)), decimalCount: 9, symbol: showSymbol ? unit : nil, showSign: false) ?? value.description
ValueFormatter.instance.formatFull(value: Decimal(Double(value)), decimalCount: 9, symbol: showSymbol ? unit : nil, signType: .never) ?? value.description
}

func wrap(value: Int, step: Int) -> Float {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ enum TransactionValue {
}
}

func formattedFull(showSign: Bool = false) -> String? {
func formattedFull(signType: ValueFormatter.SignType = .never) -> String? {
switch self {
case let .coinValue(token, value):
return ValueFormatter.instance.formatFull(value: value, decimalCount: token.decimals, symbol: token.coin.code, showSign: showSign)
return ValueFormatter.instance.formatFull(value: value, decimalCount: token.decimals, symbol: token.coin.code, signType: signType)
case let .tokenValue(_, tokenCode, tokenDecimals, value):
return ValueFormatter.instance.formatFull(value: value, decimalCount: tokenDecimals, symbol: tokenCode, showSign: showSign)
return ValueFormatter.instance.formatFull(value: value, decimalCount: tokenDecimals, symbol: tokenCode, signType: signType)
case let .nftValue(_, value, _, tokenSymbol):
return "\(value.sign == .plus ? "+" : "")\(value) \(tokenSymbol ?? "NFT")"
case .rawValue:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CoinChartFactory {
paragraphStyle.alignment = NSTextAlignment.right

for (index, pair) in maPairs.enumerated() {
let formatted = ValueFormatter.instance.formatFull(value: pair.0, decimalCount: 8, showSign: pair.0 < 0)
let formatted = ValueFormatter.instance.formatFull(value: pair.0, decimalCount: 8, signType: pair.0 < 0 ? .always : .never)
topLineString.append(NSAttributedString(string: formatted ?? "", attributes: [.foregroundColor: pair.1.withAlphaComponent(1), .paragraphStyle: paragraphStyle]))
if index < maPairs.count - 1 {
topLineString.append(NSAttributedString(string: " "))
Expand All @@ -137,7 +137,7 @@ class CoinChartFactory {
case let rsi as RsiIndicator:
let value = chartItem.indicators[rsi.json]
let formatted = value.flatMap {
ValueFormatter.instance.formatFull(value: $0, decimalCount: 2, showSign: $0 < 0)
ValueFormatter.instance.formatFull(value: $0, decimalCount: 2, signType: $0 < 0 ? .always : .never)
}
bottomLineString.append(NSAttributedString(string: formatted ?? "", attributes: [.foregroundColor: rsi.configuration.color.value.withAlphaComponent(1), .paragraphStyle: paragraphStyle]))
case let macd as MacdIndicator:
Expand All @@ -157,7 +157,7 @@ class CoinChartFactory {
pairs.append((macdValue, macd.configuration.longColor.value))
}
for (index, pair) in pairs.enumerated() {
let formatted = ValueFormatter.instance.formatFull(value: pair.0, decimalCount: 8, showSign: pair.0 < 0)
let formatted = ValueFormatter.instance.formatFull(value: pair.0, decimalCount: 8, signType: pair.0 < 0 ? .always : .never)
bottomLineString.append(NSAttributedString(string: formatted ?? "", attributes: [.foregroundColor: pair.1.withAlphaComponent(1), .paragraphStyle: paragraphStyle]))
if index < pairs.count - 1 {
bottomLineString.append(NSAttributedString(string: " "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TransactionInfoViewItemFactory {
subtitle: subtitle,
iconUrl: iconUrl,
iconPlaceholderImageName: iconPlaceholderImageName,
coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(showSign: type.showSign) ?? "n/a".localized,
coinAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(signType: type.signType) ?? "n/a".localized,
currencyAmount: balanceHidden ? BalanceHiddenManager.placeholder : currencyValue.flatMap { ValueFormatter.instance.formatFull(currencyValue: $0) },
type: type,
coinUid: transactionValue.coin?.uid
Expand All @@ -56,7 +56,7 @@ class TransactionInfoViewItemFactory {
.nftAmount(
iconUrl: metadata?.previewImageUrl,
iconPlaceholderImageName: "placeholder_nft_32",
nftAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(showSign: type.showSign) ?? "n/a".localized,
nftAmount: balanceHidden ? BalanceHiddenManager.placeholder : transactionValue.formattedFull(signType: type.signType) ?? "n/a".localized,
type: type,
providerCollectionUid: metadata?.providerCollectionUid,
nftUid: metadata?.nftUid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ enum AmountType {
case neutral
case secondary

var showSign: Bool {
var signType: ValueFormatter.SignType {
switch self {
case .incoming, .outgoing, .secondary: return true
case .neutral: return false
case .incoming, .outgoing, .secondary: return .always
case .neutral: return .never
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ extension ValueFormatter {
return decorated(string: string, suffix: suffix, symbol: symbol, signType: signType, signValue: value, tooSmall: tooSmall)
}

func formatFull(value: Decimal, decimalCount: Int, symbol: String? = nil, showSign: Bool = false) -> String? {
func formatFull(value: Decimal, decimalCount: Int, symbol: String? = nil, signType: SignType = .never) -> String? {
let (transformedValue, digits) = transformedFull(value: value, maxDigits: decimalCount, minDigits: min(decimalCount, 4))

let string: String? = rawFormatterQueue.sync {
Expand All @@ -238,15 +238,15 @@ extension ValueFormatter {
return nil
}

return decorated(string: string, symbol: symbol, signValue: value)
return decorated(string: string, symbol: symbol, signType: signType, signValue: value)
}

func formatShort(coinValue: CoinValue, showCode: Bool = true, signType: SignType = .never) -> String? {
formatShort(value: coinValue.value, decimalCount: coinValue.decimals, symbol: showCode ? coinValue.symbol : nil, signType: signType)
}

func formatFull(coinValue: CoinValue, showCode: Bool = true, showSign: Bool = false) -> String? {
formatFull(value: coinValue.value, decimalCount: coinValue.decimals, symbol: showCode ? coinValue.symbol : nil, showSign: showSign)
func formatFull(coinValue: CoinValue, showCode: Bool = true, signType: SignType = .never) -> String? {
formatFull(value: coinValue.value, decimalCount: coinValue.decimals, symbol: showCode ? coinValue.symbol : nil, signType: signType)
}

func formatShort(currency: Currency, value: Decimal, signType: SignType = .never) -> String? {
Expand Down