Skip to content

Commit 41d2350

Browse files
committed
Added comments to reusable components.
Fixed page styles
1 parent 7e82ed5 commit 41d2350

11 files changed

+91
-40
lines changed

WebFrontend/Pages/EditMarketOrder.razor

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<MatCard>
2424
<MatCardContent class="demo-mat-card-content">
2525
<h2>Edit a market order</h2>
26-
<OrderForm Edit="true" FormModel="@_initialOrderModel" Currency="@_activePortfolio.Currency" Symbol="@_activeEntry.Symbol" OnSubmitEventHandler="@OnCreateOrderFormSubmit"></OrderForm>
26+
<OrderForm Edit="true" FormModel="@_initialOrderFormModel" Currency="@_activePortfolio.Currency" Symbol="@_activeEntry.Symbol" OnSubmitEventHandler="@OnCreateOrderFormSubmit"></OrderForm>
2727
</MatCardContent>
2828
</MatCard>
2929
</div>
@@ -39,7 +39,7 @@
3939
public int OrderId { get; set; }
4040

4141
// order form model
42-
private OrderForm.NewOrderModel _initialOrderModel;
42+
private OrderForm.OrderFormModel _initialOrderFormModel;
4343

4444
// portfolio the order will belong to
4545
private Portfolio _activePortfolio;
@@ -58,23 +58,23 @@
5858
_activePortfolio = PortfolioService.GetPortfolio(_activeEntry.PortfolioId);
5959

6060
// initialize the order form model
61-
_initialOrderModel = new();
62-
_initialOrderModel.Fee = _activeMarketOrder.Fee;
63-
_initialOrderModel.Size = _activeMarketOrder.Size;
64-
_initialOrderModel.FilledPrice = _activeMarketOrder.FilledPrice;
65-
_initialOrderModel.OrderDate = _activeMarketOrder.Date;
66-
_initialOrderModel.SellOrder = !_activeMarketOrder.Buy;
61+
_initialOrderFormModel = new();
62+
_initialOrderFormModel.Fee = _activeMarketOrder.Fee;
63+
_initialOrderFormModel.Size = _activeMarketOrder.Size;
64+
_initialOrderFormModel.FilledPrice = _activeMarketOrder.FilledPrice;
65+
_initialOrderFormModel.OrderDate = _activeMarketOrder.Date;
66+
_initialOrderFormModel.SellOrder = !_activeMarketOrder.Buy;
6767
}
6868

69-
private void OnCreateOrderFormSubmit(OrderForm.NewOrderModel formModel)
69+
private void OnCreateOrderFormSubmit(OrderForm.OrderFormModel formFormModel)
7070
{
7171
// update the order
7272
MarketOrderService.UpdateMarketOrder(_activeMarketOrder with {
73-
FilledPrice = formModel.FilledPrice,
74-
Fee = formModel.Fee,
75-
Size = formModel.Size,
76-
Date = formModel.OrderDate,
77-
Buy = !formModel.SellOrder
73+
FilledPrice = formFormModel.FilledPrice,
74+
Fee = formFormModel.Fee,
75+
Size = formFormModel.Size,
76+
Date = formFormModel.OrderDate,
77+
Buy = !formFormModel.SellOrder
7878
});
7979
Toaster.Add("Order successfully edited", MatToastType.Success, "", "");
8080

WebFrontend/Pages/EditPortfolio.razor

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@
99

1010

1111
<style>
12+
.demo-mat-card {
13+
max-width: 400px;
14+
margin-bottom: 2em;
15+
}
16+
1217
.demo-mat-card-content {
1318
padding: 1rem;
1419
}
20+
21+
.clear-margin {
22+
margin: 0px;
23+
}
1524
</style>
1625

1726
<div class="mat-layout-grid">
@@ -27,7 +36,7 @@
2736
<PortfolioForm
2837
DefaultCurrency="@Currency.Usd"
2938
AvailableCurrencies="@(EnumUtils.GetEnumList<Currency>())"
30-
FormModel="_formModel"
39+
FormModel="_formFormModel"
3140
Edit="true"
3241
OnSubmitEventHandler="@OnCreateFormSubmitted">
3342
</PortfolioForm>
@@ -46,7 +55,7 @@
4655
public int PortfolioId { get; set; }
4756

4857
// model of the form
49-
private readonly PortfolioForm.NewPortfolioModel _formModel = new(Currency.Usd);
58+
private readonly PortfolioForm.PortfolioFormModel _formFormModel = new(Currency.Usd);
5059

5160
// currently edited portfolio
5261
private Portfolio _activePortfolio;
@@ -57,19 +66,19 @@
5766
_activePortfolio = PortfolioService.GetPortfolio(PortfolioId);
5867

5968
// update the form model
60-
_formModel.Name = _activePortfolio.Name;
61-
_formModel.Description = _activePortfolio.Description;
69+
_formFormModel.Name = _activePortfolio.Name;
70+
_formFormModel.Description = _activePortfolio.Description;
6271
}
6372

