Skip to content

Commit

Permalink
Merge pull request #12564 from wieslawsoltes/vdg/12351-merge-wallet-s…
Browse files Browse the repository at this point in the history
…ettings

[UI] Merge Wallet & Coinjoin settings
  • Loading branch information
soosr committed Mar 14, 2024
2 parents f80c247 + 86efd19 commit 300aab1
Show file tree
Hide file tree
Showing 24 changed files with 267 additions and 170 deletions.
1 change: 1 addition & 0 deletions WalletWasabi.Fluent/Styles/Styles.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@
<!--TODO @SuperJMN: Convert this to control? Is it worth the effort?-->
<StyleInclude Source="avares://WalletWasabi.Fluent/Controls/PreviewMessageItem.axaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Styles/CopyablePasswordTextBox.axaml" />
<StyleInclude Source="avares://WalletWasabi.Fluent/Styles/TabControl.axaml" />
</Styles>
18 changes: 18 additions & 0 deletions WalletWasabi.Fluent/Styles/TabControl.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style Selector="TabControl.Settings">
<Setter Property="Padding" Value="0" />
</Style>

<Style Selector="TabControl.Settings TabItem">
<Setter Property="FontSize" Value="12" />
<Setter Property="MinHeight" Value="50" />
<Setter Property="Padding" Value="0" />
</Style>

<Style Selector="TabControl.Settings TabItem /template/ Border#PART_LayoutRoot">
<Setter Property="Margin" Value="0 0 24 24" />
</Style>

</Styles>
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using NBitcoin;
using ReactiveUI;
using WalletWasabi.Blockchain.Keys;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.CoinJoinProfiles;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Wallets;

namespace WalletWasabi.Fluent.ViewModels.Wallets;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Settings;

[NavigationMetaData(
Title = "Coinjoin Settings",
Expand All @@ -23,7 +19,7 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets;
NavBarPosition = NavBarPosition.None,
NavigationTarget = NavigationTarget.DialogScreen,
Searchable = false)]
public partial class CoinJoinSettingsViewModel : RoutableViewModel
public partial class WalletCoinJoinSettingsViewModel : RoutableViewModel
{
private readonly IWalletModel _wallet;
[AutoNotify] private bool _autoCoinJoin;
Expand All @@ -32,7 +28,7 @@ public partial class CoinJoinSettingsViewModel : RoutableViewModel
[AutoNotify] private string _plebStopThreshold;
[AutoNotify] private string? _selectedCoinjoinProfileName;

private CoinJoinSettingsViewModel(IWalletModel walletModel)
private WalletCoinJoinSettingsViewModel(IWalletModel walletModel)
{
_wallet = walletModel;
_autoCoinJoin = _wallet.Settings.AutoCoinjoin;
Expand Down Expand Up @@ -81,32 +77,34 @@ private CoinJoinSettingsViewModel(IWalletModel walletModel)
_wallet.Settings.Save();
}
});

Update();
}

public ICommand SetAutoCoinJoin { get; }

public ICommand SelectCoinjoinProfileCommand { get; }

protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
private void Update()
{
base.OnNavigatedTo(isInHistory, disposables);
PlebStopThreshold = _wallet.Settings.PlebStopThreshold.ToString();
AnonScoreTarget = _wallet.Settings.AnonScoreTarget;

IsCoinjoinProfileSelected = _wallet.Settings.IsCoinjoinProfileSelected;
SelectedCoinjoinProfileName =
(_wallet.Settings.IsCoinjoinProfileSelected,
CoinJoinProfilesViewModel.IdentifySelectedProfile(_wallet.Settings)) switch
{
(true, CoinJoinProfileViewModelBase x) => x.Title,
(false, _) => "None",
_ => "Unknown"
};
CoinJoinProfilesViewModel.IdentifySelectedProfile(_wallet.Settings)) switch
{
(true, CoinJoinProfileViewModelBase x) => x.Title,
(false, _) => "None",
_ => "Unknown"
};
}

