diff --git a/CHANGELOG.md b/CHANGELOG.md index e300109fe..9cec45a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Adapted the decimal places for cryptocurrencies in the position detail dialog + ## 1.73.0 - 10.11.2021 ### Changed diff --git a/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts b/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts index 45d27dbef..c3824802c 100644 --- a/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/portfolio-position-detail.interface.ts @@ -1,4 +1,8 @@ +import { AssetClass, AssetSubClass } from '@prisma/client'; + export interface PortfolioPositionDetail { + assetClass?: AssetClass; + assetSubClass?: AssetSubClass; averagePrice: number; currency: string; firstBuyDate: string; diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 2f5f77bca..eebab24cc 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1,5 +1,3 @@ -// TODO /////////// - import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface'; import { OrderService } from '@ghostfolio/api/app/order/order.service'; @@ -299,6 +297,8 @@ export class PortfolioService { }; } + const assetClass = orders[0].SymbolProfile?.assetClass; + const assetSubClass = orders[0].SymbolProfile?.assetSubClass; const positionCurrency = orders[0].currency; const name = orders[0].SymbolProfile?.name ?? ''; @@ -412,6 +412,8 @@ export class PortfolioService { } return { + assetClass, + assetSubClass, currency, firstBuyDate, grossPerformance, @@ -467,6 +469,8 @@ export class PortfolioService { } return { + assetClass, + assetSubClass, marketPrice, maxPrice, minPrice, diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts index 38ab958ac..7ea82e884 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts @@ -9,6 +9,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { DataService } from '@ghostfolio/client/services/data.service'; import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface'; +import { AssetSubClass } from '@prisma/client'; import { format, isSameMonth, isToday, parseISO } from 'date-fns'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -23,6 +24,7 @@ import { PositionDetailDialogParams } from './interfaces/interfaces'; styleUrls: ['./position-detail-dialog.component.scss'] }) export class PositionDetailDialog implements OnDestroy { + public assetSubClass: AssetSubClass; public averagePrice: number; public benchmarkDataItems: LineChartItem[]; public currency: string; @@ -38,6 +40,7 @@ export class PositionDetailDialog implements OnDestroy { public netPerformance: number; public netPerformancePercent: number; public quantity: number; + public quantityPrecision = 2; public symbol: string; public transactionCount: number; @@ -54,6 +57,7 @@ export class PositionDetailDialog implements OnDestroy { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe( ({ + assetSubClass, averagePrice, currency, firstBuyDate, @@ -71,6 +75,7 @@ export class PositionDetailDialog implements OnDestroy { symbol, transactionCount }) => { + this.assetSubClass = assetSubClass; this.averagePrice = averagePrice; this.benchmarkDataItems = []; this.currency = currency; @@ -146,6 +151,18 @@ export class PositionDetailDialog implements OnDestroy { this.benchmarkDataItems[0].value = this.averagePrice; } + if (Number.isInteger(this.quantity)) { + this.quantityPrecision = 0; + } else if (assetSubClass === 'CRYPTOCURRENCY') { + if (this.quantity < 1) { + this.quantityPrecision = 7; + } else if (this.quantity < 1000) { + this.quantityPrecision = 5; + } else if (this.quantity > 10000000) { + this.quantityPrecision = 0; + } + } + this.changeDetectorRef.markForCheck(); } ); diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html index 0994e50cf..32e249c6d 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html @@ -82,7 +82,7 @@ label="Quantity" size="medium" [locale]="data.locale" - [precision]="2" + [precision]="quantityPrecision" [value]="quantity" >