Browse Source

Refactoring

pull/2167/head
Thomas 2 years ago
parent
commit
15da8dbfbf
  1. 20
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts
  2. 20
      libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts

20
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) {

20
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<PortfolioPosition, 'type'> & {
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)
};
}
}

Loading…
Cancel
Save