mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-01 03:31:20 +01:00
Update MainInterface.storyboard ADD: Cache fetched data ADD: Add "Up from/Down from" data OPS: Add Provision Profile Update project.pbxproj ADD: Synchronize user selected currency with Today extension Update Info.plist ADD: quick actions Update App.js Update App.js Update App.js Update App.js Update App.js FIX: Fix currency bugs FIX: Hide balance from quick actions ADD: cqc Update currency.js Update TodayViewController.swift Update App.js REF: headercolor Update App.js FIX: carousel would not show FIX: Fix FIX FIX Update API.swift FIX: Fixed alerts TST Revert "TST" This reverts commit bcdf62e9b238cc5da200cc4bce45e4e55f480d6d. ADD: Tests mocks REF: Device Quick Actions ref FIX: Fixed crash Update quickActions.ios.js ADD: QuickActions for Android D FIX: Tests OP
65 lines
2 KiB
Swift
65 lines
2 KiB
Swift
//
|
|
// API.swift
|
|
// TodayExtension
|
|
//
|
|
// Created by Marcos Rodriguez on 11/2/19.
|
|
// Copyright © 2019 Facebook. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
class API {
|
|
|
|
static func fetchPrice(currency: String, completion: @escaping ((Dictionary<String, Any>?, Error?) -> Void)) {
|
|
guard let url = URL(string: "https://api.coindesk.com/v1/bpi/currentPrice/\(currency).json") else {return}
|
|
|
|
URLSession.shared.dataTask(with: url) { (data, response, error) in
|
|
guard let dataResponse = data,
|
|
let json = try? JSONSerialization.jsonObject(with: dataResponse, options: .mutableContainers) as? Dictionary<String, Any>,
|
|
error == nil else {
|
|
print(error?.localizedDescription ?? "Response Error")
|
|
completion(nil, error)
|
|
return }
|
|
|
|
completion(json, nil)
|
|
}.resume()
|
|
}
|
|
|
|
static func getUserPreferredCurrency() -> String {
|
|
guard let userDefaults = UserDefaults(suiteName: "group.io.bluewallet.bluewallet"),
|
|
let preferredCurrency = userDefaults.string(forKey: "preferredCurrency")
|
|
else {
|
|
return "USD"
|
|
}
|
|
|
|
if preferredCurrency != API.getLastSelectedCurrency() {
|
|
UserDefaults.standard.removeObject(forKey: TodayData.TodayCachedDataStoreKey)
|
|
UserDefaults.standard.removeObject(forKey: TodayData.TodayDataStoreKey)
|
|
UserDefaults.standard.synchronize()
|
|
}
|
|
|
|
return preferredCurrency
|
|
}
|
|
|
|
static func getUserPreferredCurrencyLocale() -> String {
|
|
guard let userDefaults = UserDefaults(suiteName: "group.io.bluewallet.bluewallet"),
|
|
let preferredCurrency = userDefaults.string(forKey: "preferredCurrencyLocale")
|
|
else {
|
|
return "en_US"
|
|
}
|
|
return preferredCurrency
|
|
}
|
|
|
|
static func getLastSelectedCurrency() -> String {
|
|
guard let dataStore = UserDefaults.standard.string(forKey: "currency") else {
|
|
return "USD"
|
|
}
|
|
|
|
return dataStore
|
|
}
|
|
|
|
static func saveNewSelectedCurrency() {
|
|
UserDefaults.standard.setValue(API.getUserPreferredCurrency(), forKey: "currency")
|
|
}
|
|
|
|
}
|