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

Fix negative values on ETF chart. #5912

Merged
merged 1 commit into from
Jun 12, 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 @@ -858,7 +858,7 @@ enum ZCashAdapterState: Equatable {
case let .downloadingSapling(progress):
return .customSyncing(main: "balance.downloading_sapling".localized(progress), secondary: nil, progress: progress)
case let .downloadingBlocks(progress, _):
let percentValue = ValueFormatter.instance.format(percentValue: Decimal(Double(progress * 100)), showSign: false)
let percentValue = ValueFormatter.instance.format(percentValue: Decimal(Double(progress * 100)), signType: .never)
return .customSyncing(main: "balance.downloading_blocks".localized, secondary: percentValue, progress: Int(progress * 100))
case let .notSynced(error): return .notSynced(error: error)
}
Expand All @@ -872,7 +872,7 @@ enum ZCashAdapterState: Equatable {
case let .syncing(progress, lastDate): return "Syncing: progress = \(progress?.description ?? "N/A"), lastBlockDate: \(lastDate?.description ?? "N/A")"
case let .downloadingSapling(progress): return "downloadingSapling: progress = \(progress)"
case let .downloadingBlocks(progress, _):
let percentValue = ValueFormatter.instance.format(percentValue: Decimal(Double(progress * 100)), showSign: false)
let percentValue = ValueFormatter.instance.format(percentValue: Decimal(Double(progress * 100)), signType: .never)
return "Downloading Blocks: \(percentValue?.description ?? "N/A") : \(Int(progress * 100))"
case let .notSynced(error): return "Not synced \(error.localizedDescription)"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ enum TransactionValue {
}
}

