From 6059d8b123eb7f5d11cce4dad987e37c82694a7b Mon Sep 17 00:00:00 2001 From: TheDude Date: Tue, 27 Aug 2024 14:53:01 +0100 Subject: [PATCH 1/2] Removed nostr tags that are not right (#140) --- src/Angor/Client/Pages/Investor.razor | 1 - src/Angor/Shared/Services/IRelayService.cs | 3 ++- src/Angor/Shared/Services/RelayService.cs | 20 +++----------------- src/Angor/Shared/Services/SignService.cs | 18 +++++------------- 4 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/Angor/Client/Pages/Investor.razor b/src/Angor/Client/Pages/Investor.razor index 1b348359..0f93f74e 100644 --- a/src/Angor/Client/Pages/Investor.razor +++ b/src/Angor/Client/Pages/Investor.razor @@ -18,7 +18,6 @@ @inject IRelayService _RelayService @inject ISignService _SignService @inject ISerializer serializer -@inject ISignService _SignService @inject IEncryptionService _encryptionService @inject IJSRuntime JS diff --git a/src/Angor/Shared/Services/IRelayService.cs b/src/Angor/Shared/Services/IRelayService.cs index decab76b..4066b10e 100644 --- a/src/Angor/Shared/Services/IRelayService.cs +++ b/src/Angor/Shared/Services/IRelayService.cs @@ -8,7 +8,8 @@ namespace Angor.Shared.Services; public interface IRelayService { Task AddProjectAsync(ProjectInfo project, string nsec,Action action); - Task CreateNostrProfileAsync(NostrMetadata metadata, string nsec,Action action); + Task CreateNostrProfileAsync(NostrMetadata metadata, string nsec, + Action action); Task DeleteProjectAsync(string eventId, string hexPrivateKey); void LookupProjectsInfoByPubKeys(Action responseDataAction, Action? OnEndOfStreamAction, params string[] nostrPubKey); diff --git a/src/Angor/Shared/Services/RelayService.cs b/src/Angor/Shared/Services/RelayService.cs index 29bcf699..7ecc2f7a 100644 --- a/src/Angor/Shared/Services/RelayService.cs +++ b/src/Angor/Shared/Services/RelayService.cs @@ -110,7 +110,6 @@ public Task LookupSignaturesDirectMessagesForPubKeyAsync(string nostrPubKey, Dat { P = new[] { nostrPubKey }, Kinds = new[] { NostrKind.EncryptedDm }, - A = new []{ NostrCoordinatesIdentifierTag(nostrPubKey)}, Since = since, Limit = limit })); @@ -176,11 +175,6 @@ public string SendDirectMessagesForPubKeyAsync(string senderNosterPrivateKey, st return signed.Id!; } - private string NostrCoordinatesIdentifierTag(string nostrPubKey) - { - return $"{(int)NostrKind.ApplicationSpecificData}:{nostrPubKey}:AngorApp"; - } - public void CloseConnection() { _subscriptionsHandling.Dispose(); @@ -207,7 +201,7 @@ public Task AddProjectAsync(ProjectInfo project, string hexPrivateKey, A return Task.FromResult(signed.Id); } - public Task CreateNostrProfileAsync(NostrMetadata metadata, string hexPrivateKey,Action action) + public Task CreateNostrProfileAsync(NostrMetadata metadata, string hexPrivateKey, Action action) { var key = NostrPrivateKey.FromHex(hexPrivateKey); @@ -217,11 +211,7 @@ public Task CreateNostrProfileAsync(NostrMetadata metadata, string hexPr { Kind = NostrKind.Metadata, CreatedAt = DateTime.UtcNow, - Content = content, - Tags = new NostrEventTags( //TODO need to find the correct tags for the event - new NostrEventTag("d", "AngorApp", "Create a new project event"), - new NostrEventTag("L", "#projectInfo"), - new NostrEventTag("l", "ProjectDeclaration", "#projectInfo")) + Content = content }.Sign(key); _subscriptionsHandling.TryAddOKAction(signed.Id,action); @@ -257,11 +247,7 @@ private static NostrEvent GetNip78NostrEvent( string content) { Kind = NostrKind.ApplicationSpecificData, CreatedAt = DateTime.UtcNow, - Content = content, - Tags = new NostrEventTags( //TODO need to find the correct tags for the event - new NostrEventTag("d", "AngorApp", "Create a new project event"), - new NostrEventTag("L", "#projectInfo"), - new NostrEventTag("l", "ProjectDeclaration", "#projectInfo")) + Content = content }; return ev; } diff --git a/src/Angor/Shared/Services/SignService.cs b/src/Angor/Shared/Services/SignService.cs index 0408fa65..06656e00 100644 --- a/src/Angor/Shared/Services/SignService.cs +++ b/src/Angor/Shared/Services/SignService.cs @@ -30,8 +30,8 @@ public SignService(INostrCommunicationFactory communicationFactory, INetworkServ CreatedAt = DateTime.UtcNow, Content = signRecoveryRequest.EncryptedContent, Tags = new NostrEventTags( - NostrEventTag.Profile(signRecoveryRequest.NostrPubKey), - new NostrEventTag(NostrEventTag.CoordinatesIdentifier, NostrCoordinatesIdentifierTag(signRecoveryRequest.NostrPubKey))) + NostrEventTag.Profile(signRecoveryRequest.NostrPubKey), + new NostrEventTag("subject","Investment offer")) }; // Blazor does not support AES so it needs to be done manually in javascript @@ -68,7 +68,6 @@ public void LookupSignatureForInvestmentRequest(string investorNostrPubKey, stri Kinds = new[] { NostrKind.EncryptedDm }, Since = sigRequestSentTime, E = new [] { sigRequestEventId }, - //A = new[] { NostrCoordinatesIdentifierTag(projectNostrPubKey) }, //Only signature requests Limit = 1, })); } @@ -97,7 +96,6 @@ public Task LookupInvestmentRequestsAsync(string nostrPubKey, DateTime? since, A { P = new[] { nostrPubKey }, //To founder Kinds = new[] { NostrKind.EncryptedDm }, - A = new []{ NostrCoordinatesIdentifierTag(nostrPubKey)}, //Only signature requests Since = since })); @@ -127,8 +125,7 @@ public void LookupInvestmentRequestApprovals(string nostrPubKey, Action Date: Wed, 28 Aug 2024 13:39:40 +0300 Subject: [PATCH 2/2] Refactor UI and State Management for Checkbox and Button Handling (#130) * Refactor UI and State Management for Checkbox and Button Handling * Update Spend.razor * fix for dan msg * fix overlay * overlay fix * Fix code formating * rename StagePinner to StageSpinner --------- Co-authored-by: dangershony --- src/Angor/Client/Pages/Investor.razor | 116 +++++++++++++------------- src/Angor/Client/Pages/Spend.razor | 106 ++++++++++++++++++----- 2 files changed, 143 insertions(+), 79 deletions(-) diff --git a/src/Angor/Client/Pages/Investor.razor b/src/Angor/Client/Pages/Investor.razor index 0f93f74e..d020d52d 100644 --- a/src/Angor/Client/Pages/Investor.razor +++ b/src/Angor/Client/Pages/Investor.razor @@ -139,70 +139,74 @@
-
- +
+
- - - - - - - - - - - - + + + + + + + + + + + + + + @foreach (var project in projects) + { + Stats.TryGetValue(project.ProjectInfo.ProjectIdentifier, out var stats); + var nostrPubKey = project.ProjectInfo.NostrPubKey; + investmentRequestsMap.TryGetValue(nostrPubKey, out bool hasInvestmentRequests); - @foreach (var project in projects) - { - Stats.TryGetValue(project.ProjectInfo.ProjectIdentifier, out var stats); - var nostrPubKey = project.ProjectInfo.NostrPubKey; - investmentRequestsMap.TryGetValue(nostrPubKey, out bool hasInvestmentRequests); - - - - - - - - - - - - - - } + + + + + + + + + + + + + }
NameFunding Target (@network.CoinTicker)Raised (@network.CoinTicker)Raised (% Target)Project StatusMy Investment (@network.CoinTicker)Spent by FounderAvailable to FounderIn RecoveryFounder Approval
NameFunding Target (@network.CoinTicker)Raised (@network.CoinTicker)Raised (% Target)Project StatusMy Investment (@network.CoinTicker)Spent by FounderAvailable to FounderIn RecoveryFounder Approval
- @project.Metadata?.Name - @project.ProjectInfo.TargetAmount @network.CoinTicker@Money.Satoshis(stats?.AmountInvested ?? 0).ToUnit(MoneyUnit.BTC) @network.CoinTicker @((stats?.AmountInvested ?? 0) * 100 / Money.Coins(project.ProjectInfo.TargetAmount).Satoshi) % - @if (project.ProjectInfo.StartDate < DateTime.UtcNow) - { - Funding - } - else - { - Live - } - - @Money.Satoshis(project.AmountInvested ?? 0).ToUnit(MoneyUnit.BTC) @network.CoinTicker - @if (!project.SignaturesInfo?.Signatures.Any() ?? false) - { - - } - --@Money.Satoshis(project.AmountInRecovery ?? 0).ToUnit(MoneyUnit.BTC) @network.CoinTicker - @if (hasInvestmentRequests) - { - Approved - } - -
+ @project.Metadata?.Name + @project.ProjectInfo.TargetAmount @network.CoinTicker@Money.Satoshis(stats?.AmountInvested ?? 0).ToUnit(MoneyUnit.BTC) @network.CoinTicker@((stats?.AmountInvested ?? 0) * 100 / Money.Coins(project.ProjectInfo.TargetAmount).Satoshi) % + @if (project.ProjectInfo.StartDate < DateTime.UtcNow) + { + Funding + } + else + { + Live + } + + @Money.Satoshis(project.AmountInvested ?? 0).ToUnit(MoneyUnit.BTC) @network.CoinTicker + @if (!project.SignaturesInfo?.Signatures.Any() ?? false) + { + + } + --@Money.Satoshis(project.AmountInRecovery ?? 0).ToUnit(MoneyUnit.BTC) @network.CoinTicker + @if (hasInvestmentRequests) + { + Approved + } + else + { + Pending + } +
+ diff --git a/src/Angor/Client/Pages/Spend.razor b/src/Angor/Client/Pages/Spend.razor index 54e9634f..5e240dc2 100644 --- a/src/Angor/Client/Pages/Spend.razor +++ b/src/Angor/Client/Pages/Spend.razor @@ -75,7 +75,7 @@ bool stageisActive = stage.Stage.ReleaseDate < DateTime.UtcNow; var investedCount = stage.Items.Count(c => c.IsSpent == false); var investedAmount = stage.Items.Where(c => c.IsSpent == false).Sum(c => c.Amount); - bool noCoinsToClaim = investedCount == 0 || stage.StagePinner == true; + bool noCoinsToClaim = investedCount == 0 || stage.StageSpinner == true;
@@ -85,8 +85,8 @@ @if (stageisActive) { -
@@ -174,11 +174,19 @@
Stages
- @foreach (var item in selected) + @foreach (var utxo in selectedUtxos) { -

@item.Key

+ if (utxo.Value) // check if the UTXO is selected + { + var utxoKey = utxo.Key; + + var stageIndex = GetStageIndexForUtxo(utxoKey); + +

Stage: @stageIndex, Transaction: @utxoKey.Trxid, Output Index: @utxoKey.Outputindex

+ } } +

Are you sure you want to continue?

@@ -255,14 +263,14 @@ List<(Transaction Transaction, string TrxId)> transactions = new(); - Dictionary selected = new(); + Dictionary selectedUtxos = new Dictionary(); public class StageData { public int StageIndex; public Stage Stage; public List Items = new(); - public bool StagePinner = false; + public bool StageSpinner = false; } public class StageDataTrx @@ -425,8 +433,6 @@ } } - - private async Task CheckSpentFund() { List trxs = new(); @@ -480,7 +486,7 @@ { passwordComponent.ShowPassword(async () => { - await ClaimCoins(stageId); ; + await ClaimCoins(stageId); }); } } @@ -488,8 +494,7 @@ private async Task ClaimCoins(int stageId) { var stage = stageDatas.First(s => s.StageIndex == stageId); - - stage.StagePinner = true; + stage.StageSpinner = true; StateHasChanged(); await Task.Delay(10); @@ -507,13 +512,15 @@ founderContext = new FounderContext { ProjectInfo = project, ProjectSeeders = new ProjectSeeders() }; - foreach (var item in selected) + foreach (var utxo in selectedUtxos.Where(kv => GetStageIndexForUtxo(kv.Key) == stageId && kv.Value)) { - var trx = transactions.First(f => f.TrxId == item.Key); + var trxId = utxo.Key.Trxid; + var trx = transactions.First(f => f.TrxId == trxId); founderContext.InvestmentTrasnactionsHex.Add(trx.Transaction.ToHex(network.Consensus.ConsensusFactory)); } + var accountInfo = storage.GetAccountInfo(network.Name); var address = accountInfo.GetNextReceiveAddress(); var addressScript = BitcoinWitPubKeyAddress.Create(address, network).ScriptPubKey; @@ -533,12 +540,19 @@ } finally { - stage.StagePinner = false; + CalculateTotalValues(); + + if (selectedUtxos.Keys.Any(utxoKey => GetStageIndexForUtxo(utxoKey) == selectedStageId)) + { + selectedUtxos.Clear(); + } + stage.StageSpinner = false; } - + StateHasChanged(); } + private async Task FeeRangeChanged(ChangeEventArgs e) { var selectedItem = e.Value?.ToString(); @@ -628,20 +642,39 @@ private void Expand(int stageId) { expandedStageId = expandedStageId == stageId ? null : stageId; + selectedUtxos.Clear(); } - private void HandleCheckboxChange(string trxId) + private void HandleCheckboxChange(string trxId, int outputIndex) { + var key = new UtxoKey(trxId, outputIndex); - if (selected.ContainsKey(trxId)) + if (selectedUtxos.ContainsKey(key)) { - selected.Remove(trxId); + selectedUtxos.Remove(key); } else { - selected.Add(trxId, null); + selectedUtxos[key] = true; } } + + private bool IsUtxoSelected(string trxId, int outputIndex) + { + return selectedUtxos.ContainsKey(new UtxoKey(trxId, outputIndex)); + } + + private int GetStageIndexForUtxo(UtxoKey utxoKey) + { + return stageDatas.First(stage => stage.Items.Any(item => item.Trxid == utxoKey.Trxid && item.Outputindex == utxoKey.Outputindex)).StageIndex; + } + + + private bool IsCheckboxSelectedForStage(int stageIndex) + { + return selectedUtxos.Any(utxo => GetStageIndexForUtxo(utxo.Key) == stageIndex && utxo.Value); + } + private async Task CopyTRXToClipboard(string trxData) { @@ -653,4 +686,31 @@ await _clipboardService.WriteTextAsync(trxData); StateHasChanged(); } + + public struct UtxoKey + { + public string Trxid { get; set; } + public int Outputindex { get; set; } + + public UtxoKey(string trxid, int outputindex) + { + Trxid = trxid; + Outputindex = outputindex; + } + + public override bool Equals(object obj) + { + if (!(obj is UtxoKey)) + return false; + + var key = (UtxoKey)obj; + return Trxid == key.Trxid && Outputindex == key.Outputindex; + } + + public override int GetHashCode() + { + return HashCode.Combine(Trxid, Outputindex); + } + } + } \ No newline at end of file