Skip to content

Commit

Permalink
Merge pull request #523 from bounswe/refac/FE-portfolio-selection
Browse files Browse the repository at this point in the history
Refac portfolio selection
  • Loading branch information
m-erkam authored Dec 16, 2024
2 parents 969b0f5 + 550e002 commit 2fd3981
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions frontend/src/components/portfolio/PortfolioPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const PortfolioPage = () => {
const fetchedPortfolios = await PortfolioService.fetchPortfolioByUserId(userId);
log.debug('Fetched portfolios:', fetchedPortfolios);
setPortfolios(fetchedPortfolios);
// Select the first portfolio by default
if (fetchedPortfolios.length > 0) {
handleSelectPortfolio(fetchedPortfolios[0]);
}
} catch (err) {
console.error('Error fetching portfolios:', err);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/service/portfolioService.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const PortfolioService = {
const data = {
"stocks": portfolio.stocks.map(stock => ({
stock: stock.id,
price_bought: stock.boughtPrice,
price_bought: parseFloat(stock.boughtPrice).toFixed(2),
quantity: stock.quantity
}))
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/service/stockService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { apiClient } from './apiClient';
import log from '../utils/logger';

const transformStockItem = (stockItem) => {
console.log("Transforming stock item:", stockItem);
return {
id: stockItem.id,
code: stockItem.symbol,
name: stockItem.name,
price: stockItem.detail.currentPrice,
price: stockItem?.detail?.currentPrice || stockItem?.price || 0,
currency: stockItem.currency
};
}
Expand All @@ -26,6 +27,7 @@ export const StockService = {
}
);
const stocks = response.data;
console.log("Similar stocks:", stocks);
return stocks.map(transformStockItem);
}
catch (error) {
Expand Down

0 comments on commit 2fd3981

Please sign in to comment.