Browse Source

resolve comments

pull/7076/head
KenTandrian 4 weeks ago
parent
commit
bce830b6dc
  1. 64
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

64
apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

@ -140,11 +140,13 @@ export class GfAllocationsPageComponent implements OnInit {
public constructor() { public constructor() {
this.route.queryParams this.route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params: AllocationsPageParams) => { .subscribe(
if (params.accountId && params.accountDetailDialog) { ({ accountId, accountDetailDialog }: AllocationsPageParams) => {
this.openAccountDetailDialog(params.accountId); if (accountId && accountDetailDialog) {
this.openAccountDetailDialog(accountId);
}
} }
}); );
} }
protected get worldMapChartFormat(): string { protected get worldMapChartFormat(): string {
@ -355,16 +357,7 @@ export class GfAllocationsPageComponent implements OnInit {
for (const [symbol, position] of Object.entries( for (const [symbol, position] of Object.entries(
this.portfolioDetails.holdings this.portfolioDetails.holdings
)) { )) {
let value = 0;
if (this.showValuesInPercentage()) {
value = position.allocationInPercentage;
} else {
value = position.valueInBaseCurrency ?? 0;
}
this.holdings[symbol] = { this.holdings[symbol] = {
value,
assetClass: assetClass:
position.assetProfile.assetClass || (UNKNOWN_KEY as AssetClass), position.assetProfile.assetClass || (UNKNOWN_KEY as AssetClass),
assetClassLabel: position.assetProfile.assetClassLabel ?? UNKNOWN_KEY, assetClassLabel: position.assetProfile.assetClassLabel ?? UNKNOWN_KEY,
@ -378,7 +371,10 @@ export class GfAllocationsPageComponent implements OnInit {
name: position.assetProfile.name name: position.assetProfile.name
}), }),
exchange: position.exchange, exchange: position.exchange,
name: position.assetProfile.name name: position.assetProfile.name,
value: this.showValuesInPercentage()
? position.allocationInPercentage
: (position.valueInBaseCurrency ?? 0)
}; };
// Prepare analysis data by continents, countries, holdings and sectors // Prepare analysis data by continents, countries, holdings and sectors
@ -386,44 +382,49 @@ export class GfAllocationsPageComponent implements OnInit {
if (position.assetProfile.countries.length > 0) { if (position.assetProfile.countries.length > 0) {
for (const country of position.assetProfile.countries) { for (const country of position.assetProfile.countries) {
const { code, continent, weight } = country; const { code, continent, weight } = country;
const val = const value =
(isNumber(position.valueInBaseCurrency) (isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency ? position.valueInBaseCurrency
: position.valueInPercentage) ?? 0; : position.valueInPercentage) ?? 0;
const continentData = this.continents[continent]; const continentData = this.continents[continent];
if (continentData) { if (continentData) {
continentData.value += weight * val; continentData.value += weight * value;
} else { } else {
this.continents[continent] = { this.continents[continent] = {
name: translate(continent), name: translate(continent),
value: weight * val value: weight * value
}; };
} }
const countryData = this.countries[code]; const countryData = this.countries[code];
if (countryData) { if (countryData) {
countryData.value += weight * val; countryData.value += weight * value;
} else { } else {
this.countries[code] = { this.countries[code] = {
name: getCountryName({ code }), name: getCountryName({ code }),
value: weight * val value: weight * value
}; };
} }
} }
} else { } else {
const val = const value =
(isNumber(position.valueInBaseCurrency) (isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency ? position.valueInBaseCurrency
: position.valueInPercentage) ?? 0; : position.valueInPercentage) ?? 0;
const continentData = this.continents[UNKNOWN_KEY]; const continentData = this.continents[UNKNOWN_KEY];
if (continentData) { if (continentData) {
continentData.value += val; continentData.value += value;
} }
const countryData = this.countries[UNKNOWN_KEY]; const countryData = this.countries[UNKNOWN_KEY];
if (countryData) { if (countryData) {
countryData.value += val; countryData.value += value;
} }
} }
@ -434,17 +435,18 @@ export class GfAllocationsPageComponent implements OnInit {
valueInBaseCurrency valueInBaseCurrency
} of position.assetProfile.holdings) { } of position.assetProfile.holdings) {
const normalizedAssetName = this.normalizeAssetName(name); const normalizedAssetName = this.normalizeAssetName(name);
const val = isNumber(valueInBaseCurrency) const value = isNumber(valueInBaseCurrency)
? valueInBaseCurrency ? valueInBaseCurrency
: allocationInPercentage * (position.valueInPercentage ?? 0); : allocationInPercentage * (position.valueInPercentage ?? 0);
const holdingData = this.topHoldingsMap[normalizedAssetName]; const holdingData = this.topHoldingsMap[normalizedAssetName];
if (holdingData) { if (holdingData) {
holdingData.value += val; holdingData.value += value;
} else { } else {
this.topHoldingsMap[normalizedAssetName] = { this.topHoldingsMap[normalizedAssetName] = {
name, name,
value: val value
}; };
} }
} }
@ -453,30 +455,32 @@ export class GfAllocationsPageComponent implements OnInit {
if (position.assetProfile.sectors.length > 0) { if (position.assetProfile.sectors.length > 0) {
for (const sector of position.assetProfile.sectors) { for (const sector of position.assetProfile.sectors) {
const { name, weight } = sector; const { name, weight } = sector;
const val = const value =
(isNumber(position.valueInBaseCurrency) (isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency ? position.valueInBaseCurrency
: position.valueInPercentage) ?? 0; : position.valueInPercentage) ?? 0;
const sectorData = this.sectors[name]; const sectorData = this.sectors[name];
if (sectorData) { if (sectorData) {
sectorData.value += weight * val; sectorData.value += weight * value;
} else { } else {
this.sectors[name] = { this.sectors[name] = {
name: translate(name), name: translate(name),
value: weight * val value: weight * value
}; };
} }
} }
} else { } else {
const val = const value =
(isNumber(position.valueInBaseCurrency) (isNumber(position.valueInBaseCurrency)
? position.valueInBaseCurrency ? position.valueInBaseCurrency
: position.valueInPercentage) ?? 0; : position.valueInPercentage) ?? 0;
const sectorData = this.sectors[UNKNOWN_KEY]; const sectorData = this.sectors[UNKNOWN_KEY];
if (sectorData) { if (sectorData) {
sectorData.value += val; sectorData.value += value;
} }
} }

Loading…
Cancel
Save