forked from WalletWasabi/WalletWasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a57ba4
commit 9cf3b18
Showing
18 changed files
with
190 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using NBitcoin; | ||
using ReactiveUI; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using WalletWasabi.Blockchain.Analysis.Clustering; | ||
using WalletWasabi.Blockchain.TransactionOutputs; | ||
using WalletWasabi.Fluent.Helpers; | ||
using WalletWasabi.Fluent.Models.Wallets; | ||
using WalletWasabi.Fluent.ViewModels.Wallets.Send; | ||
using WalletWasabi.Wallets; | ||
|
||
namespace WalletWasabi.Fluent.Models.Transactions; | ||
|
||
public record SendFlowModel | ||
{ | ||
private SendFlowModel(Wallet wallet, ICoinsView availableCoins, ICoinListModel coinListModel) | ||
{ | ||
Wallet = wallet; | ||
AvailableCoins = availableCoins; | ||
CoinListModel = coinListModel; | ||
} | ||
|
||
/// <summary>Regular Send Flow. Uses all wallet coins</summary> | ||
public SendFlowModel(Wallet wallet, IWalletModel walletModel): | ||
this(wallet, wallet.Coins, walletModel.Coins) | ||
{ | ||
} | ||
|
||
/// <summary>Manual Control Send Flow. Uses only the specified coins.</summary> | ||
public SendFlowModel(Wallet wallet, IWalletModel walletModel, IEnumerable<SmartCoin> coins): | ||
this(wallet, new CoinsView(coins), new UserSelectionCoinListModel(wallet, walletModel, coins.ToArray())) | ||
{ | ||
} | ||
|
||
public Wallet Wallet { get; } | ||
|
||
public ICoinsView AvailableCoins { get; } | ||
|
||
public ICoinListModel CoinListModel { get; } | ||
|
||
public TransactionInfo? TransactionInfo { get; init; } = null; | ||
|
||
public decimal AvailableAmountBtc => AvailableAmount.ToDecimal(MoneyUnit.BTC); | ||
|
||
public Money AvailableAmount => AvailableCoins.TotalAmount(); | ||
|
||
public bool IsManual => AvailableCoins.TotalAmount() != Wallet.Coins.TotalAmount(); | ||
|
||
public IEnumerable<(LabelsArray Labels, ICoinsView Coins)> GetPockets() => AvailableCoins.GetPockets(Wallet.AnonScoreTarget); | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Linq; | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using DynamicData; | ||
using ReactiveUI; | ||
using WalletWasabi.Blockchain.Analysis.Clustering; | ||
using WalletWasabi.Blockchain.TransactionOutputs; | ||
using WalletWasabi.Fluent.Extensions; | ||
using WalletWasabi.Logging; | ||
using WalletWasabi.Wallets; | ||
|
||
namespace WalletWasabi.Fluent.Models.Wallets; | ||
|
||
[AutoInterface] | ||
public abstract partial class CoinListModel : IDisposable | ||
{ | ||
private readonly CompositeDisposable _disposables = new(); | ||
|
||
public CoinListModel(Wallet wallet, IWalletModel walletModel) | ||
{ | ||
Wallet = wallet; | ||
WalletModel = walletModel; | ||
var transactionProcessed = walletModel.Transactions.TransactionProcessed; | ||
var anonScoreTargetChanged = this.WhenAnyValue(x => x.WalletModel.Settings.AnonScoreTarget).Skip(1).ToSignal(); | ||
var isCoinjoinRunningChanged = walletModel.Coinjoin.IsRunning.ToSignal(); | ||
|
||
var signals = | ||
transactionProcessed | ||
.Merge(anonScoreTargetChanged) | ||
.Merge(isCoinjoinRunningChanged) | ||
.Publish(); | ||
|
||
List = signals.Fetch(GetCoins, x => x.Key).DisposeWith(_disposables); | ||
Pockets = signals.Fetch(GetPockets, x => x.Labels).DisposeWith(_disposables); | ||
|
||
signals | ||
.Do(_ => Logger.LogDebug($"Refresh signal emitted in {walletModel.Name}")) | ||
.Subscribe() | ||
.DisposeWith(_disposables); | ||
|
||
signals.Connect() | ||
.DisposeWith(_disposables); | ||
} | ||
|
||
protected Wallet Wallet { get; } | ||
protected IWalletModel WalletModel { get; } | ||
|
||
public IObservableCache<ICoinModel, int> List { get; } | ||
|
||
public IObservableCache<Pocket, LabelsArray> Pockets { get; } | ||
|
||
public ICoinModel GetCoinModel(SmartCoin smartCoin) | ||
{ | ||
return new CoinModel(smartCoin, WalletModel.Settings.AnonScoreTarget); | ||
} | ||
|
||
protected abstract Pocket[] GetPockets(); | ||
|
||
protected abstract ICoinModel[] GetCoins(); | ||
|
||
public void Dispose() => _disposables.Dispose(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using DynamicData; | ||
using WalletWasabi.Blockchain.Analysis.Clustering; | ||
using WalletWasabi.Blockchain.TransactionOutputs; | ||
|
||
namespace WalletWasabi.Fluent.Models.Wallets; | ||
|
||
partial interface IWalletCoinsModel: ICoinListModel; |
24 changes: 24 additions & 0 deletions
24
WalletWasabi.Fluent/Models/Wallets/UserSelectionCoinListModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Linq; | ||
using System.Reactive.Linq; | ||
using WalletWasabi.Blockchain.TransactionOutputs; | ||
using WalletWasabi.Fluent.Helpers; | ||
using WalletWasabi.Wallets; | ||
|
||
namespace WalletWasabi.Fluent.Models.Wallets; | ||
|
||
[AutoInterface] | ||
public partial class UserSelectionCoinListModel(Wallet wallet, IWalletModel walletModel, SmartCoin[] selectedCoins) : CoinListModel(wallet, walletModel) | ||
{ | ||
protected override ICoinModel[] GetCoins() | ||
{ | ||
return selectedCoins.Select(GetCoinModel).ToArray(); | ||
} | ||
|
||
protected override Pocket[] GetPockets() | ||
{ | ||
return | ||
new CoinsView(selectedCoins).GetPockets(WalletModel.Settings.AnonScoreTarget) | ||
.Select(x => new Pocket(x)) | ||
.ToArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,36 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Disposables; | ||
using System.Reactive.Linq; | ||
using DynamicData; | ||
using ReactiveUI; | ||
using WalletWasabi.Blockchain.Analysis.Clustering; | ||
using WalletWasabi.Blockchain.TransactionBuilding; | ||
using WalletWasabi.Blockchain.TransactionOutputs; | ||
using WalletWasabi.Fluent.Extensions; | ||
using WalletWasabi.Fluent.Helpers; | ||
using WalletWasabi.Fluent.ViewModels.Wallets.Send; | ||
using WalletWasabi.Logging; | ||
using WalletWasabi.Wallets; | ||
|
||
namespace WalletWasabi.Fluent.Models.Wallets; | ||
|
||
[AutoInterface] | ||
public partial class WalletCoinsModel : IDisposable | ||
public partial class WalletCoinsModel(Wallet wallet, IWalletModel walletModel) : CoinListModel(wallet, walletModel) | ||
{ | ||
private readonly Wallet _wallet; | ||
private readonly IWalletModel _walletModel; | ||
private readonly CompositeDisposable _disposables = new(); | ||
|
||
public WalletCoinsModel(Wallet wallet, IWalletModel walletModel) | ||
{ | ||
_wallet = wallet; | ||
_walletModel = walletModel; | ||
var transactionProcessed = walletModel.Transactions.TransactionProcessed; | ||
var anonScoreTargetChanged = this.WhenAnyValue(x => x._walletModel.Settings.AnonScoreTarget).Skip(1).ToSignal(); | ||
var isCoinjoinRunningChanged = walletModel.Coinjoin.IsRunning.ToSignal(); | ||
|
||
var signals = | ||
transactionProcessed | ||
.Merge(anonScoreTargetChanged) | ||
.Merge(isCoinjoinRunningChanged) | ||
.Publish(); | ||
|
||
List = signals.Fetch(GetCoins, x => x.Key).DisposeWith(_disposables); | ||
Pockets = signals.Fetch(GetPockets, x => x.Labels).DisposeWith(_disposables); | ||
|
||
signals | ||
.Do(_ => Logger.LogDebug($"Refresh signal emitted in {walletModel.Name}")) | ||
.Subscribe() | ||
.DisposeWith(_disposables); | ||
|
||
signals.Connect() | ||
.DisposeWith(_disposables); | ||
} | ||
|
||
public IObservableCache<ICoinModel, int> List { get; } | ||
|
||
public IObservableCache<Pocket, LabelsArray> Pockets { get; } | ||
|
||
public List<ICoinModel> GetSpentCoins(BuildTransactionResult? transaction) | ||
{ | ||
var coins = (transaction?.SpentCoins ?? new List<SmartCoin>()).ToList(); | ||
return coins.Select(GetCoinModel).ToList(); | ||
} | ||
|
||
public ICoinModel GetCoinModel(SmartCoin smartCoin) | ||
{ | ||
return new CoinModel(smartCoin, _walletModel.Settings.AnonScoreTarget); | ||
} | ||
|
||
public bool AreEnoughToCreateTransaction(TransactionInfo transactionInfo, IEnumerable<ICoinModel> coins) | ||
{ | ||
return TransactionHelpers.TryBuildTransactionWithoutPrevTx(_wallet.KeyManager, transactionInfo, _wallet.Coins, coins.GetSmartCoins(), _wallet.Kitchen.SaltSoup(), out _); | ||
return TransactionHelpers.TryBuildTransactionWithoutPrevTx(Wallet.KeyManager, transactionInfo, Wallet.Coins, coins.GetSmartCoins(), Wallet.Kitchen.SaltSoup(), out _); | ||
} | ||
|
||
private Pocket[] GetPockets() | ||
protected override Pocket[] GetPockets() | ||
{ | ||
return _wallet.GetPockets().ToArray(); | ||
return Wallet.GetPockets().ToArray(); | ||
} | ||
|
||
private ICoinModel[] GetCoins() | ||
protected override ICoinModel[] GetCoins() | ||
{ | ||
return _wallet.Coins.Select(GetCoinModel).ToArray(); | ||
return Wallet.Coins.Select(GetCoinModel).ToArray(); | ||
} | ||
|
||
public void Dispose() => _disposables.Dispose(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.