private async Task SelectCoinjoinProfileAsync()
{
await Navigate().To().CoinJoinProfiles(_wallet.Settings).GetResultAsync();
AutoCoinJoin = _wallet.Settings.AutoCoinjoin;
Update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using WalletWasabi.Fluent.Validation;
using WalletWasabi.Fluent.ViewModels.Dialogs.Base;

namespace WalletWasabi.Fluent.ViewModels.Wallets;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Settings;

[NavigationMetaData(Title = "Rename Wallet", NavigationTarget = NavigationTarget.CompactDialogScreen)]
public partial class WalletRenameViewModel : DialogViewModelBase<Unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Threading.Tasks;
using System.Windows.Input;
using ReactiveUI;
using WalletWasabi.Fluent.Models.UI;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.Navigation;

namespace WalletWasabi.Fluent.ViewModels.Wallets;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Settings;

[NavigationMetaData(
Title = "Wallet Settings",
Expand All @@ -22,31 +23,36 @@ public partial class WalletSettingsViewModel : RoutableViewModel
private readonly IWalletModel _wallet;
[AutoNotify] private bool _preferPsbtWorkflow;
[AutoNotify] private string _walletName;
[AutoNotify] private int _selectedTab;

private WalletSettingsViewModel(IWalletModel wallet)
public WalletSettingsViewModel(UiContext uiContext, IWalletModel walletModel)
{
_wallet = wallet;
_walletName = wallet.Name;
_preferPsbtWorkflow = wallet.Settings.PreferPsbtWorkflow;
IsHardwareWallet = wallet.IsHardwareWallet;
IsWatchOnly = wallet.IsWatchOnlyWallet;
UiContext = uiContext;
_wallet = walletModel;
_walletName = walletModel.Name;
_preferPsbtWorkflow = walletModel.Settings.PreferPsbtWorkflow;
_selectedTab = 0;
IsHardwareWallet = walletModel.IsHardwareWallet;
IsWatchOnly = walletModel.IsWatchOnlyWallet;

WalletCoinJoinSettings = new WalletCoinJoinSettingsViewModel(UiContext, walletModel);

SetupCancel(enableCancel: false, enableCancelOnEscape: true, enableCancelOnPressed: true);

NextCommand = CancelCommand;

VerifyRecoveryWordsCommand = ReactiveCommand.Create(() => Navigate().To().VerifyRecoveryWords(wallet));
VerifyRecoveryWordsCommand = ReactiveCommand.Create(() => Navigate().To().WalletVerifyRecoveryWords(walletModel));

this.WhenAnyValue(x => x.PreferPsbtWorkflow)
.Skip(1)
.Subscribe(value =>
{
wallet.Settings.PreferPsbtWorkflow = value;
wallet.Settings.Save();
walletModel.Settings.PreferPsbtWorkflow = value;
walletModel.Settings.Save();
});

this.WhenAnyValue(x => x._wallet.Name).BindTo(this, x => x.WalletName);

RenameCommand = ReactiveCommand.CreateFromTask(OnRenameWalletAsync);
}

Expand All @@ -56,8 +62,10 @@ private WalletSettingsViewModel(IWalletModel wallet)

public bool IsWatchOnly { get; }

public WalletCoinJoinSettingsViewModel WalletCoinJoinSettings { get; private set; }

public ICommand VerifyRecoveryWordsCommand { get; }

private async Task OnRenameWalletAsync()
{
await Navigate().To().WalletRename(_wallet).GetResultAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
using WalletWasabi.Logging;
using WalletWasabi.Models;

namespace WalletWasabi.Fluent.ViewModels.Wallets;
namespace WalletWasabi.Fluent.ViewModels.Wallets.Settings;

[NavigationMetaData(Title = "Verify Recovery Words")]
public partial class VerifyRecoveryWordsViewModel : RoutableViewModel
public partial class WalletVerifyRecoveryWordsViewModel : RoutableViewModel
{
[AutoNotify] private IEnumerable<string>? _suggestions;
[AutoNotify] private Mnemonic? _currentMnemonics;

private VerifyRecoveryWordsViewModel(IWalletModel wallet)
private WalletVerifyRecoveryWordsViewModel(IWalletModel wallet)
{
_suggestions = new Mnemonic(Wordlist.English, WordCount.Twelve).WordList.GetWords();

Expand Down
20 changes: 14 additions & 6 deletions WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using DynamicData.Binding;
using NBitcoin;
using ReactiveUI;
using WalletWasabi.BuyAnything;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Models.UI;
using WalletWasabi.Fluent.Models.Wallets;
Expand All @@ -19,6 +18,7 @@
using WalletWasabi.Fluent.ViewModels.Wallets.Buy;
using WalletWasabi.Fluent.ViewModels.Wallets.Home.History;
using WalletWasabi.Fluent.ViewModels.Wallets.Home.Tiles;
using WalletWasabi.Fluent.ViewModels.Wallets.Settings;
using WalletWasabi.Wallets;

namespace WalletWasabi.Fluent.ViewModels.Wallets;
Expand All @@ -44,7 +44,6 @@ public WalletViewModel(UiContext uiContext, IWalletModel walletModel, Wallet wal
Wallet = wallet;

Settings = new WalletSettingsViewModel(UiContext, WalletModel);
CoinJoinSettings = new CoinJoinSettingsViewModel(UiContext, WalletModel);
History = new HistoryViewModel(UiContext, WalletModel);
BuyViewModel = new BuyViewModel(UiContext, this);

Expand Down Expand Up @@ -93,11 +92,22 @@ public WalletViewModel(UiContext uiContext, IWalletModel walletModel, Wallet wal

WalletStatsCommand = ReactiveCommand.Create(() => Navigate().To().WalletStats(WalletModel));

WalletSettingsCommand = ReactiveCommand.Create(() => Navigate(NavigationTarget.DialogScreen).To(Settings));
WalletSettingsCommand = ReactiveCommand.Create(
() =>
{
Settings.SelectedTab = 0;
Navigate(NavigationTarget.DialogScreen).To(Settings);
});

WalletCoinsCommand = ReactiveCommand.Create(() => Navigate(NavigationTarget.DialogScreen).To().WalletCoins(WalletModel));

CoinJoinSettingsCommand = ReactiveCommand.Create(() => Navigate(NavigationTarget.DialogScreen).To(CoinJoinSettings), Observable.Return(!WalletModel.IsWatchOnlyWallet));
CoinJoinSettingsCommand = ReactiveCommand.Create(
() =>
{
Settings.SelectedTab = 1;
Navigate(NavigationTarget.DialogScreen).To(Settings);
},
Observable.Return(!WalletModel.IsWatchOnlyWallet));

CoinJoinStateViewModel = new CoinJoinStateViewModel(uiContext, WalletModel);

Expand Down Expand Up @@ -134,8 +144,6 @@ public WalletViewModel(UiContext uiContext, IWalletModel walletModel, Wallet wal

public bool PreferPsbtWorkflow => WalletModel.Settings.PreferPsbtWorkflow;

public CoinJoinSettingsViewModel CoinJoinSettings { get; private set; }

public bool IsWatchOnly => WalletModel.IsWatchOnlyWallet;

public IObservable<bool> IsMusicBoxVisible { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ContentArea Title="{Binding Title}"
EnableCancel="{Binding EnableCancel}"
EnableBack="{Binding EnableBack}"
NextContent="Continue" EnableNext="True"
NextContent="Done" EnableNext="True"
ScrollViewer.VerticalScrollBarVisibility="Disabled" ClipToBounds="False">

<ContentArea.Styles>
Expand Down
16 changes: 2 additions & 14 deletions WalletWasabi.Fluent/Views/Settings/SettingsPageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@
x:DataType="settings:SettingsPageViewModel"
x:CompileBindings="True"
x:Class="WalletWasabi.Fluent.Views.Settings.SettingsPageView">
<UserControl.Styles>
<Style Selector="TabItem">
<Setter Property="FontSize" Value="12" />
<Setter Property="MinHeight" Value="50" />
<Setter Property="Padding" Value="0" />
</Style>
<Style Selector="TabItem /template/ Border#PART_LayoutRoot">
<Setter Property="Margin" Value="0 0 24 24" />
</Style>
<Style Selector="TabControl">
<Setter Property="Padding" Value="0" />
</Style>
</UserControl.Styles>

<ContentArea Title="{Binding Title}"
Caption="Manage appearance, privacy and other settings"
Expand All @@ -48,7 +35,8 @@
<TextBlock Text="Modifying settings is not possible, as certain parameters have been overridden during startup." />
</InfoMessage>

<TabControl SelectedIndex="{Binding SelectedTab, Mode=TwoWay}">
<TabControl SelectedIndex="{Binding SelectedTab, Mode=TwoWay}"
Classes="Settings">
<TabItem Header="General">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<v:GeneralSettingsTabView DataContext="{Binding GeneralSettingsTab}" IsEnabled="{Binding !IsReadOnly}" />
Expand Down
37 changes: 0 additions & 37 deletions WalletWasabi.Fluent/Views/Wallets/CoinJoinSettingsView.axaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:vm="clr-namespace:WalletWasabi.Fluent.ViewModels.Wallets.Settings"
x:DataType="vm:WalletCoinJoinSettingsViewModel"
x:Class="WalletWasabi.Fluent.Views.Wallets.Settings.WalletCoinJoinSettingsView"
x:CompileBindings="True">

<StackPanel Spacing="20">

<StackPanel Classes="settingsLayout">

<DockPanel>
<TextBlock Text="Automatically start coinjoin" />
<ToggleSwitch IsChecked="{Binding AutoCoinJoin, Mode=OneWay}" Command="{Binding SetAutoCoinJoin}" />
</DockPanel>

<StackPanel Spacing="10"
ToolTip.Tip="Coinjoin will not automatically start if the wallet balance is less than this.">
<TextBlock Text="Auto-start coinjoin threshold" />
<CurrencyEntryBox Text="{Binding PlebStopThreshold}" CurrencyCode="BTC" />
</StackPanel>

<DockPanel>
<TextBlock Text="Coinjoin strategy:" VerticalAlignment="Center" DockPanel.Dock="Left" Margin="0" />
<Button Content="Change" Command="{Binding SelectCoinjoinProfileCommand}" DockPanel.Dock="Right" />
<TextBlock Text="{Binding SelectedCoinjoinProfileName}" VerticalAlignment="Center" MinWidth="120" Margin="10 0 10 0" />
</DockPanel>
</StackPanel>
</StackPanel>

</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace WalletWasabi.Fluent.Views.Wallets.Settings;

public class WalletCoinJoinSettingsView : UserControl
{
public WalletCoinJoinSettingsView()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

0 comments on commit 300aab1

Please sign in to comment.