Feature/increase decimal places for cryptocurrencies (#462)

* Calculate quantity precision

* Update changelog
pull/463/head
Thomas Kaul 3 years ago committed by GitHub
parent 7425ba94f1
commit cd76f89902
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -1,4 +1,8 @@
import { AssetClass, AssetSubClass } from '@prisma/client';
export interface PortfolioPositionDetail {
assetClass?: AssetClass;
assetSubClass?: AssetSubClass;
averagePrice: number;
currency: string;
firstBuyDate: string;

@ -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,

@ -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();
}
);

@ -82,7 +82,7 @@
label="Quantity"
size="medium"
[locale]="data.locale"
[precision]="2"
[precision]="quantityPrecision"
[value]="quantity"
></gf-value>
</div>

Loading…
Cancel
Save