koboprice/lib/index.js

40 lines
869 B
JavaScript
Raw Normal View History

2024-07-14 16:49:40 +03:00
import './logger'
import { COUNTRIES } from "./countries";
import { getPriceForCountry } from "./getPriceForCountry";
import { loadCurrencyRates, convertCurrency } from "./currency";
async function main() {
try {
const rates = await loadCurrencyRates();
l('currency rates', rates)
const prices = await Promise.all(
COUNTRIES.map(async (c) => {
l("looking price for", c.countryCode);
const originalPrice = await getPriceForCountry(c.countryCode);
const convertedPrice = await convertCurrency(
originalPrice,
c.currencyCode,
rates,
);
return { ...c, originalPrice, convertedPrice };
}),
);
l(prices);
} catch (e) {
l("error", e);
} finally {
l("done");
}
}
l("starting...");
window.onload = () => {
l("page is fully loaded");
void main();
};