Open adrianinsaval opened 1 year ago
chat gpt says to do this on https://github.com/ferraridamiano/ConverterNOW/blob/master/lib/models/currencies.dart
Future<Currencies> downloadCurrencies() async {
try {
var response = await http.get(Uri.parse('https://open.er-api.com/v6/latest'));
if (response.statusCode == 200) {
var lastUpdate = DateFormat("yyyy-MM-dd").format(DateTime.now());
Map<String, dynamic> data = json.decode(response.body);
Map<String, double> exchangeRates = {'EUR': 1};
// Update exchange rates from the API response
for (var currency in defaultExchangeRates.keys) {
if (currency != 'EUR' && data.containsKey(currency)) {
exchangeRates[currency] = data[currency];
}
}
pref.setString('currenciesRates', jsonEncode(exchangeRates));
pref.setString('lastUpdateCurrencies', lastUpdate);
return Currencies(
exchangeRates: exchangeRates,
lastUpdate: lastUpdate,
);
}
} catch (e) {
debugPrint(e.toString());
}
return readSavedCurrencies();
}
no clue if that is even valid code. I think that API uses USD as base though, might need to change that or use https://open.er-api.com/v6/latest/EUR instead
It's rate limited but the app wouldn't need to access it that often.
The website you mention says that it includes 1.5k request in the free plan. This app has more than 1.5k MAU with only the installations from the play store.
At the moment the european central bank api is the most trustworthy service without such limitations. I will leave this open for further discussion and new ideas since this is one of the most requestes features.
But I would imagine the limitation is by IP address not by app, how would it even know it's all from the same app
Isn't it related to the free API key?
I assume you looked at the "Free API" card, look at the "Open API" instead. No API key is required, each request would be associated with each individual user not the app itself. The european bank is most definitely the most trustworthy source, but it would be nice to have this as an option for more obscure currencies.
Oh, right! Yes, technically it is feasible. Maybe we could use the ECB for the current currencies and this service for the other one. I will take a look, if you want to submit a PR I can review it
Description A bigger pool of currencies would be nice. Personally would love to have PYG available, I read the disclaimer on the issue template and understand that this app is not in a position to pay for a service, however there are free services available with more currencies than the european central bank, see https://open.er-api.com/v6/latest and it's docs: https://www.exchangerate-api.com/docs/free It's rate limited but the app wouldn't need to access it that often. I would still leave the european bank as fallback API since it's more likely to stay free for posterity, but it would be nice to use this to support less popular currencies.