Skip to content

Commit

Permalink
move IRSData, apiKey to global from per profile
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jun 24, 2023
1 parent 58a3b1f commit 52add5d
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 130 deletions.
10 changes: 5 additions & 5 deletions Pages/Portfolio-Review.razor
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool
// reload is a workaround where the correct data seemed to be deleted, but i needed to navigate away and then back to retirement-assets
Navigation.NavigateTo("/portfolio-review/retirement-assets");
}
@if (steps == null || familyData == null)
@if (steps == null || appData == null)
{
<p><em>Loading...</em></p>
}
Expand Down Expand Up @@ -439,7 +439,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool

<label>Target Year:</label> <select @bind=familyData.Year><option>2022</option><option>2023</option></select><br/>

@foreach (var taxFiler in familyData.IRSData.TaxRateData.TaxData.TaxFilers)
@foreach (var taxFiler in familyData.AppData.IRSData.TaxRateData.TaxData.TaxFilers)
{
bool isMatch = false;
switch (familyData.TaxFilingStatus.ToString())
Expand Down Expand Up @@ -1130,8 +1130,8 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool
}

private async Task UpdatePrice(MouseEventArgs e, Investment investment) {
if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey)) {
var quoteDataJson = await Http.GetStreamAsync($"https://api.bogle.tools/api/getquotes?ticker={investment.Ticker}&apikey={familyData.EODHistoricalDataApiKey}");
if (!string.IsNullOrEmpty(appData.EODHistoricalDataApiKey)) {
var quoteDataJson = await Http.GetStreamAsync($"https://api.bogle.tools/api/getquotes?ticker={investment.Ticker}&apikey={appData.EODHistoricalDataApiKey}");
var quoteData = await JsonSerializer.DeserializeAsync<QuoteData>(quoteDataJson);
if (quoteData?.Close != null) {
investment.Price = quoteData.Close;
Expand Down Expand Up @@ -1238,7 +1238,7 @@ Portfolio Review@(stepPath==null?"":": "+stepPath.Replace('-',' ')) - bogle.tool
};
var topicJsonUri = "https://raw.githubusercontent.com/bogle-tools/financial-variables/main/data/portfolios/" + topicStr + ".json";
var stream = await Http.GetStreamAsync(topicJsonUri);
familyData = await FamilyData.LoadFromJsonStream(familyData, stream, options);
familyData = await FamilyData.LoadFromJsonStream(appData, stream, options);
}

private async Task CopyTextToClipboard()
Expand Down
34 changes: 17 additions & 17 deletions Pages/Portfolio.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
// reload is a workaround where the correct data seemed to be deleted, but i needed to navigate away and then back to retirement-assets
Navigation.NavigateTo("/portfolio/retirement-assets");
}
@if (steps == null || familyData == null)
@if (steps == null || appData == null)
{
<p><em>Loading...</em></p>
}
Expand All @@ -65,11 +65,9 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
Portfolio (<a href=/profiles title="profile name" @onclick=navWithBackStack @onclick:preventDefault >@appData.CurrentProfileName</a>)<br/>
</h4>

<p>Track and optimize your finances.</p>
<p>Track and optimize your finances. (Press ✏️ to edit)</p>

<div>
<p>Press ✏️ links to modify info:</p>

