From c91e20e32ed5ce1f598c715231ca9506a2b79b6a Mon Sep 17 00:00:00 2001 From: tobikugel Date: Mon, 23 Jun 2025 19:22:13 -0300 Subject: [PATCH] implements feature --- .../src/app/portfolio/portfolio.service.ts | 2 + apps/api/src/app/user/user.service.ts | 9 +++-- .../current-investment.ts | 37 +++++++++++++------ apps/client/src/app/pages/i18n/i18n-page.html | 10 +++++ 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 623a94f97..aed8e0acb 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1260,6 +1260,8 @@ export class PortfolioService { [ new AccountClusterRiskCurrentInvestment( this.exchangeRateDataService, + this.i18nService, + userSettings.language, accounts ), new AccountClusterRiskSingleAccount( diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts index 3f4dfc35e..46b46bce2 100644 --- a/apps/api/src/app/user/user.service.ts +++ b/apps/api/src/app/user/user.service.ts @@ -259,9 +259,12 @@ export class UserService { (user.Settings.settings as UserSettings).xRayRules = { AccountClusterRiskCurrentInvestment: - new AccountClusterRiskCurrentInvestment(undefined, {}).getSettings( - user.Settings.settings - ), + new AccountClusterRiskCurrentInvestment( + undefined, + undefined, + undefined, + {} + ).getSettings(user.Settings.settings), AccountClusterRiskSingleAccount: new AccountClusterRiskSingleAccount( undefined, undefined, diff --git a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts index 76b7e2f94..fb2ffac8d 100644 --- a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts @@ -1,6 +1,7 @@ import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { Rule } from '@ghostfolio/api/models/rule'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; +import { I18nService } from '@ghostfolio/api/services/i18n/i18n.service'; import { PortfolioDetails, PortfolioPosition, @@ -12,9 +13,12 @@ export class AccountClusterRiskCurrentInvestment extends Rule { public constructor( protected exchangeRateDataService: ExchangeRateDataService, + private i18nService: I18nService, + languageCode: string, accounts: PortfolioDetails['accounts'] ) { super(exchangeRateDataService, { + languageCode, key: AccountClusterRiskCurrentInvestment.name }); @@ -56,21 +60,29 @@ export class AccountClusterRiskCurrentInvestment extends Rule { if (maxInvestmentRatio > ruleSettings.thresholdMax) { return { - evaluation: `Over ${ - ruleSettings.thresholdMax * 100 - }% of your current investment is at ${maxItem.name} (${( - maxInvestmentRatio * 100 - ).toPrecision(3)}%)`, + evaluation: this.i18nService.getTranslation({ + id: 'rule.accountClusterRiskCurrentInvestment.false', + languageCode: this.getLanguageCode(), + placeholders: { + maxInvestmentRatio: (maxInvestmentRatio * 100).toPrecision(3), + maxItemName: maxItem.name, + thresholdMax: ruleSettings.thresholdMax * 100 + } + }), value: false }; } return { - evaluation: `The major part of your current investment is at ${ - maxItem.name - } (${(maxInvestmentRatio * 100).toPrecision(3)}%) and does not exceed ${ - ruleSettings.thresholdMax * 100 - }%`, + evaluation: this.i18nService.getTranslation({ + id: 'rule.accountClusterRiskCurrentInvestment.true', + languageCode: this.getLanguageCode(), + placeholders: { + maxInvestmentRatio: (maxInvestmentRatio * 100).toPrecision(3), + maxItemName: maxItem.name, + thresholdMax: ruleSettings.thresholdMax * 100 + } + }), value: true }; } @@ -88,7 +100,10 @@ export class AccountClusterRiskCurrentInvestment extends Rule { } public getName() { - return 'Investment'; + return this.i18nService.getTranslation({ + id: 'rule.accountClusterRiskCurrentInvestment', + languageCode: this.getLanguageCode() + }); } public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings { diff --git a/apps/client/src/app/pages/i18n/i18n-page.html b/apps/client/src/app/pages/i18n/i18n-page.html index 6ba581455..e4445bc01 100644 --- a/apps/client/src/app/pages/i18n/i18n-page.html +++ b/apps/client/src/app/pages/i18n/i18n-page.html @@ -11,6 +11,16 @@ performance, portfolio, software, stock, trading, wealth, web3
  • My Account
  • +
  • Investment
  • +
  • + Over ${thresholdMax}% of your current investment is at + ${maxItemName} (${maxInvestmentRatio}%) +
  • +
  • + The major part of your current investment is at ${maxItemName} + (${maxInvestmentRatio}%) and does not exceed + ${thresholdMax}% +
  • Single Account
  • Your net worth is managed by a single account