diff --git a/src/Angor/Client/Pages/Create.razor b/src/Angor/Client/Pages/Create.razor index 8e2f1325..38d7e34f 100644 --- a/src/Angor/Client/Pages/Create.razor +++ b/src/Angor/Client/Pages/Create.razor @@ -9,6 +9,7 @@ @using Blockcore.NBitcoin @using Blockcore.NBitcoin.DataEncoders +@inherits BaseComponent @inject IDerivationOperations _derivationOperations @inject IWalletStorage _walletStorage; @inject IClientStorage storage; @@ -116,6 +117,13 @@
+
+ + +
+ +
+
Stages
@foreach (var stage in project.Stages) { @@ -143,14 +151,15 @@ @code { - private NotificationComponent notificationComponent; - private bool sendConfirmModal; private bool hasWallet; private bool showCreateModal; + Transaction unsignedTransaction; Transaction signedTransaction; + private FeeData feeData = new(); + private ProjectInfo project = new ProjectInfo { StartDate = DateTime.UtcNow, @@ -218,14 +227,16 @@ var operationResult = await notificationComponent.LongOperation(async () => { - var network = _NetworkConfiguration.GetNetwork(); var accountInfo = storage.GetAccountInfo(network.Name); - var feeEstimation = await _WalletOperations.GetFeeEstimationAsync(); + var fetchFees = await _WalletOperations.GetFeeEstimationAsync(); + feeData.FeeEstimations.Fees.Clear(); + feeData.FeeEstimations.Fees.AddRange(fetchFees); + feeData.SelectedFeeEstimation = feeData.FeeEstimations.Fees.First(); - var transaction = _founderTransactionActions.CreateNewProjectTransaction(project.FounderKey, _derivationOperations.AngorKeyToScript(project.ProjectIdentifier), 10000, project.NostrPubKey); + unsignedTransaction = _founderTransactionActions.CreateNewProjectTransaction(project.FounderKey, _derivationOperations.AngorKeyToScript(project.ProjectIdentifier), 10000, project.NostrPubKey); - signedTransaction = _WalletOperations.AddInputsAndSignTransaction(accountInfo.GetNextChangeReceiveAddress(), transaction, _walletStorage.GetWallet(), accountInfo, feeEstimation.First()); + signedTransaction = _WalletOperations.AddInputsAndSignTransaction(accountInfo.GetNextChangeReceiveAddress(), unsignedTransaction, _walletStorage.GetWallet(), accountInfo, feeData.SelectedFeeEstimation); project.TransactionId = signedTransaction.GetHash().ToString(); @@ -243,14 +254,34 @@ } } + private void FeeRangeChanged(ChangeEventArgs e) + { + var selected = e.Value?.ToString(); + + if (selected != null) + { + if (int.TryParse(selected, out int res)) + { + if (res <= feeData.FeeEstimations.Fees.Count) + { + feeData.SelectedFeeEstimation = feeData.FeeEstimations.Fees.OrderBy(fee => fee.Confirmations).ToList()[res - 1]; + + var accountInfo = storage.GetAccountInfo(network.Name); + + signedTransaction = _WalletOperations.AddInputsAndSignTransaction(accountInfo.GetNextChangeReceiveAddress(), unsignedTransaction, _walletStorage.GetWallet(), accountInfo, feeData.SelectedFeeEstimation); + + StateHasChanged(); + } + } + } + } + private async Task Send() { var operationResult = await notificationComponent.LongOperation(async () => { showCreateModal = false; - var network = _NetworkConfiguration.GetNetwork(); - var response = await _WalletOperations.PublishTransactionAsync(network, signedTransaction); if (!response.Success) diff --git a/src/Angor/Client/Pages/Invest.razor b/src/Angor/Client/Pages/Invest.razor index bfc206e4..e1fe7128 100644 --- a/src/Angor/Client/Pages/Invest.razor +++ b/src/Angor/Client/Pages/Invest.razor @@ -106,6 +106,13 @@

Miner fee: [Your fee here]

Angor fee: 1000 sats

+ +
+ +
+ + +

@@ -164,7 +171,13 @@ private ProjectInfo project; private bool showCreateModal; Transaction signedTransaction; + Transaction unSignedTransaction; + //InvestorContext context; + SignatureInfo recoverySigs; + + private FeeData feeData = new(); + protected override async Task OnInitializedAsync() { @@ -275,46 +288,23 @@ var operationResult = await notificationComponent.LongOperation(async () => { - var network = _NetworkConfiguration.GetNetwork(); var accountInfo = storage.GetAccountInfo(network.Name); - var feeEstimation = await _WalletOperations.GetFeeEstimationAsync(); + var fetchFees = await _WalletOperations.GetFeeEstimationAsync(); + feeData.FeeEstimations.Fees.Clear(); + feeData.FeeEstimations.Fees.AddRange(fetchFees); + feeData.SelectedFeeEstimation = feeData.FeeEstimations.Fees.First(); var investorKey = _derivationOperations.DeriveInvestorKey(_walletStorage.GetWallet(), project.FounderKey); - - InvestorContext context = new InvestorContext - { - ProjectInfo = project, - ChangeAddress = accountInfo.GetNextChangeReceiveAddress(), - InvestorKey = investorKey, - }; - + if (Investment.IsSeeder) { var seederHash = _derivationOperations.DeriveSeederSecretHash(_walletStorage.GetWallet(), project.FounderKey); - - context.InvestorSecretHash = seederHash; } - var transaction = _InvestorTransactionActions.CreateInvestmentTransaction(context.ProjectInfo, context.InvestorKey, Money.Coins(Investment.InvestmentAmount).Satoshi); - - signedTransaction = _WalletOperations.AddInputsAndSignTransaction(context.ChangeAddress, transaction, _walletStorage.GetWallet(), accountInfo, feeEstimation.First()); + unSignedTransaction = _InvestorTransactionActions.CreateInvestmentTransaction(project, investorKey, Money.Coins(Investment.InvestmentAmount).Satoshi); - // remove signatures when requesting founder to sign - var strippedInvestmentTransaction = network.CreateTransaction(signedTransaction.ToHex()); - strippedInvestmentTransaction.Inputs.ForEach(f => f.WitScript = Blockcore.Consensus.TransactionInfo.WitScript.Empty); - - recoverySigs = await _SignService.GetInvestmentSigsAsync(new SignRecoveryRequest - { - ProjectIdentifier = project.ProjectIdentifier, - InvestmentTransaction = strippedInvestmentTransaction.ToHex(network.Consensus.ConsensusFactory) - }); - - // validate the signatures - _InvestorTransactionActions.CheckInvestorRecoverySignatures(context.ProjectInfo, signedTransaction, recoverySigs); - - // link the trx to the signatures - recoverySigs.TransactionId = signedTransaction.GetHash().ToString(); + signedTransaction = _WalletOperations.AddInputsAndSignTransaction(accountInfo.GetNextChangeReceiveAddress(), unSignedTransaction, _walletStorage.GetWallet(), accountInfo, feeData.SelectedFeeEstimation); return new OperationResult { Success = true }; @@ -330,13 +320,49 @@ } } + private void FeeRangeChanged(ChangeEventArgs e) + { + var selected = e.Value?.ToString(); + + if (selected != null) + { + if (int.TryParse(selected, out int res)) + { + if (res <= feeData.FeeEstimations.Fees.Count) + { + feeData.SelectedFeeEstimation = feeData.FeeEstimations.Fees.OrderBy(fee => fee.Confirmations).ToList()[res - 1]; + + var accountInfo = storage.GetAccountInfo(network.Name); + + signedTransaction = _WalletOperations.AddInputsAndSignTransaction(accountInfo.GetNextChangeReceiveAddress(), unSignedTransaction, _walletStorage.GetWallet(), accountInfo, feeData.SelectedFeeEstimation); + + StateHasChanged(); + } + } + } + } + private async Task Send() { var operationResult = await notificationComponent.LongOperation(async () => { showCreateModal = false; + + // remove signatures when requesting founder to sign + var strippedInvestmentTransaction = network.CreateTransaction(signedTransaction.ToHex()); + strippedInvestmentTransaction.Inputs.ForEach(f => f.WitScript = Blockcore.Consensus.TransactionInfo.WitScript.Empty); + + recoverySigs = await _SignService.GetInvestmentSigsAsync(new SignRecoveryRequest + { + ProjectIdentifier = project.ProjectIdentifier, + InvestmentTransaction = strippedInvestmentTransaction.ToHex(network.Consensus.ConsensusFactory) + }); + + // validate the signatures + _InvestorTransactionActions.CheckInvestorRecoverySignatures(project, signedTransaction, recoverySigs); - var network = _NetworkConfiguration.GetNetwork(); + // link the trx to the signatures + recoverySigs.TransactionId = signedTransaction.GetHash().ToString(); storage.AddOrUpdateSignatures(recoverySigs); diff --git a/src/Angor/Client/Pages/Recover.razor b/src/Angor/Client/Pages/Recover.razor index b9a4f911..7aa311db 100644 --- a/src/Angor/Client/Pages/Recover.razor +++ b/src/Angor/Client/Pages/Recover.razor @@ -107,8 +107,16 @@

The amount to be recovered in to a penalty = @StageInfo.Items.Where(s=> !s.IsSpent).Sum(s=> s.Amount) BTC

The penalty duration is @((project.PenaltyDate - DateTime.UtcNow).Days) days

+ +
+ +
+ + +

+

Are you sure you want to recover these funds?