Merge branch 'master' into fix-crash-when-resume-iphone-x

pull/209/head
James Sangalli 7 years ago committed by GitHub
commit 2c0613a986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Trust.xcodeproj/project.pbxproj
  2. 6
      Trust/Tokens/ViewControllers/TokensViewController.swift
  3. 67
      Trust/Tokens/ViewModels/EthCurrencyHelper.swift
  4. 33
      Trust/Tokens/ViewModels/EthTokenViewCellViewModel.swift
  5. 16
      Trust/Transactions/ViewModels/BalanceViewModel.swift
  6. 10
      Trust/Transfer/ViewControllers/SendViewController.swift
  7. 40
      Trust/Transfer/ViewModels/SendHeaderViewViewModel.swift

@ -349,6 +349,7 @@
5E7C7C658D619C70F1E3DE59 /* AdvancedSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C719B717E002583B1E2E9 /* AdvancedSettingsViewModel.swift */; };
5E7C7C98EAF40E8110241DBD /* TicketTokenViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C783E3ADA4CF9554A0E7D /* TicketTokenViewCell.swift */; };
5E7C7C9E89056069C8FEFA76 /* AlphaWalletSettingsSwitchRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7534FB6BF4D199643246 /* AlphaWalletSettingsSwitchRow.swift */; };
5E7C7CCC8D376C6E5C245715 /* EthCurrencyHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C73DF5FBFE756097D32B1 /* EthCurrencyHelper.swift */; };
5E7C7CDB837DCD57E0594CBA /* TicketsViewControllerTitleHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7821694C489D5114DB18 /* TicketsViewControllerTitleHeader.swift */; };
5E7C7CE5CA19183FCED8C907 /* TokensViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7EE467A7F5F2E5B1F660 /* TokensViewModel.swift */; };
5E7C7CF06533EDACC8E220B3 /* StaticHTMLViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C764B98F526271E4C2A6A /* StaticHTMLViewController.swift */; };
@ -810,6 +811,7 @@
5E7C731B6F01534683227123 /* TicketTokenViewCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketTokenViewCellViewModel.swift; sourceTree = "<group>"; };
5E7C73495E0C0A207152EC25 /* LockEnterPasscodeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LockEnterPasscodeViewController.swift; path = Trust/AlphaWalletLock/ViewControllers/LockEnterPasscodeViewController.swift; sourceTree = SOURCE_ROOT; };
5E7C73617E3A4C0B9A90A5F8 /* AmountTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AmountTextField.swift; sourceTree = "<group>"; };
5E7C73DF5FBFE756097D32B1 /* EthCurrencyHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EthCurrencyHelper.swift; sourceTree = "<group>"; };
5E7C741196D9D9C9C3EE5E30 /* LockCreatePasscodeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockCreatePasscodeViewController.swift; sourceTree = "<group>"; };
5E7C7419F47CC8B2996AA8F9 /* TransferTicketsQuantitySelectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferTicketsQuantitySelectionViewController.swift; sourceTree = "<group>"; };
5E7C74A2C738BF2412D412A7 /* TicketSellInfoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TicketSellInfoViewController.swift; sourceTree = "<group>"; };
@ -1666,6 +1668,7 @@
5E7C75CC640BAFFE0E789F44 /* WalletFilterViewModel.swift */,
5E7C74B82783A94091A43470 /* EthTokenViewCellViewModel.swift */,
5E7C7A16ABC8BD5D508AA641 /* ImportWalletHelpBubbleViewViewModel.swift */,
5E7C73DF5FBFE756097D32B1 /* EthCurrencyHelper.swift */,
);
path = ViewModels;
sourceTree = "<group>";
@ -3588,6 +3591,7 @@
5E7C76696EF7F27EC0788CDD /* GenerateTransferMagicLinkViewControllerViewModel.swift in Sources */,
5E7C75E5C64619ABFD246183 /* TransferTicketsViaWalletAddressViewController.swift in Sources */,
5E7C7EAEBB435F3909DA36FB /* TransferTicketsViaWalletAddressViewControllerViewModel.swift in Sources */,
5E7C7CCC8D376C6E5C245715 /* EthCurrencyHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -238,7 +238,8 @@ extension TokensViewController: UITableViewDelegate {
let cellViewModel = EthTokenViewCellViewModel(
token: token,
ticker: viewModel.ticker(for: token),
currencyAmount: session.balanceCoordinator.viewModel.currencyAmount
currencyAmount: session.balanceCoordinator.viewModel.currencyAmount,
currencyAmountWithoutSymbol: session.balanceCoordinator.viewModel.currencyAmountWithoutSymbol
)
return cellViewModel.cellHeight
case .token:
@ -303,7 +304,8 @@ extension TokensViewController: UITableViewDataSource {
viewModel: .init(
token: token,
ticker: viewModel.ticker(for: token),
currencyAmount: session.balanceCoordinator.viewModel.currencyAmount
currencyAmount: session.balanceCoordinator.viewModel.currencyAmount,
currencyAmountWithoutSymbol: session.balanceCoordinator.viewModel.currencyAmountWithoutSymbol
)
)
return cell

@ -0,0 +1,67 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Foundation
class EthCurrencyHelper {
enum Change24h {
case appreciate(percentageChange24h: Double)
case depreciate(percentageChange24h: Double)
case none
}
var ticker: CoinTicker?
var change24h: Change24h {
if let value = percentageChange24h {
if isValueAppreciated24h {
return .appreciate(percentageChange24h: value)
} else if isValueDepreciated24h {
return .depreciate(percentageChange24h: value)
} else {
return .none
}
} else {
return .none
}
}
private var percentageChange24h: Double? {
if let percent_change_24h = ticker?.percent_change_24h, let percentChange = Double(percent_change_24h) {
return percentChange
} else {
return nil
}
}
private var isValueAppreciated24h: Bool {
if let percentChange = percentageChange24h {
return percentChange > 0
} else {
return false
}
}
private var isValueDepreciated24h: Bool {
if let percentChange = percentageChange24h {
return percentChange < 0
} else {
return false
}
}
public func valueChanged24h(currencyAmountWithoutSymbol: Double?) -> String? {
if let percentChange = percentageChange24h, let value = currencyAmountWithoutSymbol {
let change = value * percentChange / 100
if let string = CurrencyFormatter.formatter.string(from: NSNumber(value: change)) {
return string
} else {
return nil
}
} else {
return nil
}
}
init(ticker: CoinTicker?) {
self.ticker = ticker
}
}

@ -8,16 +8,19 @@ struct EthTokenViewCellViewModel {
private let shortFormatter = EtherNumberFormatter.short
private let token: TokenObject
private let currencyAmount: String?
private let currencyAmountWithoutSymbol: Double?
let ticker: CoinTicker?
init(
token: TokenObject,
ticker: CoinTicker?,
currencyAmount: String?
currencyAmount: String?,
currencyAmountWithoutSymbol: Double?
) {
self.token = token
self.ticker = ticker
self.currencyAmount = currencyAmount
self.currencyAmountWithoutSymbol = currencyAmountWithoutSymbol
}
var title: String {
@ -73,8 +76,15 @@ struct EthTokenViewCellViewModel {
}
var valuePercentageChangeColor: UIColor {
//TODO must have a different color when depreciate?
return Colors.appHighlightGreen
switch EthCurrencyHelper(ticker: ticker).change24h {
case .appreciate(_):
return Colors.appHighlightGreen
case .depreciate(_):
return Colors.appRed
case .none:
//TODO use the constant in Colors
return UIColor(red: 155, green: 155, blue: 155)
}
}
var textValueFont: UIFont {
@ -86,8 +96,14 @@ struct EthTokenViewCellViewModel {
}
var valuePercentageChangeValue: String {
//TODO read from model
return "+50%"
switch EthCurrencyHelper(ticker: ticker).change24h {
case .appreciate(let percentageChange24h):
return "+\(percentageChange24h)%"
case .depreciate(let percentageChange24h):
return "-\(percentageChange24h)%"
case .none:
return "-"
}
}
var valuePercentageChangePeriod: String {
@ -95,8 +111,11 @@ struct EthTokenViewCellViewModel {
}
var valueChange: String {
//TODO read from model
return "$17,000"
if let value = EthCurrencyHelper(ticker: ticker).valueChanged24h(currencyAmountWithoutSymbol: currencyAmountWithoutSymbol) {
return value
} else {
return "-"
}
}
var valueChangeName: String {

@ -31,14 +31,18 @@ struct BalanceViewModel: BalanceBaseViewModel {
}
var currencyAmount: String? {
guard let totalAmount = currencyAmountWithoutSymbol else { return nil }
return CurrencyFormatter.formatter.string(from: NSNumber(value: totalAmount))
}
var currencyAmountWithoutSymbol: Double? {
guard let rate = rate else { return nil }
guard
let currentRate = (rate.rates.filter { $0.code == config.server.symbol }.first),
currentRate.price > 0,
amount > 0
else { return nil }
let totalAmount = amount * currentRate.price
return CurrencyFormatter.formatter.string(from: NSNumber(value: totalAmount))
let currentRate = (rate.rates.filter { $0.code == config.server.symbol }.first),
currentRate.price > 0,
amount > 0
else { return nil }
return amount * currentRate.price
}
var amountFull: String {

@ -513,6 +513,11 @@ class SendViewController: UIViewController {
guard let viewModel = viewModel else { return }
let amount = viewModel.amountShort
self.headerViewModel.title = "\(amount) \(self.session.config.server.name) (\(viewModel.symbol))"
let etherToken = TokensDataStore.etherToken(for: self.session.config)
let ticker = self.storage.coinTicker(for: etherToken)
self.headerViewModel.ticker = ticker
self.headerViewModel.currencyAmount = self.session.balanceCoordinator.viewModel.currencyAmount
self.headerViewModel.currencyAmountWithoutSymbol = self.session.balanceCoordinator.viewModel.currencyAmountWithoutSymbol
if let viewModel = self.viewModel {
self.configure(viewModel: viewModel)
}
@ -522,6 +527,11 @@ class SendViewController: UIViewController {
let viewModel = BalanceTokenViewModel(token: token)
let amount = viewModel.amountShort
headerViewModel.title = "\(amount) \(viewModel.symbol)"
let etherToken = TokensDataStore.etherToken(for: self.session.config)
let ticker = self.storage.coinTicker(for: etherToken)
self.headerViewModel.ticker = ticker
self.headerViewModel.currencyAmount = self.session.balanceCoordinator.viewModel.currencyAmount
self.headerViewModel.currencyAmountWithoutSymbol = self.session.balanceCoordinator.viewModel.currencyAmountWithoutSymbol
if let viewModel = self.viewModel {
configure(viewModel: self.viewModel)
}

@ -4,6 +4,9 @@ import UIKit
struct SendHeaderViewViewModel {
var title = ""
var ticker: CoinTicker? = nil
var currencyAmount: String? = nil
var currencyAmountWithoutSymbol: Double? = nil
var issuer: String {
return ""
@ -46,8 +49,15 @@ struct SendHeaderViewViewModel {
}
var valuePercentageChangeColor: UIColor {
//TODO must have a different color when depreciate?
return Colors.appHighlightGreen
switch EthCurrencyHelper(ticker: ticker).change24h {
case .appreciate(_):
return Colors.appHighlightGreen
case .depreciate(_):
return Colors.appRed
case .none:
//TODO use the constant in Colors
return UIColor(red: 155, green: 155, blue: 155)
}
}
var textValueFont: UIFont {
@ -59,9 +69,14 @@ struct SendHeaderViewViewModel {
}
var valuePercentageChangeValue: String {
//TODO read from model
// return "+50%"
return "N/A"
switch EthCurrencyHelper(ticker: ticker).change24h {
case .appreciate(let percentageChange24h):
return "+\(percentageChange24h)%"
case .depreciate(let percentageChange24h):
return "-\(percentageChange24h)%"
case .none:
return "-"
}
}
var valuePercentageChangePeriod: String {
@ -69,9 +84,11 @@ struct SendHeaderViewViewModel {
}
var valueChange: String {
//TODO read from model
// return "$17,000"
return "N/A"
if let value = EthCurrencyHelper(ticker: ticker).valueChanged24h(currencyAmountWithoutSymbol: currencyAmountWithoutSymbol) {
return value
} else {
return "-"
}
}
var valueChangeName: String {
@ -79,8 +96,11 @@ struct SendHeaderViewViewModel {
}
var value: String {
//TODO read from model
return "N/A"
if let currencyAmount = currencyAmount {
return currencyAmount
} else {
return "-"
}
}
var valueName: String {

Loading…
Cancel
Save