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

Refactor existing conditional expression #2032

Merged
merged 2 commits into from Jul 30, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Refactor existing conditional expression

  • Loading branch information...
yahiheb committed Jul 29, 2019
commit eba765a5f3d998ec471e3013934132d71ff0975c
@@ -492,11 +492,11 @@ public void OnCoinIsSelectedChanged(CoinViewModel cvm)
SetSelections();
SelectionChanged?.Invoke(this, cvm);
SelectedAmount = Coins.Where(x => x.IsSelected).Sum(x => x.Amount);
LabelExposeCommonOwnershipWarning = CoinListContainerType == CoinListContainerType.CoinJoinTabViewModel ?
false // Because in CoinJoin the selection algorithm makes sure not to combine red with non-red.
LabelExposeCommonOwnershipWarning = CoinListContainerType == CoinListContainerType.CoinJoinTabViewModel
? false // Because in CoinJoin the selection algorithm makes sure not to combine red with non-red.
: Coins.Any(c =>
c.AnonymitySet == 1 && c.IsSelected
&& Coins.Any(x => x.AnonymitySet > 1 && x.IsSelected));
c.AnonymitySet == 1 && c.IsSelected && Coins.Any(x =>
x.AnonymitySet > 1 && x.IsSelected));
}

public void OnCoinStatusChanged()
@@ -14,7 +14,11 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if (value is string amount)
{
// When the amount starts with a '~' then Max is selected
return amount.StartsWith("~") ? Brushes.ForestGreen : (amount.Equals("No Coins Selected", StringComparison.OrdinalIgnoreCase) ? Brushes.IndianRed : Brushes.White);
return amount.StartsWith("~")
? Brushes.ForestGreen
: amount.Equals("No Coins Selected", StringComparison.OrdinalIgnoreCase)
? Brushes.IndianRed
: Brushes.White;
}
else
{
@@ -20,8 +20,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
var global = Application.Current.Resources[Global.GlobalResourceKey] as Global;
var phaseError = global.ChaumianClient.State.IsInErrorState;

return ((CcjRoundPhase)p <= (CcjRoundPhase)value)
? (phaseError ? Brushes.IndianRed : Brushes.Green)
return (CcjRoundPhase)p <= (CcjRoundPhase)value
? phaseError
? Brushes.IndianRed
: Brushes.Green
: Brushes.Gray;
}

