Browse Source

Feature/replace lodash.uniq with Array.from + Set (#4387)

* Replace lodash.uniq with Array.from + Set

* Update chagnelog
pull/4450/merge
Szymon Łągiewka 1 day ago
committed by GitHub
parent
commit
795e4582a8
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 4
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  3. 20
      apps/api/src/app/portfolio/portfolio.service.ts
  4. 4
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
  5. 5
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts
  6. 3
      apps/client/src/app/components/user-account-settings/user-account-settings.component.ts

1
CHANGELOG.md

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the symbol validation in the _Yahoo Finance_ service (get asset profiles) - Improved the symbol validation in the _Yahoo Finance_ service (get asset profiles)
- Refactored `lodash.uniq` with `Array.from(new Set(...))`
- Refreshed the cryptocurrencies list - Refreshed the cryptocurrencies list
### Fixed ### Fixed

4
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -49,7 +49,7 @@ import {
min, min,
subDays subDays
} from 'date-fns'; } from 'date-fns';
import { isNumber, sortBy, sum, uniq, uniqBy } from 'lodash'; import { isNumber, sortBy, sum, uniqBy } from 'lodash';
export abstract class PortfolioCalculator { export abstract class PortfolioCalculator {
protected static readonly ENABLE_LOGGING = false; protected static readonly ENABLE_LOGGING = false;
@ -222,7 +222,7 @@ export abstract class PortfolioCalculator {
const exchangeRatesByCurrency = const exchangeRatesByCurrency =
await this.exchangeRateDataService.getExchangeRatesByCurrency({ await this.exchangeRateDataService.getExchangeRatesByCurrency({
currencies: uniq(Object.values(currencies)), currencies: Array.from(new Set(Object.values(currencies))),
endDate: endOfDay(this.endDate), endDate: endOfDay(this.endDate),
startDate: this.startDate, startDate: this.startDate,
targetCurrency: this.currency targetCurrency: this.currency

20
apps/api/src/app/portfolio/portfolio.service.ts

@ -82,7 +82,7 @@ import {
parseISO, parseISO,
set set
} from 'date-fns'; } from 'date-fns';
import { isEmpty, uniq } from 'lodash'; import { isEmpty } from 'lodash';
import { PortfolioCalculator } from './calculator/portfolio-calculator'; import { PortfolioCalculator } from './calculator/portfolio-calculator';
import { import {
@ -2032,14 +2032,16 @@ export class PortfolioService {
where: { id: filters[0].id } where: { id: filters[0].id }
}); });
} else { } else {
const accountIds = uniq( const accountIds = Array.from(
activities new Set(
.filter(({ accountId }) => { activities
return accountId; .filter(({ accountId }) => {
}) return accountId;
.map(({ accountId }) => { })
return accountId; .map(({ accountId }) => {
}) return accountId;
})
)
); );
currentAccounts = await this.accountService.accounts({ currentAccounts = await this.accountService.accounts({

4
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

@ -23,7 +23,7 @@ import {
isToday, isToday,
subDays subDays
} from 'date-fns'; } from 'date-fns';
import { isNumber, uniq } from 'lodash'; import { isNumber } from 'lodash';
import ms from 'ms'; import ms from 'ms';
@Injectable() @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[]) { private prepareCurrencyPairs(aCurrencies: string[]) {

5
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'; } from '@angular/forms';
import { MatDialogRef } from '@angular/material/dialog'; import { MatDialogRef } from '@angular/material/dialog';
import { isISO4217CurrencyCode } from 'class-validator'; import { isISO4217CurrencyCode } from 'class-validator';
import { uniq } from 'lodash';
import { Subject, takeUntil } from 'rxjs'; import { Subject, takeUntil } from 'rxjs';
import { CreateAssetProfileDialogMode } from './interfaces/interfaces'; import { CreateAssetProfileDialogMode } from './interfaces/interfaces';
@ -87,7 +86,9 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
this.createAssetProfileForm.get('addCurrency').value as string this.createAssetProfileForm.get('addCurrency').value as string
).toUpperCase(); ).toUpperCase();
const currencies = uniq([...this.customCurrencies, currency]).sort(); const currencies = Array.from(
new Set([...this.customCurrencies, currency])
).sort();
this.dataService this.dataService
.putAdminSetting(PROPERTY_CURRENCIES, { .putAdminSetting(PROPERTY_CURRENCIES, {

3
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 { MatSlideToggleChange } from '@angular/material/slide-toggle';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
import { format, parseISO } from 'date-fns'; import { format, parseISO } from 'date-fns';
import { uniq } from 'lodash';
import ms from 'ms'; import ms from 'ms';
import { EMPTY, Subject, throwError } from 'rxjs'; import { EMPTY, Subject, throwError } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators'; 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.push(this.user.settings.locale);
this.locales = uniq(this.locales.sort()); this.locales = Array.from(new Set(this.locales)).sort();
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
} }

Loading…
Cancel
Save