<table id=_reviewTable>
@foreach (var step in steps) {
var href = folderName + @step.step;
Expand Down Expand Up @@ -151,11 +149,11 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
</tr>
<tr>
<td>
@if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey))
@if (!string.IsNullOrEmpty(appData.EODHistoricalDataApiKey))
{
<button @onclick=@refreshPrices title=Refresh>🔃</button>
} else {
<a href="updated-quotes">Enable<br/>updates.</a>
<a href="updated-quotes">Enable<br/>updates</a>
}
</td>
<td style=text-align:right;padding-left:8px colspan=3>
Expand Down Expand Up @@ -194,11 +192,11 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
}
<tr>
<td>
@if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey))
@if (!string.IsNullOrEmpty(appData.EODHistoricalDataApiKey))
{
<button @onclick=@refreshPrices title=Refresh>🔃</button>
} else {
<a href="updated-quotes">Enable<br/>updates.</a>
<a href="updated-quotes">Enable<br/>updates</a>
}
</td>
<td style=text-align:right;padding-left:8px colspan=3>
Expand Down Expand Up @@ -226,11 +224,11 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
}
<tr>
<td>
@if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey))
@if (!string.IsNullOrEmpty(appData.EODHistoricalDataApiKey))
{
<button @onclick=@refreshPrices title=Refresh>🔃</button>
} else {
<a href="updated-quotes">Enable<br/>updates.</a>
<a href="updated-quotes">Enable<br/>updates</a>
}
</td>
<td style=text-align:right;padding-left:8px colspan="3">
Expand Down Expand Up @@ -379,7 +377,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too

<label>Target Year:</label> <select @bind=familyData.Year><option>2022</option><option>2023</option></select><br/>

