Improvment currency functionality

pull/2/head
Michael Scoff 7 years ago
parent 3f637393c7
commit ee18fd1053
  1. 2
      Trust/Assets.xcassets/settings-currency.imageset/Contents.json
  2. BIN
      Trust/Assets.xcassets/settings-currency.imageset/icons8-us-dollar-64 (1).png
  3. BIN
      Trust/Assets.xcassets/settings-currency.imageset/settings-currency@3x.png
  4. 9
      Trust/Settings/Coordinators/ExchangeRateCoordinator.swift
  5. 8
      Trust/Settings/Types/Currency.swift
  6. 58
      Trust/Settings/ViewControllers/SettingsViewController.swift
  7. 8
      Trust/Settings/ViewModels/SettingsViewModel.swift
  8. 3
      Trust/Tokens/Types/TokensDataStore.swift
  9. 5
      Trust/Transactions/Coordinators/BalanceCoordinator.swift

@ -10,7 +10,7 @@
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "settings-currency@3x.png", "filename" : "icons8-us-dollar-64 (1).png",
"scale" : "3x" "scale" : "3x"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

@ -13,13 +13,20 @@ class ExchangeRateCoordinator: NSObject {
weak var delegate: ExchangeRateCoordinatorDelegate? weak var delegate: ExchangeRateCoordinatorDelegate?
private let provider = MoyaProvider<TrustService>() private let provider = MoyaProvider<TrustService>()
let config: Config
init(
config: Config
) {
self.config = config
}
func start() { func start() {
fetch() fetch()
} }
func fetch() { func fetch() {
provider.request(.prices(currency: Config().currency, symbols:["ETH"])) { (result) in provider.request(.prices(currency: Config().currency, symbols:[config.server.symbol])) { (result) in
guard case .success(let response) = result else { return } guard case .success(let response) = result else { return }
do { do {
guard let ticker = try response.map([CoinTicker].self, atKeyPath: "response", using: JSONDecoder()).first else { return } guard let ticker = try response.map([CoinTicker].self, atKeyPath: "response", using: JSONDecoder()).first else { return }

@ -37,7 +37,11 @@ enum Currency: String {
case USD case USD
static let allValues = [ static let allValues = [
USD,
EUR,
GBP,
AUD, AUD,
RUB,
BRL, BRL,
CAD, CAD,
CHF, CHF,
@ -45,8 +49,6 @@ enum Currency: String {
CNY, CNY,
CZK, CZK,
DKK, DKK,
EUR,
GBP,
HKD, HKD,
HUF, HUF,
IDR, IDR,
@ -61,14 +63,12 @@ enum Currency: String {
PHP, PHP,
PKR, PKR,
PLN, PLN,
RUB,
SEK, SEK,
SGD, SGD,
THB, THB,
TRY, TRY,
TWD, TWD,
ZAR, ZAR,
USD,
] ]
init(value: String) { init(value: String) {

@ -14,6 +14,8 @@ class SettingsViewController: FormViewController {
struct Values { struct Values {
static let donationAddress = Address(address: "0x9f8284ce2cf0c8ce10685f537b1fff418104a317") static let donationAddress = Address(address: "0x9f8284ce2cf0c8ce10685f537b1fff418104a317")
static let currencyPopularKey = "0"
static let currencyAllKey = "1"
} }
private var config = Config() private var config = Config()
@ -78,27 +80,6 @@ class SettingsViewController: FormViewController {
cell.imageView?.image = R.image.settings_server() cell.imageView?.image = R.image.settings_server()
} }
+++ Section(NSLocalizedString("settings.currency.button.title", value: "Currency", comment: ""))
<<< PushRow<String> {
$0.title = NSLocalizedString("settings.currency.button.title", value: "Currency", comment: "")
$0.options = viewModel.currency
$0.value = config.currency.rawValue
$0.displayValueFor = { value in
return value
}
}.onChange { row in
guard let value = row.value else {
return
}
self.config.currency = Currency(value: value)
self.run(action: .currency)
}.onPresent { _, selectorController in
selectorController.enableDeselection = false
}.cellSetup { cell, _ in
cell.imageView?.image = R.image.settingsCurrency()
}
<<< AppFormAppearance.button { button in <<< AppFormAppearance.button { button in
button.cellStyle = .value1 button.cellStyle = .value1
}.onCellSelection { [unowned self] _, _ in }.onCellSelection { [unowned self] _, _ in
@ -111,6 +92,41 @@ class SettingsViewController: FormViewController {
cell.accessoryType = .disclosureIndicator cell.accessoryType = .disclosureIndicator
} }
+++ Section()
<<< PushRow<Currency> {
$0.title = viewModel.currencyTitle
$0.selectorTitle = viewModel.currencyTitle
$0.options = viewModel.currency
$0.value = config.currency
$0.displayValueFor = { value in
return value?.rawValue
}
}.onChange { row in
guard let value = row.value else { return }
self.config.currency = value
self.run(action: .currency)
}.onPresent { _, selectorController in
selectorController.enableDeselection = false
selectorController.sectionKeyForValue = { option in
switch option {
case .USD, .EUR, .GBP, .AUD, .RUB: return Values.currencyPopularKey
default: return Values.currencyAllKey
}
}
selectorController.sectionHeaderTitleForKey = { option in
switch option {
case Values.currencyPopularKey:
return NSLocalizedString("settings.currency.popular.label.title", value: "Popular", comment: "")
case Values.currencyAllKey:
return NSLocalizedString("settings.currency.all.label.title", value: "All", comment: "")
default: return ""
}
}
}.cellSetup { cell, _ in
cell.imageView?.image = R.image.settingsCurrency()
}
+++ Section(NSLocalizedString("settings.security.label.title", value: "Security", comment: "")) +++ Section(NSLocalizedString("settings.security.label.title", value: "Security", comment: ""))
<<< SwitchRow { <<< SwitchRow {

@ -22,8 +22,8 @@ struct SettingsViewModel {
] ]
} }
var currency: [String] { var currency: [Currency] {
return Currency.allValues.map { $0.rawValue }.sorted() return Currency.allValues.map { $0 }
} }
var passcodeTitle: String { var passcodeTitle: String {
@ -41,4 +41,8 @@ struct SettingsViewModel {
var networkTitle: String { var networkTitle: String {
return NSLocalizedString("settings.network.button.title", value: "Network", comment: "") return NSLocalizedString("settings.network.button.title", value: "Network", comment: "")
} }
var currencyTitle: String {
return NSLocalizedString("settings.currency.button.title", value: "Currency", comment: "")
}
} }

@ -86,7 +86,8 @@ class TokensDataStore {
} }
updatePrices() updatePrices()
case .classic, .kovan, .poa, .ropsten: case .classic, .kovan, .poa, .ropsten:
self.refreshBalance() updatePrices()
refreshBalance()
} }
} }

@ -10,7 +10,10 @@ protocol BalanceCoordinatorDelegate: class {
class BalanceCoordinator { class BalanceCoordinator {
let exchangeRateCoordinator = ExchangeRateCoordinator() lazy var exchangeRateCoordinator: ExchangeRateCoordinator = {
return ExchangeRateCoordinator(config: self.session.config)
}()
let session: WalletSession let session: WalletSession
weak var delegate: BalanceCoordinatorDelegate? weak var delegate: BalanceCoordinatorDelegate?

Loading…
Cancel
Save