|
|
@ -11,8 +11,9 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
|
|
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
|
|
|
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
|
|
|
import { Currency } from '@prisma/client';
|
|
|
|
import { Currency } from '@prisma/client';
|
|
|
|
import { Observable, Subject } from 'rxjs';
|
|
|
|
import { EMPTY, Observable, Subject } from 'rxjs';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
|
|
|
|
catchError,
|
|
|
|
debounceTime,
|
|
|
|
debounceTime,
|
|
|
|
distinctUntilChanged,
|
|
|
|
distinctUntilChanged,
|
|
|
|
startWith,
|
|
|
|
startWith,
|
|
|
@ -49,7 +50,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTransactionDialogParams
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTransactionDialogParams
|
|
|
|
) {}
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
public ngOnInit() {
|
|
|
|
const { currencies, platforms } = this.dataService.fetchInfo();
|
|
|
|
const { currencies, platforms } = this.dataService.fetchInfo();
|
|
|
|
|
|
|
|
|
|
|
|
this.currencies = currencies;
|
|
|
|
this.currencies = currencies;
|
|
|
@ -84,17 +85,45 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|
|
|
this.data.transaction.unitPrice = this.currentMarketPrice;
|
|
|
|
this.data.transaction.unitPrice = this.currentMarketPrice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public onBlurSymbol() {
|
|
|
|
|
|
|
|
const symbol = this.searchSymbolCtrl.value;
|
|
|
|
|
|
|
|
this.updateSymbol(symbol);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public onCancel(): void {
|
|
|
|
public onCancel(): void {
|
|
|
|
this.dialogRef.close();
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public onUpdateSymbol(event: MatAutocompleteSelectedEvent) {
|
|
|
|
public onUpdateSymbol(event: MatAutocompleteSelectedEvent) {
|
|
|
|
|
|
|
|
this.updateSymbol(event.option.value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private updateSymbol(symbol: string) {
|
|
|
|
this.isLoading = true;
|
|
|
|
this.isLoading = true;
|
|
|
|
this.data.transaction.symbol = event.option.value;
|
|
|
|
|
|
|
|
|
|
|
|
this.data.transaction.symbol = symbol;
|
|
|
|
|
|
|
|
|
|
|
|
this.dataService
|
|
|
|
this.dataService
|
|
|
|
.fetchSymbolItem(this.data.transaction.symbol)
|
|
|
|
.fetchSymbolItem(this.data.transaction.symbol)
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.pipe(
|
|
|
|
|
|
|
|
catchError(() => {
|
|
|
|
|
|
|
|
this.data.transaction.currency = null;
|
|
|
|
|
|
|
|
this.data.transaction.dataSource = null;
|
|
|
|
|
|
|
|
this.data.transaction.unitPrice = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.isLoading = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return EMPTY;
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
takeUntil(this.unsubscribeSubject)
|
|
|
|
|
|
|
|
)
|
|
|
|
.subscribe(({ currency, dataSource, marketPrice }) => {
|
|
|
|
.subscribe(({ currency, dataSource, marketPrice }) => {
|
|
|
|
this.data.transaction.currency = currency;
|
|
|
|
this.data.transaction.currency = currency;
|
|
|
|
this.data.transaction.dataSource = dataSource;
|
|
|
|
this.data.transaction.dataSource = dataSource;
|
|
|
@ -105,17 +134,4 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public onUpdateSymbolByTyping(value: string) {
|
|
|
|
|
|
|
|
this.data.transaction.currency = null;
|
|
|
|
|
|
|
|
this.data.transaction.dataSource = null;
|
|
|
|
|
|
|
|
this.data.transaction.unitPrice = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.data.transaction.symbol = value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|