From 20cb8294b365c4777d40aab83af703a25b2f2ddd Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Sun, 3 Sep 2023 16:17:40 +0200 Subject: [PATCH 01/11] Add some improvements. --- src/Helpers/ValidationHelper.cs | 4 +- src/Pages/ChannelRequests.razor | 11 +- src/Pages/Wallets.razor | 2 +- src/Pages/Withdrawals.razor | 173 +++++++++++++++++++++-------- src/Shared/UTXOSelectorModal.razor | 23 +++- 5 files changed, 152 insertions(+), 61 deletions(-) diff --git a/src/Helpers/ValidationHelper.cs b/src/Helpers/ValidationHelper.cs index d75dcbc5..f81bb291 100644 --- a/src/Helpers/ValidationHelper.cs +++ b/src/Helpers/ValidationHelper.cs @@ -87,13 +87,13 @@ public static void ValidateWithdrawalAmount(ValidatorEventArgs obj, Boolean isAm decimal minimum = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; decimal maximum = Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; - if (amount < minimum && !isAmountDisabled) + if (amount < minimum && isAmountDisabled) { obj.Status = ValidationStatus.Error; obj.ErrorText = $"Error, the minimum amount to withdraw is at least {minimum:f8} BTC"; } - if (amount > maximum && !isAmountDisabled) + if (amount > maximum && isAmountDisabled) { obj.Status = ValidationStatus.Error; obj.ErrorText = $"Error, the maximum amount to withdraw is {maximum:f8} BTC"; diff --git a/src/Pages/ChannelRequests.razor b/src/Pages/ChannelRequests.razor index 7a4a97b8..169b871e 100644 --- a/src/Pages/ChannelRequests.razor +++ b/src/Pages/ChannelRequests.razor @@ -147,9 +147,14 @@ - - @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") - + @if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount) + { + @($"Amount in BTC. Maximum {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT}.") + } + else + { + @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") + }
diff --git a/src/Pages/Wallets.razor b/src/Pages/Wallets.razor index 531d50de..35b3d752 100644 --- a/src/Pages/Wallets.razor +++ b/src/Pages/Wallets.razor @@ -471,7 +471,7 @@ - Amount + Amount diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index 36488d04..efa5ef6f 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -1,9 +1,13 @@ @page "/withdrawals" -@using Humanizer @using System.Security.Claims +@using Blazorise.Extensions @using Quartz +@using Humanizer @using NBitcoin @using NodeGuard.Jobs +@using Google.Protobuf +@using NBXplorer.Models +@using NodeGuard.Helpers; @attribute [Authorize(Roles = "Superadmin,NodeManager,FinanceManager")] @@ -144,10 +148,7 @@ - - - - + @@ -165,23 +166,31 @@ } - @if (!_isAmountDisabled) - { - - - - - - - - @($"Current amount: {Math.Round(PriceConversionService.BtcToUsdConversion((decimal)context.CellValue, _btcPrice), 2)} USD") - + + + + @if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount) + { + @($"Maximum amount {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT} BTC.") + } + else + { + @($"Amount in BTC. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") + } + - } - else - { - - } +
+ or use + +
+ @if (_selectedWalletId.HasValue && SelectedUTXOs.Count > 0) + { + Selected @(SelectedUTXOs.Count) UTXOs, this is a changeless operation + } + else + { + Default coin selection strategy selected + }
@@ -218,6 +227,7 @@ +
No records were found. @@ -237,7 +247,7 @@

Withdrawal requests

