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

Convert to conditional expression #1916

Merged
merged 2 commits into from Jul 17, 2019
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
11 changes: 4 additions & 7 deletions WalletWasabi.Backend/Controllers/OffchainController.cs
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -39,12 +39,9 @@ public async Task<IActionResult> GetExchangeRatesAsync()
{
IEnumerable<ExchangeRate> exchangeRates = await GetExchangeRatesCollectionAsync();

if (!exchangeRates.Any())
{
return NotFound("Exchange rates are not available.");
}

return Ok(exchangeRates);
return !exchangeRates.Any()
? NotFound("Exchange rates are not available.")
: (IActionResult)Ok(exchangeRates);
yahiheb marked this conversation as resolved.
Show resolved Hide resolved
}

internal async Task<IEnumerable<ExchangeRate>> GetExchangeRatesCollectionAsync()
Expand Down
11 changes: 4 additions & 7 deletions WalletWasabi.Gui/Converters/UpdateStatusBrushConverter.cs
@@ -1,4 +1,4 @@
using Avalonia;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;
using System;
Expand All @@ -20,12 +20,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
}
}

if (Application.Current.Resources.TryGetResource("ApplicationAccentBrushLow", out object brush))
{
return brush;
}

return null;
return Application.Current.Resources.TryGetResource("ApplicationAccentBrushLow", out object brush)
? brush :
null;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
12 changes: 4 additions & 8 deletions WalletWasabi.Gui/Tabs/WalletManager/LoadWalletViewModel.cs
Expand Up @@ -248,14 +248,10 @@ public void SetLoadButtonText()
}
else
{
if (SelectedWallet?.HardwareWalletInfo != null && !SelectedWallet.HardwareWalletInfo.Initialized) // If the hardware wallet was not initialized, then make the button say Setup, not Load.
{
LoadButtonText = "Setup Wallet";
}
else
{
LoadButtonText = "Load Wallet";
}
// If the hardware wallet was not initialized, then make the button say Setup, not Load.
LoadButtonText = SelectedWallet?.HardwareWalletInfo != null && !SelectedWallet.HardwareWalletInfo.Initialized
? "Setup Wallet"
: "Load Wallet";
yahiheb marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
11 changes: 3 additions & 8 deletions WalletWasabi/Extensions/ExceptionExtensions.cs
Expand Up @@ -9,14 +9,9 @@ public static class ExceptionExtensions
public static string ToTypeMessageString(this Exception ex)
{
var trimmed = Guard.Correct(ex.Message);
if (trimmed == "")
{
return ex.GetType().Name;
}
else
{
return $"{ex.GetType().Name}: {ex.Message}";
}
return trimmed == ""
? ex.GetType().Name
: $"{ex.GetType().Name}: {ex.Message}";
yahiheb marked this conversation as resolved.
Show resolved Hide resolved
}

public static Dictionary<string, string> BitcoinCoreTranslations { get; } = new Dictionary<string, string>
Expand Down
9 changes: 4 additions & 5 deletions WalletWasabi/Helpers/HttpMessageHelper.cs
Expand Up @@ -85,6 +85,7 @@ public static async Task<string> ReadHeadersAsync(Stream stream, CancellationTok

builder.Append(header + CRLF); // CRLF is part of the headerstring
}

headers = builder.ToString();
if (string.IsNullOrEmpty(headers))
{
Expand Down Expand Up @@ -117,12 +118,10 @@ private static async Task<string> ReadCRLFLineAsync(Stream stream, Encoding enco
}
bab.Append((byte)ch);
}
if (bab.Length > 0)
{
return bab.ToString(encoding);
}

return null;
return bab.Length > 0
? bab.ToString(encoding)
: null;
nopara73 marked this conversation as resolved.
Show resolved Hide resolved
}

public static byte[] HandleGzipCompression(HttpContentHeaders contentHeaders, byte[] decodedBodyArray)
Expand Down
10 changes: 2 additions & 8 deletions WalletWasabi/Services/MempoolService.cs
Expand Up @@ -56,6 +56,7 @@ public bool TryRemoveFromBroadcastStore(uint256 transactionHash, out Transaction
{
var found = BroadcastStore.FirstOrDefault(x => x.TransactionId == transactionHash);
entry = found;

if (found is null)
{
return false;
Expand All @@ -75,14 +76,7 @@ public bool TryGetFromBroadcastStore(uint256 transactionHash, out TransactionBro
var found = BroadcastStore.FirstOrDefault(x => x.TransactionId == transactionHash);
entry = found;

if (found is null)
{
return false;
}
else
{
return true;
}
return !(found is null);
yahiheb marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
14 changes: 5 additions & 9 deletions WalletWasabi/WebClients/BlockCypher/BlockCypherClient.cs
@@ -1,4 +1,4 @@
using NBitcoin;
using NBitcoin;
using Newtonsoft.Json;
using Nito.AsyncEx;
using System;
Expand All @@ -20,14 +20,10 @@ public class BlockCypherClient : IDisposable
public BlockCypherClient(Network network, HttpMessageHandler handler = null, bool disposeHandler = false)
{
Network = network ?? throw new ArgumentNullException(nameof(network));
if (handler != null)
{
HttpClient = new HttpClient(handler, disposeHandler);
}
else
{
HttpClient = new HttpClient();
}
HttpClient = handler != null
? new HttpClient(handler, disposeHandler)
: new HttpClient();
yahiheb marked this conversation as resolved.
Show resolved Hide resolved

if (network == Network.Main)
{
HttpClient.BaseAddress = new Uri("https://api.blockcypher.com/v1/btc/main");
Expand Down
14 changes: 5 additions & 9 deletions WalletWasabi/WebClients/SmartBit/SmartBitClient.cs
@@ -1,4 +1,4 @@
using NBitcoin;
using NBitcoin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Nito.AsyncEx;
Expand All @@ -23,14 +23,10 @@ public class SmartBitClient : IDisposable
public SmartBitClient(Network network, HttpMessageHandler handler = null, bool disposeHandler = false)
{
Network = network ?? throw new ArgumentNullException(nameof(network));
if (handler != null)
{
HttpClient = new HttpClient(handler, disposeHandler);
}
else
{
HttpClient = new HttpClient();
}
HttpClient = handler != null
? new HttpClient(handler, disposeHandler)
: new HttpClient();
yahiheb marked this conversation as resolved.
Show resolved Hide resolved

if (network == Network.Main)
{
HttpClient.BaseAddress = new Uri("https://api.smartbit.com.au/v1/");
Expand Down