Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/hide irrelevant errors in client (#1623)

Thomas Kaul6cd51fb04427
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1fb5bf6978..231873fd23 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 48f1e75071..9c659c1672 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 558a988ecf..3410be2203 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 eb8f0c81c4..be1191b170 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 9a0cbb54ce..6c06440212 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 5601e42cc0..025259c23b 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 @@
<div
class="flex-grow-1 status text-muted text-right"
[title]="
- hasError && !isLoading
+ errors?.length > 0 && !isLoading
? 'Sorry! Our data provider partner is experiencing the hiccups.'
: ''
"
(click)="errors?.length > 0 && onShowErrors()"
>
<ion-icon
- *ngIf="hasError && !isLoading"
+ *ngIf="errors?.length > 0 && !isLoading"
name="alert-circle-outline"
></ion-icon>
</div>
diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts
index 1d23236766..586d16ebff 100644
--- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts
+++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts
@@ -28,7 +28,6 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit {
@Input() baseCurrency: string;
@Input() deviceType: string;
@Input() errors: ResponseError['errors'];
- @Input() hasError: boolean;
@Input() isAllTimeHigh: boolean;
@Input() isAllTimeLow: boolean;
@Input() isLoading: boolean;