64-
private void OnCreateFormSubmitted(PortfolioForm.NewPortfolioModel formModel)
73+
private void OnCreateFormSubmitted(PortfolioForm.PortfolioFormModel formFormModel)
6574
{
6675
// update the portfolio
6776
PortfolioService.UpdatePortfolio(_activePortfolio with {
68-
Name = formModel.Name,
69-
Description = formModel.Description
77+
Name = formFormModel.Name,
78+
Description = formFormModel.Description
7079
});
7180
// reset the form
72-
formModel.Reset();
81+
formFormModel.Reset();
7382
Toaster.Add("Portfolio successfully edited", MatToastType.Success, "", "");
7483

7584
// navigate back to the portfolio detail

WebFrontend/Pages/Index.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
bottom: 1rem;
2727
right: 1rem;
2828
}
29+
30+
.mat-paper {
31+
display: flex;
32+
flex-direction: column;
33+
justify-content: center;
34+
align-items: center;
35+
padding: 1em;
36+
}
2937
</style>
3038
<div class="mat-layout-grid mat-layout-grid-align-center">
3139
<div class="mat-layout-grid-inner center">

WebFrontend/Pages/NewMarketOrder.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
_activePortfolio = PortfolioService.GetPortfolio(_activeEntry.PortfolioId);
5353
}
5454

55-
private void OnCreateOrderFormSubmit(OrderForm.NewOrderModel formModel)
55+
private void OnCreateOrderFormSubmit(OrderForm.OrderFormModel formFormModel)
5656
{
5757
// create the market order
58-
MarketOrderService.CreateMarketOrder(formModel.FilledPrice, formModel.Fee, formModel.Size, formModel.OrderDate, !formModel.SellOrder, _activeEntry.Id);
58+
MarketOrderService.CreateMarketOrder(formFormModel.FilledPrice, formFormModel.Fee, formFormModel.Size, formFormModel.OrderDate, !formFormModel.SellOrder, _activeEntry.Id);
5959
// reset the form model
60-
formModel.Reset();
60+
formFormModel.Reset();
6161
// notify user
6262
Toaster.Add("New order successfully added", MatToastType.Success, "", "");
6363
}

WebFrontend/Pages/NewPortfolio.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040

4141
@code
4242
{
43-
private void OnCreateFormSubmitted(PortfolioForm.NewPortfolioModel formModel)
43+
private void OnCreateFormSubmitted(PortfolioForm.PortfolioFormModel formFormModel)
4444
{
4545
// create the portfolio
46-
PortfolioService.CreatePortfolio(formModel.Name, formModel.Description, formModel.SelectedCurrency);
46+
PortfolioService.CreatePortfolio(formFormModel.Name, formFormModel.Description, formFormModel.SelectedCurrency);
4747
// reset the model
48-
formModel.Reset();
48+
formFormModel.Reset();
4949
// notify the user
5050
Toaster.Add("New portfolio successfully added", MatToastType.Success, "", "");
5151
}

WebFrontend/Pages/PortfolioDetail.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
bottom: 1rem;
3030
right: 1rem;
3131
}
32+
33+
.mat-paper {
34+
display: flex;
35+
flex-direction: column;
36+
justify-content: center;
37+
align-items: center;
38+
padding: 1em;
39+
}
3240
</style>
3341
<div class="mat-layout-grid mat-layout-grid-align-center">
3442
<div class="mat-layout-grid-inner center">

