From 15da8dbfbf8a73fb682a386034f063171a596286 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sat, 22 Jul 2023 09:36:34 +0200 Subject: [PATCH] Refactoring --- .../allocations/allocations-page.component.ts | 20 +++++++++---------- .../portfolio-proportion-chart.component.ts | 20 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index b9dd990c5..c975cc45b 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -65,13 +65,8 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { public positions: { [symbol: string]: Pick< PortfolioPosition, - | 'assetClass' - | 'assetSubClass' - | 'currency' - | 'exchange' - | 'name' - | 'valueInBaseCurrency' - > & { etfProvider: string }; + 'assetClass' | 'assetSubClass' | 'currency' | 'exchange' | 'name' + > & { etfProvider: string; value: number }; }; public sectors: { [name: string]: { name: string; value: number }; @@ -81,7 +76,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { dataSource?: DataSource; name: string; symbol: string; - valueInBaseCurrency: number; + value: number; }; }; @@ -259,7 +254,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { [UNKNOWN_KEY]: { name: UNKNOWN_KEY, symbol: UNKNOWN_KEY, - valueInBaseCurrency: 0 + value: 0 } }; } @@ -296,7 +291,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } this.positions[symbol] = { - valueInBaseCurrency: value, + value, assetClass: position.assetClass, assetSubClass: position.assetSubClass, currency: position.currency, @@ -389,7 +384,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { dataSource: position.dataSource, name: position.name, symbol: prettifySymbol(symbol), - valueInBaseCurrency: isNumber(position.valueInBaseCurrency) + value: isNumber(position.valueInBaseCurrency) ? position.valueInBaseCurrency : position.valueInPercentage }; @@ -425,6 +420,9 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { this.markets.emergingMarkets.value / marketsTotal; this.markets.otherMarkets.value = this.markets.otherMarkets.value / marketsTotal; + + console.log(this.positions); + console.log(this.symbols); } public onAccountChartClicked({ symbol }: UniqueAsset) { diff --git a/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts b/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts index b994338a7..dbdaeb85e 100644 --- a/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts +++ b/libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts @@ -44,12 +44,10 @@ export class PortfolioProportionChartComponent @Input() maxItems?: number; @Input() showLabels = false; @Input() positions: { - [symbol: string]: Pick< - PortfolioPosition, - 'type' | 'valueInBaseCurrency' - > & { + [symbol: string]: Pick & { dataSource?: DataSource; name: string; + value: number; }; } = {}; @@ -107,7 +105,7 @@ export class PortfolioProportionChartComponent chartData[this.positions[symbol][this.keys[0]].toUpperCase()].value = chartData[ this.positions[symbol][this.keys[0]].toUpperCase() - ].value.plus(this.positions[symbol].valueInBaseCurrency); + ].value.plus(this.positions[symbol].value); if ( chartData[this.positions[symbol][this.keys[0]].toUpperCase()] @@ -119,19 +117,19 @@ export class PortfolioProportionChartComponent chartData[ this.positions[symbol][this.keys[0]].toUpperCase() ].subCategory[this.positions[symbol][this.keys[1]]].value.plus( - this.positions[symbol].valueInBaseCurrency + this.positions[symbol].value ); } else { chartData[ this.positions[symbol][this.keys[0]].toUpperCase() ].subCategory[this.positions[symbol][this.keys[1]] ?? UNKNOWN_KEY] = - { value: new Big(this.positions[symbol].valueInBaseCurrency) }; + { value: new Big(this.positions[symbol].value) }; } } else { chartData[this.positions[symbol][this.keys[0]].toUpperCase()] = { name: this.positions[symbol][this.keys[0]], subCategory: {}, - value: new Big(this.positions[symbol].valueInBaseCurrency ?? 0) + value: new Big(this.positions[symbol].value ?? 0) }; if (this.positions[symbol][this.keys[1]]) { @@ -139,7 +137,7 @@ export class PortfolioProportionChartComponent this.positions[symbol][this.keys[0]].toUpperCase() ].subCategory = { [this.positions[symbol][this.keys[1]]]: { - value: new Big(this.positions[symbol]?.valueInBaseCurrency ?? 0) + value: new Big(this.positions[symbol]?.value ?? 0) } }; } @@ -147,7 +145,7 @@ export class PortfolioProportionChartComponent } else { if (chartData[UNKNOWN_KEY]) { chartData[UNKNOWN_KEY].value = chartData[UNKNOWN_KEY].value.plus( - this.positions[symbol].valueInBaseCurrency + this.positions[symbol].value ); } else { chartData[UNKNOWN_KEY] = { @@ -155,7 +153,7 @@ export class PortfolioProportionChartComponent subCategory: this.keys[1] ? { [this.keys[1]]: { value: new Big(0) } } : undefined, - value: new Big(this.positions[symbol].valueInBaseCurrency) + value: new Big(this.positions[symbol].value) }; } }