@foreach (var taxFiler in familyData.IRSData.TaxRateData.TaxData.TaxFilers)
@foreach (var taxFiler in familyData.AppData.IRSData.TaxRateData.TaxData.TaxFilers)
{
bool isMatch = false;
switch (familyData.TaxFilingStatus.ToString())
Expand Down Expand Up @@ -1065,7 +1063,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too

private async Task UpdateInvestmentPrice(Investment investment)
{
var quoteDataJson = await Http.GetStreamAsync($"https://api.bogle.tools/api/getquotes?ticker={investment.Ticker}&apikey={familyData.EODHistoricalDataApiKey}");
var quoteDataJson = await Http.GetStreamAsync($"https://api.bogle.tools/api/getquotes?ticker={investment.Ticker}&apikey={appData.EODHistoricalDataApiKey}");
var quoteData = await JsonSerializer.DeserializeAsync<QuoteData>(quoteDataJson);
if (quoteData?.Close != null) {
investment.Price = quoteData.Close;
Expand All @@ -1082,13 +1080,14 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
}
private async Task UpdateInvestmentsPrice(string ticker, List<Investment> investments)
{
if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey)) {
var quoteDataJson = await Http.GetStreamAsync($"https://api.bogle.tools/api/getquotes?ticker={ticker}&apikey={familyData.EODHistoricalDataApiKey}");
if (!string.IsNullOrEmpty(appData.EODHistoricalDataApiKey)) {
var quoteDataJson = await Http.GetStreamAsync($"https://api.bogle.tools/api/getquotes?ticker={ticker}&apikey={appData.EODHistoricalDataApiKey}");
var quoteData = await JsonSerializer.DeserializeAsync<QuoteData>(quoteDataJson);
if (quoteData?.Close != null) {
foreach (var investment in investments) {
investment.Price = quoteData.Close;
if (quoteData.Volume == 0) {
bool isWeekend = DateTime.Now.DayOfWeek == DayOfWeek.Sunday || DateTime.Now.DayOfWeek == DayOfWeek.Saturday;
if (quoteData.Volume == 0 && !isWeekend) {
investment.PreviousClose = quoteData.Close;
investment.PercentChange = null;
}
Expand All @@ -1097,6 +1096,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
investment.PreviousClose = quoteData.PreviousClose;
investment.PercentChange = quoteData.ChangeP;
}

if (quoteData.Timestamp != null) {
investment.LastUpdated = UnixTimeStampToDateTime(quoteData.Timestamp);
}
Expand All @@ -1107,7 +1107,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
}

private async Task UpdatePrice(MouseEventArgs e, Investment investment) {
if (!string.IsNullOrEmpty(familyData.EODHistoricalDataApiKey)) {
if (!string.IsNullOrEmpty(appData.EODHistoricalDataApiKey)) {
UpdateInvestmentPrice(investment);
}
}
Expand Down Expand Up @@ -1210,7 +1210,7 @@ Portfolio@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.too
};
var topicJsonUri = "https://raw.githubusercontent.com/bogle-tools/financial-variables/main/data/portfolios/" + topicStr + ".json";
var stream = await Http.GetStreamAsync(topicJsonUri);
familyData = await FamilyData.LoadFromJsonStream(familyData, stream, options);
familyData = await FamilyData.LoadFromJsonStream(appData, stream, options);
}

private async Task CopyTextToClipboard()
Expand Down
90 changes: 49 additions & 41 deletions Pages/Profiles.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,56 @@

<h1>bogle.tools profiles</h1>

Click on profile name to make it the active profile. You'll be navigated back to your prior page.<br/>

<table>
<tr>
<th></th>
<th>Name</th>
<th>Action</th>
</tr>
@foreach(var profileName in appData.ProfileNames)
@if (appData.ProfileNames != null && appData.ProfileNames.Count > 0)
{
<tr>
<td>
@if(profileName==appData.CurrentProfileName){<b>&nbsp;[active]&nbsp;</b>}
</td>
<td>
@if (renameProfileName == profileName)
{
<EditForm Model="appData">
<InputText @bind-Value=newName />
</EditForm>
}
else
{
<a href=/portfolio @onclick="@(e=>makeProfileActive(e,profileName))" @onclick:preventDefault>@profileName</a><span>&nbsp;</span>
}
</td>
<td>
@if (renameProfileName == null || renameProfileName == profileName)
{
<button @onclick="@(e=>renameProfile(e,profileName))">Rename</button>
}
@if (renameProfileName == null)
{
<button @onclick="@(e=>deleteProfile(e,profileName))">Del</button>
}
</td>
</tr>
}

</table>
<p>Click on profile name to make it the active profile. You'll be navigated back to your prior page.</p>

<table>
<tr>
<th></th>
<th>Name</th>
<th>Action</th>
</tr>
@foreach(var profileName in appData.ProfileNames)
{
<tr>
<td>
@if(profileName==appData.CurrentProfileName){<b>&nbsp;[active]&nbsp;</b>}
</td>
<td>
@if (renameProfileName == profileName)
{
<EditForm Model="appData">
<InputText @bind-Value=newName />
</EditForm>
}
else
{
<a href=/portfolio @onclick="@(e=>makeProfileActive(e,profileName))" @onclick:preventDefault>@profileName</a><span>&nbsp;</span>
}
</td>
<td>
@if (renameProfileName == null || renameProfileName == profileName)
{
<button @onclick="@(e=>renameProfile(e,profileName))">Rename</button>
}
@if (renameProfileName == null)
{
<button @onclick="@(e=>deleteProfile(e,profileName))">Del</button>
}
</td>
</tr>
}
</table>
} else {
newProfileName = "primary";

<p>Choose a profile name (defaults to 'primary') to store your data locally.</p>
}
<br/>
<label>Create new profile:</label><br/>
<InputText placeholder="name" @bind-Value="@newProfileName" /><button @onclick="createProfile">➕ create</button>
<InputText placeholder="profile name" @bind-Value="@newProfileName" /><button @onclick="createProfile">➕ create</button>

@code {
private ElementReference renameBox;
Expand All @@ -65,6 +72,7 @@ Click on profile name to make it the active profile. You'll be navigated back to
Navigation.NavigateTo(appData.LastPageUri);
}
}

private async Task renameProfile(EventArgs e, string profileName)
{
if (renameProfileName == null)
Expand All @@ -88,6 +96,7 @@ Click on profile name to make it the active profile. You'll be navigated back to
}
}
}

