remove time period code duplications
MODIFY
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceChartTileViewModel.cs
WalletWasabi.Fluent/ViewModels/Wallets/Home/Tiles/WalletBalanceChartTileViewModel.cs
@@ -7,77 +7,96 @@ using System.Windows.Input;
using DynamicData.Binding;
using NBitcoin;
using ReactiveUI;
+using WalletWasabi.Extensions;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.Wallets.Home.History;
+using WalletWasabi.Models;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
{
- public partial class WalletBalanceChartTileViewModel : TileViewModel
- {
- private readonly ObservableCollection<HistoryItemViewModel> _history;
- [AutoNotify] private ObservableCollection<double> _yValues;
- [AutoNotify] private ObservableCollection<double> _xValues;
- [AutoNotify] private double? _xMinimum;
- [AutoNotify] private List<string>? _yLabels;
- [AutoNotify] private List<string>? _xLabels;
- private TimePeriodOption _currentTimePeriod = TimePeriodOption.ThreeMonths;
-
- public WalletBalanceChartTileViewModel(ObservableCollection<HistoryItemViewModel> history)
- {
- _history = history;
- _yValues = new ObservableCollection<double>();
- _xValues = new ObservableCollection<double>();
-
- DayCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Day));
- WeekCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Week));
- MonthCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Month));
- ThreeMonthCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.ThreeMonths));
- SixMonthCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.SixMonths));
- YearCommand = ReactiveCommand.Create(() => UpdateSample(TimePeriodOption.Year));
- AllCommand = ReactiveCommand.Create(() => { UpdateSample(TimePeriodOption.All); });
- }
-
- private enum TimePeriodOption
+ public enum TimePeriodOption
{
All,
+ [FriendlyName("1D")]
Day,
+ [FriendlyName("1W")]
Week,
+ [FriendlyName("1M")]
Month,
+ [FriendlyName("3M")]
ThreeMonths,
+ [FriendlyName("6M")]
SixMonths,
+ [FriendlyName("1Y")]
Year
}
- public ICommand DayCommand { get; }
+ public partial class TimePeriodOptionViewModel
+ {
+ public TimePeriodOption Option { get; }
+ [AutoNotify] private bool _isSelected;
- public ICommand WeekCommand { get; }
+ public TimePeriodOptionViewModel(TimePeriodOption option, Action<TimePeriodOptionViewModel> updateAction, uint orderIndex)
+ {
+ Option = option;
+ Text = option.FriendlyName();
+ SelectCommand = ReactiveCommand.Create(() => updateAction(this));
+ OrderIndex = orderIndex;
+ }
- public ICommand MonthCommand { get; }
+ public string Text { get; }
- public ICommand ThreeMonthCommand { get; }
+ public uint OrderIndex { get; }
- public ICommand SixMonthCommand { get; }
+ public ICommand SelectCommand { get; }
+ }
- public ICommand YearCommand { get; }
+ public partial class WalletBalanceChartTileViewModel : TileViewModel
+ {
+ private readonly ObservableCollection<HistoryItemViewModel> _history;
+ [AutoNotify] private ObservableCollection<double> _yValues;
+ [AutoNotify] private ObservableCollection<double> _xValues;
+ [AutoNotify] private double? _xMinimum;
+ [AutoNotify] private List<string>? _yLabels;
+ [AutoNotify] private List<string>? _xLabels;
+
+ public WalletBalanceChartTileViewModel(ObservableCollection<HistoryItemViewModel> history)
+ {
+ _history = history;
+ _yValues = new ObservableCollection<double>();
+ _xValues = new ObservableCollection<double>();
+ TimePeriodOptions = new ObservableCollection<TimePeriodOptionViewModel>
+ {
+ new (TimePeriodOption.All, UpdateSample, 0),
+ new (TimePeriodOption.Day, UpdateSample, 1),
+ new (TimePeriodOption.Week, UpdateSample, 2),
+ new (TimePeriodOption.Month, UpdateSample, 3),
+ new (TimePeriodOption.ThreeMonths, UpdateSample, 4),
+ new (TimePeriodOption.SixMonths, UpdateSample, 5),
+ new (TimePeriodOption.Year, UpdateSample, 6),
+ };
+ }
- public ICommand AllCommand { get; }
+ public ObservableCollection<TimePeriodOptionViewModel> TimePeriodOptions { get; }
protected override void OnActivated(CompositeDisposable disposables)
{
base.OnActivated(disposables);
_history.ToObservableChangeSet()
- .Subscribe(_ => UpdateSample())
+ .Subscribe(_ => UpdateSample(TimePeriodOptions.First(x => x.Option == TimePeriodOption.ThreeMonths)))
.DisposeWith(disposables);
}
- private void UpdateSample()
+ private void UpdateSample(TimePeriodOptionViewModel selectedPeriodOption)
+ {
+ foreach (var item in TimePeriodOptions)
{
- UpdateSample(_currentTimePeriod);
+ item.IsSelected = item == selectedPeriodOption;
}
- private void UpdateSample(TimePeriodOption timePeriod)
- {
+ var timePeriod = selectedPeriodOption.Option;
+
switch (timePeriod)
{
case TimePeriodOption.All:
@@ -114,8 +133,6 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles
UpdateSample(TimeSpan.FromDays(7), TimeSpan.FromDays(365));
break;
}
-
- _currentTimePeriod = timePeriod;
}
private void UpdateSample(TimeSpan sampleTime, TimeSpan sampleBackFor)

MODIFY
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartNormalTileView.axaml
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartNormalTileView.axaml
</UserControl.Styles>
<Border ClipToBounds="False" CornerRadius="5" Background="{DynamicResource TileRegionColor}" Margin="6" Padding="16" BoxShadow="{DynamicResource InfoBoxShadow}">
<DockPanel>
- <StackPanel DockPanel.Dock="Top" HorizontalAlignment="Stretch" Spacing="10">
- <TextBlock Text="Balance over time" />
- <Grid ColumnDefinitions="*,*,*,*,*,*,*" Margin="0 0 -30 0">
- <RadioButton Classes="text" Content="All" Command="{Binding AllCommand}" Grid.Column="0"/>
- <RadioButton Classes="text" Content="1D" Command="{Binding DayCommand}" Grid.Column="1" />
- <RadioButton Classes="text" Content="1W" Command="{Binding WeekCommand}" Grid.Column="2" />
- <RadioButton Classes="text" Content="1M" Command="{Binding MonthCommand}" Grid.Column="3" />
- <RadioButton Classes="text" Content="3M" Command="{Binding ThreeMonthCommand}" IsChecked="True" Grid.Column="4" />
- <RadioButton Classes="text" Content="6M" Command="{Binding SixMonthCommand}" Grid.Column="5" />
- <RadioButton Classes="text" Content="1Y" Command="{Binding YearCommand}" Grid.Column="6" />
- </Grid>
- </StackPanel>
+ <DockPanel DockPanel.Dock="Top" HorizontalAlignment="Stretch">
+ <TextBlock Text="Balance over time" DockPanel.Dock="Left" />
+ <ItemsControl DockPanel.Dock="Right" HorizontalAlignment="Right" Items="{Binding TimePeriodOptions}">
+ <ItemsControl.ItemsPanel>
+ <ItemsPanelTemplate>
+ <StackPanel Orientation="Horizontal" Spacing="8" Margin="0 0 0 -3"/>
+ </ItemsPanelTemplate>
+ </ItemsControl.ItemsPanel>
+ <ItemsControl.ItemTemplate>
+ <DataTemplate>
+ <RadioButton x:DataType="vm:TimePeriodOptionViewModel" Classes="text"
+ Content="{Binding Text}" Command="{Binding SelectCommand}"
+ IsChecked="{Binding IsSelected}" />
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
+ </DockPanel>
- <Separator DockPanel.Dock="Top" Margin="-16 10" />
+ <Separator DockPanel.Dock="Top" Margin="-16 15" />
<c:LineChart x:CompileBindings="True" x:DataType="vm:WalletBalanceChartTileViewModel" x:Name="GradientLineChart" DockPanel.Dock="Bottom" Margin="30 10 15 30"
Classes="area border xAxis xAxisLabels yAxis yAxisLabels"

MODIFY
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartSmallTileView.axaml
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartSmallTileView.axaml
<Button Classes="plain" DockPanel.Dock="Right" HorizontalAlignment="Right" Margin="0 0 0 -3">
<Button.Flyout>
<Flyout Placement="Bottom" ShowMode="TransientWithDismissOnPointerMoveAway">
- <StackPanel Orientation="Horizontal" Spacing="10">
- <RadioButton Classes="text" Content="All" Command="{Binding AllCommand}" />
- <RadioButton Classes="text" Content="1D" Command="{Binding DayCommand}" />
- <RadioButton Classes="text" Content="1W" Command="{Binding WeekCommand}" />
- <RadioButton Classes="text" Content="1M" Command="{Binding MonthCommand}" />
- <RadioButton Classes="text" Content="3M" Command="{Binding ThreeMonthCommand}" IsChecked="True" />
- <RadioButton Classes="text" Content="6M" Command="{Binding SixMonthCommand}" />
- <RadioButton Classes="text" Content="1Y" Command="{Binding YearCommand}" />
- </StackPanel>
+ <ItemsControl Items="{Binding TimePeriodOptions}">
+ <ItemsControl.ItemsPanel>
+ <ItemsPanelTemplate>
+ <StackPanel Orientation="Horizontal" Spacing="8" Margin="0 0 0 -3" />
+ </ItemsPanelTemplate>
+ </ItemsControl.ItemsPanel>
+ <ItemsControl.ItemTemplate>
+ <DataTemplate>
+ <RadioButton x:DataType="vm:TimePeriodOptionViewModel" Classes="text"
+ Content="{Binding Text}" Command="{Binding SelectCommand}"
+ IsChecked="{Binding IsSelected}" />
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
</Flyout>
</Button.Flyout>
<PathIcon Data="{StaticResource more_regular}" Foreground="{DynamicResource TextForegroundColor}" />

MODIFY
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartWideTileView.axaml
WalletWasabi.Fluent/Views/Wallets/Home/Tiles/WalletBalanceChart/WalletBalanceChartWideTileView.axaml
<DockPanel>
<DockPanel DockPanel.Dock="Top" HorizontalAlignment="Stretch">
<TextBlock Text="Balance over time" DockPanel.Dock="Left"/>
- <StackPanel Orientation="Horizontal" Spacing="10" DockPanel.Dock="Right" HorizontalAlignment="Right">
- <RadioButton Classes="text" Content="All" Command="{Binding AllCommand}" />
- <RadioButton Classes="text" Content="1D" Command="{Binding DayCommand}" />
- <RadioButton Classes="text" Content="1W" Command="{Binding WeekCommand}" />
- <RadioButton Classes="text" Content="1M" Command="{Binding MonthCommand}" />
- <RadioButton Classes="text" Content="3M" Command="{Binding ThreeMonthCommand}" IsChecked="True" />
- <RadioButton Classes="text" Content="6M" Command="{Binding SixMonthCommand}" />
- <RadioButton Classes="text" Content="1Y" Command="{Binding YearCommand}" />
- </StackPanel>
+ <ItemsControl DockPanel.Dock="Right" HorizontalAlignment="Right" Items="{Binding TimePeriodOptions}">
+ <ItemsControl.ItemsPanel>
+ <ItemsPanelTemplate>
+ <StackPanel Orientation="Horizontal" Spacing="8" Margin="0 0 0 -3" />
+ </ItemsPanelTemplate>
+ </ItemsControl.ItemsPanel>
+ <ItemsControl.ItemTemplate>
+ <DataTemplate>
+ <RadioButton x:DataType="vm:TimePeriodOptionViewModel" Classes="text" Content="{Binding Text}" Command="{Binding SelectCommand}" IsChecked="{Binding IsSelected}" />
+ </DataTemplate>
+ </ItemsControl.ItemTemplate>
+ </ItemsControl>
</DockPanel>
<Separator DockPanel.Dock="Top" Margin="-16 15" />

remove time period code duplications