|
|
@ -65,6 +65,7 @@ import {
|
|
|
|
max,
|
|
|
|
max,
|
|
|
|
parse,
|
|
|
|
parse,
|
|
|
|
parseISO,
|
|
|
|
parseISO,
|
|
|
|
|
|
|
|
set,
|
|
|
|
setDayOfYear,
|
|
|
|
setDayOfYear,
|
|
|
|
startOfDay,
|
|
|
|
startOfDay,
|
|
|
|
subDays,
|
|
|
|
subDays,
|
|
|
@ -215,22 +216,40 @@ export class PortfolioService {
|
|
|
|
investment: item.investment.toNumber()
|
|
|
|
investment: item.investment.toNumber()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
investments = portfolioCalculator.getInvestments().map((item) => {
|
|
|
|
// Add investment of current month
|
|
|
|
return {
|
|
|
|
const dateOfCurrentMonth = format(
|
|
|
|
date: item.date,
|
|
|
|
set(new Date(), { date: 1 }),
|
|
|
|
investment: item.investment.toNumber()
|
|
|
|
DATE_FORMAT
|
|
|
|
};
|
|
|
|
);
|
|
|
|
|
|
|
|
const investmentOfCurrentMonth = investments.filter(({ date }) => {
|
|
|
|
|
|
|
|
return date === dateOfCurrentMonth;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (investmentOfCurrentMonth.length <= 0) {
|
|
|
|
|
|
|
|
investments.push({
|
|
|
|
|
|
|
|
date: dateOfCurrentMonth,
|
|
|
|
|
|
|
|
investment: 0
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
investments = portfolioCalculator
|
|
|
|
|
|
|
|
.getInvestments()
|
|
|
|
|
|
|
|
.map(({ date, investment }) => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
date,
|
|
|
|
|
|
|
|
investment: investment.toNumber()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Add investment of today
|
|
|
|
// Add investment of today
|
|
|
|
const investmentOfToday = investments.filter((investment) => {
|
|
|
|
const investmentOfToday = investments.filter(({ date }) => {
|
|
|
|
return investment.date === format(new Date(), DATE_FORMAT);
|
|
|
|
return date === format(new Date(), DATE_FORMAT);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (investmentOfToday.length <= 0) {
|
|
|
|
if (investmentOfToday.length <= 0) {
|
|
|
|
const pastInvestments = investments.filter((investment) => {
|
|
|
|
const pastInvestments = investments.filter(({ date }) => {
|
|
|
|
return isBefore(parseDate(investment.date), new Date());
|
|
|
|
return isBefore(parseDate(date), new Date());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const lastInvestment = pastInvestments[pastInvestments.length - 1];
|
|
|
|
const lastInvestment = pastInvestments[pastInvestments.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|