+ + @inject IToastService ToastService @inject IWalletWithdrawalRequestRepository WalletWithdrawalRequestRepository @inject IWalletWithdrawalRequestPsbtRepository WalletWithdrawalRequestPsbtRepository @inject IWalletRepository WalletRepository @inject IBitcoinService BitcoinService +@inject ICoinSelectionService CoinSelectionService @inject ISchedulerFactory SchedulerFactory @inject ILocalStorageService LocalStorageService @inject IPriceConversionService PriceConversionService +@inject ILightningService LightningService @code { [CascadingParameter] @@ -406,42 +423,55 @@ [CascadingParameter] private ClaimsPrincipal? ClaimsPrincipal { get; set; } - - private List _userPendingRequests = new List(); - private List _availableWallets = new List(); - private List _allRequests = new List(); - + private List _allWallets = new List(); + private ColumnLayout PendingRequestsColumnLayout; + private List _userPendingRequests = new(); + private List _availableWallets = new(); + private List? _allRequests; + private List _withdrawalRequests = new(); + private List? _channelRequests; private string? mempoolUrl = Constants.MEMPOOL_ENDPOINT; private bool _isFinanceManager; - + private List SelectedUTXOs = new(); private WalletWithdrawalRequest? _selectedRequest; private PSBTSign? _psbtSignRef; + private Node? _selectedDestNode; private string _signedPSBT; private string? _templatePsbtString; - + private int? _selectedWalletId; + private static readonly decimal _minimumChannelCapacity = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); + private decimal _amount { get; set; } = _minimumChannelCapacity; + private int _selectedSourceNodeId; + //Validation + private Validation? _walletValidation; + private Validation? _sourceNodeValidation; + private Validation? _destNodeValidation; + private Validation? _capacityValidation; private DataGrid? _allRequestsDatagrid; - + private UTXOSelectorModal _utxoSelectorModalRef; private ConfirmationModal _confirmationModal; private CancelOrRejectPopup? _rejectCancelModalRef; + private bool _isNodeManager = false; private WalletWithdrawalRequestStatus? _rejectCancelStatus = WalletWithdrawalRequestStatus.Rejected; - private bool _isAmountDisabled; private decimal? _selectedRequestWalletBalance; - + private List? _manageableNodes; private decimal _maxWithdrawal = Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _minWithdrawal = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _btcPrice; - - private ColumnLayout PendingRequestsColumnLayout; private ColumnLayout AllRequestsColumnLayout; private Dictionary PendingRequestsColumns = new(); private Dictionary AllRequestsColumns = new(); private bool columnsLoaded; - + private decimal _selectedWalletBalance; + private bool _validationError; + private decimal _previousAmount; + public abstract class PendingWithdrawalsColumnName { public static readonly ColumnDefault Description = new("Description"); public static readonly ColumnDefault Wallet = new("Wallet"); public static readonly ColumnDefault Requestor = new("Requestor"); + public static readonly ColumnDefault Capacity = new("Capacity"); public static readonly ColumnDefault DestinationAddress = new("Destination Address"); public static readonly ColumnDefault Amount = new("Amount (BTC)"); public static readonly ColumnDefault SignaturesCollected = new("Signatures Collected"); @@ -463,7 +493,7 @@ public static readonly ColumnDefault UpdateDate = new("Update Date"); public static readonly ColumnDefault Links = new("Links"); } - + protected override async Task OnInitializedAsync() { if (LoggedUser == null) return; @@ -487,6 +517,11 @@ } } + private decimal SelectedUTXOsValue() + { + return SelectedUTXOs.Sum(x => ((Money)x.Value).ToUnit(MoneyUnit.BTC)); + } + private async Task LoadColumnLayout() { AllRequestsColumns = await LocalStorageService.LoadStorage(nameof(AllWithdrawalsColumnName), ColumnHelpers.GetColumnsDictionary()); @@ -495,12 +530,19 @@ StateHasChanged(); } + private async Task ResetChannelRequestRejectModal() + { + _selectedDestNode = null; + _selectedWalletId = null; + _amount = _minimumChannelCapacity; + } + private async Task GetData() { if (LoggedUser?.Id != null) _userPendingRequests = await WalletWithdrawalRequestRepository.GetUnsignedPendingRequestsByUser(LoggedUser.Id); - _allRequests = (await WalletWithdrawalRequestRepository.GetAll()).Except(_userPendingRequests).ToList(); + _withdrawalRequests = (await WalletWithdrawalRequestRepository.GetAll()).Except(_userPendingRequests).ToList(); _availableWallets = await WalletRepository.GetAvailableWallets(false); //TODO Fix BIP39 withdrawals, until then, manual hack to filter them out @@ -508,13 +550,24 @@ } + private void OnCloseCoinSelectionModal(List selectedUTXOs) + { + SelectedUTXOs = selectedUTXOs; + if (SelectedUTXOs.Count > 0) + { + _amount = SelectedUTXOsValue(); + } + StateHasChanged(); + } + private async Task OnRowInserted(SavedRowItem> arg) { if (arg.Item == null) return; //Balance validation if (await ValidateBalance(arg)) return; - + var amount = SelectedUTXOs.Count > 0 ? SelectedUTXOsValue() : _amount; arg.Item.Wallet = await WalletRepository.GetById(arg.Item.WalletId); + arg.Item.Amount = amount; if (arg.Item.Wallet.IsHotWallet) { await GetData(); @@ -531,6 +584,13 @@ { ToastService.ShowSuccess("Success"); await GetData(); + + if (SelectedUTXOs.Count > 0) + { + await CoinSelectionService.LockUTXOs(SelectedUTXOs, arg.Item, BitcoinRequestType.ChannelOperation); + } + + _utxoSelectorModalRef.ClearModal(); } else { @@ -627,7 +687,6 @@ if (LoggedUser != null) { obj.UserRequestorId = LoggedUser.Id; - _isAmountDisabled = false; _selectedRequestWalletBalance = null; } } @@ -635,7 +694,7 @@ private async Task ShowApprovalModal(WalletWithdrawalRequest walletWithdrawalRequest) { _selectedRequest = walletWithdrawalRequest; - + //PSBT Generation try { @@ -656,10 +715,11 @@ } - private async Task Approve(WalletWithdrawalRequest context) + private async Task Approve(WalletWithdrawalRequest request) { if (_selectedRequest == null || string.IsNullOrEmpty(_psbtSignRef?.SignedPSBT) || LoggedUser == null) { + _utxoSelectorModalRef.ClearModal(); ToastService.ShowError("Invalid request"); } else @@ -672,7 +732,7 @@ }; var addResult = await WalletWithdrawalRequestPsbtRepository.AddAsync(walletWithdrawalRequestPsbt); - + if (addResult.Item1) { _selectedRequest.Status = WalletWithdrawalRequestStatus.PSBTSignaturesPending; @@ -730,7 +790,7 @@ if (_selectedRequest != null) await Approve(_selectedRequest); } - + private async Task RejectOrCancel() { if ((_rejectCancelStatus == WalletWithdrawalRequestStatus.Cancelled || _rejectCancelStatus == WalletWithdrawalRequestStatus.Rejected) @@ -774,15 +834,26 @@ context.CellValue = id; var wallet = _availableWallets.SingleOrDefault(x => x.Id == id); - + _selectedWalletId = id == 0 ? null : id; if (wallet != null) { - var (balance,_) = await BitcoinService.GetWalletConfirmedBalance(wallet); - - _selectedRequestWalletBalance = balance; + var (balance,_) = await BitcoinService.GetWalletConfirmedBalance(wallet); + _selectedRequestWalletBalance = balance; } } + private async Task OpenCoinSelectionModal() + { + _utxoSelectorModalRef.ShowModal(_selectedWalletId.Value); + } + + private void ClearSelectedUTXOs() + { + _utxoSelectorModalRef.ClearModal(); + SelectedUTXOs.Clear(); + StateHasChanged(); + } + private void RejectReasonValidator(ValidatorEventArgs e) { if (_rejectCancelStatus == WalletWithdrawalRequestStatus.Rejected) @@ -817,17 +888,21 @@ try { _selectedRequest.Wallet = null; + _selectedRequest.Changeless = SelectedUTXOs.Count > 0; var createWithdrawalResult = await WalletWithdrawalRequestRepository.AddAsync(_selectedRequest); if (!createWithdrawalResult.Item1) { throw new ShowToUserException(createWithdrawalResult.Item2); } - ToastService.ShowSuccess("Withdrawal request created!"); + if (SelectedUTXOs.Count > 0) + { + await CoinSelectionService.LockUTXOs(SelectedUTXOs, _selectedRequest, BitcoinRequestType.WalletWithdrawal); + } var templatePSBT = await BitcoinService.GenerateTemplatePSBT(_selectedRequest); - //TODO Save template PSBT (?) + //TODO Save template PSBT (?) var walletWithdrawalRequestPsbt = new WalletWithdrawalRequestPSBT() { WalletWithdrawalRequestId = _selectedRequest.Id, diff --git a/src/Shared/UTXOSelectorModal.razor b/src/Shared/UTXOSelectorModal.razor index 070e18a7..e1a352ff 100644 --- a/src/Shared/UTXOSelectorModal.razor +++ b/src/Shared/UTXOSelectorModal.razor @@ -139,6 +139,9 @@ public Action> OnClose { get; set; } = _ => { }; private Validation _validation { get; set; } = new(); + + [Parameter] + public bool IsWalletWithdrawalValidation { get; set; } = true; public void ClearModal() { @@ -216,20 +219,28 @@ if (e.Value is not List) return; var selectedUTXOsValue = ((List)e.Value).Sum(x => ((Money)x.Value).ToUnit(MoneyUnit.BTC)); if (selectedUTXOsValue == 0) return; - var minimumChannelValue = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); - var maxChannelRegtestValue = new Money(Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST).ToUnit(MoneyUnit.BTC); - if (selectedUTXOsValue < minimumChannelValue) + decimal minimumValue; + if (IsWalletWithdrawalValidation) { - e.ErrorText = $"The combined amount of the UTXOs selected must be greater than {minimumChannelValue:f8} BTC"; + minimumValue = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; + } + else + { + minimumValue = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); + } + var maxChannelRegtestValue = new Money(Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST).ToUnit(MoneyUnit.BTC); + if (selectedUTXOsValue < minimumValue) + { + e.ErrorText = $"The combined amount of the UTXOs selected must be greater than {minimumValue:f8} BTC"; e.Status = ValidationStatus.Error; } - else if (selectedUTXOsValue > maxChannelRegtestValue && network == Network.RegTest) + else if (selectedUTXOsValue > maxChannelRegtestValue && network == Network.RegTest && IsWalletWithdrawalValidation) { e.ErrorText = $"The combined amount of the UTXOs selected must be lower than {maxChannelRegtestValue:f8} BTC"; e.Status = ValidationStatus.Error; } else - { + { e.Status = ValidationStatus.Success; } } From 795e7e1d474e741989234589692a2022e4a11028 Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Wed, 27 Sep 2023 13:45:26 +0200 Subject: [PATCH 02/11] Added some fixes according to the comments. --- src/Helpers/ValidationHelper.cs | 6 +++--- src/Pages/Wallets.razor | 2 +- src/Pages/Withdrawals.razor | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Helpers/ValidationHelper.cs b/src/Helpers/ValidationHelper.cs index f81bb291..7e230824 100644 --- a/src/Helpers/ValidationHelper.cs +++ b/src/Helpers/ValidationHelper.cs @@ -78,7 +78,7 @@ public static void ValidateChannelCapacity(ValidatorEventArgs obj) } } - public static void ValidateWithdrawalAmount(ValidatorEventArgs obj, Boolean isAmountDisabled) + public static void ValidateWithdrawalAmount(ValidatorEventArgs obj) { var amount = (decimal)obj.Value; @@ -87,13 +87,13 @@ public static void ValidateWithdrawalAmount(ValidatorEventArgs obj, Boolean isAm decimal minimum = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; decimal maximum = Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; - if (amount < minimum && isAmountDisabled) + if (amount < minimum) { obj.Status = ValidationStatus.Error; obj.ErrorText = $"Error, the minimum amount to withdraw is at least {minimum:f8} BTC"; } - if (amount > maximum && isAmountDisabled) + if (amount > maximum) { obj.Status = ValidationStatus.Error; obj.ErrorText = $"Error, the maximum amount to withdraw is {maximum:f8} BTC"; diff --git a/src/Pages/Wallets.razor b/src/Pages/Wallets.razor index 35b3d752..0b6a81df 100644 --- a/src/Pages/Wallets.razor +++ b/src/Pages/Wallets.razor @@ -469,7 +469,7 @@ - + Amount diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index efa5ef6f..c6e75cf4 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -166,7 +166,7 @@ } - + @if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount) From 5073eed56f66ada36f0642ec2a335a1539fe530f Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Wed, 27 Sep 2023 13:48:03 +0200 Subject: [PATCH 03/11] Removed unused code. --- src/Pages/Withdrawals.razor | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index c6e75cf4..a97330c3 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -471,7 +471,6 @@ public static readonly ColumnDefault Description = new("Description"); public static readonly ColumnDefault Wallet = new("Wallet"); public static readonly ColumnDefault Requestor = new("Requestor"); - public static readonly ColumnDefault Capacity = new("Capacity"); public static readonly ColumnDefault DestinationAddress = new("Destination Address"); public static readonly ColumnDefault Amount = new("Amount (BTC)"); public static readonly ColumnDefault SignaturesCollected = new("Signatures Collected"); From a793248c517055a6a57ceb75537421862d04c2fb Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Wed, 27 Sep 2023 13:54:02 +0200 Subject: [PATCH 04/11] Added some improvements. --- src/Pages/Withdrawals.razor | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index a97330c3..2be99079 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -175,7 +175,7 @@ } else { - @($"Amount in BTC. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") + @($"Amount in BTC. Minimum {_minimumWithdrawalAmount:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") } @@ -439,8 +439,8 @@ private string _signedPSBT; private string? _templatePsbtString; private int? _selectedWalletId; - private static readonly decimal _minimumChannelCapacity = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); - private decimal _amount { get; set; } = _minimumChannelCapacity; + private static readonly decimal _minimumWithdrawalAmount = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; + private decimal _amount { get; set; } = _minimumWithdrawalAmount; private int _selectedSourceNodeId; //Validation private Validation? _walletValidation; @@ -529,13 +529,6 @@ StateHasChanged(); } - private async Task ResetChannelRequestRejectModal() - { - _selectedDestNode = null; - _selectedWalletId = null; - _amount = _minimumChannelCapacity; - } - private async Task GetData() { if (LoggedUser?.Id != null) From 27bc8556977ac7be343c049bd5a25a41050bd46b Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Sun, 1 Oct 2023 14:35:59 +0200 Subject: [PATCH 05/11] Improvements fields. --- src/Pages/ChannelRequests.razor | 23 +++++++++-------------- src/Pages/Withdrawals.razor | 15 +++++++-------- src/Shared/UTXOSelectorModal.razor | 4 ++-- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Pages/ChannelRequests.razor b/src/Pages/ChannelRequests.razor index 169b871e..8264ccc3 100644 --- a/src/Pages/ChannelRequests.razor +++ b/src/Pages/ChannelRequests.razor @@ -141,20 +141,15 @@ - - - - - + - @if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount) - { - @($"Amount in BTC. Maximum {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT}.") - } - else - { - @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") - } + @{ + decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT + ? _amount + : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; + decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); + } + @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD")
@@ -465,7 +460,7 @@ private string? _destNodeName; private static readonly decimal _minimumChannelCapacity = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); private decimal _amount { get; set; } = _minimumChannelCapacity; - private bool _selectedPrivate = false; + private bool _selectedPrivate; //Validation private Validation? _walletValidation; diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index 2be99079..6ce17b42 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -169,14 +169,13 @@ - @if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount) - { - @($"Maximum amount {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT} BTC.") - } - else - { - @($"Amount in BTC. Minimum {_minimumWithdrawalAmount:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") - } + @{ + decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT + ? _amount + : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; + decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); + } + @($"Amount in BTC. Minimum {_minimumWithdrawalAmount:f8}. Current amount: {convertedAmount} USD")
diff --git a/src/Shared/UTXOSelectorModal.razor b/src/Shared/UTXOSelectorModal.razor index e1a352ff..5b0ff897 100644 --- a/src/Shared/UTXOSelectorModal.razor +++ b/src/Shared/UTXOSelectorModal.razor @@ -228,13 +228,13 @@ { minimumValue = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); } - var maxChannelRegtestValue = new Money(Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST).ToUnit(MoneyUnit.BTC); + var maxChannelRegtestValue = new Money(Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST).ToUnit(MoneyUnit.BTC); if (selectedUTXOsValue < minimumValue) { e.ErrorText = $"The combined amount of the UTXOs selected must be greater than {minimumValue:f8} BTC"; e.Status = ValidationStatus.Error; } - else if (selectedUTXOsValue > maxChannelRegtestValue && network == Network.RegTest && IsWalletWithdrawalValidation) + else if (selectedUTXOsValue > maxChannelRegtestValue && network == Network.RegTest && !IsWalletWithdrawalValidation) { e.ErrorText = $"The combined amount of the UTXOs selected must be lower than {maxChannelRegtestValue:f8} BTC"; e.Status = ValidationStatus.Error; From 0c5d866b65f89d283f41435dcd98d01aa7975954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20A=2EP?= <53834183+Jossec101@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:04:35 +0200 Subject: [PATCH 06/11] feat(NodeChannelSubscribeJob.cs, ProcessNodeChannelAcceptorJob.cs): add delay after error to prevent excessive requests (#310) This change is implemented to avoid overloading the server with massive requests in case of an error. --- src/Jobs/NodeChannelSubscribeJob.cs | 7 +++++++ src/Jobs/ProcessNodeChannelAcceptorJob.cs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/Jobs/NodeChannelSubscribeJob.cs b/src/Jobs/NodeChannelSubscribeJob.cs index 24995818..98b82ff4 100644 --- a/src/Jobs/NodeChannelSubscribeJob.cs +++ b/src/Jobs/NodeChannelSubscribeJob.cs @@ -87,11 +87,18 @@ public async Task Execute(IJobExecutionContext context) _logger.LogError(e, "Error reading and update event of node {NodeId}", nodeId); throw new JobExecutionException(e, true); } + + } + + } catch (Exception e) { _logger.LogError(e, "Error while subscribing for the channel updates of node {NodeId}", nodeId); + //Sleep to avoid massive requests + await Task.Delay(1000); + throw new JobExecutionException(e, true); } diff --git a/src/Jobs/ProcessNodeChannelAcceptorJob.cs b/src/Jobs/ProcessNodeChannelAcceptorJob.cs index 89a33a83..413bcb5c 100644 --- a/src/Jobs/ProcessNodeChannelAcceptorJob.cs +++ b/src/Jobs/ProcessNodeChannelAcceptorJob.cs @@ -241,7 +241,12 @@ await AcceptChannelOpeningRequestWithUpfrontShutdown(_nBXplorerService, catch (Exception e) { _logger.LogError(e, "Error on {JobName}", nameof(ProcessNodeChannelAcceptorJob)); + + //Sleep to avoid massive requests + await Task.Delay(1000); + throw new JobExecutionException(e, true); + } } } \ No newline at end of file From 77da1ba7b954daae69e52173da52cde337defd29 Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Mon, 9 Oct 2023 15:09:48 +0200 Subject: [PATCH 07/11] Improvements --- src/Pages/ChannelRequests.razor | 15 ++++++++------- src/Pages/Withdrawals.razor | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Pages/ChannelRequests.razor b/src/Pages/ChannelRequests.razor index 8264ccc3..d2603142 100644 --- a/src/Pages/ChannelRequests.razor +++ b/src/Pages/ChannelRequests.razor @@ -143,13 +143,14 @@ - @{ - decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT - ? _amount - : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; - decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); - } - @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD") + @* @{ *@ + @* decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT *@ + @* ? _amount *@ + @* : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; *@ + @* decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); *@ + @* } *@ + @* @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD") *@ + @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD")
diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index 6ce17b42..aff61eb6 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -148,7 +148,7 @@ - + @@ -166,8 +166,8 @@ } - - + + @{ decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT @@ -464,6 +464,7 @@ private decimal _selectedWalletBalance; private bool _validationError; private decimal _previousAmount; + public bool _isCheckedAllFunds; public abstract class PendingWithdrawalsColumnName { @@ -592,6 +593,16 @@ } + private void HandleCheckboxChange(CellEditContext context, bool value) + { + context.CellValue = value; + _isCheckedAllFunds = value; + if (_isCheckedAllFunds) + { + ClearSelectedUTXOs(); + } + } + private async Task OnRowRemoving(CancellableRowChange arg) { if (arg.Item != null) @@ -996,4 +1007,5 @@ } return AllRequestsColumnLayout.IsColumnVisible(column); } + } From 09ec03ccb68d837f54069a57e277dac692798924 Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Tue, 10 Oct 2023 22:26:25 +0200 Subject: [PATCH 08/11] Resolving issues according to the comments --- src/Pages/ChannelRequests.razor | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Pages/ChannelRequests.razor b/src/Pages/ChannelRequests.razor index d2603142..4668b88f 100644 --- a/src/Pages/ChannelRequests.razor +++ b/src/Pages/ChannelRequests.razor @@ -141,16 +141,16 @@ - + - @* @{ *@ - @* decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT *@ - @* ? _amount *@ - @* : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; *@ - @* decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); *@ - @* } *@ - @* @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD") *@ - @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") + @{ + decimal amountToShow = _amount < _maxChannelCapacity + ? _amount + : _maxChannelCapacity; + decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); + } + @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD") + @* @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") *@
@@ -460,6 +460,7 @@ private decimal _selectedWalletBalance; private string? _destNodeName; private static readonly decimal _minimumChannelCapacity = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); + private static readonly decimal _maxChannelCapacity = CurrentNetworkHelper.GetCurrentNetwork() == Network.RegTest ? Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _amount { get; set; } = _minimumChannelCapacity; private bool _selectedPrivate; From 39b80f439031f3f2304deea6c441433eceb822e4 Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Tue, 10 Oct 2023 23:33:40 +0200 Subject: [PATCH 09/11] Fixed chanel capacity for regtest. --- src/Pages/ChannelRequests.razor | 5 ++--- src/Shared/UTXOSelectorModal.razor | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Pages/ChannelRequests.razor b/src/Pages/ChannelRequests.razor index 4668b88f..af388055 100644 --- a/src/Pages/ChannelRequests.razor +++ b/src/Pages/ChannelRequests.razor @@ -150,8 +150,7 @@ decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); } @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD") - @* @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD") *@ - +
or use @@ -460,7 +459,7 @@ private decimal _selectedWalletBalance; private string? _destNodeName; private static readonly decimal _minimumChannelCapacity = new Money(Constants.MINIMUM_CHANNEL_CAPACITY_SATS).ToUnit(MoneyUnit.BTC); - private static readonly decimal _maxChannelCapacity = CurrentNetworkHelper.GetCurrentNetwork() == Network.RegTest ? Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; + private static readonly decimal _maxChannelCapacity = CurrentNetworkHelper.GetCurrentNetwork() == Network.RegTest ? new Money(Constants.MAXIMUM_CHANNEL_CAPACITY_SATS_REGTEST).ToUnit(MoneyUnit.BTC) : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _amount { get; set; } = _minimumChannelCapacity; private bool _selectedPrivate; diff --git a/src/Shared/UTXOSelectorModal.razor b/src/Shared/UTXOSelectorModal.razor index 5b0ff897..9a8c0c5b 100644 --- a/src/Shared/UTXOSelectorModal.razor +++ b/src/Shared/UTXOSelectorModal.razor @@ -234,7 +234,7 @@ e.ErrorText = $"The combined amount of the UTXOs selected must be greater than {minimumValue:f8} BTC"; e.Status = ValidationStatus.Error; } - else if (selectedUTXOsValue > maxChannelRegtestValue && network == Network.RegTest && !IsWalletWithdrawalValidation) + else if (selectedUTXOsValue > maxChannelRegtestValue && network == Network.RegTest && IsWalletWithdrawalValidation) { e.ErrorText = $"The combined amount of the UTXOs selected must be lower than {maxChannelRegtestValue:f8} BTC"; e.Status = ValidationStatus.Error; From 19ba91280e5604ffbd17c1057daae811263ab94f Mon Sep 17 00:00:00 2001 From: oleksandrK Date: Sun, 15 Oct 2023 09:24:47 +0200 Subject: [PATCH 10/11] Fixed amount field. --- src/Pages/Withdrawals.razor | 53 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index aff61eb6..f93a35b9 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -8,6 +8,7 @@ @using Google.Protobuf @using NBXplorer.Models @using NodeGuard.Helpers; +@using Polly @attribute [Authorize(Roles = "Superadmin,NodeManager,FinanceManager")] @@ -40,7 +41,7 @@ - + @**@ @@ -148,7 +149,7 @@ - + @@ -167,7 +168,7 @@ - + @{ decimal amountToShow = _amount < Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT @@ -222,7 +223,7 @@ - + @@ -353,7 +354,7 @@ - + @@ -413,7 +414,6 @@ @inject ISchedulerFactory SchedulerFactory @inject ILocalStorageService LocalStorageService @inject IPriceConversionService PriceConversionService -@inject ILightningService LightningService @code { [CascadingParameter] @@ -422,30 +422,22 @@ [CascadingParameter] private ClaimsPrincipal? ClaimsPrincipal { get; set; } - private List _allWallets = new List(); + private ColumnLayout PendingRequestsColumnLayout; private List _userPendingRequests = new(); private List _availableWallets = new(); - private List? _allRequests; private List _withdrawalRequests = new(); - private List? _channelRequests; private string? mempoolUrl = Constants.MEMPOOL_ENDPOINT; private bool _isFinanceManager; private List SelectedUTXOs = new(); private WalletWithdrawalRequest? _selectedRequest; private PSBTSign? _psbtSignRef; - private Node? _selectedDestNode; private string _signedPSBT; private string? _templatePsbtString; private int? _selectedWalletId; private static readonly decimal _minimumWithdrawalAmount = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _amount { get; set; } = _minimumWithdrawalAmount; - private int _selectedSourceNodeId; //Validation - private Validation? _walletValidation; - private Validation? _sourceNodeValidation; - private Validation? _destNodeValidation; - private Validation? _capacityValidation; private DataGrid? _allRequestsDatagrid; private UTXOSelectorModal _utxoSelectorModalRef; private ConfirmationModal _confirmationModal; @@ -453,18 +445,14 @@ private bool _isNodeManager = false; private WalletWithdrawalRequestStatus? _rejectCancelStatus = WalletWithdrawalRequestStatus.Rejected; private decimal? _selectedRequestWalletBalance; - private List? _manageableNodes; private decimal _maxWithdrawal = Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _minWithdrawal = Constants.MINIMUM_WITHDRAWAL_BTC_AMOUNT; private decimal _btcPrice; private ColumnLayout AllRequestsColumnLayout; - private Dictionary PendingRequestsColumns = new(); - private Dictionary AllRequestsColumns = new(); - private bool columnsLoaded; - private decimal _selectedWalletBalance; - private bool _validationError; - private decimal _previousAmount; - public bool _isCheckedAllFunds; + private Dictionary _pendingRequestsColumns = new(); + private Dictionary _allRequestsColumns = new(); + private bool _columnsLoaded; + public bool IsCheckedAllFunds; public abstract class PendingWithdrawalsColumnName { @@ -510,7 +498,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { - if (!firstRender && !columnsLoaded) + if (!firstRender && !_columnsLoaded) { await LoadColumnLayout(); } @@ -523,9 +511,9 @@ private async Task LoadColumnLayout() { - AllRequestsColumns = await LocalStorageService.LoadStorage(nameof(AllWithdrawalsColumnName), ColumnHelpers.GetColumnsDictionary()); - PendingRequestsColumns = await LocalStorageService.LoadStorage(nameof(PendingWithdrawalsColumnName), ColumnHelpers.GetColumnsDictionary()); - columnsLoaded = true; + _allRequestsColumns = await LocalStorageService.LoadStorage(nameof(AllWithdrawalsColumnName), ColumnHelpers.GetColumnsDictionary()); + _pendingRequestsColumns = await LocalStorageService.LoadStorage(nameof(PendingWithdrawalsColumnName), ColumnHelpers.GetColumnsDictionary()); + _columnsLoaded = true; StateHasChanged(); } @@ -596,8 +584,8 @@ private void HandleCheckboxChange(CellEditContext context, bool value) { context.CellValue = value; - _isCheckedAllFunds = value; - if (_isCheckedAllFunds) + IsCheckedAllFunds = value; + if (IsCheckedAllFunds) { ClearSelectedUTXOs(); } @@ -818,7 +806,7 @@ { _rejectCancelStatus = null; _selectedRequest = null; - + _selectedRequestWalletBalance = 0; await GetData(); await _rejectCancelModalRef.CloseModal(); } @@ -1008,4 +996,9 @@ return AllRequestsColumnLayout.IsColumnVisible(column); } + private void OnShowNewWalletWithdrawalModal() + { + _amount = _minimumWithdrawalAmount; + } + } From 038f74ae0228871ed67d8a4731aca14827e80e9b Mon Sep 17 00:00:00 2001 From: Marcos Date: Mon, 16 Oct 2023 16:16:54 +0200 Subject: [PATCH 11/11] fix: currency message not needed anymore and symbol change --- src/Pages/ChannelRequests.razor | 4 ++-- src/Pages/Withdrawals.razor | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Pages/ChannelRequests.razor b/src/Pages/ChannelRequests.razor index af388055..70c2359b 100644 --- a/src/Pages/ChannelRequests.razor +++ b/src/Pages/ChannelRequests.razor @@ -141,7 +141,7 @@ - + @{ decimal amountToShow = _amount < _maxChannelCapacity @@ -149,7 +149,7 @@ : _maxChannelCapacity; decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); } - @($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD") + @($"Minimum {_minimumChannelCapacity:f8}. Current amount: {convertedAmount} USD")
diff --git a/src/Pages/Withdrawals.razor b/src/Pages/Withdrawals.razor index f93a35b9..e9682c0e 100644 --- a/src/Pages/Withdrawals.razor +++ b/src/Pages/Withdrawals.razor @@ -176,7 +176,7 @@ : Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT; decimal convertedAmount = Math.Round(PriceConversionService.SatToUsdConversion(new Money(amountToShow, MoneyUnit.BTC).Satoshi, _btcPrice), 2); } - @($"Amount in BTC. Minimum {_minimumWithdrawalAmount:f8}. Current amount: {convertedAmount} USD") + @($"Minimum {_minimumWithdrawalAmount:f8}. Current amount: {convertedAmount} USD")