func formattedShort(showSign: Bool = false) -> String? {
func formattedShort(signType: ValueFormatter.SignType = .never) -> String? {
switch self {
case let .coinValue(token, value):
return ValueFormatter.instance.formatShort(value: value, decimalCount: token.decimals, symbol: token.coin.code, showSign: showSign)
return ValueFormatter.instance.formatShort(value: value, decimalCount: token.decimals, symbol: token.coin.code, signType: signType)
case let .tokenValue(_, tokenCode, tokenDecimals, value):
return ValueFormatter.instance.formatShort(value: value, decimalCount: tokenDecimals, symbol: tokenCode, showSign: showSign)
return ValueFormatter.instance.formatShort(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 @@ -87,7 +87,7 @@ extension CoinIndicatorViewItemFactory {
rsiLine = "70%"
}

let rsiValue = technicalAdvice.rsi.flatMap { ValueFormatter.instance.format(percentValue: $0, showSign: false) }
let rsiValue = technicalAdvice.rsi.flatMap { ValueFormatter.instance.format(percentValue: $0, signType: .never) }
let signalTimeString = technicalAdvice.signalTimestamp.flatMap {
let date = DateHelper.instance.formatShortDateOnly(date: Date(timeIntervalSince1970: $0))
return "technical_advice.over.indicators.signal_date".localized(date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CoinChartFactory {

let chartData = ChartData(items: items, startWindow: firstPoint.timestamp, endWindow: lastPoint.timestamp)
let diff = (lastPoint.value - firstPoint.value) / firstPoint.value * 100
let diffString = ValueFormatter.instance.format(percentValue: diff, showSign: true)
let diffString = ValueFormatter.instance.format(percentValue: diff, signType: .always)
let valueDiff = diffString.map { ValueDiff(value: $0, trend: diff.isSignMinus ? .down : .up) }
return ChartModule.ViewItem(
value: ValueFormatter.instance.formatFull(currencyValue: CurrencyValue(currency: currency, value: item.rate)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct MarketGlobalView: View {

diffView(
title: "market.global.btc_dominance".localized,
amount: marketGlobal?.btcDominance.flatMap { ValueFormatter.instance.format(percentValue: $0, showSign: false) },
amount: marketGlobal?.btcDominance.flatMap { ValueFormatter.instance.format(percentValue: $0, signType: .never) },
diff: marketGlobal?.btcDominanceChange.map { .percent(value: $0) },
redacted: redacted
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MetricChartFactory {

switch valueType {
case .percent:
return ValueFormatter.instance.format(percentValue: value, showSign: false)
return ValueFormatter.instance.format(percentValue: value, signType: .never)
case let .currencyValue(currency):
return ValueFormatter.instance.formatFull(currency: currency, value: value)
case .counter:
Expand All @@ -40,9 +40,9 @@ class MetricChartFactory {
return [valueString, coin.code].compactMap { $0 }.joined(separator: " ")
case let .compactCurrencyValue(currency):
if exactlyValue {
return ValueFormatter.instance.formatFull(currency: currency, value: value, showSign: true)
return ValueFormatter.instance.formatFull(currency: currency, value: value, signType: .always)
} else {
return ValueFormatter.instance.formatShort(currency: currency, value: value)
return ValueFormatter.instance.formatShort(currency: currency, value: value, signType: .auto)
}
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ extension MetricChartFactory {
let diff = (lastItem.value - firstItem.value) / firstItem.value * 100
chartTrend = diff.isSignMinus ? .down : .up

let valueString = ValueFormatter.instance.format(percentValue: diff, showSign: true)
let valueString = ValueFormatter.instance.format(percentValue: diff, signType: .always)
valueDiff = valueString.map { ValueDiff(value: $0, trend: chartTrend) }

if let hardcodedRightMode {
Expand All @@ -98,7 +98,7 @@ extension MetricChartFactory {
value = Self.format(value: last, valueType: valueType)
}

let valueString = ValueFormatter.instance.formatShort(currency: currencyManager.baseCurrency, value: lastItem.value)
let valueString = ValueFormatter.instance.formatShort(currency: currencyManager.baseCurrency, value: lastItem.value, signType: .always)
valueDiff = valueString.map { ValueDiff(value: $0, trend: lastItem.value.isSignMinus ? .down : .up) }
chartTrend = .neutral

Expand Down Expand Up @@ -187,7 +187,7 @@ extension MetricChartFactory {
// if etf chart
if let totalInflow = chartItem.indicators[ChartIndicator.LineConfiguration.totalInflowId] {
let formattedValue = ValueFormatter.instance.formatShort(currency: currencyManager.baseCurrency, value: totalInflow)
let diffString = ValueFormatter.instance.formatShort(currency: currencyManager.baseCurrency, value: value)
let diffString = ValueFormatter.instance.formatShort(currency: currencyManager.baseCurrency, value: value, signType: .always)
let diff = diffString.map { ValueDiff(value: $0, trend: value.isSignMinus ? .down : .up) }

return ChartModule.SelectedPointViewItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class NftCollectionOverviewViewModel {
contracts: collection.contracts.map { contractViewItem(contract: $0) },
links: linkViewItems(collection: collection),
statsViewItems: statViewItem(collection: collection),
royalty: collection.royalty.flatMap { ValueFormatter.instance.format(percentValue: $0, showSign: false) },
royalty: collection.royalty.flatMap { ValueFormatter.instance.format(percentValue: $0, signType: .never) },
inceptionDate: collection.inceptionDate.map { DateFormatter.cachedFormatter(format: "MMMM d, yyyy").string(from: $0) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class TransactionsViewItemFactory {
contactLabelService.contactData(for: address, blockchainType: blockchainType).name ?? evmLabelManager.mapped(address: address)
}

private func coinString(from transactionValue: TransactionValue, showSign: Bool = true) -> String {
guard let value = transactionValue.formattedShort(showSign: showSign) else {
private func coinString(from transactionValue: TransactionValue, signType: ValueFormatter.SignType = .always) -> String {
guard let value = transactionValue.formattedShort(signType: signType) else {
return "n/a".localized
}

Expand Down Expand Up @@ -192,7 +192,7 @@ class TransactionsViewItemFactory {
title = "transactions.send".localized
subTitle = "transactions.to".localized(mapped(address: record.to, blockchainType: item.record.source.blockchainType))

primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, showSign: !record.sentToSelf), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: record.sentToSelf ? .never : .always), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))
secondaryValue = singleValueSecondaryValue(value: record.value, currencyValue: item.currencyValue, nftMetadata: item.nftMetadata)

sentToSelf = record.sentToSelf
Expand Down Expand Up @@ -229,7 +229,7 @@ class TransactionsViewItemFactory {
primaryValue = BaseTransactionsViewModel.Value(text: "∞ \(record.value.coinCode)", type: .neutral)
secondaryValue = BaseTransactionsViewModel.Value(text: "transactions.value.unlimited".localized, type: .secondary)
} else {
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, showSign: false), type: .neutral)
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: .never), type: .neutral)

if let currencyValue = item.currencyValue {
secondaryValue = BaseTransactionsViewModel.Value(text: currencyString(from: currencyValue), type: .secondary)
Expand Down Expand Up @@ -290,7 +290,7 @@ class TransactionsViewItemFactory {
title = "transactions.send".localized
subTitle = record.to.flatMap { "transactions.to".localized(mapped(address: $0, blockchainType: item.record.source.blockchainType)) } ?? "---"

primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, showSign: !record.sentToSelf), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: record.sentToSelf ? .never : .always), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))

if let currencyValue = item.currencyValue {
secondaryValue = BaseTransactionsViewModel.Value(text: currencyString(from: currencyValue), type: .secondary)
Expand All @@ -317,7 +317,7 @@ class TransactionsViewItemFactory {
title = "transactions.send".localized
subTitle = "transactions.to".localized(mapped(address: record.to, blockchainType: item.record.source.blockchainType))

primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, showSign: !record.sentToSelf), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: record.sentToSelf ? .never : .always), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))

if let currencyValue = item.currencyValue {
secondaryValue = BaseTransactionsViewModel.Value(text: currencyString(from: currencyValue), type: .secondary)
Expand All @@ -341,7 +341,7 @@ class TransactionsViewItemFactory {
title = "transactions.send".localized
subTitle = "transactions.to".localized(mapped(address: record.to, blockchainType: item.record.source.blockchainType))

primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, showSign: !record.sentToSelf), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: record.sentToSelf ? .never : .always), type: type(value: record.value, condition: record.sentToSelf, .neutral, .outgoing))
secondaryValue = singleValueSecondaryValue(value: record.value, currencyValue: item.currencyValue, nftMetadata: item.nftMetadata)

sentToSelf = record.sentToSelf
Expand All @@ -355,7 +355,7 @@ class TransactionsViewItemFactory {
primaryValue = BaseTransactionsViewModel.Value(text: "∞ \(record.value.coinCode)", type: .neutral)
secondaryValue = BaseTransactionsViewModel.Value(text: "transactions.value.unlimited".localized, type: .secondary)
} else {
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, showSign: false), type: .neutral)
primaryValue = BaseTransactionsViewModel.Value(text: coinString(from: record.value, signType: .never), type: .neutral)

if let currencyValue = item.currencyValue {
secondaryValue = BaseTransactionsViewModel.Value(text: currencyString(from: currencyValue), type: .secondary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class WalletViewItemFactory {
return nil
}

guard let formattedValue = ValueFormatter.instance.format(percentValue: value, showSign: true) else {
guard let formattedValue = ValueFormatter.instance.format(percentValue: value, signType: .always) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct DiffText: View {

switch diff {
case let .percent(value): return ValueFormatter.instance.format(percentValue: value).map { ($0, value) }
case let .change(value, currency): return ValueFormatter.instance.formatShort(currency: currency, value: value, showSign: true).map { ($0, value) }
case let .change(value, currency): return ValueFormatter.instance.formatShort(currency: currency, value: value, signType: .always).map { ($0, value) }
}
}
}
Expand Down
Loading