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

Confirmation Expected Text moved to FeeTarget Converter #2177

Merged
merged 2 commits into from Aug 27, 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

@@ -10,6 +10,7 @@
<UserControl.Resources>
<converters:AmountForegroundConverter x:Key="AmountForegroundConverter" />
<converters:BooleanStringConverter x:Key="BooleanStringConverter" />
<converters:FeeTargetTimeConverter x:Key="FeeTargetTimeConverter" />
<converters:UsdExchangeRateAmountToolTipConverter x:Key="UsdExchangeRateAmountToolTipConverter" />
</UserControl.Resources>
<i:Interaction.Behaviors>
@@ -92,7 +93,7 @@
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4">
<TextBlock Text="Confirmation Expected In:" VerticalAlignment="Center" />
<TextBlock Foreground="YellowGreen" Text="{Binding ConfirmationExpectedText}" Width="80" VerticalAlignment="Center" />
<TextBlock Foreground="YellowGreen" Text="{Binding FeeTarget, Converter={StaticResource FeeTargetTimeConverter}}" Width="80" VerticalAlignment="Center" />
<Button Content="{Binding FeeText}" ToolTip.Tip="{Binding FeeToolTip}" Command="{Binding FeeRateCommand}" Padding="0" Background="{DynamicResource EditorBackgroundBrush}" BorderBrush="{DynamicResource EditorBackgroundBrush}" VerticalAlignment="Top" />
</StackPanel>
</StackPanel>
@@ -43,7 +43,6 @@ public class SendTabViewModel : WalletActionViewModel
private int _minimumFeeTarget;
private int _maximumFeeTarget;
private ObservableAsPropertyHelper<bool> _minMaxFeeTargetsEqual;
private string _confirmationExpectedText;
private string _feeText;
private decimal _usdFee;
private Money _estimatedBtcFee;
@@ -661,29 +660,6 @@ private void SetFeesAndTexts()
}
}

if (feeTarget >= 2 && feeTarget <= 6) // minutes
{
ConfirmationExpectedText = $"{feeTarget}0 minutes";
}
else if (feeTarget >= 7 && feeTarget <= Constants.OneDayConfirmationTarget) // hours
{
var h = feeTarget / 6;
ConfirmationExpectedText = $"{h} {IfPlural(h, "hour", "hours")}";
}
else if (feeTarget >= 145 && feeTarget < Constants.SevenDaysConfirmationTarget) // days
{
var d = feeTarget / Constants.OneDayConfirmationTarget;
ConfirmationExpectedText = $"{d} {IfPlural(d, "day", "days")}";
}
else if (feeTarget == Constants.SevenDaysConfirmationTarget)
{
ConfirmationExpectedText = "one week";
}
else if (feeTarget == -1)
{
ConfirmationExpectedText = $"Invalid";
}

if (allFeeEstimate != null)
{
SetFees(allFeeEstimate, feeTarget);
@@ -725,16 +701,6 @@ private void SetFeesAndTexts()
SetAmountIfMax();
}

private static string IfPlural(int val, string singular, string plural)
{
if (val == 1)
{
return singular;
}

return plural;
}

private void SetAmountIfMax()
{
if (IsMax)
@@ -959,12 +925,6 @@ public int MaximumFeeTarget

public bool MinMaxFeeTargetsEqual => _minMaxFeeTargetsEqual?.Value ?? false;

public string ConfirmationExpectedText
{
get => _confirmationExpectedText;
set => this.RaiseAndSetIfChanged(ref _confirmationExpectedText, value);
}

public string FeeText
{
get => _feeText;
@@ -0,0 +1,54 @@
using Avalonia.Data.Converters;
using System;
using System.Globalization;
using WalletWasabi.Helpers;
using WalletWasabi.Gui.Models;

namespace WalletWasabi.Gui.Converters
{
public class FeeTargetTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is int feeTarget)
{
if (feeTarget >= 2 && feeTarget <= 6) // minutes
This conversation was marked as resolved by benthecarman

This comment has been minimized.

Copy link
@yahiheb

yahiheb Aug 27, 2019

Collaborator

2 can be replaced by Constants.TwentyMinutesConfirmationTarget.

{
return $"{feeTarget}0 minutes";
}
else if (feeTarget >= 7 && feeTarget <= Constants.OneDayConfirmationTarget) // hours
{
var hours = feeTarget / 6;
return $"{hours} {IfPlural(hours, "hour", "hours")}";
}
else if (feeTarget >= 145 && feeTarget < Constants.SevenDaysConfirmationTarget) // days
This conversation was marked as resolved by benthecarman

This comment has been minimized.

Copy link
@lontivero

lontivero Aug 27, 2019

Collaborator

What about replacing 145 by Constants.OneDayConfirmationTarget + 1?

{
var days = feeTarget / Constants.OneDayConfirmationTarget;
return $"{days} {IfPlural(days, "day", "days")}";
}
else if (feeTarget == Constants.SevenDaysConfirmationTarget)
{
return "one week";
}
else
{
return "Invalid";
}
}
else
{
throw new TypeArgumentException(value, typeof(SmartCoinStatus), nameof(value));
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}

private static string IfPlural(int val, string singular, string plural)
{
return val == 1 ? singular : plural;
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.