Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/replace lodash.uniq with Array.from + Set (#4387)
Szymon Łągiewka795e4582a800
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ea12f2ca90..8f58b23f8d 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- Improved the symbol validation in the _Yahoo Finance_ service (get asset profiles)+- Refactored `lodash.uniq` with `Array.from(new Set(...))`- Refreshed the cryptocurrencies list### Fixeddiff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.tsindex 54d80a9553..52d57230bc 100644--- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts+++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts@@ -49,7 +49,7 @@ import {min,subDays} from 'date-fns';-import { isNumber, sortBy, sum, uniq, uniqBy } from 'lodash';+import { isNumber, sortBy, sum, uniqBy } from 'lodash';export abstract class PortfolioCalculator {protected static readonly ENABLE_LOGGING = false;@@ -222,7 +222,7 @@ export abstract class PortfolioCalculator {const exchangeRatesByCurrency =await this.exchangeRateDataService.getExchangeRatesByCurrency({- currencies: uniq(Object.values(currencies)),+ currencies: Array.from(new Set(Object.values(currencies))),endDate: endOfDay(this.endDate),startDate: this.startDate,targetCurrency: this.currencydiff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.tsindex e90ebd4ae5..a3d9e3c4a0 100644--- a/apps/api/src/app/portfolio/portfolio.service.ts+++ b/apps/api/src/app/portfolio/portfolio.service.ts@@ -82,7 +82,7 @@ import {parseISO,set} from 'date-fns';-import { isEmpty, uniq } from 'lodash';+import { isEmpty } from 'lodash';import { PortfolioCalculator } from './calculator/portfolio-calculator';import {@@ -2032,14 +2032,16 @@ export class PortfolioService {where: { id: filters[0].id }});} else {- const accountIds = uniq(- activities- .filter(({ accountId }) => {- return accountId;- })- .map(({ accountId }) => {- return accountId;- })+ const accountIds = Array.from(+ new Set(+ activities+ .filter(({ accountId }) => {+ return accountId;+ })+ .map(({ accountId }) => {+ return accountId;+ })+ ));currentAccounts = await this.accountService.accounts({diff --git a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.tsindex db95a34872..0a2d177ce2 100644--- a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts+++ b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts@@ -23,7 +23,7 @@ import {isToday,subDays} from 'date-fns';-import { isNumber, uniq } from 'lodash';+import { isNumber } from 'lodash';import ms from 'ms';@Injectable()@@ -515,7 +515,7 @@ export class ExchangeRateDataService {}}- return uniq(currencies).filter(Boolean).sort();+ return Array.from(new Set(currencies)).filter(Boolean).sort();}private prepareCurrencyPairs(aCurrencies: string[]) {diff --git a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.tsindex b0f69fa5ce..e845545775 100644--- a/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts+++ b/apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts@@ -20,7 +20,6 @@ import {} from '@angular/forms';import { MatDialogRef } from '@angular/material/dialog';import { isISO4217CurrencyCode } from 'class-validator';-import { uniq } from 'lodash';import { Subject, takeUntil } from 'rxjs';import { CreateAssetProfileDialogMode } from './interfaces/interfaces';@@ -87,7 +86,9 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {this.createAssetProfileForm.get('addCurrency').value as string).toUpperCase();- const currencies = uniq([...this.customCurrencies, currency]).sort();+ const currencies = Array.from(+ new Set([...this.customCurrencies, currency])+ ).sort();this.dataService.putAdminSetting(PROPERTY_CURRENCIES, {diff --git a/apps/client/src/app/components/user-account-settings/user-account-settings.component.ts b/apps/client/src/app/components/user-account-settings/user-account-settings.component.tsindex ced617117b..1ee23ff8aa 100644--- a/apps/client/src/app/components/user-account-settings/user-account-settings.component.ts+++ b/apps/client/src/app/components/user-account-settings/user-account-settings.component.ts@@ -24,7 +24,6 @@ import { FormBuilder, Validators } from '@angular/forms';import { MatSlideToggleChange } from '@angular/material/slide-toggle';import { MatSnackBar } from '@angular/material/snack-bar';import { format, parseISO } from 'date-fns';-import { uniq } from 'lodash';import ms from 'ms';import { EMPTY, Subject, throwError } from 'rxjs';import { catchError, takeUntil } from 'rxjs/operators';@@ -108,7 +107,7 @@ export class UserAccountSettingsComponent implements OnDestroy, OnInit {);this.locales.push(this.user.settings.locale);- this.locales = uniq(this.locales.sort());+ this.locales = Array.from(new Set(this.locales)).sort();this.changeDetectorRef.markForCheck();}