Simple convert to conditional expression
MODIFY
WalletWasabi.Backend/Controllers/HomeController.cs
WalletWasabi.Backend/Controllers/HomeController.cs
@@ -11,15 +11,9 @@ namespace WalletWasabi.Backend.Controllers
{
string host = HttpContext?.Request?.Host.Host;
- VirtualFileResult response;
- if (!string.IsNullOrWhiteSpace(host) && host.TrimEnd('/').EndsWith(".onion", StringComparison.OrdinalIgnoreCase))
- {
- response = File("onion-index.html", "text/html");
- }
- else
- {
- response = File("index.html", "text/html");
- }
+ VirtualFileResult response = !string.IsNullOrWhiteSpace(host) && host.TrimEnd('/').EndsWith(".onion", StringComparison.OrdinalIgnoreCase)
+ ? File("onion-index.html", "text/html")
+ : File("index.html", "text/html");
response.LastModified = DateTimeOffset.UtcNow;
return response;

MODIFY
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
WalletWasabi.Gui/Controls/LockScreen/SlideLockScreenViewModel.cs
@@ -132,14 +132,7 @@ namespace WalletWasabi.Gui.Controls.LockScreen
case SlideLockState.UserIsDragging:
if (!IsUserDragging)
{
- if (Math.Abs(Offset) > Threshold)
- {
- _state = SlideLockState.UserDragPassedThreshold;
- }
- else
- {
- _state = SlideLockState.Idle;
- }
+ _state = Math.Abs(Offset) > Threshold ? SlideLockState.UserDragPassedThreshold : SlideLockState.Idle;
}
break;

MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/CoinJoinTabViewModel.cs
@@ -336,14 +336,9 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
else
{
var available = Global.WalletService.Coins.Where(x => x.Confirmed && !x.Unavailable);
- if (available.Any())
- {
- RequiredBTC = registrableRound.State.CalculateRequiredAmount(available.Where(x => x.AnonymitySet < Global.Config.PrivacyLevelStrong).Select(x => x.Amount).ToArray());
- }
- else
- {
- RequiredBTC = registrableRound.State.CalculateRequiredAmount();
- }
+ RequiredBTC = available.Any()
+ ? registrableRound.State.CalculateRequiredAmount(available.Where(x => x.AnonymitySet < Global.Config.PrivacyLevelStrong).Select(x => x.Amount).ToArray())
+ : registrableRound.State.CalculateRequiredAmount();
}
}
}

MODIFY
WalletWasabi.Gui/ManagedDialogs/ManagedFileChooserViewModel.cs
WalletWasabi.Gui/ManagedDialogs/ManagedFileChooserViewModel.cs
@@ -230,14 +230,9 @@ namespace WalletWasabi.Gui.ManagedDialogs
if (!ShowHiddenFiles)
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- infos = infos.Where(i => (i.Attributes & (FileAttributes.Hidden | FileAttributes.System)) != 0);
- }
- else
- {
- infos = infos.Where(i => !i.Name.StartsWith("."));
- }
+ infos = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
+ ? infos.Where(i => (i.Attributes & (FileAttributes.Hidden | FileAttributes.System)) != 0)
+ : infos.Where(i => !i.Name.StartsWith("."));
}
if (SelectedFilter != null)

