|
|
@ -1,6 +1,7 @@ |
|
|
|
import { AdminService } from '@ghostfolio/client/services/admin.service'; |
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
|
import { |
|
|
|
DEFAULT_CURRENCY, |
|
|
|
ghostfolioPrefix, |
|
|
|
PROPERTY_CURRENCIES |
|
|
|
} from '@ghostfolio/common/config'; |
|
|
@ -29,8 +30,9 @@ import { MatDialogModule, MatDialogRef } from '@angular/material/dialog'; |
|
|
|
import { MatFormFieldModule } from '@angular/material/form-field'; |
|
|
|
import { MatInputModule } from '@angular/material/input'; |
|
|
|
import { MatRadioModule } from '@angular/material/radio'; |
|
|
|
import { DataSource } from '@prisma/client'; |
|
|
|
import { isISO4217CurrencyCode } from 'class-validator'; |
|
|
|
import { Subject, takeUntil } from 'rxjs'; |
|
|
|
import { Subject, switchMap, takeUntil } from 'rxjs'; |
|
|
|
|
|
|
|
import { CreateAssetProfileDialogMode } from './interfaces/interfaces'; |
|
|
|
|
|
|
@ -56,6 +58,7 @@ export class GfCreateAssetProfileDialogComponent implements OnInit, OnDestroy { |
|
|
|
public mode: CreateAssetProfileDialogMode; |
|
|
|
|
|
|
|
private customCurrencies: string[]; |
|
|
|
private dataSourceForExchangeRates: DataSource; |
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
|
|
|
|
|
public constructor( |
|
|
@ -67,7 +70,7 @@ export class GfCreateAssetProfileDialogComponent implements OnInit, OnDestroy { |
|
|
|
) {} |
|
|
|
|
|
|
|
public ngOnInit() { |
|
|
|
this.initializeCustomCurrencies(); |
|
|
|
this.initialize(); |
|
|
|
|
|
|
|
this.createAssetProfileForm = this.formBuilder.group( |
|
|
|
{ |
|
|
@ -115,7 +118,15 @@ export class GfCreateAssetProfileDialogComponent implements OnInit, OnDestroy { |
|
|
|
.putAdminSetting(PROPERTY_CURRENCIES, { |
|
|
|
value: JSON.stringify(currencies) |
|
|
|
}) |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.pipe( |
|
|
|
switchMap(() => { |
|
|
|
return this.adminService.gatherSymbol({ |
|
|
|
dataSource: this.dataSourceForExchangeRates, |
|
|
|
symbol: `${DEFAULT_CURRENCY}${currency}` |
|
|
|
}); |
|
|
|
}), |
|
|
|
takeUntil(this.unsubscribeSubject) |
|
|
|
) |
|
|
|
.subscribe(() => { |
|
|
|
this.dialogRef.close(); |
|
|
|
}); |
|
|
@ -170,13 +181,19 @@ export class GfCreateAssetProfileDialogComponent implements OnInit, OnDestroy { |
|
|
|
return { atLeastOneValid: true }; |
|
|
|
} |
|
|
|
|
|
|
|
private initializeCustomCurrencies() { |
|
|
|
private initialize() { |
|
|
|
this.adminService |
|
|
|
.fetchAdminData() |
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
|
.subscribe(({ settings }) => { |
|
|
|
.subscribe(({ dataProviders, settings }) => { |
|
|
|
this.customCurrencies = settings[PROPERTY_CURRENCIES] as string[]; |
|
|
|
|
|
|
|
const { dataSource } = dataProviders.find(({ useForExchangeRates }) => { |
|
|
|
return useForExchangeRates; |
|
|
|
}); |
|
|
|
|
|
|
|
this.dataSourceForExchangeRates = dataSource; |
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
|
}); |
|
|
|
} |
|
|
|