diff --git a/Trust/Assets.xcassets/settings-currency.imageset/Contents.json b/Trust/Assets.xcassets/settings-currency.imageset/Contents.json index d7708cd4e..0bddbdc16 100644 --- a/Trust/Assets.xcassets/settings-currency.imageset/Contents.json +++ b/Trust/Assets.xcassets/settings-currency.imageset/Contents.json @@ -10,7 +10,7 @@ }, { "idiom" : "universal", - "filename" : "settings-currency@3x.png", + "filename" : "icons8-us-dollar-64 (1).png", "scale" : "3x" } ], diff --git a/Trust/Assets.xcassets/settings-currency.imageset/icons8-us-dollar-64 (1).png b/Trust/Assets.xcassets/settings-currency.imageset/icons8-us-dollar-64 (1).png new file mode 100644 index 000000000..88bbe2ae8 Binary files /dev/null and b/Trust/Assets.xcassets/settings-currency.imageset/icons8-us-dollar-64 (1).png differ diff --git a/Trust/Assets.xcassets/settings-currency.imageset/settings-currency@3x.png b/Trust/Assets.xcassets/settings-currency.imageset/settings-currency@3x.png deleted file mode 100644 index fa82890ca..000000000 Binary files a/Trust/Assets.xcassets/settings-currency.imageset/settings-currency@3x.png and /dev/null differ diff --git a/Trust/Settings/Coordinators/ExchangeRateCoordinator.swift b/Trust/Settings/Coordinators/ExchangeRateCoordinator.swift index 24fb0881c..261868ed6 100644 --- a/Trust/Settings/Coordinators/ExchangeRateCoordinator.swift +++ b/Trust/Settings/Coordinators/ExchangeRateCoordinator.swift @@ -13,13 +13,20 @@ class ExchangeRateCoordinator: NSObject { weak var delegate: ExchangeRateCoordinatorDelegate? private let provider = MoyaProvider() + 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 } diff --git a/Trust/Settings/Types/Currency.swift b/Trust/Settings/Types/Currency.swift index bc1144797..fe96f3d93 100644 --- a/Trust/Settings/Types/Currency.swift +++ b/Trust/Settings/Types/Currency.swift @@ -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) { diff --git a/Trust/Settings/ViewControllers/SettingsViewController.swift b/Trust/Settings/ViewControllers/SettingsViewController.swift index 611f17695..1d57c2781 100644 --- a/Trust/Settings/ViewControllers/SettingsViewController.swift +++ b/Trust/Settings/ViewControllers/SettingsViewController.swift @@ -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 { - $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 { + $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 { diff --git a/Trust/Settings/ViewModels/SettingsViewModel.swift b/Trust/Settings/ViewModels/SettingsViewModel.swift index ed34169fb..200936645 100644 --- a/Trust/Settings/ViewModels/SettingsViewModel.swift +++ b/Trust/Settings/ViewModels/SettingsViewModel.swift @@ -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: "") + } } diff --git a/Trust/Tokens/Types/TokensDataStore.swift b/Trust/Tokens/Types/TokensDataStore.swift index eb522306d..199dadc7a 100644 --- a/Trust/Tokens/Types/TokensDataStore.swift +++ b/Trust/Tokens/Types/TokensDataStore.swift @@ -86,7 +86,8 @@ class TokensDataStore { } updatePrices() case .classic, .kovan, .poa, .ropsten: - self.refreshBalance() + updatePrices() + refreshBalance() } } diff --git a/Trust/Transactions/Coordinators/BalanceCoordinator.swift b/Trust/Transactions/Coordinators/BalanceCoordinator.swift index cea45208b..3ca83a014 100644 --- a/Trust/Transactions/Coordinators/BalanceCoordinator.swift +++ b/Trust/Transactions/Coordinators/BalanceCoordinator.swift @@ -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?