Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numeric field in the channel request and withdrawal pages. #306

Merged
merged 10 commits into from
Oct 16, 2023
6 changes: 3 additions & 3 deletions src/Helpers/ValidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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";
Expand Down
21 changes: 11 additions & 10 deletions src/Pages/ChannelRequests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@
</DisplayTemplate>
<EditTemplate>
<Validation Validator="@ValidationHelper.ValidateChannelCapacity" @ref="_capacityValidation">
<NumericPicker TValue="decimal" @bind-Value="@_amount" Min="0" Decimals="8" Step="0.00001m" CurrencySymbol=" BTC" CurrencySymbolPlacement="CurrencySymbolPlacement.Suffix" Disabled="@(SelectedUTXOs.Count > 0)">
<Feedback>
<ValidationError/>
</Feedback>
</NumericPicker>
<NumericPicker TValue="decimal" @bind-Value="@_amount" Min="@_minimumChannelCapacity" Max="@_maxChannelCapacity" Decimals="8" Step="0.00001m" CurrencySymbol=" BTC" CurrencySymbolPlacement="CurrencySymbolPlacement.Suffix" Disabled="@(SelectedUTXOs.Count > 0)"/>
<FieldHelp>

@($"Amount in Satoshis. Minimum {_minimumChannelCapacity:f8}. Current amount: {Math.Round(PriceConversionService.SatToUsdConversion(new Money(_amount, MoneyUnit.BTC).Satoshi, _btcPrice), 2)} USD")

</FieldHelp>
@{
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is in BTC. Should we fix it later?

</FieldHelp>
</Validation>
<div class="mb-3">
<Button Color="Color.Primary" Disabled="@(!_selectedWalletId.HasValue)" Clicked="@OpenCoinSelectionModal">Select Coins</Button> or use
Expand Down Expand Up @@ -390,7 +390,7 @@
TemplatePsbtString="@_templatePSBTString"
SignedPSBT="@_psbt"/>

<CancelOrRejectPopup

Check warning on line 393 in src/Pages/ChannelRequests.razor

View workflow job for this annotation

GitHub Actions / build-and-test

Component 'CancelOrRejectPopup' expects a value for the parameter 'Reason', but a value may not have been provided.

Check warning on line 393 in src/Pages/ChannelRequests.razor

View workflow job for this annotation

GitHub Actions / build-and-test

Component 'CancelOrRejectPopup' expects a value for the parameter 'Reason', but a value may not have been provided.
@ref=@_rejectCancelModalRef
Title='@(_selectedStatusActionString + " operation: " + _selectedRequest?.Id)'
Validator="@RejectReasonValidator"
Expand Down Expand Up @@ -459,8 +459,9 @@
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 ? 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 = false;
private bool _selectedPrivate;

//Validation
private Validation? _walletValidation;
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Wallets.razor
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@
</Field>
</Column>
<Column ColumnSize="ColumnSize.Is6">
<Validation Validator="args => ValidationHelper.ValidateWithdrawalAmount(args, _transferAllFunds)">
<Validation Validator="args => ValidationHelper.ValidateWithdrawalAmount(args)">
<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
Loading
Loading