Browse Source

chore: refactor code

pull/2581/head
Dhoni77 2 years ago
parent
commit
2be4fd488e
  1. 38
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  2. 2
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html

38
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts

@ -26,8 +26,8 @@ import {
} from '@prisma/client';
import { format } from 'date-fns';
import { parse as csvToJson } from 'papaparse';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { EMPTY, Subject } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators';
import { AssetProfileDialogParams } from './interfaces/interfaces';
@ -51,12 +51,12 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
assetClass: new FormControl<AssetClass>(undefined),
assetSubClass: new FormControl<AssetSubClass>(undefined),
comment: '',
name: ['', Validators.required],
scraperConfiguration: '',
symbolMapping: '',
historicalData: this.formBuilder.group({
csvString: ''
})
}),
name: ['', Validators.required],
scraperConfiguration: '',
symbolMapping: ''
});
public assetProfileSubClass: string;
public benchmarks: Partial<SymbolProfile>[];
@ -132,14 +132,14 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
assetClass: this.assetProfile.assetClass ?? null,
assetSubClass: this.assetProfile.assetSubClass ?? null,
comment: this.assetProfile?.comment ?? '',
historicalData: {
csvString: AssetProfileDialog.HISTORICAL_DATA_TEMPLATE
},
name: this.assetProfile.name ?? this.assetProfile.symbol,
scraperConfiguration: JSON.stringify(
this.assetProfile?.scraperConfiguration ?? {}
),
symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {}),
historicalData: {
csvString: AssetProfileDialog.HISTORICAL_DATA_TEMPLATE
}
symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {})
});
this.assetProfileForm.markAsPristine();
@ -188,12 +188,24 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
},
symbol: this.data.symbol
})
.pipe(takeUntil(this.unsubscribeSubject))
.pipe(
takeUntil(this.unsubscribeSubject),
catchError(({ error, message }) => {
this.snackBar.open(`${error}: ${message[0]}`, undefined, {
duration: 3000
});
return EMPTY;
})
)
.subscribe(() => {
this.initialize();
});
} catch (err) {
this.snackBar.open('Unable to parse data', undefined, { duration: 3000 });
} catch {
this.snackBar.open(
$localize`Oops! Could not parse historical data`,
undefined,
{ duration: 3000 }
);
}
}

2
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html

@ -73,7 +73,7 @@
color="accent"
mat-flat-button
type="button"
[disabled]="assetProfileForm.controls['symbolMapping']?.value === ''"
[disabled]="assetProfileForm.controls['historicalData']?.controls['csvString']?.value === ''"
(click)="onImportHistoricalData()"
>
<ng-container i18n>Import</ng-container>

Loading…
Cancel
Save