Skip to content

Commit

Permalink
Add a refresh button in the invest page (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangershony authored Apr 10, 2024
1 parent 001ed7a commit 068679c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
65 changes: 54 additions & 11 deletions src/Angor/Client/Pages/Invest.razor
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,26 @@
<div class="card mt-3 text-center">
<div class="card-header d-flex justify-content-between align-items-center">
<h4>Waiting for the founder to approve</h4>
<button type="button" class="btn btn-danger" @onclick="CancelInvestment">Cancel</button>
<div>
<button type="button" class="btn btn-danger" @onclick="CancelInvestment">Cancel</button>
<button class="btn btn-primary" @onclick="RefreshSignatures" disabled="@refreshSpinner">
@if (refreshSpinner)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
<span>Refresh...</span>
}
else
{
<span>Refresh</span>
}
</button>
</div>
</div>
<div class="card-body">
@*<p>Waiting for the founder to sign the investment request</p>*@

<div class="loader-slow"></div>
</div>
</div>

}
else
{
Expand Down Expand Up @@ -244,6 +256,7 @@
private bool buildSpinner = false;
private bool investSpinner = false;
private bool publishSpinner = false;
private bool refreshSpinner = false;


public InvestmentModel Investment { get; set; } = new InvestmentModel { InvestmentAmount = 10 };
Expand Down Expand Up @@ -318,6 +331,17 @@
}
}

if (firstRender)
{
if (hasWallet)
{
await RefreshSignatures();
}
}
}

private async Task RefreshSignatures()
{
if (project is InvestorProject investmentProject && investmentProject.WaitingForFounderResponse())
{
if (passwordComponent.HasPassword())
Expand All @@ -341,18 +365,37 @@
return;
}

var words = await passwordComponent.GetWalletAsync();
refreshSpinner = true;
StateHasChanged();
await Task.Delay(10);

var accountInfo = storage.GetAccountInfo(_networkConfiguration.GetNetwork().Name);
try
{
var words = await passwordComponent.GetWalletAsync();

var nostrPrivateKey = _derivationOperations.DeriveProjectNostrPrivateKey(words, accountInfo.InvestmentsCount + 1);
var accountInfo = storage.GetAccountInfo(_networkConfiguration.GetNetwork().Name);

var nostrPrivateKeyHex = Encoders.Hex.EncodeData(nostrPrivateKey.ToBytes());
var nostrPrivateKey = _derivationOperations.DeriveProjectNostrPrivateKey(words, accountInfo.InvestmentsCount + 1);

_SignService.LookupSignatureForInvestmentRequest(
NostrPrivateKey.FromHex(nostrPrivateKeyHex).DerivePublicKey().Hex
, project.ProjectInfo.NostrPubKey, investmentProject.SignaturesInfo!.TimeOfSignatureRequest!.Value, investmentProject.SignaturesInfo!.SignatureRequestEventId!,
async _ => await HandleSignatureReceivedAsync(nostrPrivateKeyHex, _));
var nostrPrivateKeyHex = Encoders.Hex.EncodeData(nostrPrivateKey.ToBytes());

_SignService.LookupSignatureForInvestmentRequest(
NostrPrivateKey.FromHex(nostrPrivateKeyHex).DerivePublicKey().Hex
, project.ProjectInfo.NostrPubKey, investmentProject.SignaturesInfo!.TimeOfSignatureRequest!.Value, investmentProject.SignaturesInfo!.SignatureRequestEventId!,
async _ => await HandleSignatureReceivedAsync(nostrPrivateKeyHex, _));
}
catch (Exception e)
{
_Logger.LogError(e, e.Message);
notificationComponent.ShowErrorMessage(e.Message);
}
finally
{
refreshSpinner = false;
}

StateHasChanged();
await Task.Delay(10);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Angor/Client/Pages/Recover.razor
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
</div>

<div>
<button class="btn btn-primary" @onclick="Scan" disabled="@refreshSpinner">
<button class="btn btn-primary" @onclick="RefreshInvestments" disabled="@refreshSpinner">
@if (refreshSpinner)
{
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
Expand Down Expand Up @@ -374,12 +374,12 @@
{
if (hasWallet)
{
await Scan();
await RefreshInvestments();
}
}
}

private async Task Scan()
private async Task RefreshInvestments()
{
refreshSpinner = true;
StateHasChanged();
Expand Down

0 comments on commit 068679c

Please sign in to comment.