feature/app now receives exchange rates from API

This commit is contained in:
Joaquin committed 2025-05-06 17:02:37 -07:00
1 parent f3a1a2191a
commit a173b8c70c
6 files changed
+167 -8

No files matched your search

+25 -6
View File
@@ -1,24 +1,43 @@
async function diffCountries() {
const res = await fetch("/static/json/countries.json");
const data = await res.json();
return data.countries;
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
}
function success(position) {
async function success(position) {
const { latitude, longitude } = position.coords;
let countryCurrency;
fetch("api/location" , {
const countries = await diffCountries();
const res = await fetch("api/location" , {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ latitude, longitude })
}).then(res => res.json())
.then(data => {
console.log(data.results[0].formatted_address);
})
});
const data = await res.json();
countries.forEach(country => {
if (country.country === data.results[0].formatted_address) {
countryCurrency = country.currency_abbreviation;
convert(countryCurrency);
}
});
}
function error(err) {
console.error("Geolocation error: ", err);
}
getLocation();