WebFrontend/Pages/PortfolioEntryDetail.razor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
bottom: 1rem;
3838
right: 1rem;
3939
}
40+
41+
.mat-paper {
42+
display: flex;
43+
flex-direction: column;
44+
justify-content: center;
45+
align-items: center;
46+
padding: 1em;
47+
}
4048
4149
</style>
4250
<div class="mat-layout-grid mat-layout-grid-align-center">

WebFrontend/Pages/PortfolioEntryManagement.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@
119119
protected override async Task OnInitializedAsync()
120120
{
121121
// find all available cryptocurrencies
122-
_availableCryptocurrencies = await CryptoStatsSource.GetAvailableCryptocurrencies();
122+
_availableCryptocurrencies = (await CryptoStatsSource.GetAvailableCryptocurrencies())
123+
// workaround till Coingecko removes binance-peg entries
124+
.Where(c => !c.Id.Contains("binance-peg")).ToList();
123125
_filteredCryptocurrencies = _availableCryptocurrencies;
124126
UpdateAvailableCryptocurrencies(_availableCryptocurrencies);
125127
}

WebFrontend/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"commandName": "Project",
2020
"dotnetRunMessages": "true",
2121
"launchBrowser": false,
22-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
22+
"applicationUrl": "http://localhost:5001;http://localhost:5000",
2323
"environmentVariables": {
2424
"ASPNETCORE_ENVIRONMENT": "Development"
2525
}

WebFrontend/Shared/OrderForm.razor

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,34 +56,44 @@
5656
</EditForm>
5757

5858
@code {
59+
// model of the form
5960
[Parameter]
60-
public NewOrderModel FormModel { get; set; } = new ();
61+
public OrderFormModel FormModel { get; set; } = new ();
6162

62-
[Parameter] public EventCallback<NewOrderModel> OnSubmitEventHandler { get; set; }
63+
// callback when the form is submitted
64+
[Parameter] public EventCallback<OrderFormModel> OnSubmitEventHandler { get; set; }
6365

66+
// currency of the transaction
6467
[Parameter] public Currency Currency { get; set; }
6568

69+
// traded cryptocurrency symbol
6670
[Parameter] public string Symbol { get; set; }
6771

72+
// flag indicating whether the order should be created or an existing one should be edited
6873
[Parameter] public bool Edit { get; set; }
6974

7075

71-
public class NewOrderModel
76+
public class OrderFormModel
7277
{
78+
// transaction filled price
7379
[Required]
74-
[CustomValidation(typeof(NewOrderModel), nameof(NonZeroValue))]
80+
[CustomValidation(typeof(OrderFormModel), nameof(NonZeroValue))]
7581
public decimal FilledPrice { get; set; }
7682

83+
// size of the transaction
7784
[Required]
78-
[CustomValidation(typeof(NewOrderModel), nameof(NonZeroValue))]
85+
[CustomValidation(typeof(OrderFormModel), nameof(NonZeroValue))]
7986
public decimal Size { get; set; }
8087

88+
// fee for the transaction
8189
[Required]
82-
[CustomValidation(typeof(NewOrderModel), nameof(NonNegativeValue))]
90+
[CustomValidation(typeof(OrderFormModel), nameof(NonNegativeValue))]
8391
public decimal Fee { get; set; }
8492

93+
// date at which the transaction was performed
8594
[Required] public DateTime OrderDate = DateTime.Now;
8695

96+
// a flag indicating whether the transaction was a sell
8797
[Required] public bool SellOrder;
8898

8999
public void Reset()

0 commit comments

Comments
 (0)