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

[VDG] Fix Amount Paste #12661

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions WalletWasabi.Fluent/Controls/CurrencyEntryBox.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;

Check notice on line 1 in WalletWasabi.Fluent/Controls/CurrencyEntryBox.axaml.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (master)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.20 to 4.27, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -308,9 +308,15 @@
return;
}

// Ignore paste if there are invalid characters
if (!RegexDecimalCharsOnly().IsMatch(text))
{
return;
}
soosr marked this conversation as resolved.
Show resolved Hide resolved

text = text.Replace("\r", "").Replace("\n", "").Trim();

if (!TryParse(text, out text))
if (!TryParsePastedValue(text, out text))
{
return;
}
Expand All @@ -327,7 +333,7 @@
}
}

private bool TryParse(string text, [NotNullWhen(true)] out string? result)
private bool TryParsePastedValue(string text, [NotNullWhen(true)] out string? result)
{
if (!IsFiat)
{
Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Fluent/Controls/DualCurrencyEntryBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void InputText(string? text)
}
else
{
if (CurrencyInput.TryCorrectBitcoinAmount(text, out var better) && better != Constants.MaximumNumberOfBitcoins.ToString())
if (CurrencyInput.TryCorrectBitcoinAmount(text, out var better))
{
text = better;
}
Expand Down
2 changes: 1 addition & 1 deletion WalletWasabi.Fluent/Views/Wallets/Send/SendView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
IsConversionReversed="{Binding ConversionReversed, Mode=TwoWay}"
BalanceBtc="{Binding Balance^.Btc}"
BalanceUsd="{Binding Balance^.Usd^}"
ValidatePasteBalance="True">
ValidatePasteBalance="False">
<DualCurrencyEntryBox.Resources>

<converters:BooleanConverter x:Key="SuggestionPlacementConverter"
Expand Down
6 changes: 0 additions & 6 deletions WalletWasabi/Userfacing/CurrencyInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ public static bool TryCorrectBitcoinAmount(string original, [NotNullWhen(true)]
corrected = corrected[..(dotIndex + 1 + 8)];
}

// Make sure you don't send more bitcoins than how much there is in existence.
if (corrected.Length != 0 && corrected != "." && (!decimal.TryParse(corrected, out decimal btcDecimal) || btcDecimal > Constants.MaximumNumberOfBitcoins))
{
corrected = Constants.MaximumNumberOfBitcoins.ToString();
}

if (corrected != original)
{
best = corrected;
Expand Down