|
3 | 3 | @using Services
|
4 | 4 | @using Utils
|
5 | 5 | @inject Microsoft.AspNetCore.Components.NavigationManager NavigationManager
|
| 6 | +@inject IPortfolioService PortfolioService |
6 | 7 |
|
7 | 8 | <style>
|
8 | 9 | .demo-mat-card {
|
|
29 | 30 |
|
30 | 31 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3"></div>
|
31 | 32 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6">
|
32 |
| - <MatCard class="demo-mat-card"> |
33 |
| - <MatCardContent> |
34 |
| - <div class="demo-mat-card-content"> |
35 |
| - <MatHeadline6 class="clear-margin"> |
36 |
| - <MatChipSet Style="align-items: center"> |
37 |
| - <MatH5 Class="clear-margin">@activePortfolio.Name</MatH5> |
38 |
| - <MatChip Style="vertical-align: center" Label="@CurrencyUtils.GetCurrencyLabel(activePortfolio.Currency)"/> |
39 |
| - </MatChipSet> |
40 |
| - </MatHeadline6> |
41 |
| - </div> |
42 |
| - |
43 |
| - <MatBody2 class="demo-mat-card-content clear-margin"> |
44 |
| - <div class="mat-layout-grid"> |
45 |
| - <div class="mat-layout-grid-inner" style="align-items: center"> |
46 |
| - <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6"> |
47 |
| - <MatH4 Class="clear-margin">@(CurrencyUtils.Format(portfolioSummary.MarketValue, activePortfolio.Currency))</MatH4> |
48 |
| - </div> |
49 |
| - <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6" style="text-align: end"> |
50 |
| - @(portfolioSummary.RelativeChange * 100m) % |
| 33 | + @if (activePortfolio != null) |
| 34 | + { |
| 35 | + <MatCard class="demo-mat-card"> |
| 36 | + <MatCardContent> |
| 37 | + <div class="demo-mat-card-content"> |
| 38 | + <MatHeadline6 class="clear-margin"> |
| 39 | + <MatChipSet Style="align-items: center"> |
| 40 | + <MatH5 Class="clear-margin">@activePortfolio.Name</MatH5> |
| 41 | + <MatChip Style="vertical-align: center" Label="@CurrencyUtils.GetCurrencyLabel(activePortfolio.Currency)"/> |
| 42 | + </MatChipSet> |
| 43 | + </MatHeadline6> |
| 44 | + </div> |
| 45 | + |
| 46 | + <MatBody2 class="demo-mat-card-content clear-margin"> |
| 47 | + <div class="mat-layout-grid"> |
| 48 | + <div class="mat-layout-grid-inner" style="align-items: center"> |
| 49 | + <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6"> |
| 50 | + <MatH4 Class="clear-margin">@(CurrencyUtils.Format(portfolioSummary.MarketValue, activePortfolio.Currency))</MatH4> |
| 51 | + </div> |
| 52 | + <div class="mat-layout-grid-cell mat-layout-grid-cell-span-6" style="text-align: end"> |
| 53 | + @(portfolioSummary.RelativeChange * 100m) % |
| 54 | + </div> |
51 | 55 | </div>
|
52 | 56 | </div>
|
53 |
| - </div> |
54 |
| - </MatBody2> |
55 |
| - </MatCardContent> |
56 |
| - </MatCard> |
57 |
| - <MatTable Items="@portfolioEntryRows" Striped="true" AllowSelection="true" RowClass="tester" class="mat-elevation-z5" ShowPaging="false" PageSize="9999" SelectionChanged="SelectionChangedEvent"> |
58 |
| - <MatTableHeader> |
59 |
| - <th>Coin</th> |
60 |
| - <th>Price</th> |
61 |
| - <th>Change (1h)</th> |
62 |
| - <th>Holdings</th> |
63 |
| - </MatTableHeader> |
64 |
| - <MatTableRow> |
65 |
| - <td>@context.symbol.ToUpper()</td> |
66 |
| - <td>@(CurrencyUtils.Format(context.currentPrice, activePortfolio.Currency))</td> |
67 |
| - <td style='color: @(context.relativeChange >= 0 ? "#17a104" : "#FF0000")'>@context.relativeChange%</td> |
68 |
| - <td>@context.percentage%</td> |
69 |
| - </MatTableRow> |
70 |
| - </MatTable> |
| 57 | + </MatBody2> |
| 58 | + </MatCardContent> |
| 59 | + </MatCard> |
| 60 | + <MatTable Items="@portfolioEntryRows" Striped="true" AllowSelection="true" RowClass="tester" class="mat-elevation-z5" ShowPaging="false" PageSize="9999" SelectionChanged="SelectionChangedEvent"> |
| 61 | + <MatTableHeader> |
| 62 | + <th>Coin</th> |
| 63 | + <th>Price</th> |
| 64 | + <th>Change (1h)</th> |
| 65 | + <th>Holdings</th> |
| 66 | + </MatTableHeader> |
| 67 | + <MatTableRow> |
| 68 | + <td>@context.symbol.ToUpper()</td> |
| 69 | + <td>@(CurrencyUtils.Format(context.currentPrice, activePortfolio.Currency))</td> |
| 70 | + <td style='color: @(context.relativeChange >= 0 ? "#17a104" : "#FF0000")'>@context.relativeChange%</td> |
| 71 | + <td>@context.percentage%</td> |
| 72 | + </MatTableRow> |
| 73 | + </MatTable> |
| 74 | + } |
| 75 | + else |
| 76 | + { |
| 77 | + <MatProgressBar Indeterminate="true"></MatProgressBar> |
| 78 | + } |
71 | 79 | </div>
|
72 | 80 | <div class="mat-layout-grid-cell mat-layout-grid-cell-span-3"></div>
|
73 | 81 | </div>
|
74 | 82 | </div>
|
75 |
| -<MatFAB Class="app-fab--absolute" Icon="@MatIconNames.Add" Label="Add a new entry"></MatFAB> |
| 83 | +<MatFAB Class="app-fab--absolute" Icon="@MatIconNames.Add" Label="Add a new entry" OnClick='() => { NavigationManager.NavigateTo($"newportfolioentry/{activePortfolio.Id}"); }'></MatFAB> |
76 | 84 |
|
77 | 85 |
|
78 | 86 | @code
|
79 | 87 | {
|
80 |
| - protected Portfolio activePortfolio = new Portfolio("Main Portfolio", "My main portfolio to be used", Currency.Usd); |
| 88 | + protected Portfolio activePortfolio; |
81 | 89 |
|
82 | 90 | protected ISummaryService.Summary portfolioSummary = new(1341m, 1.8m, 9982.489m, 1000m);
|
83 | 91 |
|
|
110 | 118 |
|
111 | 119 | protected record PortfolioEntryRow(string symbol, decimal currentPrice, decimal relativeChange, decimal percentage);
|
112 | 120 |
|
| 121 | + protected override void OnInitialized() |
| 122 | + { |
| 123 | + activePortfolio = PortfolioService.GetPortfolios()[0]; |
| 124 | + } |
| 125 | + |
113 | 126 | protected override async Task OnInitializedAsync()
|
114 | 127 | {
|
115 | 128 | //_existingPortfolios = PortfolioService.GetPortfolios();
|
|
0 commit comments