From 2a77dc67f5eacbdac924b4a9b3b3253c1f59b181 Mon Sep 17 00:00:00 2001 From: itailiors <78041027+itailiors@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:44:09 +0200 Subject: [PATCH 1/5] add in wallet, and create the component --- .../Components/RawTransactionModal.razor | 42 ++++++++++ src/Angor/Client/Pages/Wallet.razor | 84 +++++++++++-------- 2 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 src/Angor/Client/Components/RawTransactionModal.razor diff --git a/src/Angor/Client/Components/RawTransactionModal.razor b/src/Angor/Client/Components/RawTransactionModal.razor new file mode 100644 index 00000000..ff0a8b8b --- /dev/null +++ b/src/Angor/Client/Components/RawTransactionModal.razor @@ -0,0 +1,42 @@ +@using Angor.Shared.Models +@inject IClipboardService ClipboardService + +@if (IsVisible) +{ + +} + +@code { + [Parameter] public string RawTransactionJson { get; set; } + [Parameter] public bool IsVisible { get; set; } + [Parameter] public EventCallback IsVisibleChanged { get; set; } + + private async Task CloseModal() + { + await IsVisibleChanged.InvokeAsync(false); + } + + private async Task CopyToClipboard() + { + await ClipboardService.WriteTextAsync(RawTransactionJson); + } +} \ No newline at end of file diff --git a/src/Angor/Client/Pages/Wallet.razor b/src/Angor/Client/Pages/Wallet.razor index 0afab735..bd082f6f 100644 --- a/src/Angor/Client/Pages/Wallet.razor +++ b/src/Angor/Client/Pages/Wallet.razor @@ -499,6 +499,7 @@ else @if (sendConfirmModal) { + + + + } @@ -725,6 +727,8 @@ else private bool showRawTransactionModal; private string rawTransactionJson = string.Empty; + private string transactionJson; + private bool showTransactionJsonModal = false; private readonly AccountBalanceInfo accountBalanceInfo = new(); @@ -1300,12 +1304,14 @@ else showRawTransactionModal = true; } + private void HandleModalVisibility(bool isVisible) + { + showRawTransactionModal = isVisible; + } + private string GetRawTransactionJson(AddressInfo addressInfo) { - var options = new JsonSerializerOptions - { - WriteIndented = true - }; + var options = new JsonSerializerOptions { WriteIndented = true }; return JsonSerializer.Serialize(addressInfo, options); } @@ -1315,31 +1321,41 @@ else notificationComponent.ShowNotificationMessage("Copied to clipboard!", 3); StateHasChanged(); } + + private async Task PrepareTransactionJson() + { + var transactionDetails = new + { + Amount = _sendInfo.SendAmount, + ToAddress = _sendInfo.SendToAddress, + Fee = _sendInfo.SendFee, + FeeRate = $"{_sendInfo.FeeRate} sats per byte for {_sendInfo.FeeBlockCount} block confirmations", + ChangeAddress = _sendInfo.ChangeAddress, + Inputs = _sendInfo.SendUtxos.Select(u => new + { + Address = u.Value.UtxoData.address, + Amount = Money.Satoshis(u.Value.UtxoData.value).ToUnit(MoneyUnit.BTC), + Outpoint = u.Key, + CoinTicker = network.CoinTicker + }) + }; + + transactionJson = JsonSerializer.Serialize(transactionDetails, new JsonSerializerOptions { WriteIndented = true }); + } + + + private async Task ShowTransactionJson() + { + await PrepareTransactionJson(); + showTransactionJsonModal = true; + } + + private void HandleTransactionJsonModalVisibility(bool isVisible) + { + showTransactionJsonModal = isVisible; + } -} -@if (showRawTransactionModal) -{ - } \ No newline at end of file From 855cee3903e775093c6bdc2581942814fc36f7db Mon Sep 17 00:00:00 2001 From: itailiors <78041027+itailiors@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:59:04 +0200 Subject: [PATCH 2/5] add RawTransactioModal for invest --- src/Angor/Client/Pages/Invest.razor | 47 ++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Angor/Client/Pages/Invest.razor b/src/Angor/Client/Pages/Invest.razor index e9e91544..03d073a7 100644 --- a/src/Angor/Client/Pages/Invest.razor +++ b/src/Angor/Client/Pages/Invest.razor @@ -12,6 +12,8 @@ @using Nostr.Client.Keys @using System.Diagnostics @using Angor.Client.Models +@using System.Text.Json + @inherits BaseComponent @@ -242,6 +244,11 @@ } + + + @@ -353,7 +360,8 @@ else private bool investSpinner = false; private bool publishSpinner = false; private bool refreshSpinner = false; - + private bool showTransactionJsonModal = false; + private string transactionJson; public InvestmentModel Investment { get; set; } = new InvestmentModel { InvestmentAmount = 10 }; private bool IsSeederTimePassed { get; set; } @@ -883,4 +891,41 @@ else public DateTime StageDateTime { get; set; } public int DaysFromStartDate { get; set; } } + + private async Task PrepareInvestmentTransactionJson() + { + var transactionDetails = new + { + ProjectIdentifier = project.ProjectInfo.ProjectIdentifier, + FounderKey = project.ProjectInfo.FounderKey.Substring(0, 10) + "...", + TargetAmount = $"{project.ProjectInfo.TargetAmount} {network.CoinTicker}", + StartDate = project.ProjectInfo.StartDate.ToString("dd/MM/yyyy"), + ExpiryDate = project.ProjectInfo.ExpiryDate.ToString("dd/MM/yyyy"), + PenaltyDays = project.ProjectInfo.PenaltyDays, + MinerFee = Money.Satoshis(signedTransaction?.TransactionFee ?? 0).ToUnit(MoneyUnit.BTC), + AngorFee = signedTransaction?.Transaction.Outputs.First().Value.ToUnit(MoneyUnit.BTC) ?? 0, + FeeRate = $"{feeData.SelectedFeeEstimation.FeeRate} sats", + Confirmations = feeData.SelectedFeeEstimation.Confirmations, + Stages = project.ProjectInfo.Stages.Select((stage, index) => new + { + StageAmount = $"{StagesBreakdown[index].Amount} BTC - {stage.AmountToRelease}%", + StageDate = stage.ReleaseDate.ToString("dd/MM/yyyy"), + DaysAfterStart = (stage.ReleaseDate - project.ProjectInfo.StartDate).Days + }).ToList() + }; + + transactionJson = JsonSerializer.Serialize(transactionDetails, new JsonSerializerOptions { WriteIndented = true }); + } + + + private async Task ShowTransactionJsonModal() + { + await PrepareInvestmentTransactionJson(); + showTransactionJsonModal = true; + } + + private void HandleTransactionJsonModalVisibility(bool isVisible) + { + showTransactionJsonModal = isVisible; + } } From b9c9b72a32a43d391af7a6abe61242f2ea0f2dcf Mon Sep 17 00:00:00 2001 From: itailiors <78041027+itailiors@users.noreply.github.com> Date: Thu, 7 Nov 2024 01:05:02 +0200 Subject: [PATCH 3/5] add max --- src/Angor/Client/Pages/Invest.razor | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Angor/Client/Pages/Invest.razor b/src/Angor/Client/Pages/Invest.razor index 03d073a7..cbfc4884 100644 --- a/src/Angor/Client/Pages/Invest.razor +++ b/src/Angor/Client/Pages/Invest.razor @@ -372,7 +372,7 @@ else private bool showCreateModal; TransactionInfo? signedTransaction; Transaction unSignedTransaction; - + private FeeData feeData = new(); @@ -540,11 +540,18 @@ else if (Investment.IsSeeder) { var minSeederAmount = 2; + var maxSeederAmount = 5; if (Investment.InvestmentAmount < minSeederAmount) { notificationComponent.ShowErrorMessage($"Seeder minimum investment amount of {minSeederAmount} BTC was not reached"); return; } + + if (Investment.InvestmentAmount > maxSeederAmount) + { + notificationComponent.ShowErrorMessage($"Maximum investment amount of {maxSeederAmount} BTC exceeded"); + return; + } } else { From 582996bc92fc7500c4270ef17f14fda65ba1248b Mon Sep 17 00:00:00 2001 From: itailiors <78041027+itailiors@users.noreply.github.com> Date: Thu, 7 Nov 2024 01:07:30 +0200 Subject: [PATCH 4/5] add for Spend.razor --- src/Angor/Client/Pages/Spend.razor | 41 +++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Angor/Client/Pages/Spend.razor b/src/Angor/Client/Pages/Spend.razor index 96049845..f47fc1e9 100644 --- a/src/Angor/Client/Pages/Spend.razor +++ b/src/Angor/Client/Pages/Spend.razor @@ -10,6 +10,8 @@ @using Blockcore.NBitcoin.DataEncoders @using Angor.Shared.Utilities @using ITransactionSignature = NBitcoin.ITransactionSignature +@using System.Text.Json + @inject IClientStorage storage; @inject ICacheStorage _cacheStorage; @@ -25,6 +27,7 @@ + @if (!hasWallet) @@ -193,7 +196,7 @@ @@ -244,6 +250,9 @@ private int? expandedStageId; private bool showCreateModal; + + private bool showRawTransactionModal = false; + private string rawTransactionJson; private bool refreshSpinner = false; private bool firstTimeRefreshSpinner = false; @@ -713,4 +722,34 @@ } } + private async Task ShowTransactionJsonModal() + { + rawTransactionJson = PrepareTransactionDetails(); + showRawTransactionModal = true; + } + + private string PrepareTransactionDetails() + { + var transactionDetails = new + { + ProjectIdentifier = project.ProjectIdentifier, + TotalSpent = signedTransaction.Transaction.Outputs.Sum(s => s.Value.ToUnit(MoneyUnit.BTC)), + MinerFee = Money.Satoshis(signedTransaction.TransactionFee).ToUnit(MoneyUnit.BTC), + FeeRate = feeData.SelectedFeeEstimation.FeeRate, + Confirmations = feeData.SelectedFeeEstimation.Confirmations, + Utxos = selectedUtxos.Select(utxo => new + { + Stage = GetStageIndexForUtxo(utxo.Key), + TransactionId = utxo.Key.Trxid, + OutputIndex = utxo.Key.Outputindex + }).ToList() + }; + + return JsonSerializer.Serialize(transactionDetails, new JsonSerializerOptions { WriteIndented = true }); + } + + private void HandleRawTransactionModalVisibility(bool isVisible) + { + showRawTransactionModal = isVisible; + } } \ No newline at end of file From 2b87055988dbc6da3f1f6c679885a3ccb6e86ea8 Mon Sep 17 00:00:00 2001 From: itailiors <78041027+itailiors@users.noreply.github.com> Date: Thu, 7 Nov 2024 01:24:59 +0200 Subject: [PATCH 5/5] config --- src/Angor/Client/Pages/Invest.razor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Angor/Client/Pages/Invest.razor b/src/Angor/Client/Pages/Invest.razor index cbfc4884..15f3c501 100644 --- a/src/Angor/Client/Pages/Invest.razor +++ b/src/Angor/Client/Pages/Invest.razor @@ -539,8 +539,8 @@ else { if (Investment.IsSeeder) { - var minSeederAmount = 2; - var maxSeederAmount = 5; + var minSeederAmount = 0.01m; + var maxSeederAmount = 0.1m; if (Investment.InvestmentAmount < minSeederAmount) { notificationComponent.ShowErrorMessage($"Seeder minimum investment amount of {minSeederAmount} BTC was not reached");