Skip to content

Commit

Permalink
coding keys
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Aug 2, 2023
1 parent f2b42fe commit 9f8bc53
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
45 changes: 37 additions & 8 deletions BDKSwiftExampleWallet/Model/PriceResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,45 @@ import Foundation

struct PriceResponse: Codable {
let prices: [Price]
let exchangeRates: [String: Double]
let exchangeRates: ExchangeRates
}

struct Price: Codable {
let time: Int
let USD: Double
let EUR: Double
let GBP: Double
let CAD: Double
let CHF: Double
let AUD: Double
let JPY: Double
let usd: Double
let eur: Double
let gbp: Double
let cad: Double
let chf: Double
let aud: Double
let jpy: Double

enum CodingKeys: String, CodingKey {
case time
case usd = "USD"
case eur = "EUR"
case gbp = "GBP"
case cad = "CAD"
case chf = "CHF"
case aud = "AUD"
case jpy = "JPY"
}
}

struct ExchangeRates : Codable {
let uSDEUR : Double?
let uSDGBP : Double?
let uSDCAD : Double?
let uSDCHF : Double?
let uSDAUD : Double?
let uSDJPY : Double?

enum CodingKeys: String, CodingKey {
case uSDEUR = "USDEUR"
case uSDGBP = "USDGBP"
case uSDCAD = "USDCAD"
case uSDCHF = "USDCHF"
case uSDAUD = "USDAUD"
case uSDJPY = "USDJPY"
}
}
2 changes: 1 addition & 1 deletion BDKSwiftExampleWallet/View/WalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class WalletViewModel: ObservableObject {
func fetchPrice() async {
do {
let response = try await priceService.hourlyPrice()
if let latestPrice = response.prices.first?.USD {
if let latestPrice = response.prices.first?.usd {
DispatchQueue.main.async {
self.price = latestPrice
}
Expand Down

0 comments on commit 9f8bc53

Please sign in to comment.