Add some small simplifications
MODIFY
WalletWasabi.Backend/Controllers/OffchainController.cs
WalletWasabi.Backend/Controllers/OffchainController.cs
@@ -36,8 +36,9 @@ namespace WalletWasabi.Backend.Controllers
[ResponseCache(Duration = 60, Location = ResponseCacheLocation.Client)]
public async Task<IEnumerable<ExchangeRate>> GetExchangeRatesAsync()
{
- if (!Cache.TryGetValue(nameof(GetExchangeRatesAsync), out List<ExchangeRate> exchangeRates))
- {
+ if (Cache.TryGetValue(nameof(GetExchangeRatesAsync), out List<ExchangeRate> exchangeRates))
+ return exchangeRates;
+
exchangeRates = await ExchangeRateProvider.GetExchangeRateAsync();
if (exchangeRates == null)
@@ -49,7 +50,6 @@ namespace WalletWasabi.Backend.Controllers
.SetAbsoluteExpiration(TimeSpan.FromSeconds(20));
Cache.Set(nameof(GetExchangeRatesAsync), exchangeRates, cacheEntryOptions);
- }
return exchangeRates;
}

MODIFY
WalletWasabi/Helpers/EnvironmentHelpers.cs
WalletWasabi/Helpers/EnvironmentHelpers.cs
@@ -38,11 +38,10 @@ namespace WalletWasabi.Helpers
}
}
- if (!Directory.Exists(directory))
- {
+ if (Directory.Exists(directory)) return directory;
+
Logger.LogInfo($"Creating data directory at `{directory}`.");
Directory.CreateDirectory(directory);
- }
return directory;
}

MODIFY
WalletWasabi/Helpers/HttpMessageHelper.cs
WalletWasabi/Helpers/HttpMessageHelper.cs
@@ -504,8 +504,7 @@ namespace System.Net.Http
public static void CopyHeaders(HttpHeaders source, HttpHeaders destination)
{
- if (source.NotNullAndNotEmpty())
- {
+ if (!source.NotNullAndNotEmpty()) return;
foreach (var header in source)
{
destination.TryAddWithoutValidation(header.Key, header.Value);
@@ -513,4 +512,3 @@ namespace System.Net.Http
}
}
}
-}

MODIFY
WalletWasabi/KeyManagement/HdPubKey.cs
WalletWasabi/KeyManagement/HdPubKey.cs
@@ -37,26 +37,17 @@ namespace WalletWasabi.KeyManagement
public void SetLabel(string label, KeyManager kmToFile = null)
{
label = Guard.Correct(label);
- if (Label != label)
- {
+ if (Label == label) return;
Label = label;
- if (kmToFile != null)
- {
- kmToFile.ToFile();
- }
- }
+
+ kmToFile?.ToFile();
}
public void SetKeyState(KeyState state, KeyManager kmToFile = null)
{
- if (KeyState != state)
- {
+ if (KeyState == state) return;
KeyState = state;
- if (kmToFile != null)
- {
- kmToFile.ToFile();
- }
- }
+ kmToFile?.ToFile();
}
private Script _p2pkScript = null;

MODIFY
WalletWasabi/KeyManagement/KeyManager.cs
WalletWasabi/KeyManagement/KeyManager.cs
@@ -105,17 +105,16 @@ namespace WalletWasabi.KeyManagement
public void SetFilePath(string filePath)
{
FilePath = string.IsNullOrWhiteSpace(filePath) ? null : filePath;
- if (FilePath != null)
- {
+ if (FilePath == null) return;
+
var directoryPath = Path.GetDirectoryName(Path.GetFullPath(filePath));
Directory.CreateDirectory(directoryPath);
}
- }
public void ToFile()
{
- if (FilePath != null)
- {
+ if (FilePath == null) return;
+
lock (ToFileLock)
{
string jsonString = JsonConvert.SerializeObject(this, Formatting.Indented);
@@ -124,7 +123,6 @@ namespace WalletWasabi.KeyManagement
Encoding.UTF8);
}
}
- }
public static KeyManager FromFile(string filePath)
{

MODIFY
WalletWasabi/Logging/Logger.cs
WalletWasabi/Logging/Logger.cs
@@ -46,14 +46,12 @@ namespace WalletWasabi.Logging
Modes.Clear();
}
- if (modes != null)
- {
+ if (modes == null) return;
foreach (var mode in modes)
{
Modes.Add(mode);
}
}
- }
public static void SetFilePath(string filePath) => FilePath = Guard.NotNullOrEmptyOrWhitespace(nameof(filePath), filePath, trim: true);
@@ -145,8 +143,8 @@ namespace WalletWasabi.Logging
Debug.Write(finalLogMessage);
}
- if (Modes.Contains(LogMode.File))
- {
+ if (!Modes.Contains(LogMode.File)) return;
+
var dir = Path.GetDirectoryName(FilePath);
if (dir != "")
{
@@ -176,7 +174,6 @@ namespace WalletWasabi.Logging
}
}
}
- }
catch (Exception ex)
{
Interlocked.Increment(ref _logerFailed);

MODIFY
WalletWasabi/Services/IndexDownloader.cs
WalletWasabi/Services/IndexDownloader.cs
@@ -213,15 +213,8 @@ namespace WalletWasabi.Services
using (IndexLock.Lock())
{
var single = Index.Single(x => x.BlockHash == blockHash);
- if (single != null)
- {
return single.BlockHeight;
}
- else
- {
- return Height.Unknown;
- }
- }
}
public async Task StopAsync()

Add some small simplifications