Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/improve currency validation in search functionality of data provider service (#5745)

Thomas Kaul2ff02a0a9ce4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a555fa34b..38981a8c68 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Disabled the zoom functionality in the _Progressive Web App_ (PWA)
+- Improved the currency validation in the search functionality of the data provider service
- Optimized the get quotes functionality by utilizing the asset profile resolutions in the _Financial Modeling Prep_ service
- Extracted the footer to a component
diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts
index 8754c35372..c70d643db7 100644
--- a/apps/api/src/services/data-provider/data-provider.service.ts
+++ b/apps/api/src/services/data-provider/data-provider.service.ts
@@ -645,8 +645,11 @@ export class DataProviderService implements OnModuleInit {
const filteredItems = lookupItems
.filter(({ currency }) => {
- // Only allow symbols with supported currency
- return currency ? true : false;
+ if (includeIndices) {
+ return true;
+ }
+
+ return currency ? isCurrency(currency) : false;
})
.map((lookupItem) => {
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts
index e5dc187ff6..97b762267a 100644
--- a/libs/common/src/lib/helper.ts
+++ b/libs/common/src/lib/helper.ts
@@ -1,7 +1,7 @@
-import * as currencies from '@dinero.js/currencies';
import { NumberParser } from '@internationalized/number';
import { Type as ActivityType, DataSource, MarketData } from '@prisma/client';
import { Big } from 'big.js';
+import { isISO4217CurrencyCode } from 'class-validator';
import {
getDate,
getMonth,
@@ -340,8 +340,12 @@ export function interpolate(template: string, context: any) {
});
}
-export function isCurrency(aCurrency = '') {
- return currencies[aCurrency] || isDerivedCurrency(aCurrency);
+export function isCurrency(aCurrency: string) {
+ if (!aCurrency) {
+ return false;
+ }
+
+ return isISO4217CurrencyCode(aCurrency) || isDerivedCurrency(aCurrency);
}
export function isDerivedCurrency(aCurrency: string) {
diff --git a/package-lock.json b/package-lock.json
index 75e1f50fe8..e65c23ac7a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -28,7 +28,6 @@
"@dfinity/candid": "0.15.7",
"@dfinity/identity": "0.15.7",
"@dfinity/principal": "0.15.7",
- "@dinero.js/currencies": "2.0.0-alpha.8",
"@internationalized/number": "3.6.3",
"@ionic/angular": "8.7.3",
"@keyv/redis": "4.4.0",
@@ -5018,12 +5017,6 @@
"ts-node": "^10.8.2"
}
},
- "node_modules/@dinero.js/currencies": {
- "version": "2.0.0-alpha.8",
- "resolved": "https://registry.npmjs.org/@dinero.js/currencies/-/currencies-2.0.0-alpha.8.tgz",
- "integrity": "sha512-zApiqtuuPwjiM9LJA5/kNcT48VSHRiz2/mktkXjIpfxrJKzthXybUAgEenExIH6dYhLDgVmsLQZtZFOsdYl0Ag==",
- "license": "MIT"
- },
"node_modules/@discoveryjs/json-ext": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.6.3.tgz",
diff --git a/package.json b/package.json
index 28968c2c0a..cb0ba67311 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,6 @@
"@dfinity/candid": "0.15.7",
"@dfinity/identity": "0.15.7",
"@dfinity/principal": "0.15.7",
- "@dinero.js/currencies": "2.0.0-alpha.8",
"@internationalized/number": "3.6.3",
"@ionic/angular": "8.7.3",
"@keyv/redis": "4.4.0",