Skip to content

Commit

Permalink
- FeeRate button business logic
Browse files Browse the repository at this point in the history
  • Loading branch information
molnard committed Dec 20, 2018
1 parent 3acadd4 commit 7f9549a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion WalletWasabi.Gui/Controls/WalletExplorer/SendTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Spacing="4">
<TextBlock Text="Confirmation Expected In:" VerticalAlignment="Center"/>
<TextBlock Foreground="YellowGreen" Text="{Binding ConfirmationExpectedText}" Width="80" VerticalAlignment="Center" />
<Button Content="{Binding FeeText}" Padding="0" Background="{DynamicResource EditorBackgroundBrush}" BorderBrush="{DynamicResource EditorBackgroundBrush}" VerticalAlignment="Top" />
<Button Content="{Binding FeeText}" Command="{Binding FeeRateCommand}" Padding="0" Background="{DynamicResource EditorBackgroundBrush}" BorderBrush="{DynamicResource EditorBackgroundBrush}" VerticalAlignment="Top" />
</StackPanel>
</StackPanel>
</StackPanel>
Expand Down
27 changes: 23 additions & 4 deletions WalletWasabi.Gui/Controls/WalletExplorer/SendTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
{
public class SendTabViewModel : WalletActionViewModel
{
enum FeeRateDisplayFormatEnum
{
SatoshiPerByte,
USD,
BTC
};
private CoinListViewModel _coinList;
private string _buildTransactionButtonText;
private bool _isMax;
Expand All @@ -45,6 +51,7 @@ public class SendTabViewModel : WalletActionViewModel
private const string BuildingTransactionButtonTextString = "Sending Transaction...";
private int _caretIndex;
private ObservableCollection<SuggestionViewModel> _suggestions;
FeeRateDisplayFormatEnum FeeRateDisplayFormat { get; set; }

public SendTabViewModel(WalletViewModel walletViewModel)
: base("Send", walletViewModel)
Expand Down Expand Up @@ -185,10 +192,9 @@ public SendTabViewModel(WalletViewModel walletViewModel)
(this).WhenAny(x => x.IsMax, x => x.Amount, x => x.Address, x => x.IsBusy,
(isMax, amount, address, busy) => ((isMax.Value || !string.IsNullOrWhiteSpace(amount.Value)) && !string.IsNullOrWhiteSpace(Address) && !IsBusy)));

MaxCommand = ReactiveCommand.Create(() =>
{
SetMax();
});
MaxCommand = ReactiveCommand.Create(SetMax);

FeeRateCommand = ReactiveCommand.Create(ChangeFeeRateDisplay);

this.WhenAnyValue(x => x.IsBusy).Subscribe(busy =>
{
Expand Down Expand Up @@ -232,6 +238,16 @@ public SendTabViewModel(WalletViewModel walletViewModel)
_suggestions = new ObservableCollection<SuggestionViewModel>();
}

private void ChangeFeeRateDisplay()
{
var nextval= (from FeeRateDisplayFormatEnum val in Enum.GetValues(typeof(FeeRateDisplayFormatEnum))
where val > FeeRateDisplayFormat
orderby val
select val).DefaultIfEmpty().First();
FeeRateDisplayFormat = nextval;
SetFeeTexts();
}

private void SetFeeTexts()
{
AllFeeEstimate allFeeEstimate = Global.Synchronizer?.AllFeeEstimate;
Expand Down Expand Up @@ -278,6 +294,7 @@ private void SetFeeTexts()

if (allFeeEstimate != null)
{
//TODO: display values according to FeeRateDisplayFormat
FeeText = $"({allFeeEstimate.GetFeeRate(feeTarget).Satoshi} sat/byte)";
}
}
Expand Down Expand Up @@ -564,5 +581,7 @@ public string SuccessMessage
public ReactiveCommand BuildTransactionCommand { get; }

public ReactiveCommand MaxCommand { get; }

public ReactiveCommand FeeRateCommand { get; }
}
}

0 comments on commit 7f9549a

Please sign in to comment.