Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Bugfix/empty historical market data in asset profile dialog for asset profiles without activities (#7623)
Thomas Kaul4926d59d4d55
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d52aa9794c..7316b4d5e4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed- Fixed the cash balance update related to activities in a custom currency+- Fixed the empty historical market data of the asset profile dialog of the admin control panel for asset profiles without activities- Fixed the missing mapping for Czech Republic in the country weightings of the _Financial Modeling Prep_ service- Fixed the missing mapping for Macau in the data enhancer for asset profile data via _Yahoo Finance_- Fixed the outdated exchange rates of currency pairs which are calculated indirectly via the base currencydiff --git a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.tsindex f99c34b039..aa6177cff9 100644--- a/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts+++ b/libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts@@ -41,7 +41,6 @@ import {parse,parseISO} from 'date-fns';-import { first, last } from 'lodash';import ms from 'ms';import { DeviceDetectorService } from 'ngx-device-detector';import { parse as csvToJson } from 'papaparse';@@ -123,75 +122,78 @@ export class GfHistoricalMarketDataEditorComponent}public ngOnChanges() {- if (this.dateOfFirstActivity) {- let date = this.dateOfFirstActivity;-- const missingMarketData: { date: Date; marketPrice?: number }[] = [];-- if (this.historicalDataItems()?.[0]?.date) {- while (- isBefore(- date,- parse(this.historicalDataItems()[0].date, DATE_FORMAT, new Date())- )- ) {- missingMarketData.push({- date,- marketPrice: undefined- });-- date = addDays(date, 1);- }- }+ const startDate = this.dateOfFirstActivity ?? this.marketData()[0]?.date;++ if (!startDate) {+ return;+ }++ let date = startDate;++ const missingMarketData: { date: Date; marketPrice?: number }[] = [];- const marketDataItems = [...missingMarketData, ...this.marketData()];+ if (this.historicalDataItems()?.[0]?.date) {+ while (+ isBefore(+ date,+ parse(this.historicalDataItems()[0].date, DATE_FORMAT, new Date())+ )+ ) {+ missingMarketData.push({+ date,+ marketPrice: undefined+ });- const lastDate = last(marketDataItems)?.date;- if (!lastDate || !isToday(lastDate)) {- marketDataItems.push({ date: new Date() });+ date = addDays(date, 1);}+ }- this.marketDataByMonth = {};+ const marketDataItems = [...missingMarketData, ...this.marketData()];- for (const marketDataItem of marketDataItems) {- const currentDay = parseInt(format(marketDataItem.date, 'd'), 10);- const key = format(marketDataItem.date, 'yyyy-MM');+ const lastDate = marketDataItems.at(-1)?.date;+ if (!lastDate || !isToday(lastDate)) {+ marketDataItems.push({ date: new Date() });+ }- if (!this.marketDataByMonth[key]) {- this.marketDataByMonth[key] = {};- }+ this.marketDataByMonth = {};++ for (const marketDataItem of marketDataItems) {+ const currentDay = parseInt(format(marketDataItem.date, 'd'), 10);+ const key = format(marketDataItem.date, 'yyyy-MM');- this.marketDataByMonth[key][- currentDay < 10 ? `0${currentDay}` : currentDay- ] = {- date: marketDataItem.date,- day: currentDay,- marketPrice: marketDataItem.marketPrice- };+ if (!this.marketDataByMonth[key]) {+ this.marketDataByMonth[key] = {};}- // Fill up missing months- const dates = Object.keys(this.marketDataByMonth).sort();- const startDateString = first(dates);- const startDate = min([- this.dateOfFirstActivity,- ...(startDateString ? [parseISO(startDateString)] : [])- ]);- const endDateString = last(dates);+ this.marketDataByMonth[key][+ currentDay < 10 ? `0${currentDay}` : currentDay+ ] = {+ date: marketDataItem.date,+ day: currentDay,+ marketPrice: marketDataItem.marketPrice+ };+ }- if (endDateString) {- const endDate = parseISO(endDateString);+ // Fill up missing months+ const dates = Object.keys(this.marketDataByMonth).sort();+ const startDateString = dates[0];+ const endDateString = dates.at(-1);- let currentDate = startDate;+ if (endDateString) {+ const endDate = parseISO(endDateString);- while (isBefore(currentDate, endDate)) {- const key = format(currentDate, 'yyyy-MM');- if (!this.marketDataByMonth[key]) {- this.marketDataByMonth[key] = {};- }+ let currentDate = min([+ startDate,+ ...(startDateString ? [parseISO(startDateString)] : [])+ ]);- currentDate = addMonths(currentDate, 1);+ while (isBefore(currentDate, endDate)) {+ const key = format(currentDate, 'yyyy-MM');+ if (!this.marketDataByMonth[key]) {+ this.marketDataByMonth[key] = {};}++ currentDate = addMonths(currentDate, 1);}}}