Skip to content

Commit

Permalink
Fix some music box visibility issues (WalletWasabi#13418)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolay authored Sep 19, 2024
1 parent d44e377 commit 4524df1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
61 changes: 48 additions & 13 deletions WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using DynamicData;
Expand Down Expand Up @@ -42,6 +42,15 @@ public partial class WalletViewModel : RoutableViewModel, IWalletViewModel

[AutoNotify(SetterModifier = AccessModifier.Private)] private bool _isWalletBalanceZero;
[AutoNotify(SetterModifier = AccessModifier.Private)] private bool _areAllCoinsPrivate;
[AutoNotify(SetterModifier = AccessModifier.Private)] private bool _hasMusicBoxBeenDisplayed;
[AutoNotify] private bool _isMusicBoxFlyoutDisplayed;

// This proxy fixes a stack overflow bug in Avalonia
public bool IsMusicBoxFlyoutOpenedProxy
{
get => IsMusicBoxFlyoutDisplayed;
set => IsMusicBoxFlyoutDisplayed = value;
}

private string _title = "";
[AutoNotify(SetterModifier = AccessModifier.Protected)] private WalletState _walletState;
Expand Down Expand Up @@ -80,19 +89,39 @@ public WalletViewModel(UiContext uiContext, IWalletModel walletModel, Wallet wal
this.WhenAnyValue(x => x.IsWalletBalanceZero)
.Subscribe(_ => IsSendButtonVisible = !IsWalletBalanceZero && (!WalletModel.IsWatchOnlyWallet || WalletModel.IsHardwareWallet));

this.WhenAnyValue(model => model.CoinJoinStateViewModel!.AreAllCoinsPrivate)
.BindTo(this, x => x.AreAllCoinsPrivate);
WalletModel.Privacy.IsWalletPrivate
.BindTo(this, x => x.AreAllCoinsPrivate);

IsMusicBoxVisible = this.WhenAnyValue(
x => x.HasMusicBoxBeenDisplayed,
x => x.IsSelected,
x => x.IsWalletBalanceZero,
x => x.AreAllCoinsPrivate,
x => x.IsPointerOver,
x => x.IsMusicBoxFlyoutDisplayed,
(hasBeenDisplayed, isSelected, hasNoBalance, areAllCoinsPrivate, isPointerOver, isMusicBoxFlyoutDisplayed) =>
{
Logger.LogWarning($"({hasBeenDisplayed}, {isSelected}, {hasNoBalance}, {areAllCoinsPrivate}, {isPointerOver}, {isMusicBoxFlyoutDisplayed})");
if (!hasBeenDisplayed)
{
if (!WalletModel.IsCoinJoinEnabled)
{
// If there is no coordinator configured and it's the first time, display MusicBox even without pointer over
Task.Run(() => DelaySwitchHasMusicBoxBeenDisplayedAsync(CancellationToken.None));
return isSelected && !WalletModel.IsCoinJoinEnabled;
}

HasMusicBoxBeenDisplayed = true;
}

if (!WalletModel.IsCoinJoinEnabled)
{
return isSelected && !WalletModel.IsCoinJoinEnabled && (isPointerOver || isMusicBoxFlyoutDisplayed);
}

return (isSelected && !hasNoBalance && (!areAllCoinsPrivate || (isPointerOver || isMusicBoxFlyoutDisplayed))) && !WalletModel.IsWatchOnlyWallet;
});

IsMusicBoxVisible =
this.WhenAnyValue(
x => x.IsSelected,
x => x.IsWalletBalanceZero,
x => x.AreAllCoinsPrivate,
x => x.IsPointerOver,
(isSelected, hasNoBalance, areAllCoinsPrivate, isPointerOver) => (isSelected &&
(!WalletModel.IsCoinJoinEnabled || !hasNoBalance && (!areAllCoinsPrivate || isPointerOver))
&& !WalletModel.IsWatchOnlyWallet))
.Throttle(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler);

SendCommand = ReactiveCommand.Create(() => Navigate().To().Send(walletModel, new SendFlowModel(wallet, walletModel)));
SendManualControlCommand = ReactiveCommand.Create(() => Navigate().To().ManualControlDialog(walletModel, wallet));
Expand Down Expand Up @@ -313,4 +342,10 @@ private async Task<bool> AuthorizeForPasswordAsync()

return true;
}

private async Task DelaySwitchHasMusicBoxBeenDisplayedAsync(CancellationToken cancellationToken)
{
await Task.Delay(10000, cancellationToken);
HasMusicBoxBeenDisplayed = true;
}
}
4 changes: 2 additions & 2 deletions WalletWasabi.Fluent/Views/Wallets/MusicControlsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

<Button Classes="plain" IsVisible="{Binding CoinJoinStateViewModel.CanNavigateToCoinjoinSettings^}">
<Button.Flyout>
<MenuFlyout Placement="Top">
<MenuFlyout Placement="Top" IsOpen="{Binding IsMusicBoxFlyoutOpenedProxy, Mode=OneWayToSource}">
<MenuItem Header="Coinjoin Settings" Command="{Binding CoinJoinStateViewModel.NavigateToSettingsCommand}">
<MenuItem.Icon>
<PathIcon Data="{StaticResource settings_general_regular}" />
Expand All @@ -137,7 +137,7 @@
<PathIcon Margin="3 0 0 0" Data="{StaticResource more_regular}" Opacity="0.6" />
</Button.Content>
<Button.Flyout>
<MenuFlyout>
<MenuFlyout Placement="Top" IsOpen="{Binding IsMusicBoxFlyoutOpenedProxy, Mode=OneWayToSource}">
<MenuItem Header="Coordinator Settings" Command="{Binding NavigateToCoordinatorSettingsCommand}">
<MenuItem.Icon>
<PathIcon Data="{StaticResource coordinator}" />
Expand Down

0 comments on commit 4524df1

Please sign in to comment.