@@ -21,8 +21,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
}

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

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
@@ -36,29 +36,33 @@ private static async Task<string[]> ShowAsync(this FileDialog me, Window parent,
{
WalletWasabi.Logging.Logger.LogWarning(ex, me.GetType().Name);

string title =
!string.IsNullOrWhiteSpace(me.Title) ? me.Title :
me is OpenFileDialog ? "Open File" :
me is SaveFileDialog ? "Save File" :
throw new NotImplementedException();
string title = !string.IsNullOrWhiteSpace(me.Title)
? me.Title
: me is OpenFileDialog
? "Open File"
: me is SaveFileDialog
? "Save File"
: throw new NotImplementedException();

string instructions =
me is OpenFileDialog ? $"Failed to use your operating system's {nameof(OpenFileDialog)}. Please provide the path of the file you want to open manually:" :
me is SaveFileDialog ? $"Failed to use your operating system's {nameof(SaveFileDialog)}. Please provide the path where you want your file to be saved to:" :
throw new NotImplementedException();
string instructions = me is OpenFileDialog
? $"Failed to use your operating system's {nameof(OpenFileDialog)}. Please provide the path of the file you want to open manually:"
: me is SaveFileDialog
? $"Failed to use your operating system's {nameof(SaveFileDialog)}. Please provide the path where you want your file to be saved to:"
: throw new NotImplementedException();

string exampleFilePath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
@"C:\path\to\the\file.ext" :
@"/path/to/the/file";
string exampleFilePath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? @"C:\path\to\the\file.ext"
: @"/path/to/the/file";

string defaultTextInput =
me is OpenFileDialog ? Path.Combine(me.InitialDirectory ?? "", me.InitialFileName ?? "") :
me is SaveFileDialog sfd ? Path.ChangeExtension(
Path.Combine(
string.IsNullOrEmpty(me.InitialDirectory) ? Path.GetDirectoryName(exampleFilePath) : me.InitialDirectory,
string.IsNullOrEmpty(me.InitialFileName) ? Path.GetFileName(exampleFilePath) : me.InitialFileName),
string.IsNullOrEmpty(sfd.DefaultExtension) ? "ext" : sfd.DefaultExtension) :
throw new NotImplementedException();
string defaultTextInput = me is OpenFileDialog
? Path.Combine(me.InitialDirectory ?? "", me.InitialFileName ?? "")
: me is SaveFileDialog sfd
? Path.ChangeExtension(
Path.Combine(
string.IsNullOrEmpty(me.InitialDirectory) ? Path.GetDirectoryName(exampleFilePath) : me.InitialDirectory,
string.IsNullOrEmpty(me.InitialFileName) ? Path.GetFileName(exampleFilePath) : me.InitialFileName),
string.IsNullOrEmpty(sfd.DefaultExtension) ? "ext" : sfd.DefaultExtension)
: throw new NotImplementedException();

var dialog = new TextInputDialogViewModel(title, instructions, exampleFilePath, defaultTextInput);
var success = await MainWindowViewModel.Instance.ShowDialogAsync(dialog);
@@ -526,7 +526,9 @@ private void Coins_CollectionChanged(object sender, NotifyCollectionChangedEvent
using (var process = Process.Start(new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "osascript" : "notify-send",
Arguments = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? $"-e \"display notification \\\"Received {amountString} BTC\\\" with title \\\"Wasabi\\\"\"" : $"--expire-time=3000 \"Wasabi\" \"Received {amountString} BTC\"",
Arguments = RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? $"-e \"display notification \\\"Received {amountString} BTC\\\" with title \\\"Wasabi\\\"\""
: $"--expire-time=3000 \"Wasabi\" \"Received {amountString} BTC\"",
CreateNoWindow = true
}))
{ }
@@ -689,8 +691,10 @@ public string GetNextWalletName()

public string GetNextHardwareWalletName(Hwi.Models.HardwareWalletInfo hwi = null, string customPrefix = null)
{
var prefix = customPrefix is null ?
(hwi is null ? "HardwareWallet" : hwi.Type.ToString())
var prefix = customPrefix is null
? hwi is null
? "HardwareWallet"
: hwi.Type.ToString()
: customPrefix;

for (int i = 0; i < int.MaxValue; i++)
@@ -13,9 +13,10 @@

namespace WalletWasabi.Gui.ManagedDialogs
{
class ManagedFileChooserViewModel : ViewModelBase
internal class ManagedFileChooserViewModel : ViewModelBase
{
public event Action CancelRequested;

public event Action<string[]> CompleteRequested;

public AvaloniaList<ManagedFileChooserItemViewModel> QuickLinks { get; } =
@@ -30,8 +31,8 @@ class ManagedFileChooserViewModel : ViewModelBase
public AvaloniaList<ManagedFileChooserItemViewModel> SelectedItems { get; } =
new AvaloniaList<ManagedFileChooserItemViewModel>();

string _location;
string _fileName;
private string _location;
private string _fileName;
private bool _showHiddenFiles;
private ManagedFileChooserFilterViewModel _selectedFilter;
private bool _selectingDirectory;
@@ -105,10 +106,12 @@ public ManagedFileChooserViewModel(FileSystemDialog dialog)

QuickLinks.AddRange(quickSources.GetAllItems().Select(i => new ManagedFileChooserItemViewModel(i)));

Title = dialog.Title ?? (
dialog is OpenFileDialog ? "Open file"
: dialog is SaveFileDialog ? "Save file"
: dialog is OpenFolderDialog ? "Select directory"
Title = dialog.Title ?? (dialog is OpenFileDialog
? "Open file"
: dialog is SaveFileDialog
? "Save file"
: dialog is OpenFolderDialog
? "Select directory"
: throw new ArgumentException(nameof(dialog)));

var directory = dialog.InitialDirectory;
@@ -136,9 +139,9 @@ public ManagedFileChooserViewModel(FileSystemDialog dialog)
}
}

_selectingDirectory = dialog is OpenFolderDialog;
_selectingDirectory = dialog is OpenFolderDialog;

if(dialog is SaveFileDialog sfd)
if (dialog is SaveFileDialog sfd)
{
_savingFile = true;
_defaultExtension = sfd.DefaultExtension;
@@ -185,7 +188,7 @@ private async void OnSelectionChangedAsync(object sender, NotifyCollectionChange
SelectedItems.Remove(item);
}

if(!_selectingDirectory)
if (!_selectingDirectory)
{
FileName = SelectedItems.FirstOrDefault()?.DisplayName;
}
@@ -198,7 +201,7 @@ private async void OnSelectionChangedAsync(object sender, NotifyCollectionChange
});
}

void NavigateRoot(string initialSelectionName)
private void NavigateRoot(string initialSelectionName)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -257,7 +260,7 @@ public void Navigate(string path, string initialSelectionName = null)

return true;
})
.Where(x=>x.Exists)
.Where(x => x.Exists)
.Select(info => new ManagedFileChooserItemViewModel
{
DisplayName = info.Name,
@@ -311,7 +314,7 @@ public void Ok()
{
CompleteRequested?.Invoke(new[] { Location });
}
else if(_savingFile)
else if (_savingFile)
{
if (!string.IsNullOrWhiteSpace(FileName))
{
@@ -58,9 +58,9 @@ public SettingsViewModel(Global global) : base(global, "Settings")

var configBitcoinP2pEndPoint = Network == Network.Main
? config.MainNetBitcoinP2pEndPoint
: (Network == Network.TestNet
: Network == Network.TestNet
? config.TestNetBitcoinP2pEndPoint
: config.RegTestBitcoinP2pEndPoint);
: config.RegTestBitcoinP2pEndPoint;

BitcoinP2pEndPoint = configBitcoinP2pEndPoint.ToString(defaultPort: -1);
});
@@ -305,9 +305,9 @@ private void Save()

var configBitcoinP2pEndPoint = network == NBitcoin.Network.Main
? config.MainNetBitcoinP2pEndPoint
: (network == NBitcoin.Network.TestNet
: network == NBitcoin.Network.TestNet
? config.TestNetBitcoinP2pEndPoint
: config.RegTestBitcoinP2pEndPoint);
: config.RegTestBitcoinP2pEndPoint;

if (config.Network != network
|| config.TorSocks5EndPoint != torSocks5EndPoint
@@ -59,7 +59,8 @@ internal class LoadWalletViewModel : CategoryViewModel

private object WalletLock { get; }

public LoadWalletViewModel(WalletManagerViewModel owner, LoadWalletType loadWalletType) : base(loadWalletType == LoadWalletType.Password ? "Test Password" : (loadWalletType == LoadWalletType.Desktop ? "Load Wallet" : "Hardware Wallet"))
public LoadWalletViewModel(WalletManagerViewModel owner, LoadWalletType loadWalletType)
: base(loadWalletType == LoadWalletType.Password ? "Test Password" : (loadWalletType == LoadWalletType.Desktop ? "Load Wallet" : "Hardware Wallet"))
{
Owner = owner;
Password = "";
@@ -97,8 +97,8 @@ private static async Task<string> EnsureDownloadedAsync(string version)
return bitcoind;
}

zip = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ?
Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-x86_64-linux-gnu.tar.gz")
zip = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-x86_64-linux-gnu.tar.gz")
: Path.Combine(Global.Instance.DataDir, $"bitcoin-{version}-osx64.tar.gz");

string url = string.Format("https://bitcoincore.org/bin/bitcoin-core-{0}/" + Path.GetFileName(zip), version);
@@ -40,12 +40,14 @@ private static MatrixPoint PointForInfo1(int bitsIndex)
{
if (bitsIndex <= 7)
{
return bitsIndex >= 6 ? new MatrixPoint(bitsIndex + 1, 8)
return bitsIndex >= 6
? new MatrixPoint(bitsIndex + 1, 8)
: new MatrixPoint(bitsIndex, 8);
}
else
{
return bitsIndex == 8 ? new MatrixPoint(8, 8 - (bitsIndex - 7))
return bitsIndex == 8
? new MatrixPoint(8, 8 - (bitsIndex - 7))
: new MatrixPoint(8, 8 - (bitsIndex - 7) - 1);
}
}
@@ -26,13 +26,15 @@ private int PenaltyCalculation(BitMatrix matrix, bool isHorizontal)
{
while (j < width - 4)
{
bool preBit = isHorizontal ? matrix[j + 4, i]
bool preBit = isHorizontal
? matrix[j + 4, i]
: matrix[i, j + 4];
int numSameBitCell = 1;

for (int x = 1; x <= 4; x++)
{
bool bit = isHorizontal ? matrix[j + 4 - x, i]
bool bit = isHorizontal
? matrix[j + 4 - x, i]
: matrix[i, j + 4 - x];
if (bit == preBit)
{
@@ -53,7 +55,8 @@ private int PenaltyCalculation(BitMatrix matrix, bool isHorizontal)
int x = 5;
while ((j + x) < width)
{
bool bit = isHorizontal ? matrix[j + x, i]
bool bit = isHorizontal
? matrix[j + x, i]
: matrix[i, j + x];
if (bit == preBit)
{
@@ -21,11 +21,13 @@ private int PenaltyCalculation(BitMatrix matrix, bool isHorizontal)
{
while (j < width - 5)
{
bit = isHorizontal ? matrix[j + 4, i]
bit = isHorizontal
? matrix[j + 4, i]
: matrix[i, j + 4];
if (!bit)
{
bit = isHorizontal ? matrix[j, i]
bit = isHorizontal
? matrix[j, i]
: matrix[i, j];
if (!bit)
{
@@ -41,7 +43,8 @@ private int PenaltyCalculation(BitMatrix matrix, bool isHorizontal)
{
for (int num = 4; num > 0; num--)
{
bit = isHorizontal ? matrix[j + num, i]
bit = isHorizontal
? matrix[j + num, i]
: matrix[i, j + num];
if (!bit)
{
@@ -66,7 +69,8 @@ private int PatternCheck(BitMatrix matrix, int i, int j, bool isHorizontal)
bool bit;
for (int num = 3; num >= 1; num--)
{
bit = isHorizontal ? matrix[j + num, i]
bit = isHorizontal
? matrix[j + num, i]
: matrix[i, j + num];
if (!bit)
{
@@ -79,14 +83,16 @@ private int PatternCheck(BitMatrix matrix, int i, int j, bool isHorizontal)
return 0;
}

bit = isHorizontal ? matrix[j + 5, i]
bit = isHorizontal
? matrix[j + 5, i]
: matrix[i, j + 5];
if (!bit)
{
return 0;
}

bit = isHorizontal ? matrix[j - 1, i]
bit = isHorizontal
? matrix[j - 1, i]
: matrix[i, j - 1];
if (!bit)
{
@@ -97,7 +103,8 @@ private int PatternCheck(BitMatrix matrix, int i, int j, bool isHorizontal)
{
for (int num = -2; num >= -5; num--)
{
bit = isHorizontal ? matrix[j + num, i]
bit = isHorizontal
? matrix[j + num, i]
: matrix[i, j + num];
if (bit)
{
@@ -115,7 +122,8 @@ private int PatternCheck(BitMatrix matrix, int i, int j, bool isHorizontal)
{
for (int num = 6; num <= 9; num++)
{
bit = isHorizontal ? matrix[j + num, i]
bit = isHorizontal
? matrix[j + num, i]
: matrix[i, j + num];
if (bit)
{
@@ -123,7 +123,11 @@ public static void OpenFolderInFileExplorer(string dirPath)
{
using (Process process = Process.Start(new ProcessStartInfo
{
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "explorer.exe" : (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "open" : "xdg-open"),
FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? "explorer.exe"
: (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? "open"
: "xdg-open"),
Arguments = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? $"\"{dirPath}\"" : dirPath,
CreateNoWindow = true
}))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.