diff --git a/UnstoppableWallet/UnstoppableWallet/Models/FeePriceScale.swift b/UnstoppableWallet/UnstoppableWallet/Models/FeePriceScale.swift index 15613092fd..dc5d97007c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/FeePriceScale.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/FeePriceScale.swift @@ -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 { diff --git a/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift b/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift index 6dd24cbbf3..c911494ff9 100644 --- a/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift +++ b/UnstoppableWallet/UnstoppableWallet/Models/TransactionValue.swift @@ -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: diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Coin/CoinChartFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Coin/CoinChartFactory.swift index 5478b15e30..10b36c3487 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Coin/CoinChartFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Coin/CoinChartFactory.swift @@ -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: " ")) @@ -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: @@ -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: " ")) diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift b/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift index 96b9f27247..8f9fc89e22 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/TransactionInfo/TransactionInfoViewItemFactory.swift @@ -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 @@ -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 diff --git a/UnstoppableWallet/UnstoppableWallet/UserInterface/CellComponent.swift b/UnstoppableWallet/UnstoppableWallet/UserInterface/CellComponent.swift index 037c802aba..a237dbaf8e 100644 --- a/UnstoppableWallet/UnstoppableWallet/UserInterface/CellComponent.swift +++ b/UnstoppableWallet/UnstoppableWallet/UserInterface/CellComponent.swift @@ -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 } } diff --git a/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift b/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift index 1e33f0abe7..161db8ee16 100644 --- a/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift +++ b/UnstoppableWallet/UnstoppableWallet/UserInterface/ValueFormatter.swift @@ -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 { @@ -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? {