Tweak Wallet tab price display #2864

pull/2868/head
Vladyslav shepitko 3 years ago
parent e4efe6a253
commit a8d4d3cc51
  1. 4
      AlphaWallet/Style/AppStyle.swift
  2. 4
      AlphaWallet/Tokens/Types/TokenObject.swift
  3. 20
      AlphaWallet/Tokens/ViewModels/EthCurrencyHelper.swift
  4. 14
      AlphaWallet/Tokens/ViewModels/EthTokenViewCellViewModel.swift
  5. 18
      AlphaWallet/Tokens/ViewModels/FungibleTokenViewCellViewModel.swift
  6. 12
      AlphaWallet/Tokens/Views/EthTokenViewCell.swift
  7. 12
      AlphaWallet/Tokens/Views/FungibleTokenViewCell.swift

@ -257,9 +257,9 @@ enum Screen {
enum TokenCard {
enum Font {
static let title: UIFont = Fonts.regular(size: 20)
static let subtitle = Fonts.regular(size: 12)
static let subtitle = Fonts.regular(size: 15)
static let blockChainName = Fonts.semibold(size: 12)
static let valueChangeLabel = Fonts.regular(size: 12)
static let valueChangeLabel = Fonts.regular(size: 15)
static let placeholderLabel = Fonts.regular(size: 17)
static let valueChangeValue = Fonts.semibold(size: 17)
}

@ -79,6 +79,10 @@ class TokenObject: Object {
self.isDisabled = isDisabled
self.type = type
}
var optionalDecimalValue: NSDecimalNumber? {
return EtherNumberFormatter.plain.string(from: valueBigInt, decimals: decimals).optionalDecimalValue
}
var contractAddress: AlphaWallet.Address {
return AlphaWallet.Address(uncheckedAgainstNullAddress: contract)!

@ -28,6 +28,18 @@ class EthCurrencyHelper {
return ticker?.price_usd
}
func valueChanged24h(value: NSDecimalNumber?) -> Double? {
guard let fiatValue = fiatValue(value: value), let ticker = ticker else { return .none }
return fiatValue * ticker.percent_change_24h / 100
}
func fiatValue(value: NSDecimalNumber?) -> Double? {
guard let value = value, let ticker = ticker else { return .none }
return value.doubleValue * ticker.price_usd
}
private var percentageChange24h: Double? {
if let percent_change_24h = ticker?.percent_change_24h {
return percent_change_24h.rounded(to: 2)
@ -52,14 +64,6 @@ class EthCurrencyHelper {
}
}
public func valueChanged24h(currencyAmountWithoutSymbol: Double?) -> String? {
if let percentChange = percentageChange24h, let value = currencyAmountWithoutSymbol {
return NumberFormatter.usd.string(from: value * percentChange / 100)
} else {
return nil
}
}
init(ticker: CoinTicker?) {
self.ticker = ticker
}

@ -73,24 +73,24 @@ struct EthTokenViewCellViewModel {
private var valuePercentageChangeValue: String {
switch EthCurrencyHelper(ticker: ticker).change24h {
case .appreciate(let percentageChange24h):
return "(\(percentageChange24h)%)"
return "\(percentageChange24h)%"
case .depreciate(let percentageChange24h):
return "(\(percentageChange24h)%)"
return "\(percentageChange24h)%"
case .none:
return "-"
}
}
private var marketPriceValue: String {
if let value = EthCurrencyHelper(ticker: ticker).marketPrice {
return NumberFormatter.usd.string(from: value) ?? "-"
private var priceChangeUSDValue: String {
if let result = EthCurrencyHelper(ticker: ticker).valueChanged24h(value: token.optionalDecimalValue) {
return NumberFormatter.usd.string(from: result) ?? "-"
} else {
return "-"
}
}
var marketPriceAttributedString: NSAttributedString {
return NSAttributedString(string: marketPriceValue, attributes: [
var priceChangeUSDAttributedString: NSAttributedString {
return NSAttributedString(string: priceChangeUSDValue, attributes: [
.foregroundColor: Screen.TokenCard.Color.valueChangeLabel,
.font: Screen.TokenCard.Font.valueChangeLabel
])

@ -66,33 +66,31 @@ struct FungibleTokenViewCellViewModel {
private var valuePercentageChangeValue: String {
switch EthCurrencyHelper(ticker: ticker).change24h {
case .appreciate(let percentageChange24h):
return "(\(percentageChange24h)%)"
return "\(percentageChange24h)%"
case .depreciate(let percentageChange24h):
return "(\(percentageChange24h)%)"
return "\(percentageChange24h)%"
case .none:
return "-"
}
}
private var marketPriceValue: String {
if let value = EthCurrencyHelper(ticker: ticker).marketPrice {
return NumberFormatter.usd.string(from: value) ?? "-"
private var priceChangeUSDValue: String {
if let result = EthCurrencyHelper(ticker: ticker).valueChanged24h(value: token.optionalDecimalValue) {
return NumberFormatter.usd.string(from: result) ?? "-"
} else {
return "-"
}
}
var marketPriceAttributedString: NSAttributedString {
return NSAttributedString(string: marketPriceValue, attributes: [
var priceChangeUSDAttributedString: NSAttributedString {
return NSAttributedString(string: priceChangeUSDValue, attributes: [
.foregroundColor: Screen.TokenCard.Color.valueChangeLabel,
.font: Screen.TokenCard.Font.valueChangeLabel
])
}
private var fiatValue: String {
let amount = EtherNumberFormatter.plain.string(from: BigInt(token.value) ?? BigInt(), decimals: token.decimals)
if let value = amount.optionalDecimalValue, let ticker = ticker {
let fiatValue = value.doubleValue * ticker.price_usd
if let fiatValue = EthCurrencyHelper(ticker: ticker).fiatValue(value: token.optionalDecimalValue) {
return NumberFormatter.usd.string(from: fiatValue) ?? "-"
} else {
return "-"

@ -8,14 +8,14 @@ class EthTokenViewCell: UITableViewCell {
private let background = UIView()
private let titleLabel = UILabel()
private let apprecation24hoursLabel = UILabel()
private let marketPriceLabel = UILabel()
private let priceChangeLabel = UILabel()
private let fiatValueLabel = UILabel()
private let cryptoValueLabel = UILabel()
private var viewsWithContent: [UIView] {
[titleLabel, apprecation24hoursLabel, marketPriceLabel]
[titleLabel, apprecation24hoursLabel, priceChangeLabel]
}
private lazy var changeValueContainer: UIView = [marketPriceLabel, apprecation24hoursLabel].asStackView(spacing: 5)
private lazy var changeValueContainer: UIView = [priceChangeLabel, apprecation24hoursLabel].asStackView(spacing: 5)
private var tokenIconImageView: TokenImageView = {
let imageView = TokenImageView()
@ -31,7 +31,7 @@ class EthTokenViewCell: UITableViewCell {
contentView.addSubview(background)
background.translatesAutoresizingMaskIntoConstraints = false
apprecation24hoursLabel.textAlignment = .center
marketPriceLabel.textAlignment = .center
priceChangeLabel.textAlignment = .center
fiatValueLabel.textAlignment = .center
fiatValueLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
fiatValueLabel.setContentHuggingPriority(.required, for: .horizontal)
@ -73,7 +73,7 @@ class EthTokenViewCell: UITableViewCell {
apprecation24hoursLabel.attributedText = viewModel.apprecation24hoursAttributedString
apprecation24hoursLabel.backgroundColor = viewModel.apprecation24hoursBackgroundColor
marketPriceLabel.attributedText = viewModel.marketPriceAttributedString
priceChangeLabel.attributedText = viewModel.priceChangeUSDAttributedString
fiatValueLabel.attributedText = viewModel.fiatValueAttributedString
@ -89,6 +89,6 @@ class EthTokenViewCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
marketPriceLabel.layer.cornerRadius = 2.0
priceChangeLabel.layer.cornerRadius = 2.0
}
}

@ -8,14 +8,14 @@ class FungibleTokenViewCell: UITableViewCell {
private let background = UIView()
private let titleLabel = UILabel()
private let apprecation24hoursLabel = UILabel()
private let marketPriceLabel = UILabel()
private let priceChangeLabel = UILabel()
private let fiatValueLabel = UILabel()
private let cryptoValueLabel = UILabel()
private var viewsWithContent: [UIView] {
[titleLabel, apprecation24hoursLabel, marketPriceLabel]
[titleLabel, apprecation24hoursLabel, priceChangeLabel]
}
private lazy var changeValueContainer: UIView = [marketPriceLabel, apprecation24hoursLabel].asStackView(spacing: 5)
private lazy var changeValueContainer: UIView = [priceChangeLabel, apprecation24hoursLabel].asStackView(spacing: 5)
private var tokenIconImageView: TokenImageView = {
let imageView = TokenImageView()
@ -31,7 +31,7 @@ class FungibleTokenViewCell: UITableViewCell {
contentView.addSubview(background)
background.translatesAutoresizingMaskIntoConstraints = false
apprecation24hoursLabel.textAlignment = .center
marketPriceLabel.textAlignment = .center
priceChangeLabel.textAlignment = .center
fiatValueLabel.textAlignment = .center
fiatValueLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
fiatValueLabel.setContentHuggingPriority(.required, for: .horizontal)
@ -73,7 +73,7 @@ class FungibleTokenViewCell: UITableViewCell {
apprecation24hoursLabel.attributedText = viewModel.apprecation24hoursAttributedString
apprecation24hoursLabel.backgroundColor = viewModel.apprecation24hoursBackgroundColor
marketPriceLabel.attributedText = viewModel.marketPriceAttributedString
priceChangeLabel.attributedText = viewModel.priceChangeUSDAttributedString
fiatValueLabel.attributedText = viewModel.fiatValueAttributedString
@ -89,6 +89,6 @@ class FungibleTokenViewCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
marketPriceLabel.layer.cornerRadius = 2.0
priceChangeLabel.layer.cornerRadius = 2.0
}
}

Loading…
Cancel
Save