Skip to content

Commit bd7c697

Browse files
committed
Improved the PortfolioEntryDetail.razor page in such way that now when market orders are deleted the summary of the entry is automatically updated.
1 parent 94a4d5d commit bd7c697

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

WebFrontend/Pages/PortfolioEntryDetail.razor

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,19 @@
7373
<MatBody2 class="demo-mat-card-content clear-margin">
7474
<div class="mat-layout-grid">
7575
<div class="mat-layout-grid-inner" style="align-items: center">
76-
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-6">
77-
<MatH4 Class="clear-margin">@(CurrencyUtils.Format(entrySummary.MarketValue, ActivePortfolio.Currency))</MatH4>
78-
</div>
79-
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-6" style="text-align: end">
80-
@(entrySummary.RelativeChange * 100m) %
81-
</div>
76+
@if (entrySummary != null)
77+
{
78+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-6">
79+
<MatH4 Class="clear-margin">@(CurrencyUtils.Format(entrySummary.MarketValue, ActivePortfolio.Currency))</MatH4>
80+
</div>
81+
<div class="mat-layout-grid-cell mat-layout-grid-cell-span-6" style="text-align: end">
82+
@(entrySummary.RelativeChange * 100m) %
83+
</div>
84+
}
85+
else
86+
{
87+
<MatProgressCircle Indeterminate="true"/>
88+
}
8289
</div>
8390
</div>
8491
</MatBody2>
@@ -167,8 +174,22 @@
167174

168175
protected override async Task OnInitializedAsync()
169176
{
170-
// resolve the name of the cryptocurrency (using the symbol)
177+
// resolve the name of the cryptocurrency (using the symbol)
171178
portfolioEntryName = await CryptoNameResolver.Resolve(ActivePortfolioEntry.Symbol);
179+
180+
await UpdateEntrySummary();
181+
}
182+
183+
private void SetEntryLoading()
184+
{
185+
CurrentEntryAssetMarketEntry = null;
186+
tableRowsItems = null;
187+
entrySummary = null;
188+
StateHasChanged();
189+
}
190+
191+
private async Task UpdateEntrySummary()
192+
{
172193

173194
// fetch the price of the entry's asset
174195
// TODO null?
@@ -179,12 +200,14 @@
179200

180201
// get all orders of the portfolio entry
181202
var entryOrders = MarketOrderService.GetPortfolioEntryOrders(ActivePortfolioEntry.Id);
182-
203+
183204
// compute summaries of all orders in the entry
184-
var entrySummaries = entryOrders.Select(order => SummaryService.GetMarketOrderSummary(order, CurrentEntryAssetMarketEntry.CurrentPrice));
205+
var entrySummaries = entryOrders.Select(order =>
206+
SummaryService.GetMarketOrderSummary(order, CurrentEntryAssetMarketEntry.CurrentPrice));
185207

186208
// zip entry orders and summaries into a table rows
187-
tableRowsItems = entryOrders.Zip(entrySummaries).Select(tuple => new Tuple<MarketOrder, ISummaryService.Summary>(tuple.First, tuple.Second)).ToList();
209+
tableRowsItems = entryOrders.Zip(entrySummaries)
210+
.Select(tuple => new Tuple<MarketOrder, ISummaryService.Summary>(tuple.First, tuple.Second)).ToList();
188211

189212
// compute suummary of this entry
190213
entrySummary = SummaryService.GetPortfolioEntrySummary(entryOrders, CurrentEntryAssetMarketEntry.CurrentPrice);
@@ -200,8 +223,10 @@
200223
var result = await MatDialogService.ConfirmAsync("Do you really wish to delete this market order?");
201224
if (result)
202225
{
203-
// TODO update summary
204226
MarketOrderService.DeleteMarketOrder(order);
227+
SetEntryLoading();
228+
await UpdateEntrySummary();
229+
StateHasChanged();
205230
}
206231
}
207232
}

0 commit comments

Comments
 (0)