Skip to content

Commit

Permalink
fix CoinModel design issue
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandUI committed Jul 3, 2024
1 parent e65bae3 commit a549465
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 6 additions & 2 deletions WalletWasabi.Fluent/Models/Wallets/CoinListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using WalletWasabi.Blockchain.Analysis.Clustering;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.Fluent.Extensions;
using WalletWasabi.Fluent.Helpers;
using WalletWasabi.Logging;
using WalletWasabi.Wallets;

Expand All @@ -32,7 +31,7 @@ public CoinListModel(Wallet wallet, IWalletModel walletModel)
.Publish();

Pockets = signals.Fetch(GetPockets, x => x.Labels).DisposeWith(_disposables);
List = Pockets.Connect().MergeMany(x => x.Coins.Select(GetCoinModel).AsObservableChangeSet()).AddKey(x => x.Key).AsObservableCache();
List = Pockets.Connect().MergeMany(x => x.Coins.Select(CreateCoinModel).AsObservableChangeSet()).AddKey(x => x.Key).AsObservableCache();

signals
.Do(_ => Logger.LogDebug($"Refresh signal emitted in {walletModel.Name}"))
Expand All @@ -51,6 +50,11 @@ public CoinListModel(Wallet wallet, IWalletModel walletModel)
public IObservableCache<Pocket, LabelsArray> Pockets { get; }

public ICoinModel GetCoinModel(SmartCoin smartCoin)
{
return List.Items.First(coinModel => coinModel.Key == smartCoin.Outpoint.GetHashCode());
}

private ICoinModel CreateCoinModel(SmartCoin smartCoin)
{
return new CoinModel(smartCoin, WalletModel.Settings.AnonScoreTarget);
}
Expand Down
2 changes: 2 additions & 0 deletions WalletWasabi.Fluent/Models/Wallets/CoinModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void SubscribeToCoinChanges(CompositeDisposable disposable)
return;
}

disposable.Add(Disposable.Create(() => _subscribedToCoinChanges = false));

this.WhenAnyValue(c => c.Coin.IsExcludedFromCoinJoin).BindTo(this, x => x.IsExcludedFromCoinJoin).DisposeWith(disposable);
this.WhenAnyValue(c => c.Coin.Confirmed).BindTo(this, x => x.IsConfirmed).DisposeWith(disposable);
this.WhenAnyValue(c => c.Coin.HdPubKey.AnonymitySet).Select(x => (int)x).BindTo(this, x => x.AnonScore).DisposeWith(disposable);
Expand Down
6 changes: 0 additions & 6 deletions WalletWasabi.Fluent/Models/Wallets/WalletCoinsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public async Task UpdateExcludedCoinsFromCoinjoinAsync(ICoinModel[] coinsToExclu
{
await Task.Run(() =>
{
// TODO: To keep models in sync with business objects. Should be automatic.
foreach (var coinModel in List.Items)
{
coinModel.IsExcludedFromCoinJoin = coinsToExclude.Any(x => x.IsSame(coinModel));
}
var outPoints = coinsToExclude.Select(x => x.GetSmartCoin().Outpoint).ToArray();
Wallet.UpdateExcludedCoinsFromCoinJoin(outPoints);
});
Expand Down

0 comments on commit a549465

Please sign in to comment.