Skip to content

Commit

Permalink
PrivacyControl + SendFlow
Browse files Browse the repository at this point in the history
  • Loading branch information
ichthus1604 committed Apr 29, 2024
1 parent 260c70d commit 42a0523
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion WalletWasabi.Fluent/Models/Transactions/SendFlowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ public SendFlowModel(Wallet wallet, IWalletModel walletModel, IEnumerable<SmartC

public bool IsManual => AvailableCoins.TotalAmount() != Wallet.Coins.TotalAmount();

public IEnumerable<(LabelsArray Labels, ICoinsView Coins)> GetPockets() => AvailableCoins.GetPockets(Wallet.AnonScoreTarget);
public Pocket[] GetPockets() =>
AvailableCoins.GetPockets(Wallet.AnonScoreTarget)
.Select(x => new Pocket(x))
.ToArray();
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LabelSelectionViewModel(KeyManager keyManager, string password, Transacti

public Pocket[] NonPrivatePockets { get; set; } = Array.Empty<Pocket>();

public IEnumerable<LabelViewModel> AllLabelsViewModel { get; set; } = Array.Empty<LabelViewModel>();
public IEnumerable<LabelViewModel> AllLabelsViewModel { get; private set; } = Array.Empty<LabelViewModel>();

public IEnumerable<LabelViewModel> LabelsWhiteList => AllLabelsViewModel.Where(x => !x.IsBlackListed);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Threading;
using DynamicData;
using ReactiveUI;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.Models;
using WalletWasabi.Fluent.Models.Transactions;
using WalletWasabi.Fluent.Models.Wallets;
using WalletWasabi.Fluent.ViewModels.Dialogs.Base;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.Wallets;
Expand All @@ -19,13 +22,15 @@ namespace WalletWasabi.Fluent.ViewModels.Wallets.Send;
public partial class PrivacyControlViewModel : DialogViewModelBase<IEnumerable<SmartCoin>>
{
private readonly Wallet _wallet;
private readonly SendFlowModel _sendFlow;
private readonly TransactionInfo _transactionInfo;
private readonly bool _isSilent;
private readonly IEnumerable<SmartCoin>? _usedCoins;

public PrivacyControlViewModel(Wallet wallet, TransactionInfo transactionInfo, IEnumerable<SmartCoin>? usedCoins, bool isSilent)
public PrivacyControlViewModel(Wallet wallet, SendFlowModel sendFlow, TransactionInfo transactionInfo, IEnumerable<SmartCoin>? usedCoins, bool isSilent)
{
_wallet = wallet;
_sendFlow = sendFlow;
_transactionInfo = transactionInfo;
_isSilent = isSilent;
_usedCoins = usedCoins;
Expand Down Expand Up @@ -56,14 +61,17 @@ private async Task InitializeLabelsAsync()
var cjManager = Services.HostedServices.Get<CoinJoinManager>();
var coinsToExclude = cjManager.CoinsInCriticalPhase[_wallet.WalletId].ToList();

await LabelSelection.ResetAsync(_wallet.Coins.GetPockets(privateThreshold).Select(x => new Pocket(x)).ToArray(), coinsToExclude);
var pockets = _sendFlow.GetPockets();

await LabelSelection.ResetAsync(pockets, coinsToExclude);
await LabelSelection.SetUsedLabelAsync(_usedCoins, privateThreshold);
}

protected override void OnNavigatedTo(bool isInHistory, CompositeDisposable disposables)
{
base.OnNavigatedTo(isInHistory, disposables);

// TODO: Decoupling
Observable
.FromEventPattern(_wallet.TransactionProcessor, nameof(Wallet.TransactionProcessor.WalletRelevantTransactionProcessed))
.ObserveOn(RxApp.MainThreadScheduler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private async Task<bool> InitialiseTransactionAsync()
if (!_info.Coins.Any())
{
var privacyControlDialogResult =
await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, Transaction?.SpentCoins, isSilent: true));
await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _sendFlow, _info, Transaction?.SpentCoins, isSilent: true));
if (privacyControlDialogResult.Kind == DialogResultKind.Normal &&
privacyControlDialogResult.Result is { } coins)
{
Expand Down Expand Up @@ -266,7 +266,7 @@ await ShowErrorAsync(
if (canSelectMoreCoins)
{
var selectPocketsDialog =
await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, usedCoins: Transaction?.SpentCoins, isSilent: true));
await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _sendFlow, _info, usedCoins: Transaction?.SpentCoins, isSilent: true));

if (selectPocketsDialog.Result is { } newCoins)
{
Expand Down Expand Up @@ -478,7 +478,7 @@ private async Task CheckChangePocketAvailableAsync(BuildTransactionResult transa
var cjManager = Services.HostedServices.Get<CoinJoinManager>();

var usedCoins = transaction.SpentCoins;
var pockets = _sendFlow.GetPockets().Select(x => new Pocket(x)).ToArray();
var pockets = _sendFlow.GetPockets();
var labelSelection = new LabelSelectionViewModel(_wallet.KeyManager, _wallet.Kitchen.SaltSoup(), _info, isSilent: true);
await labelSelection.ResetAsync(pockets, coinsToExclude: cjManager.CoinsInCriticalPhase[_wallet.WalletId].ToList());

Expand All @@ -492,7 +492,7 @@ private async Task ApplyPrivacySuggestionAsync(PrivacySuggestion suggestion)
case LabelManagementSuggestion:
{
var selectPocketsDialog =
await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _info, Transaction?.SpentCoins, false));
await NavigateDialogAsync(new PrivacyControlViewModel(_wallet, _sendFlow, _info, Transaction?.SpentCoins, false));

if (selectPocketsDialog.Kind == DialogResultKind.Normal && selectPocketsDialog.Result is { })
{
Expand Down

0 comments on commit 42a0523

Please sign in to comment.