From 068679cccd3c45bc8ac2e8da18f689212a22f07e Mon Sep 17 00:00:00 2001 From: Dan Gershony Date: Wed, 10 Apr 2024 21:12:37 +0200 Subject: [PATCH] Add a refresh button in the invest page (#67) --- src/Angor/Client/Pages/Invest.razor | 65 +++++++++++++++++++++++----- src/Angor/Client/Pages/Recover.razor | 6 +-- 2 files changed, 57 insertions(+), 14 deletions(-) diff --git a/src/Angor/Client/Pages/Invest.razor b/src/Angor/Client/Pages/Invest.razor index 6ef2dd79..3ddad9d7 100644 --- a/src/Angor/Client/Pages/Invest.razor +++ b/src/Angor/Client/Pages/Invest.razor @@ -196,14 +196,26 @@

Waiting for the founder to approve

- +
+ + +
- @*

Waiting for the founder to sign the investment request

*@ -
+ } else { @@ -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 }; @@ -318,6 +331,17 @@ } } + if (firstRender) + { + if (hasWallet) + { + await RefreshSignatures(); + } + } + } + + private async Task RefreshSignatures() + { if (project is InvestorProject investmentProject && investmentProject.WaitingForFounderResponse()) { if (passwordComponent.HasPassword()) @@ -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); } } diff --git a/src/Angor/Client/Pages/Recover.razor b/src/Angor/Client/Pages/Recover.razor index b892347a..140397d3 100644 --- a/src/Angor/Client/Pages/Recover.razor +++ b/src/Angor/Client/Pages/Recover.razor @@ -115,7 +115,7 @@
-