Browse Source

Improve data reloading

pull/3314/head
Thomas Kaul 1 year ago
parent
commit
6b8bb30562
  1. 102
      apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts
  2. 2
      apps/client/src/app/pages/accounts/accounts-page.component.ts

102
apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts

@ -84,55 +84,10 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.dataService this.fetchAccount();
.fetchAccount(this.data.accountId)
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(
({
balance,
currency,
name,
Platform,
transactionCount,
value,
valueInBaseCurrency
}) => {
this.balance = balance;
this.currency = currency;
if (isNumber(balance) && isNumber(value)) {
this.equity = new Big(value).minus(balance).toNumber();
} else {
this.equity = null;
}
this.name = name;
this.platformName = Platform?.name ?? '-';
this.transactionCount = transactionCount;
this.valueInBaseCurrency = valueInBaseCurrency;
this.changeDetectorRef.markForCheck();
}
);
this.dataService
.fetchPortfolioHoldings({
filters: [
{
type: 'ACCOUNT',
id: this.data.accountId
}
]
})
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ holdings }) => {
this.holdings = holdings;
this.changeDetectorRef.markForCheck();
});
this.fetchAccountBalances(); this.fetchAccountBalances();
this.fetchActivities(); this.fetchActivities();
this.fetchPortfolioHoldings();
this.fetchPortfolioPerformance(); this.fetchPortfolioPerformance();
} }
@ -155,6 +110,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
}) })
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {
this.fetchAccount();
this.fetchAccountBalances(); this.fetchAccountBalances();
this.fetchPortfolioPerformance(); this.fetchPortfolioPerformance();
}); });
@ -165,6 +121,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
.deleteAccountBalance(aId) .deleteAccountBalance(aId)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {
this.fetchAccount();
this.fetchAccountBalances(); this.fetchAccountBalances();
this.fetchPortfolioPerformance(); this.fetchPortfolioPerformance();
}); });
@ -199,6 +156,39 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
this.fetchActivities(); this.fetchActivities();
} }
private fetchAccount() {
this.dataService
.fetchAccount(this.data.accountId)
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(
({
balance,
currency,
name,
Platform,
transactionCount,
value,
valueInBaseCurrency
}) => {
this.balance = balance;
this.currency = currency;
if (isNumber(balance) && isNumber(value)) {
this.equity = new Big(value).minus(balance).toNumber();
} else {
this.equity = null;
}
this.name = name;
this.platformName = Platform?.name ?? '-';
this.transactionCount = transactionCount;
this.valueInBaseCurrency = valueInBaseCurrency;
this.changeDetectorRef.markForCheck();
}
);
}
private fetchAccountBalances() { private fetchAccountBalances() {
this.dataService this.dataService
.fetchAccountBalances(this.data.accountId) .fetchAccountBalances(this.data.accountId)
@ -230,6 +220,24 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
}); });
} }
private fetchPortfolioHoldings() {
this.dataService
.fetchPortfolioHoldings({
filters: [
{
type: 'ACCOUNT',
id: this.data.accountId
}
]
})
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ holdings }) => {
this.holdings = holdings;
this.changeDetectorRef.markForCheck();
});
}
private fetchPortfolioPerformance() { private fetchPortfolioPerformance() {
this.isLoadingChart = true; this.isLoadingChart = true;

2
apps/client/src/app/pages/accounts/accounts-page.component.ts

@ -233,6 +233,8 @@ export class AccountsPageComponent implements OnDestroy, OnInit {
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {
this.fetchAccounts();
this.router.navigate(['.'], { relativeTo: this.route }); this.router.navigate(['.'], { relativeTo: this.route });
}); });
} }

Loading…
Cancel
Save