Skip to content

Commit

Permalink
Manual Control Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ichthus1604 committed Apr 20, 2024
1 parent 0eda1c6 commit efbdd50
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 5 deletions.
7 changes: 6 additions & 1 deletion WalletWasabi.Fluent/Models/Transactions/SendParameters.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NBitcoin;
using System.Collections.Generic;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionOutputs;
Expand All @@ -16,7 +17,11 @@ public record SendParameters(

public static SendParameters CreateManual(Wallet wallet, IEnumerable<SmartCoin> coins) => new SendParameters(wallet, new CoinsView(coins));

public decimal AvailableAmountBtc => AvailableCoins.TotalAmount().ToDecimal(NBitcoin.MoneyUnit.BTC);
public decimal AvailableAmountBtc => AvailableAmount.ToDecimal(MoneyUnit.BTC);

public Money AvailableAmount => AvailableCoins.TotalAmount();

public IEnumerable<(LabelsArray Labels, ICoinsView Coins)> GetPockets() => AvailableCoins.GetPockets(Wallet.AnonScoreTarget);

public bool IsManual => AvailableCoins.TotalAmount() != Wallet.Coins.TotalAmount();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using DynamicData;
using DynamicData.Binding;
using ReactiveUI;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Fluent.Models.Transactions;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.Dialogs.Base;
using WalletWasabi.Fluent.ViewModels.Wallets.Coins;
using WalletWasabi.Wallets;

namespace WalletWasabi.Fluent.ViewModels.Wallets.Send;

[NavigationMetaData(
Title = "Manual Control",
IconName = "wallet_action_send",
NavBarPosition = NavBarPosition.None,
Searchable = false,
NavigationTarget = NavigationTarget.DialogScreen)]
public partial class ManualControlDialogViewModel: DialogViewModelBase<IEnumerable<SmartCoin>>
{
private readonly IWalletModel _walletModel;
private readonly Wallet _wallet;

private ManualControlDialogViewModel(IWalletModel walletModel, Wallet wallet)
{
CoinList = new CoinListViewModel(walletModel, [], true);

EnableBack = true;

var nextCommandCanExecute =
CoinList.Selection
.ToObservableChangeSet()
.ToCollection()
.Select(c => c.Count > 0);

NextCommand = ReactiveCommand.Create(OnNext, nextCommandCanExecute);

SetupCancel(true, true, true);
_walletModel = walletModel;
_wallet = wallet;
}

public CoinListViewModel CoinList { get; }

protected override void OnNavigatedFrom(bool isInHistory)
{
CoinList.Dispose();

base.OnNavigatedFrom(isInHistory);
}

private void OnNext()
{
var coins = CoinList.Selection.GetSmartCoins().ToList();

var sendParameters = SendParameters.CreateManual(_wallet, coins);

Navigate().To().Send(_walletModel, sendParameters);
}
}
12 changes: 11 additions & 1 deletion WalletWasabi.Fluent/ViewModels/Wallets/Send/SendViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ public SendViewModel(UiContext uiContext, IWalletModel walletModel, SendParamete

ExchangeRate = _walletModel.AmountProvider.UsdExchangeRate;

Balance = _walletModel.Balances;
Balance =
_parameters.IsManual
? Observable.Return(_walletModel.AmountProvider.Create(_parameters.AvailableAmount))
: _walletModel.Balances;

BalanceCaption =
_parameters.IsManual
? "Max:"
: "Balance:";

_suggestionLabels = new SuggestionLabelsViewModel(_walletModel, Intent.Send, 3);

Expand Down Expand Up @@ -121,6 +129,8 @@ public SendViewModel(UiContext uiContext, IWalletModel walletModel, SendParamete
_clipboardObserver = new ClipboardObserver(Balance);
}

public string BalanceCaption { get; }

public IObservable<Amount> Balance { get; }

public IObservable<string?> UsdContent => _clipboardObserver.ClipboardUsdContentChanged(RxApp.MainThreadScheduler);
Expand Down
3 changes: 3 additions & 0 deletions WalletWasabi.Fluent/ViewModels/Wallets/WalletViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public WalletViewModel(UiContext uiContext, IWalletModel walletModel, Wallet wal
});

SendCommand = ReactiveCommand.Create(() => Navigate().To().Send(walletModel, SendParameters.Create(wallet)));
SendManualControlCommand = ReactiveCommand.Create(() => Navigate().To().ManualControlDialog(walletModel, wallet));

ReceiveCommand = ReactiveCommand.Create(() => Navigate().To().Receive(WalletModel));

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

public ICommand SendCommand { get; private set; }

public ICommand SendManualControlCommand { get; }

public ICommand? BroadcastPsbtCommand { get; set; }

public ICommand ReceiveCommand { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:WalletWasabi.Fluent.ViewModels.Wallets.Send"
xmlns:sorting="clr-namespace:WalletWasabi.Fluent.Controls.Sorting"
xmlns:coins="clr-namespace:WalletWasabi.Fluent.Views.Wallets.Coins"
x:DataType="vm:ManualControlDialogViewModel"
x:CompileBindings="True"
x:Class="WalletWasabi.Fluent.Views.Wallets.Send.ManualControlDialogView">

<ContentArea Title="{Binding Title}"
Caption="Select the coins that are allowed for the transaction to use"
EnableNext="True" NextContent="Continue"
EnableCancel="{Binding EnableCancel}"
EnableBack="{Binding EnableBack}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ContentArea.TopContent>
<Button DockPanel.Dock="Right" Theme="{StaticResource DialogSortButton}" ToolTip.Tip="Sorting">
<Button.Flyout>
<Flyout Placement="BottomEdgeAlignedRight">
<sorting:SortControl Sortables="{Binding CoinList.Sortables}" />
</Flyout>
</Button.Flyout>
</Button>
</ContentArea.TopContent>
<coins:CoinListView DataContext="{Binding CoinList}" />
</ContentArea>
</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.Send;

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

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
9 changes: 6 additions & 3 deletions WalletWasabi.Fluent/Views/Wallets/Send/SendView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@
<ContentArea.TopContent>
<!-- Balance -->
<PrivacyContentControl PrivacyReplacementMode="Text" DockPanel.Dock="Top" HorizontalAlignment="Center" Classes="h8" Opacity="0.6">
<Button Focusable="False" Classes="plainHyperlink h8" Command="{Binding InsertMaxCommand}">
<AmountControl Amount="{Binding Balance^}" />
</Button>
<StackPanel Orientation="Horizontal" Spacing="5">
<TextBlock Text="{Binding BalanceCaption}"/>
<Button Focusable="False" Classes="plainHyperlink h8" Command="{Binding InsertMaxCommand}">
<AmountControl Amount="{Binding Balance^}"/>
</Button>
</StackPanel>
</PrivacyContentControl>
</ContentArea.TopContent>
<DockPanel LastChildFill="False">
Expand Down
12 changes: 12 additions & 0 deletions WalletWasabi.Fluent/Views/Wallets/WalletView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
<TextBlock Text="Send" />
</StackPanel>
</Button>

<!-- Manual Control Button, needs to be replaced by SubActionButton-->
<Button Classes="function"
IsVisible="{Binding IsSendButtonVisible}"
Command="{Binding SendManualControlCommand}">
<StackPanel Orientation="Horizontal">
<PathIcon Data="{StaticResource wallet_action_send}" />
<TextBlock Text="Manual Control" />
</StackPanel>
</Button>


<Button Classes="function"
Command="{Binding ReceiveCommand}">
<StackPanel Orientation="Horizontal">
Expand Down
6 changes: 6 additions & 0 deletions WalletWasabi.Fluent/WalletWasabi.Fluent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\Wallets\Send\ManualControlDialogView.axaml.cs">
<DependentUpon>ManualControlDialogView.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>

0 comments on commit efbdd50

Please sign in to comment.