From 6cd51fb044271da3baca74013e5a19c1af8d6b3d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:30:53 +0100 Subject: [PATCH] Feature/hide irrelevant errors in client (#1623) * Hide irrelevant errors in client * Update changelog --- CHANGELOG.md | 1 + .../src/app/portfolio/portfolio-calculator.ts | 2 +- .../src/app/portfolio/portfolio.service.ts | 54 ++++++++----------- .../home-overview/home-overview.component.ts | 9 ++-- .../home-overview/home-overview.html | 1 - .../portfolio-performance.component.html | 4 +- .../portfolio-performance.component.ts | 1 - 7 files changed, 31 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fb5bf697..231873fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Removed the toggle _Original Shares_ vs. _Current Shares_ on the allocations page +- Hid error messages related to no current investment in the client ### Fixed diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index 48f1e7507..9c659c167 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -447,7 +447,7 @@ export class PortfolioCalculator { transactionCount: item.transactionCount }); - if (hasErrors) { + if (hasErrors && item.investment.gt(0)) { errors.push({ dataSource: item.dataSource, symbol: item.symbol }); } } diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 558a988ec..3410be220 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1039,29 +1039,21 @@ export class PortfolioService { const portfolioStart = parseDate(transactionPoints[0].date); const startDate = this.getStartDate(dateRange, portfolioStart); - const currentPositions = await portfolioCalculator.getCurrentPositions( - startDate - ); - - const hasErrors = currentPositions.hasErrors; - const currentValue = currentPositions.currentValue.toNumber(); - const currentGrossPerformance = currentPositions.grossPerformance; - const currentGrossPerformancePercent = - currentPositions.grossPerformancePercentage; - let currentNetPerformance = currentPositions.netPerformance; - let currentNetPerformancePercent = - currentPositions.netPerformancePercentage; - const totalInvestment = currentPositions.totalInvestment; - - // if (currentGrossPerformance.mul(currentGrossPerformancePercent).lt(0)) { - // // If algebraic sign is different, harmonize it - // currentGrossPerformancePercent = currentGrossPerformancePercent.mul(-1); - // } - - // if (currentNetPerformance.mul(currentNetPerformancePercent).lt(0)) { - // // If algebraic sign is different, harmonize it - // currentNetPerformancePercent = currentNetPerformancePercent.mul(-1); - // } + const { + currentValue, + errors, + grossPerformance, + grossPerformancePercentage, + hasErrors, + netPerformance, + netPerformancePercentage, + totalInvestment + } = await portfolioCalculator.getCurrentPositions(startDate); + + const currentGrossPerformance = grossPerformance; + const currentGrossPerformancePercent = grossPerformancePercentage; + let currentNetPerformance = netPerformance; + let currentNetPerformancePercent = netPerformancePercentage; const historicalDataContainer = await this.getChart({ dateRange, @@ -1083,28 +1075,28 @@ export class PortfolioService { } return { + errors, + hasErrors, chart: historicalDataContainer.items.map( ({ date, - netPerformance, + netPerformance: netPerformanceOfItem, netPerformanceInPercentage, - totalInvestment, + totalInvestment: totalInvestmentOfItem, value }) => { return { date, - netPerformance, netPerformanceInPercentage, - totalInvestment, - value + value, + netPerformance: netPerformanceOfItem, + totalInvestment: totalInvestmentOfItem }; } ), - errors: currentPositions.errors, firstOrderDate: parseDate(historicalDataContainer.items[0]?.date), - hasErrors: currentPositions.hasErrors || hasErrors, performance: { - currentValue, + currentValue: currentValue.toNumber(), currentGrossPerformance: currentGrossPerformance.toNumber(), currentGrossPerformancePercent: currentGrossPerformancePercent.toNumber(), diff --git a/apps/client/src/app/components/home-overview/home-overview.component.ts b/apps/client/src/app/components/home-overview/home-overview.component.ts index eb8f0c81c..be1191b17 100644 --- a/apps/client/src/app/components/home-overview/home-overview.component.ts +++ b/apps/client/src/app/components/home-overview/home-overview.component.ts @@ -110,13 +110,12 @@ export class HomeOverviewComponent implements OnDestroy, OnInit { range: this.user?.settings?.dateRange }) .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((response) => { - this.errors = response.errors; - this.hasError = response.hasErrors; - this.performance = response.performance; + .subscribe(({ chart, errors, performance }) => { + this.errors = errors; + this.performance = performance; this.isLoadingPerformance = false; - this.historicalDataItems = response.chart.map( + this.historicalDataItems = chart.map( ({ date, netPerformanceInPercentage }) => { return { date, diff --git a/apps/client/src/app/components/home-overview/home-overview.html b/apps/client/src/app/components/home-overview/home-overview.html index 9a0cbb54c..6c0644021 100644 --- a/apps/client/src/app/components/home-overview/home-overview.html +++ b/apps/client/src/app/components/home-overview/home-overview.html @@ -37,7 +37,6 @@ [baseCurrency]="user?.settings?.baseCurrency" [deviceType]="deviceType" [errors]="errors" - [hasError]="hasError" [isAllTimeHigh]="isAllTimeHigh" [isAllTimeLow]="isAllTimeLow" [isLoading]="isLoadingPerformance" diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html index 5601e42cc..025259c23 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html @@ -3,14 +3,14 @@