PetrenkoDaria / Converter

Converter is a SwiftUI currency converter app for iOS and macOS using Catalyst to work with the status bar. MVVM architecture.
MIT License
1 stars 0 forks source link

Doesn't check whether JSON call was successful #2

Open hippietrail opened 1 year ago

hippietrail commented 1 year ago

If you try to run this without a valid API key, you just end up with every currency converted to either "Inf" or "0.000000"

In CurrencyViewModel.swift line 55

let currencies = await self.loadData()
let dictData: Dictionary<String, String> = currencies?["data"] as? Dictionary<String, String> ?? [:]

Should be checking currencies?["status"] is 200 and currencies?["message"] is currency_list between those two lines.


Also, once you've run it with a bad key, next time you run it doesn't try to get the JSON again. I couldn't find a way to force it, how to clear the cached data, or follow that code path yet.

PetrenkoDaria commented 1 year ago

Uploaded new version. Added api query error check. In case of an error, default values are not saved in the date.