private async Task deleteProfile(EventArgs e, string profileName)
{
await LocalStorageAccessor.RemoveAsync(profileName);
Expand All @@ -104,14 +113,13 @@ Click on profile name to make it the active profile. You'll be navigated back to
{
if (!string.IsNullOrEmpty(newProfileName)) {
appData.ProfileNames.Add(newProfileName);
await ProfileUtilities.Save(newProfileName, new FamilyData(irsData));
await ProfileUtilities.Save(newProfileName, new FamilyData(appData));
newProfileName = "";
}
}

protected override async Task OnInitializedAsync()
{

}

private string newProfileName { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions Pages/Retirement.razor
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ Retirement - bogle.tools
}

private void OnClearPortfolio() {
familyData = new FamilyData(irsData);
familyData = new FamilyData(appData);
Navigation.NavigateTo("/portfolio");
}

Expand Down Expand Up @@ -729,10 +729,10 @@ Retirement - bogle.tools

private async Task loadPortfolioFromStream(Stream stream, JsonSerializerOptions options) {
if (familyData != null) {
var irsData = familyData.IRSData;
var irsData = familyData.AppData.IRSData;
familyData = await JsonSerializer.DeserializeAsync<FamilyData>(stream, options);
if (familyData != null) {
familyData.IRSData = irsData;
familyData.AppData.IRSData = irsData;
familyData.Year = 2023;
familyData.SetBackPointers();
}
Expand Down
22 changes: 12 additions & 10 deletions Pages/Saving.razor
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Saving@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.tools
}
</style>

@if (steps == null || familyData == null)
@if (steps == null || appData == null)
{
<p><em>Loading...</em></p>
}
Expand Down Expand Up @@ -1088,15 +1088,17 @@ Saving@(stepPath==null?": review":": "+stepPath.Replace('-',' ')) - bogle.tools

protected override async Task OnAfterRenderAsync(bool firstRender)
{
for (var i = 0; i < familyData.PersonCount; i++) {
var benefits = familyData.People[i].EmployerBenefits;

if (lastEmployer[i] != benefits.Company)
{
await benefits.GetEmployerDataAsync(familyData.Year);
lastEmployer[i] = benefits.Company;
if (benefits.Downloaded) {
await InvokeAsync(StateHasChanged);
if (appData != null && familyData != null) {
for (var i = 0; i < familyData.PersonCount; i++) {
var benefits = familyData.People[i].EmployerBenefits;

if (lastEmployer[i] != benefits.Company)
{
await benefits.GetEmployerDataAsync(familyData.Year);
lastEmployer[i] = benefits.Company;
if (benefits.Downloaded) {
await InvokeAsync(StateHasChanged);
}
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions Pages/Updated-quotes.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@page "/updated-quotes"
@inject IAppData appData

@inject NavigationManager NavigationManager
@inject LocalStorageAccessor LocalStorageAccessor

<PageTitle>Updated Quotes</PageTitle>

Expand All @@ -13,7 +14,7 @@ Steps:
<li><a href=https://eodhistoricaldata.com/register target=_new>Register</a> for free account for updated quotes at EODHistoricalData.com. They will email a free API key. You'll get 20 free quotes a day. (One can buy another 100,000 quotes for $5 from that site, which is 200 quotes per penny.)</li>
<li>Enter key into this tool. Then press Save button at top-right of page.</li>
<EditForm Model="familyData">
<label>EODHistoricalData.com free API key:</label><input type=text @bind-Value=familyData.EODHistoricalDataApiKey @bind-Value:event=oninput placeholder='apikey' />
<label>EODHistoricalData.com free API key:</label><input type=text @bind-Value=appData.EODHistoricalDataApiKey @bind-Value:event=oninput placeholder='apikey' />
</EditForm>
</ol>
<p></p>
Expand All @@ -27,4 +28,23 @@ Steps:
appData.FamilyData = value;
}
}

protected override async Task OnInitializedAsync()
{
NavigationManager.LocationChanged += LocationChanged;
base.OnInitialized();
}

async void LocationChanged(object sender, LocationChangedEventArgs e)
{
if (string.IsNullOrEmpty(appData.EODHistoricalDataApiKey))
{
await LocalStorageAccessor.RemoveAsync("EODHistoricalDataApiKey");
appData.EODHistoricalDataApiKey = null;
}
else
{
await LocalStorageAccessor.SetValueAsync("EODHistoricalDataApiKey", appData.EODHistoricalDataApiKey);
}
}
}
Loading

0 comments on commit 52add5d

Please sign in to comment.