MODIFY
WalletWasabi/Extensions/RPCClientExtensions.cs
WalletWasabi/Extensions/RPCClientExtensions.cs
@@ -104,15 +104,9 @@ namespace NBitcoin.RPC
private static EstimateSmartFeeResponse SimulateRegTestFeeEstimation(int confirmationTarget, EstimateSmartFeeMode estimateMode)
{
- int satoshiPerBytes;
- if (estimateMode == EstimateSmartFeeMode.Conservative)
- {
- satoshiPerBytes = ((Constants.SevenDaysConfirmationTarget + 1 + 6) - confirmationTarget) / 7;
- }
- else // Economical
- {
- satoshiPerBytes = ((Constants.SevenDaysConfirmationTarget + 1 + 5) - confirmationTarget) / 7;
- }
+ int satoshiPerBytes = estimateMode == EstimateSmartFeeMode.Conservative
+ ? (Constants.SevenDaysConfirmationTarget + 1 + 6 - confirmationTarget) / 7
+ : (Constants.SevenDaysConfirmationTarget + 1 + 5 - confirmationTarget) / 7; // Economical
Money feePerK = Money.Satoshis(satoshiPerBytes * 1000);
FeeRate feeRate = new FeeRate(feePerK);
@@ -225,15 +219,9 @@ namespace NBitcoin.RPC
/// <returns>All the dependents of the provided transactionHashes.</returns>
public static async Task<ISet<uint256>> GetAllDependentsAsync(this RPCClient rpc, IEnumerable<uint256> transactionHashes, bool includingProvided, bool likelyProvidedManyConfirmedOnes)
{
- IEnumerable<uint256> workingTxHashes;
- if (likelyProvidedManyConfirmedOnes) // If confirmed txIds are provided, then do a big check first.
- {
- workingTxHashes = await rpc.GetUnconfirmedAsync(transactionHashes);
- }
- else
- {
- workingTxHashes = transactionHashes;
- }
+ IEnumerable<uint256> workingTxHashes = likelyProvidedManyConfirmedOnes // If confirmed txIds are provided, then do a big check first.
+ ? await rpc.GetUnconfirmedAsync(transactionHashes)
+ : transactionHashes;
var hashSet = new HashSet<uint256>();
foreach (var txId in workingTxHashes)

MODIFY
WalletWasabi/Helpers/ByteHelpers.cs
WalletWasabi/Helpers/ByteHelpers.cs
@@ -98,14 +98,7 @@ namespace System
for (int i = 0; i < 256; i++)
{
string s = i.ToString("X2");
- if (BitConverter.IsLittleEndian)
- {
- result[i] = s[0] + ((uint)s[1] << 16);
- }
- else
- {
- result[i] = s[1] + ((uint)s[0] << 16);
- }
+ result[i] = BitConverter.IsLittleEndian ? s[0] + ((uint)s[1] << 16) : s[1] + ((uint)s[0] << 16);
}
return result;
}

MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -110,14 +110,9 @@ namespace WalletWasabi.Helpers
var home = Environment.GetEnvironmentVariable("HOME");
if (!string.IsNullOrEmpty(home))
{
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
- {
- directory = Path.Combine(home, "Library", "Application Support", "Bitcoin");
- }
- else // Linux
- {
- directory = Path.Combine(home, ".bitcoin");
- }
+ directory = RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
+ ? Path.Combine(home, "Library", "Application Support", "Bitcoin")
+ : Path.Combine(home, ".bitcoin"); // Linux
}
else
{

MODIFY
WalletWasabi/Helpers/NBitcoinHelpers.cs
WalletWasabi/Helpers/NBitcoinHelpers.cs
@@ -89,14 +89,7 @@ namespace WalletWasabi.Helpers
{
// Try hex, Old wallet format was like this.
var bytes = ByteHelpers.FromHex(hdFingerprintString);
- if (reverseByteOrder)
- {
- hdfp = new HDFingerprint(bytes.Reverse().ToArray());
- }
- else
- {
- hdfp = new HDFingerprint(bytes);
- }
+ hdfp = reverseByteOrder ? new HDFingerprint(bytes.Reverse().ToArray()) : new HDFingerprint(bytes);
}
return hdfp;
}

MODIFY
WalletWasabi/Io/DigestableSafeMutexIoManager.cs
WalletWasabi/Io/DigestableSafeMutexIoManager.cs
@@ -212,15 +212,9 @@ namespace WalletWasabi.Io
{
if (DigestRandomIndex.HasValue)
{
- int index;
- if (DigestRandomIndex == -1 || DigestRandomIndex >= line.Length) // Last char.
- {
- index = line.Length - 1;
- }
- else
- {
- index = DigestRandomIndex.Value;
- }
+ int index = DigestRandomIndex == -1 || DigestRandomIndex >= line.Length // Last char.
+ ? line.Length - 1
+ : DigestRandomIndex.Value;
var c = line[index];
var b = (byte)c;

MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -183,14 +183,7 @@ namespace WalletWasabi.KeyManagement
public void SetMinGapLimit(int? minGapLimit)
{
- if (minGapLimit is int val)
- {
- MinGapLimit = Math.Max(AbsoluteMinGapLimit, val);
- }
- else
- {
- MinGapLimit = AbsoluteMinGapLimit;
- }
+ MinGapLimit = minGapLimit is int val ? Math.Max(AbsoluteMinGapLimit, val) : AbsoluteMinGapLimit;
// AssertCleanKeysIndexed(); Do not do this. Wallet file is null yet.
}
@@ -416,15 +409,7 @@ namespace WalletWasabi.KeyManagement
lock (HdPubKeysLock)
{
- IEnumerable<HdPubKey> relevantHdPubKeys;
- if (isInternal)
- {
- relevantHdPubKeys = HdPubKeys.Where(x => x.IsInternal);
- }
- else
- {
- relevantHdPubKeys = HdPubKeys.Where(x => !x.IsInternal);
- }
+ IEnumerable<HdPubKey> relevantHdPubKeys = isInternal ? HdPubKeys.Where(x => x.IsInternal) : HdPubKeys.Where(x => !x.IsInternal);
KeyPath path;
if (relevantHdPubKeys.Any())

MODIFY
WalletWasabi/Models/ChaumianCoinJoin/CcjClientState.cs
WalletWasabi/Models/ChaumianCoinJoin/CcjClientState.cs
@@ -220,14 +220,9 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
if (lazyMode) // Do the largest valid combination.
{
IEnumerable<SmartCoin> highestValueEnumeration = coins.OrderByDescending(x => x.Amount).Take(i);
- if (highestValueEnumeration.Sum(x => x.Amount) >= amountNeeded)
- {
- coinGroups = new List<IEnumerable<SmartCoin>> { highestValueEnumeration };
- }
- else
- {
- coinGroups = new List<IEnumerable<SmartCoin>>();
- }
+ coinGroups = highestValueEnumeration.Sum(x => x.Amount) >= amountNeeded
+ ? new List<IEnumerable<SmartCoin>> { highestValueEnumeration }
+ : new List<IEnumerable<SmartCoin>>();
}
else
{

MODIFY
WalletWasabi/Models/SmartTransaction.cs
WalletWasabi/Models/SmartTransaction.cs
@@ -158,17 +158,7 @@ namespace WalletWasabi.Models
public static bool operator ==(Transaction tx1, SmartTransaction tx2)
{
- bool rc;
-
- if (tx1 is null || tx2 is null)
- {
- rc = false;
- }
- else
- {
- rc = tx1.GetHash().Equals(tx2.GetHash());
- }
-
+ bool rc = tx1 is null || tx2 is null ? false : tx1.GetHash().Equals(tx2.GetHash());
return rc;
}
@@ -176,17 +166,7 @@ namespace WalletWasabi.Models
public static bool operator ==(SmartTransaction tx1, Transaction tx2)
{
- bool rc;
-
- if (tx1 is null || tx2 is null)
- {
- rc = false;
- }
- else
- {
- rc = tx1.GetHash().Equals(tx2.GetHash());
- }
-
+ bool rc = tx1 is null || tx2 is null ? false : tx1.GetHash().Equals(tx2.GetHash());
return rc;
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -1088,25 +1088,13 @@ namespace WalletWasabi.Services
throw new ArgumentException($"{nameof(allowedInputs)} is not null, but empty.");
}
- if (allowUnconfirmed)
- {
- allowedSmartCoinInputs = Coins.Where(x => !x.Unavailable && allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index)).ToList();
- }
- else
- {
- allowedSmartCoinInputs = Coins.Where(x => !x.Unavailable && x.Confirmed && allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index)).ToList();
- }
+ allowedSmartCoinInputs = allowUnconfirmed
+ ? Coins.Where(x => !x.Unavailable && allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index)).ToList()
+ : Coins.Where(x => !x.Unavailable && x.Confirmed && allowedInputs.Any(y => y.TransactionId == x.TransactionId && y.Index == x.Index)).ToList();
}
else
{
- if (allowUnconfirmed)
- {
- allowedSmartCoinInputs = Coins.Where(x => !x.Unavailable).ToList();
- }
- else
- {
- allowedSmartCoinInputs = Coins.Where(x => !x.Unavailable && x.Confirmed).ToList();
- }
+ allowedSmartCoinInputs = allowUnconfirmed ? Coins.Where(x => !x.Unavailable).ToList() : Coins.Where(x => !x.Unavailable && x.Confirmed).ToList();
}
// 4. Get and calculate fee

MODIFY
WalletWasabi/TorSocks5/TorHttpClient.cs
WalletWasabi/TorSocks5/TorHttpClient.cs
@@ -66,14 +66,7 @@ namespace WalletWasabi.TorSocks5
private void Create(EndPoint torSocks5EndPoint, bool isolateStream, Func<Uri> baseUriAction)
{
DestinationUriAction = Guard.NotNull(nameof(baseUriAction), baseUriAction);
- if (DestinationUri.IsLoopback)
- {
- TorSocks5EndPoint = null;
- }
- else
- {
- TorSocks5EndPoint = torSocks5EndPoint;
- }
+ TorSocks5EndPoint = DestinationUri.IsLoopback ? null : torSocks5EndPoint;
TorSocks5Client = null;
IsolateStream = isolateStream;
}

MODIFY
WalletWasabi/TorSocks5/TorSocks5Client.cs
WalletWasabi/TorSocks5/TorSocks5Client.cs
@@ -132,15 +132,9 @@ namespace WalletWasabi.TorSocks5
Guard.NotNull(nameof(identity), identity);
- MethodsField methods;
- if (string.IsNullOrWhiteSpace(identity))
- {
- methods = new MethodsField(MethodField.NoAuthenticationRequired);
- }
- else
- {
- methods = new MethodsField(MethodField.UsernamePassword);
- }
+ MethodsField methods = string.IsNullOrWhiteSpace(identity)
+ ? new MethodsField(MethodField.NoAuthenticationRequired)
+ : new MethodsField(MethodField.UsernamePassword);
var sendBuffer = new VersionMethodRequest(methods).ToBytes();
@@ -213,14 +207,7 @@ namespace WalletWasabi.TorSocks5
using (await AsyncLock.LockAsync())
{
TcpClient?.Dispose();
- if (IPAddress.TryParse(host, out IPAddress ip))
- {
- TcpClient = new TcpClient(ip.AddressFamily);
- }
- else
- {
- TcpClient = new TcpClient();
- }
+ TcpClient = IPAddress.TryParse(host, out IPAddress ip) ? new TcpClient(ip.AddressFamily) : new TcpClient();
await TcpClient.ConnectAsync(host, port);
Stream = TcpClient.GetStream();
RemoteEndPoint = TcpClient.Client.RemoteEndPoint;
@@ -359,15 +346,9 @@ namespace WalletWasabi.TorSocks5
// If receiveBufferSize is null, zero or negative or bigger than TcpClient.ReceiveBufferSize
// then work with TcpClient.ReceiveBufferSize
var tcpReceiveBuffSize = TcpClient.ReceiveBufferSize;
- var actualReceiveBufferSize = 0;
- if (receiveBufferSize is null || receiveBufferSize <= 0 || receiveBufferSize > tcpReceiveBuffSize)
- {
- actualReceiveBufferSize = tcpReceiveBuffSize;
- }
- else
- {
- actualReceiveBufferSize = (int)receiveBufferSize;
- }
+ var actualReceiveBufferSize = receiveBufferSize is null || receiveBufferSize <= 0 || receiveBufferSize > tcpReceiveBuffSize
+ ? tcpReceiveBuffSize
+ : (int)receiveBufferSize;
// Receive the response
var receiveBuffer = new byte[actualReceiveBufferSize];

Simple convert to conditional expression