Hard
You're debugging a financial dashboard where transaction totals aren't updating correctly. The code processes multiple currency conversions asynchronously. What's the fundamental issue with this implementation?
1async function calculatePortfolioValue(transactions) {2 let totalUSD = 0;3 const exchangeRates = new Map();45 async function getExchangeRate(currency) {6 if (exchangeRates.has(currency)) {7 return exchangeRates.get(currency);8 }9 const response = await fetch(`/api/rates/${currency}`);10 const rate = await response.json();11 exchangeRates.set(currency, rate.value);12 return rate.value;13 }1415 transactions.forEach(async (tx) => {16 const rate = await getExchangeRate(tx.currency);17 const valueUSD = tx.amount * rate;18 totalUSD += valueUSD;19 });2021 return {22 total: totalUSD,23 timestamp: Date.now()24 };25}2627// Usage28const dashboard = {29 async updateTotals(transactions) {30 const result = await calculatePortfolioValue(transactions);31 this.setState({ portfolioValue: result.total });32 }33};