diff --git a/CHANGELOG.md b/CHANGELOG.md index ad8fa954..0108ad02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + +### Fixed + +- Fixed the functionality to delete an asset profile of a custom currency in the admin control panel + ## 2.143.0 - 2025-03-02 ### Added diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index ee79059f..7f2b0da5 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -109,7 +109,26 @@ export class AdminService { symbol }: AssetProfileIdentifier) { await this.marketDataService.deleteMany({ dataSource, symbol }); - await this.symbolProfileService.delete({ dataSource, symbol }); + + const currency = getCurrencyFromSymbol(symbol); + const customCurrencies = (await this.propertyService.getByKey( + PROPERTY_CURRENCIES + )) as string[]; + + if (customCurrencies.includes(currency)) { + const updatedCustomCurrencies = customCurrencies.filter( + (customCurrency) => { + return customCurrency !== currency; + } + ); + + await this.putSetting( + PROPERTY_CURRENCIES, + JSON.stringify(updatedCustomCurrencies) + ); + } else { + await this.symbolProfileService.delete({ dataSource, symbol }); + } } public async get(): Promise { diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts index 86965cd8..0e2cb7ef 100644 --- a/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts +++ b/apps/client/src/app/components/admin-market-data/admin-market-data.service.ts @@ -4,7 +4,8 @@ import { AdminService } from '@ghostfolio/client/services/admin.service'; import { ghostfolioScraperApiSymbolPrefix } from '@ghostfolio/common/config'; import { getCurrencyFromSymbol, - isDerivedCurrency + isDerivedCurrency, + isRootCurrency } from '@ghostfolio/common/helper'; import { AssetProfileIdentifier, @@ -77,6 +78,7 @@ export class AdminMarketDataService { activitiesCount === 0 && !isBenchmark && !isDerivedCurrency(getCurrencyFromSymbol(symbol)) && + !isRootCurrency(getCurrencyFromSymbol(symbol)) && !symbol.startsWith(ghostfolioScraperApiSymbolPrefix) ); } diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index bd0c7418..e5104a99 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -354,6 +354,16 @@ export function isDerivedCurrency(aCurrency: string) { }); } +export function isRootCurrency(aCurrency: string) { + if (aCurrency === 'USD') { + return true; + } + + return DERIVED_CURRENCIES.find(({ rootCurrency }) => { + return rootCurrency === aCurrency; + }); +} + export function parseDate(date: string): Date { if (!date) { return undefined;