Skip to content

Commit

Permalink
Added some fixes according to the comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksKSoftware committed Sep 25, 2023
1 parent ec27a8d commit 504e2fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/Helpers/ValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/ChannelRequests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
<FieldHelp>
@if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount)
{
<span class="text-danger">@($"Amount in Satoshis. Maximum {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT}.")</span>
<span class="text-danger">@($"Amount in BTC. Maximum {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT}.")</span>
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Wallets.razor
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@
<Column ColumnSize="ColumnSize.Is6">
<Validation Validator="args => ValidationHelper.ValidateWithdrawalAmount(args, _transferAllFunds)">
<Field>
<FieldLabel>Amount</FieldLabel>
<FieldLabel>Amount</FieldLabel>
<FieldBody>
<NumericPicker TValue="decimal" Disabled="_transferAllFunds" @bind-Value="@_amountToTransfer" CurrencySymbol="₿ " Max="@_maxWithdrawal" Min="@_minWithdrawal" Decimals="8">
<Feedback>
Expand Down
30 changes: 9 additions & 21 deletions src/Pages/Withdrawals.razor
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@
</DataGridColumn>
<DataGridColumn TItem="WalletWithdrawalRequest" PopupFieldColumnSize="ColumnSize.Is6" Field="@nameof(WalletWithdrawalRequest.WithdrawAllFunds)" Caption="@nameof(WalletWithdrawalRequest.WithdrawAllFunds).Humanize(LetterCasing.Sentence)" Editable="true" Displayable="false">
<EditTemplate>

<Check TValue="bool" Checked="@((bool) context.CellValue)" CheckedChanged="(value) => {context.CellValue = value; _isAmountDisabled = value;}"> </Check>


<Check TValue="bool" Checked="@((bool) context.CellValue)" CheckedChanged="(value) => {context.CellValue = value;}"> </Check>
</EditTemplate>
</DataGridColumn>
<DataGridColumn PopupFieldColumnSize="ColumnSize.Is6" Caption="Wallet Balance" Editable="true" Displayable="false">
Expand All @@ -169,26 +166,19 @@
}
</DisplayTemplate>
<EditTemplate>
@if (!_isAmountDisabled)
{
<Validation Validator="args => ValidationHelper.ValidateWithdrawalAmount(args, _isAmountDisabled)">
<NumericPicker TValue="decimal" @bind-Value="@_amount" Disabled="_isAmountDisabled" Step="0.00001m" CurrencySymbol="" Max="@(_maxWithdrawal)" Min="_minWithdrawal" Decimals="8" />
<Validation Validator="args => ValidationHelper.ValidateWithdrawalAmount(args, false)">
<NumericPicker TValue="decimal" @bind-Value="@_amount" Step="0.00001m" CurrencySymbol="" Max="@(_maxWithdrawal)" Min="_minWithdrawal" Decimals="8" />
<FieldHelp>
@if (Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT < _amount)
{
<span class="text-danger">@($"Amount in Satoshis. Maximum {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT}.")</span>
<span class="text-danger">@($"Maximum amount {Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT} BTC.")</span>
}
else
{
@($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD")
@($"Amount in BTC. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD")
}
</FieldHelp>
</Validation>
}
else
{
<NumericPicker TValue="decimal" Disabled="_isAmountDisabled" Value="@((decimal)context.CellValue)" ValueChanged="(value) => { context.CellValue = value; }" CurrencySymbol="SAT "/>
}
<div class="mb-3">
<Button Color="Color.Primary" Disabled="@(!_selectedWalletId.HasValue)" Clicked="@OpenCoinSelectionModal">Select Coins</Button> or use
<Button Color="Color.Primary" Disabled="@(SelectedUTXOs.Count == 0)" Clicked="@ClearSelectedUTXOs">Default Coin Selection</Button>
Expand Down Expand Up @@ -257,7 +247,7 @@
<h3>Withdrawal requests</h3>
<DataGrid TItem="WalletWithdrawalRequest"
@ref="_allRequestsDatagrid"
Data="@_allWalletRequests"
Data="@_withdrawalRequests"
Filterable="true"
FilterMethod="DataGridFilterMethod.Contains"
Editable="false"
Expand Down Expand Up @@ -413,7 +403,7 @@
<UTXOSelectorModal
@ref="_utxoSelectorModalRef"
OnClose="@OnCloseCoinSelectionModal"
isAmountValidatioEnabled="false"/>
IsWalletWithdrawalValidation="false"/>

@inject IToastService ToastService
@inject IWalletWithdrawalRequestRepository WalletWithdrawalRequestRepository
Expand All @@ -438,7 +428,7 @@
private List<WalletWithdrawalRequest> _userPendingRequests = new();
private List<Wallet> _availableWallets = new();
private List<ChannelOperationRequest>? _allRequests;
private List<WalletWithdrawalRequest> _allWalletRequests = new();
private List<WalletWithdrawalRequest> _withdrawalRequests = new();
private List<ChannelOperationRequest>? _channelRequests;
private string? mempoolUrl = Constants.MEMPOOL_ENDPOINT;
private bool _isFinanceManager;
Expand All @@ -463,7 +453,6 @@
private CancelOrRejectPopup? _rejectCancelModalRef;
private bool _isNodeManager = false;
private WalletWithdrawalRequestStatus? _rejectCancelStatus = WalletWithdrawalRequestStatus.Rejected;
private bool _isAmountDisabled;
private decimal? _selectedRequestWalletBalance;
private List<Node>? _manageableNodes;
private decimal _maxWithdrawal = Constants.MAXIMUM_WITHDRAWAL_BTC_AMOUNT;
Expand Down Expand Up @@ -553,7 +542,7 @@
if (LoggedUser?.Id != null)
_userPendingRequests = await WalletWithdrawalRequestRepository.GetUnsignedPendingRequestsByUser(LoggedUser.Id);

_allWalletRequests = (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
Expand Down Expand Up @@ -698,7 +687,6 @@
if (LoggedUser != null)
{
obj.UserRequestorId = LoggedUser.Id;
_isAmountDisabled = false;
_selectedRequestWalletBalance = null;
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/Shared/UTXOSelectorModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
private Validation _validation { get; set; } = new();

[Parameter]
public bool isAmountValidatioEnabled { get; set; } = true;
public bool IsWalletWithdrawalValidation { get; set; } = true;

public void ClearModal()
{
Expand Down Expand Up @@ -219,14 +219,22 @@
if (e.Value is not List<UTXO>) return;
var selectedUTXOsValue = ((List<UTXO>)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 && isAmountValidatioEnabled)
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 && isAmountValidatioEnabled)
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;
Expand Down

0 comments on commit 504e2fd

Please sign in to comment.