Skip to content

Commit

Permalink
replace wallet coins and pockets
Browse files Browse the repository at this point in the history
  • Loading branch information
ichthus1604 committed Apr 19, 2024
1 parent 9f316f7 commit 8a1e312
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private IEnumerable<PrivacyItem> VerifyLabels(Parameters parameters)

private PrivacyItem? GetLabelWarning(BuildTransactionResult transactionResult, LabelsArray recipient)
{
var pockets = _wallet.GetPockets();
var pockets = _sendParameters.GetPockets();
var spentCoins = transactionResult.SpentCoins;
var nonPrivateSpentCoins = spentCoins.Where(x => x.GetPrivacyLevel(_wallet.AnonScoreTarget) == PrivacyLevel.NonPrivate).ToList();
var usedPockets = pockets.Where(x => x.Coins.Any(coin => nonPrivateSpentCoins.Contains(coin))).ToList();
Expand Down Expand Up @@ -274,7 +274,7 @@ private async Task<List<ChangeAvoidanceSuggestion>> CreateChangeAvoidanceSuggest
// Only allow to create 1 more input with BnB. This accounts for the change created.
int maxInputCount = transaction.SpentCoins.Count() + 1;

var pockets = _wallet.GetPockets();
var pockets = _sendParameters.GetPockets();
var spentCoins = transaction.SpentCoins;
var usedPockets = pockets.Where(x => x.Coins.Any(coin => spentCoins.Contains(coin)));
ImmutableArray<SmartCoin> coinsToUse = usedPockets.SelectMany(x => x.Coins).ToImmutableArray();
Expand Down
4 changes: 4 additions & 0 deletions WalletWasabi.Fluent/Models/Transactions/SendParameters.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.ViewModels.Wallets.Send;
using WalletWasabi.Wallets;

Expand All @@ -15,4 +17,6 @@ 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 IEnumerable<(LabelsArray Labels, ICoinsView Coins)> GetPockets() => AvailableCoins.GetPockets(Wallet.AnonScoreTarget);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Fluent.Infrastructure;
using WalletWasabi.Fluent.Validation;
using WalletWasabi.Fluent.ViewModels.Dialogs;
using WalletWasabi.Fluent.ViewModels.Navigation;
using WalletWasabi.Logging;
using WalletWasabi.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public partial class TransactionPreviewViewModel : RoutableViewModel
private readonly Stack<(BuildTransactionResult, TransactionInfo)> _undoHistory;
private readonly Wallet _wallet;
private readonly IWalletModel _walletModel;
private readonly SendParameters _parameters;
private TransactionInfo _info;
private TransactionInfo _currentTransactionInfo;
private CancellationTokenSource _cancellationTokenSource;
Expand All @@ -46,12 +47,13 @@ public TransactionPreviewViewModel(UiContext uiContext, IWalletModel walletModel
_undoHistory = new();
_wallet = parameters.Wallet;
_walletModel = walletModel;

_info = parameters.TransactionInfo ?? throw new InvalidOperationException($"Missing required TransactionInfo.");
_parameters = parameters;

_info = _parameters.TransactionInfo ?? throw new InvalidOperationException($"Missing required TransactionInfo.");
_currentTransactionInfo = _info.Clone();
_cancellationTokenSource = new CancellationTokenSource();

PrivacySuggestions = new PrivacySuggestionsFlyoutViewModel(walletModel, parameters);
PrivacySuggestions = new PrivacySuggestionsFlyoutViewModel(walletModel, _parameters);
CurrentTransactionSummary = new TransactionSummaryViewModel(uiContext, this, walletModel, _info);
PreviewTransactionSummary = new TransactionSummaryViewModel(uiContext, this, walletModel, _info, true);

Expand Down Expand Up @@ -259,7 +261,7 @@ await ShowErrorAsync(
}
catch (InsufficientBalanceException)
{
var canSelectMoreCoins = _wallet.Coins.Any(coin => !_info.Coins.Contains(coin));
var canSelectMoreCoins = _parameters.AvailableCoins.Any(coin => !_info.Coins.Contains(coin));

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

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

Expand Down

0 comments on commit 8a1e312

Please sign in to comment.