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",
"filename" : "settings-currency@3x.png",
"filename" : "icons8-us-dollar-64 (1).png",
"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?
private let provider = MoyaProvider<TrustService>()
let config: Config
init(
config: Config
) {
self.config = config
}
func start() {
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 }
do {
guard let ticker = try response.map([CoinTicker].self, atKeyPath: "response", using: JSONDecoder()).first else { return }

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

@ -14,6 +14,8 @@ class SettingsViewController: FormViewController {
struct Values {
static let donationAddress = Address(address: "0x9f8284ce2cf0c8ce10685f537b1fff418104a317")
static let currencyPopularKey = "0"
static let currencyAllKey = "1"
}
private var config = Config()
@ -78,27 +80,6 @@ class SettingsViewController: FormViewController {
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
button.cellStyle = .value1
}.onCellSelection { [unowned self] _, _ in
@ -111,6 +92,41 @@ class SettingsViewController: FormViewController {
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: ""))
<<< SwitchRow {

@ -22,8 +22,8 @@ struct SettingsViewModel {
]
}
var currency: [String] {
return Currency.allValues.map { $0.rawValue }.sorted()
var currency: [Currency] {
return Currency.allValues.map { $0 }
}
var passcodeTitle: String {
@ -41,4 +41,8 @@ struct SettingsViewModel {
var networkTitle: String {
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()
case .classic, .kovan, .poa, .ropsten:
self.refreshBalance()
updatePrices()
refreshBalance()
}
}

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

Loading…
Cancel
Save